2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-2009, 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];
91 struct oob_conf_data {
93 OOB_METHOD_UNKNOWN = 0,
98 struct wpabuf *dev_password;
99 struct wpabuf *pubkey_hash;
103 * struct wps_config - WPS configuration for a single registration protocol run
107 * wps - Pointer to long term WPS context
109 struct wps_context *wps;
112 * registrar - Whether this end is a Registrar
117 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
122 * pin_len - Length on pin in octets
127 * pbc - Whether this is protocol run uses PBC
132 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
134 const struct wpabuf *assoc_wps_ie;
137 * new_ap_settings - New AP settings (%NULL if not used)
139 * This parameter provides new AP settings when using a wireless
140 * stations as a Registrar to configure the AP. %NULL means that AP
141 * will not be reconfigured, i.e., the station will only learn the
142 * current AP settings by using AP PIN.
144 const struct wps_credential *new_ap_settings;
147 struct wps_data * wps_init(const struct wps_config *cfg);
149 void wps_deinit(struct wps_data *data);
152 * enum wps_process_res - WPS message processing result
154 enum wps_process_res {
156 * WPS_DONE - Processing done
161 * WPS_CONTINUE - Processing continues
166 * WPS_FAILURE - Processing failed
171 * WPS_PENDING - Processing continues, but waiting for an external
172 * event (e.g., UPnP message from an external Registrar)
176 enum wps_process_res wps_process_msg(struct wps_data *wps,
177 enum wsc_op_code op_code,
178 const struct wpabuf *msg);
180 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
182 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
183 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
184 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
186 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
187 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
189 enum wps_request_type req_type);
193 * struct wps_registrar_config - WPS Registrar configuration
195 struct wps_registrar_config {
197 * new_psk_cb - Callback for new PSK
198 * @ctx: Higher layer context data (cb_ctx)
199 * @mac_addr: MAC address of the Enrollee
201 * @psk_len: The length of psk in octets
202 * Returns: 0 on success, -1 on failure
204 * This callback is called when a new per-device PSK is provisioned.
206 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
210 * set_ie_cb - Callback for WPS IE changes
211 * @ctx: Higher layer context data (cb_ctx)
212 * @beacon_ie: WPS IE for Beacon
213 * @beacon_ie_len: WPS IE length for Beacon
214 * @probe_resp_ie: WPS IE for Probe Response
215 * @probe_resp_ie_len: WPS IE length for Probe Response
216 * Returns: 0 on success, -1 on failure
218 * This callback is called whenever the WPS IE in Beacon or Probe
219 * Response frames needs to be changed (AP only).
221 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
222 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
225 * pin_needed_cb - Callback for requesting a PIN
226 * @ctx: Higher layer context data (cb_ctx)
227 * @uuid_e: UUID-E of the unknown Enrollee
228 * @dev: Device Data from the unknown Enrollee
230 * This callback is called whenever an unknown Enrollee requests to use
231 * PIN method and a matching PIN (Device Password) is not found in
234 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
235 const struct wps_device_data *dev);
238 * reg_success_cb - Callback for reporting successful registration
239 * @ctx: Higher layer context data (cb_ctx)
240 * @mac_addr: MAC address of the Enrollee
241 * @uuid_e: UUID-E of the Enrollee
243 * This callback is called whenever an Enrollee completes registration
246 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
250 * cb_ctx: Higher layer context data for Registrar callbacks
255 * skip_cred_build: Do not build credential
257 * This option can be used to disable internal code that builds
258 * Credential attribute into M8 based on the current network
259 * configuration and Enrollee capabilities. The extra_cred data will
260 * then be used as the Credential(s).
265 * extra_cred: Additional Credential attribute(s)
267 * This optional data (set to %NULL to disable) can be used to add
268 * Credential attribute(s) for other networks into M8. If
269 * skip_cred_build is set, this will also override the automatically
270 * generated Credential attribute.
272 const u8 *extra_cred;
275 * extra_cred_len: Length of extra_cred in octets
277 size_t extra_cred_len;
280 * disable_auto_conf - Disable auto-configuration on first registration
282 * By default, the AP that is started in not configured state will
283 * generate a random PSK and move to configured state when the first
284 * registration protocol run is completed successfully. This option can
285 * be used to disable this functionality and leave it up to an external
286 * program to take care of configuration. This requires the extra_cred
287 * to be set with a suitable Credential and skip_cred_build being used.
289 int disable_auto_conf;
292 * static_wep_only - Whether the BSS supports only static WEP
299 * enum wps_event - WPS event types
303 * WPS_EV_M2D - M2D received (Registrar did not know us)
308 * WPS_EV_FAIL - Registration failed
313 * WPS_EV_SUCCESS - Registration succeeded
318 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
324 * union wps_event_data - WPS event data
326 union wps_event_data {
328 * struct wps_event_m2d - M2D event data
330 struct wps_event_m2d {
332 const u8 *manufacturer;
333 size_t manufacturer_len;
334 const u8 *model_name;
335 size_t model_name_len;
336 const u8 *model_number;
337 size_t model_number_len;
338 const u8 *serial_number;
339 size_t serial_number_len;
342 const u8 *primary_dev_type; /* 8 octets */
348 * struct wps_event_fail - Registration failure information
349 * @msg: enum wps_msg_type
351 struct wps_event_fail {
355 struct wps_event_pwd_auth_fail {
362 * struct upnp_pending_message - Pending PutWLANResponse messages
363 * @next: Pointer to next pending message or %NULL
364 * @addr: NewWLANEventMAC
366 * @type: Message Type
368 struct upnp_pending_message {
369 struct upnp_pending_message *next;
372 enum wps_msg_type type;
376 * struct wps_context - Long term WPS context data
378 * This data is stored at the higher layer Authenticator or Supplicant data
379 * structures and it is maintained over multiple registration protocol runs.
383 * ap - Whether the local end is an access point
388 * registrar - Pointer to WPS registrar data from wps_registrar_init()
390 struct wps_registrar *registrar;
393 * wps_state - Current WPS state
395 enum wps_state wps_state;
398 * ap_setup_locked - Whether AP setup is locked (only used at AP)
410 * This SSID is used by the Registrar to fill in information for
411 * Credentials. In addition, AP uses it when acting as an Enrollee to
412 * notify Registrar of the current configuration.
417 * ssid_len - Length of ssid in octets
422 * dev - Own WPS device data
424 struct wps_device_data dev;
427 * oob_conf - OOB Config data
429 struct oob_conf_data oob_conf;
432 * oob_dev_pw_id - OOB Device password id
437 * dh_privkey - Diffie-Hellman private key
439 struct wpabuf *dh_privkey;
442 * dh_pubkey_oob - Diffie-Hellman public key
444 struct wpabuf *dh_pubkey;
447 * config_methods - Enabled configuration methods
449 * Bit field of WPS_CONFIG_*
454 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
459 * auth_types - Authentication types (bit field of WPS_AUTH_*)
464 * network_key - The current Network Key (PSK) or %NULL to generate new
466 * If %NULL, Registrar will generate per-device PSK. In addition, AP
467 * uses this when acting as an Enrollee to notify Registrar of the
468 * current configuration.
473 * network_key_len - Length of network_key in octets
475 size_t network_key_len;
478 * ap_settings - AP Settings override for M7 (only used at AP)
480 * If %NULL, AP Settings attributes will be generated based on the
481 * current network configuration.
486 * ap_settings_len - Length of ap_settings in octets
488 size_t ap_settings_len;
491 * friendly_name - Friendly Name (required for UPnP)
496 * manufacturer_url - Manufacturer URL (optional for UPnP)
498 char *manufacturer_url;
501 * model_description - Model Description (recommended for UPnP)
503 char *model_description;
506 * model_url - Model URL (optional for UPnP)
511 * upc - Universal Product Code (optional for UPnP)
516 * cred_cb - Callback to notify that new Credentials were received
517 * @ctx: Higher layer context data (cb_ctx)
518 * @cred: The received Credential
519 * Return: 0 on success, -1 on failure
521 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
524 * event_cb - Event callback (state information about progress)
525 * @ctx: Higher layer context data (cb_ctx)
529 void (*event_cb)(void *ctx, enum wps_event event,
530 union wps_event_data *data);
533 * cb_ctx: Higher layer context data for callbacks
537 struct upnp_wps_device_sm *wps_upnp;
539 /* Pending messages from UPnP PutWLANResponse */
540 struct upnp_pending_message *upnp_msgs;
543 struct oob_device_data {
546 void * (*init_func)(struct wps_context *, struct oob_device_data *,
548 struct wpabuf * (*read_func)(void *);
549 int (*write_func)(void *, struct wpabuf *);
550 void (*deinit_func)(void *);
553 struct oob_nfc_device_data {
554 int (*init_func)(char *);
555 void * (*read_func)(size_t *);
556 int (*write_func)(void *, size_t);
557 void (*deinit_func)(void);
560 struct wps_registrar *
561 wps_registrar_init(struct wps_context *wps,
562 const struct wps_registrar_config *cfg);
563 void wps_registrar_deinit(struct wps_registrar *reg);
564 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
565 const u8 *pin, size_t pin_len, int timeout);
566 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
567 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
568 int wps_registrar_button_pushed(struct wps_registrar *reg);
569 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
570 const struct wpabuf *wps_data);
571 int wps_registrar_update_ie(struct wps_registrar *reg);
572 int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
573 const struct wpabuf *msg);
575 unsigned int wps_pin_checksum(unsigned int pin);
576 unsigned int wps_pin_valid(unsigned int pin);
577 unsigned int wps_generate_pin(void);
578 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
580 struct oob_device_data * wps_get_oob_device(char *device_type);
581 struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
582 int wps_get_oob_method(char *method);
583 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,