2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
21 * enum wsc_op_code - EAP-WSC OP-Code values
24 WSC_UPnP = 0 /* No OP Code in UPnP transport */,
34 struct upnp_wps_device_sm;
37 * struct wps_credential - WPS Credential
39 * @ssid_len: Length of SSID
40 * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
41 * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
44 * @key_len: Key length in octets
45 * @mac_addr: MAC address of the peer
46 * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
47 * this may be %NULL, if not used
48 * @cred_attr_len: Length of cred_attr in octets
50 struct wps_credential {
58 u8 mac_addr[ETH_ALEN];
64 * struct wps_device_data - WPS Device Data
65 * @mac_addr: Device MAC address
66 * @device_name: Device Name (0..32 octets encoded in UTF-8)
67 * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
68 * @model_name: Model Name (0..32 octets encoded in UTF-8)
69 * @model_number: Model Number (0..32 octets encoded in UTF-8)
70 * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
71 * @categ: Primary Device Category
72 * @oui: Primary Device OUI
73 * @sub_categ: Primary Device Sub-Category
74 * @os_version: OS Version
75 * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
77 struct wps_device_data {
78 u8 mac_addr[ETH_ALEN];
92 * struct wps_config - WPS configuration for a single registration protocol run
96 * wps - Pointer to long term WPS context
98 struct wps_context *wps;
101 * registrar - Whether this end is a Registrar
106 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
111 * pin_len - Length on pin in octets
116 * pbc - Whether this is protocol run uses PBC
121 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
123 const struct wpabuf *assoc_wps_ie;
126 struct wps_data * wps_init(const struct wps_config *cfg);
128 void wps_deinit(struct wps_data *data);
131 * enum wps_process_res - WPS message processing result
133 enum wps_process_res {
135 * WPS_DONE - Processing done
140 * WPS_CONTINUE - Processing continues
145 * WPS_FAILURE - Processing failed
150 * WPS_PENDING - Processing continues, but waiting for an external
151 * event (e.g., UPnP message from an external Registrar)
155 enum wps_process_res wps_process_msg(struct wps_data *wps,
156 enum wsc_op_code op_code,
157 const struct wpabuf *msg);
159 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
161 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
162 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
163 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
165 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
166 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
168 enum wps_request_type req_type);
172 * struct wps_registrar_config - WPS Registrar configuration
174 struct wps_registrar_config {
176 * new_psk_cb - Callback for new PSK
177 * @ctx: Higher layer context data (cb_ctx)
178 * @mac_addr: MAC address of the Enrollee
180 * @psk_len: The length of psk in octets
181 * Returns: 0 on success, -1 on failure
183 * This callback is called when a new per-device PSK is provisioned.
185 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
189 * set_ie_cb - Callback for WPS IE changes
190 * @ctx: Higher layer context data (cb_ctx)
191 * @beacon_ie: WPS IE for Beacon
192 * @beacon_ie_len: WPS IE length for Beacon
193 * @probe_resp_ie: WPS IE for Probe Response
194 * @probe_resp_ie_len: WPS IE length for Probe Response
195 * Returns: 0 on success, -1 on failure
197 * This callback is called whenever the WPS IE in Beacon or Probe
198 * Response frames needs to be changed (AP only).
200 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
201 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
204 * pin_needed_cb - Callback for requesting a PIN
205 * @ctx: Higher layer context data (cb_ctx)
206 * @uuid_e: UUID-E of the unknown Enrollee
207 * @dev: Device Data from the unknown Enrollee
209 * This callback is called whenever an unknown Enrollee requests to use
210 * PIN method and a matching PIN (Device Password) is not found in
213 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
214 const struct wps_device_data *dev);
217 * reg_success_cb - Callback for reporting successful registration
218 * @ctx: Higher layer context data (cb_ctx)
219 * @mac_addr: MAC address of the Enrollee
220 * @uuid_e: UUID-E of the Enrollee
222 * This callback is called whenever an Enrollee completes registration
225 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
229 * cb_ctx: Higher layer context data for Registrar callbacks
234 * skip_cred_build: Do not build credential
236 * This option can be used to disable internal code that builds
237 * Credential attribute into M8 based on the current network
238 * configuration and Enrollee capabilities. The extra_cred data will
239 * then be used as the Credential(s).
244 * extra_cred: Additional Credential attribute(s)
246 * This optional data (set to %NULL to disable) can be used to add
247 * Credential attribute(s) for other networks into M8. If
248 * skip_cred_build is set, this will also override the automatically
249 * generated Credential attribute.
251 const u8 *extra_cred;
254 * extra_cred_len: Length of extra_cred in octets
256 size_t extra_cred_len;
259 * disable_auto_conf - Disable auto-configuration on first registration
261 * By default, the AP that is started in not configured state will
262 * generate a random PSK and move to configured state when the first
263 * registration protocol run is completed successfully. This option can
264 * be used to disable this functionality and leave it up to an external
265 * program to take care of configuration. This requires the extra_cred
266 * to be set with a suitable Credential and skip_cred_build being used.
268 int disable_auto_conf;
273 * enum wps_event - WPS event types
277 * WPS_EV_M2D - M2D received (Registrar did not know us)
282 * WPS_EV_FAIL - Registration failed
287 * WPS_EV_SUCCESS - Registration succeeded
292 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
298 * union wps_event_data - WPS event data
300 union wps_event_data {
302 * struct wps_event_m2d - M2D event data
304 struct wps_event_m2d {
306 const u8 *manufacturer;
307 size_t manufacturer_len;
308 const u8 *model_name;
309 size_t model_name_len;
310 const u8 *model_number;
311 size_t model_number_len;
312 const u8 *serial_number;
313 size_t serial_number_len;
316 const u8 *primary_dev_type; /* 8 octets */
322 * struct wps_event_fail - Registration failure information
323 * @msg: enum wps_msg_type
325 struct wps_event_fail {
329 struct wps_event_pwd_auth_fail {
336 * struct upnp_pending_message - Pending PutWLANResponse messages
337 * @next: Pointer to next pending message or %NULL
338 * @addr: NewWLANEventMAC
340 * @type: Message Type
342 struct upnp_pending_message {
343 struct upnp_pending_message *next;
346 enum wps_msg_type type;
350 * struct wps_context - Long term WPS context data
352 * This data is stored at the higher layer Authenticator or Supplicant data
353 * structures and it is maintained over multiple registration protocol runs.
357 * ap - Whether the local end is an access point
362 * registrar - Pointer to WPS registrar data from wps_registrar_init()
364 struct wps_registrar *registrar;
367 * wps_state - Current WPS state
369 enum wps_state wps_state;
372 * ap_setup_locked - Whether AP setup is locked (only used at AP)
384 * This SSID is used by the Registrar to fill in information for
385 * Credentials. In addition, AP uses it when acting as an Enrollee to
386 * notify Registrar of the current configuration.
391 * ssid_len - Length of ssid in octets
396 * dev - Own WPS device data
398 struct wps_device_data dev;
401 * config_methods - Enabled configuration methods
403 * Bit field of WPS_CONFIG_*
408 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
413 * auth_types - Authentication types (bit field of WPS_AUTH_*)
418 * network_key - The current Network Key (PSK) or %NULL to generate new
420 * If %NULL, Registrar will generate per-device PSK. In addition, AP
421 * uses this when acting as an Enrollee to notify Registrar of the
422 * current configuration.
427 * network_key_len - Length of network_key in octets
429 size_t network_key_len;
432 * ap_settings - AP Settings override for M7 (only used at AP)
434 * If %NULL, AP Settings attributes will be generated based on the
435 * current network configuration.
440 * ap_settings_len - Length of ap_settings in octets
442 size_t ap_settings_len;
445 * friendly_name - Friendly Name (required for UPnP)
450 * manufacturer_url - Manufacturer URL (optional for UPnP)
452 char *manufacturer_url;
455 * model_description - Model Description (recommended for UPnP)
457 char *model_description;
460 * model_url - Model URL (optional for UPnP)
465 * upc - Universal Product Code (optional for UPnP)
470 * cred_cb - Callback to notify that new Credentials were received
471 * @ctx: Higher layer context data (cb_ctx)
472 * @cred: The received Credential
473 * Return: 0 on success, -1 on failure
475 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
478 * event_cb - Event callback (state information about progress)
479 * @ctx: Higher layer context data (cb_ctx)
483 void (*event_cb)(void *ctx, enum wps_event event,
484 union wps_event_data *data);
487 * cb_ctx: Higher layer context data for callbacks
491 struct upnp_wps_device_sm *wps_upnp;
493 /* Pending messages from UPnP PutWLANResponse */
494 struct upnp_pending_message *upnp_msgs;
498 struct wps_registrar *
499 wps_registrar_init(struct wps_context *wps,
500 const struct wps_registrar_config *cfg);
501 void wps_registrar_deinit(struct wps_registrar *reg);
502 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
503 const u8 *pin, size_t pin_len);
504 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
505 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
506 int wps_registrar_button_pushed(struct wps_registrar *reg);
507 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
508 const struct wpabuf *wps_data);
509 int wps_registrar_update_ie(struct wps_registrar *reg);
510 int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
511 const struct wpabuf *msg);
513 unsigned int wps_pin_checksum(unsigned int pin);
514 unsigned int wps_pin_valid(unsigned int pin);
515 unsigned int wps_generate_pin(void);
516 void wps_free_pending_msgs(struct upnp_pending_message *msgs);