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;
38 * struct wps_credential - WPS Credential
40 * @ssid_len: Length of SSID
41 * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
42 * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
45 * @key_len: Key length in octets
46 * @mac_addr: MAC address of the Credential receiver
47 * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
48 * this may be %NULL, if not used
49 * @cred_attr_len: Length of cred_attr in octets
51 struct wps_credential {
59 u8 mac_addr[ETH_ALEN];
64 #define WPS_DEV_TYPE_LEN 8
65 #define WPS_DEV_TYPE_BUFSIZE 21
68 * struct wps_device_data - WPS Device Data
69 * @mac_addr: Device MAC address
70 * @device_name: Device Name (0..32 octets encoded in UTF-8)
71 * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
72 * @model_name: Model Name (0..32 octets encoded in UTF-8)
73 * @model_number: Model Number (0..32 octets encoded in UTF-8)
74 * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
75 * @pri_dev_type: Primary Device Type
76 * @os_version: OS Version
77 * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
79 struct wps_device_data {
80 u8 mac_addr[ETH_ALEN];
86 u8 pri_dev_type[WPS_DEV_TYPE_LEN];
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 * peer_addr: MAC address of the peer in AP; %NULL if not AP
152 * use_psk_key - Use PSK format key in Credential
154 * Force PSK format to be used instead of ASCII passphrase when
155 * building Credential for an Enrollee. The PSK value is set in
156 * struct wpa_context::psk.
161 struct wps_data * wps_init(const struct wps_config *cfg);
163 void wps_deinit(struct wps_data *data);
166 * enum wps_process_res - WPS message processing result
168 enum wps_process_res {
170 * WPS_DONE - Processing done
175 * WPS_CONTINUE - Processing continues
180 * WPS_FAILURE - Processing failed
185 * WPS_PENDING - Processing continues, but waiting for an external
186 * event (e.g., UPnP message from an external Registrar)
190 enum wps_process_res wps_process_msg(struct wps_data *wps,
191 enum wsc_op_code op_code,
192 const struct wpabuf *msg);
194 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
196 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
197 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
198 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
200 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
201 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
203 enum wps_request_type req_type);
207 * struct wps_registrar_config - WPS Registrar configuration
209 struct wps_registrar_config {
211 * new_psk_cb - Callback for new PSK
212 * @ctx: Higher layer context data (cb_ctx)
213 * @mac_addr: MAC address of the Enrollee
215 * @psk_len: The length of psk in octets
216 * Returns: 0 on success, -1 on failure
218 * This callback is called when a new per-device PSK is provisioned.
220 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
224 * set_ie_cb - Callback for WPS IE changes
225 * @ctx: Higher layer context data (cb_ctx)
226 * @beacon_ie: WPS IE for Beacon
227 * @probe_resp_ie: WPS IE for Probe Response
228 * Returns: 0 on success, -1 on failure
230 * This callback is called whenever the WPS IE in Beacon or Probe
231 * Response frames needs to be changed (AP only). Callee is responsible
232 * for freeing the buffers.
234 int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
235 struct wpabuf *probe_resp_ie);
238 * pin_needed_cb - Callback for requesting a PIN
239 * @ctx: Higher layer context data (cb_ctx)
240 * @uuid_e: UUID-E of the unknown Enrollee
241 * @dev: Device Data from the unknown Enrollee
243 * This callback is called whenever an unknown Enrollee requests to use
244 * PIN method and a matching PIN (Device Password) is not found in
247 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
248 const struct wps_device_data *dev);
251 * reg_success_cb - Callback for reporting successful registration
252 * @ctx: Higher layer context data (cb_ctx)
253 * @mac_addr: MAC address of the Enrollee
254 * @uuid_e: UUID-E of the Enrollee
256 * This callback is called whenever an Enrollee completes registration
259 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
263 * set_sel_reg_cb - Callback for reporting selected registrar changes
264 * @ctx: Higher layer context data (cb_ctx)
265 * @sel_reg: Whether the Registrar is selected
266 * @dev_passwd_id: Device Password ID to indicate with method or
267 * specific password the Registrar intends to use
268 * @sel_reg_config_methods: Bit field of active config methods
270 * This callback is called whenever the Selected Registrar state
271 * changes (e.g., a new PIN becomes available or PBC is invoked). This
272 * callback is only used by External Registrar implementation;
273 * set_ie_cb() is used by AP implementation in similar caes, but it
274 * provides the full WPS IE data instead of just the minimal Registrar
277 void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
278 u16 sel_reg_config_methods);
281 * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq
282 * @ctx: Higher layer context data (cb_ctx)
283 * @addr: MAC address of the Enrollee
284 * @uuid_e: UUID of the Enrollee
285 * @pri_dev_type: Primary device type
286 * @config_methods: Config Methods
287 * @dev_password_id: Device Password ID
288 * @request_type: Request Type
289 * @dev_name: Device Name (if available)
291 void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
292 const u8 *pri_dev_type, u16 config_methods,
293 u16 dev_password_id, u8 request_type,
294 const char *dev_name);
297 * cb_ctx: Higher layer context data for Registrar callbacks
302 * skip_cred_build: Do not build credential
304 * This option can be used to disable internal code that builds
305 * Credential attribute into M8 based on the current network
306 * configuration and Enrollee capabilities. The extra_cred data will
307 * then be used as the Credential(s).
312 * extra_cred: Additional Credential attribute(s)
314 * This optional data (set to %NULL to disable) can be used to add
315 * Credential attribute(s) for other networks into M8. If
316 * skip_cred_build is set, this will also override the automatically
317 * generated Credential attribute.
319 const u8 *extra_cred;
322 * extra_cred_len: Length of extra_cred in octets
324 size_t extra_cred_len;
327 * disable_auto_conf - Disable auto-configuration on first registration
329 * By default, the AP that is started in not configured state will
330 * generate a random PSK and move to configured state when the first
331 * registration protocol run is completed successfully. This option can
332 * be used to disable this functionality and leave it up to an external
333 * program to take care of configuration. This requires the extra_cred
334 * to be set with a suitable Credential and skip_cred_build being used.
336 int disable_auto_conf;
339 * static_wep_only - Whether the BSS supports only static WEP
346 * enum wps_event - WPS event types
350 * WPS_EV_M2D - M2D received (Registrar did not know us)
355 * WPS_EV_FAIL - Registration failed
360 * WPS_EV_SUCCESS - Registration succeeded
365 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
367 WPS_EV_PWD_AUTH_FAIL,
370 * WPS_EV_PBC_OVERLAP - PBC session overlap detected
375 * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
380 * WPS_EV_ER_AP_ADD - ER: AP added
385 * WPS_EV_ER_AP_REMOVE - ER: AP removed
390 * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
392 WPS_EV_ER_ENROLLEE_ADD,
395 * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
397 WPS_EV_ER_ENROLLEE_REMOVE
401 * union wps_event_data - WPS event data
403 union wps_event_data {
405 * struct wps_event_m2d - M2D event data
407 struct wps_event_m2d {
409 const u8 *manufacturer;
410 size_t manufacturer_len;
411 const u8 *model_name;
412 size_t model_name_len;
413 const u8 *model_number;
414 size_t model_number_len;
415 const u8 *serial_number;
416 size_t serial_number_len;
419 const u8 *primary_dev_type; /* 8 octets */
425 * struct wps_event_fail - Registration failure information
426 * @msg: enum wps_msg_type
428 struct wps_event_fail {
432 struct wps_event_pwd_auth_fail {
437 struct wps_event_er_ap {
440 const char *friendly_name;
441 const char *manufacturer;
442 const char *manufacturer_url;
443 const char *model_description;
444 const char *model_name;
445 const char *model_number;
446 const char *model_url;
447 const char *serial_number;
449 const u8 *pri_dev_type;
453 struct wps_event_er_enrollee {
459 const u8 *pri_dev_type;
460 const char *dev_name;
461 const char *manufacturer;
462 const char *model_name;
463 const char *model_number;
464 const char *serial_number;
469 * struct upnp_pending_message - Pending PutWLANResponse messages
470 * @next: Pointer to next pending message or %NULL
471 * @addr: NewWLANEventMAC
473 * @type: Message Type
475 struct upnp_pending_message {
476 struct upnp_pending_message *next;
479 enum wps_msg_type type;
483 * struct wps_context - Long term WPS context data
485 * This data is stored at the higher layer Authenticator or Supplicant data
486 * structures and it is maintained over multiple registration protocol runs.
490 * ap - Whether the local end is an access point
495 * registrar - Pointer to WPS registrar data from wps_registrar_init()
497 struct wps_registrar *registrar;
500 * wps_state - Current WPS state
502 enum wps_state wps_state;
505 * ap_setup_locked - Whether AP setup is locked (only used at AP)
517 * This SSID is used by the Registrar to fill in information for
518 * Credentials. In addition, AP uses it when acting as an Enrollee to
519 * notify Registrar of the current configuration.
524 * ssid_len - Length of ssid in octets
529 * dev - Own WPS device data
531 struct wps_device_data dev;
534 * oob_conf - OOB Config data
536 struct oob_conf_data oob_conf;
539 * oob_dev_pw_id - OOB Device password id
544 * dh_ctx - Context data for Diffie-Hellman operation
549 * dh_privkey - Diffie-Hellman private key
551 struct wpabuf *dh_privkey;
554 * dh_pubkey_oob - Diffie-Hellman public key
556 struct wpabuf *dh_pubkey;
559 * config_methods - Enabled configuration methods
561 * Bit field of WPS_CONFIG_*
566 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
571 * auth_types - Authentication types (bit field of WPS_AUTH_*)
576 * network_key - The current Network Key (PSK) or %NULL to generate new
578 * If %NULL, Registrar will generate per-device PSK. In addition, AP
579 * uses this when acting as an Enrollee to notify Registrar of the
580 * current configuration.
582 * When using WPA/WPA2-Person, this key can be either the ASCII
583 * passphrase (8..63 characters) or the 32-octet PSK (64 hex
584 * characters). When this is set to the ASCII passphrase, the PSK can
585 * be provided in the psk buffer and used per-Enrollee to control which
586 * key type is included in the Credential (e.g., to reduce calculation
587 * need on low-powered devices by provisioning PSK while still allowing
588 * other devices to get the passphrase).
593 * network_key_len - Length of network_key in octets
595 size_t network_key_len;
598 * psk - The current network PSK
600 * This optional value can be used to provide the current PSK if
601 * network_key is set to the ASCII passphrase.
606 * psk_set - Whether psk value is set
611 * ap_settings - AP Settings override for M7 (only used at AP)
613 * If %NULL, AP Settings attributes will be generated based on the
614 * current network configuration.
619 * ap_settings_len - Length of ap_settings in octets
621 size_t ap_settings_len;
624 * friendly_name - Friendly Name (required for UPnP)
629 * manufacturer_url - Manufacturer URL (optional for UPnP)
631 char *manufacturer_url;
634 * model_description - Model Description (recommended for UPnP)
636 char *model_description;
639 * model_url - Model URL (optional for UPnP)
644 * upc - Universal Product Code (optional for UPnP)
649 * cred_cb - Callback to notify that new Credentials were received
650 * @ctx: Higher layer context data (cb_ctx)
651 * @cred: The received Credential
652 * Return: 0 on success, -1 on failure
654 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
657 * event_cb - Event callback (state information about progress)
658 * @ctx: Higher layer context data (cb_ctx)
662 void (*event_cb)(void *ctx, enum wps_event event,
663 union wps_event_data *data);
666 * cb_ctx: Higher layer context data for callbacks
670 struct upnp_wps_device_sm *wps_upnp;
672 /* Pending messages from UPnP PutWLANResponse */
673 struct upnp_pending_message *upnp_msgs;
676 struct oob_device_data {
679 void * (*init_func)(struct wps_context *, struct oob_device_data *,
681 struct wpabuf * (*read_func)(void *);
682 int (*write_func)(void *, struct wpabuf *);
683 void (*deinit_func)(void *);
686 struct oob_nfc_device_data {
687 int (*init_func)(char *);
688 void * (*read_func)(size_t *);
689 int (*write_func)(void *, size_t);
690 void (*deinit_func)(void);
693 struct wps_registrar *
694 wps_registrar_init(struct wps_context *wps,
695 const struct wps_registrar_config *cfg);
696 void wps_registrar_deinit(struct wps_registrar *reg);
697 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
698 const u8 *pin, size_t pin_len, int timeout);
699 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
700 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
701 int wps_registrar_button_pushed(struct wps_registrar *reg);
702 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
703 const struct wpabuf *wps_data);
704 int wps_registrar_update_ie(struct wps_registrar *reg);
705 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
706 char *buf, size_t buflen);
708 unsigned int wps_pin_checksum(unsigned int pin);
709 unsigned int wps_pin_valid(unsigned int pin);
710 unsigned int wps_generate_pin(void);
711 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
713 struct oob_device_data * wps_get_oob_device(char *device_type);
714 struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
715 int wps_get_oob_method(char *method);
716 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
718 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
720 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname);
721 void wps_er_refresh(struct wps_er *er);
722 void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
723 void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
724 u16 sel_reg_config_methods);
725 int wps_er_pbc(struct wps_er *er, const u8 *uuid);
726 int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
729 int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
730 char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
732 void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
733 u16 wps_config_methods_str2bin(const char *str);