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)
78 * @p2p: Whether the device is a P2P device
80 struct wps_device_data {
81 u8 mac_addr[ETH_ALEN];
87 u8 pri_dev_type[WPS_DEV_TYPE_LEN];
94 struct oob_conf_data {
96 OOB_METHOD_UNKNOWN = 0,
101 struct wpabuf *dev_password;
102 struct wpabuf *pubkey_hash;
106 * struct wps_config - WPS configuration for a single registration protocol run
110 * wps - Pointer to long term WPS context
112 struct wps_context *wps;
115 * registrar - Whether this end is a Registrar
120 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
125 * pin_len - Length on pin in octets
130 * pbc - Whether this is protocol run uses PBC
135 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
137 const struct wpabuf *assoc_wps_ie;
140 * new_ap_settings - New AP settings (%NULL if not used)
142 * This parameter provides new AP settings when using a wireless
143 * stations as a Registrar to configure the AP. %NULL means that AP
144 * will not be reconfigured, i.e., the station will only learn the
145 * current AP settings by using AP PIN.
147 const struct wps_credential *new_ap_settings;
150 * peer_addr: MAC address of the peer in AP; %NULL if not AP
155 * use_psk_key - Use PSK format key in Credential
157 * Force PSK format to be used instead of ASCII passphrase when
158 * building Credential for an Enrollee. The PSK value is set in
159 * struct wpa_context::psk.
164 * dev_pw_id - Device Password ID for Enrollee when PIN is used
169 struct wps_data * wps_init(const struct wps_config *cfg);
171 void wps_deinit(struct wps_data *data);
174 * enum wps_process_res - WPS message processing result
176 enum wps_process_res {
178 * WPS_DONE - Processing done
183 * WPS_CONTINUE - Processing continues
188 * WPS_FAILURE - Processing failed
193 * WPS_PENDING - Processing continues, but waiting for an external
194 * event (e.g., UPnP message from an external Registrar)
198 enum wps_process_res wps_process_msg(struct wps_data *wps,
199 enum wsc_op_code op_code,
200 const struct wpabuf *msg);
202 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
204 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
205 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
206 int wps_ap_priority_compar(const struct wpabuf *wps_a,
207 const struct wpabuf *wps_b);
208 int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
210 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
212 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
213 struct wpabuf * wps_build_assoc_resp_ie(void);
214 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
216 enum wps_request_type req_type);
220 * struct wps_registrar_config - WPS Registrar configuration
222 struct wps_registrar_config {
224 * new_psk_cb - Callback for new PSK
225 * @ctx: Higher layer context data (cb_ctx)
226 * @mac_addr: MAC address of the Enrollee
228 * @psk_len: The length of psk in octets
229 * Returns: 0 on success, -1 on failure
231 * This callback is called when a new per-device PSK is provisioned.
233 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
237 * set_ie_cb - Callback for WPS IE changes
238 * @ctx: Higher layer context data (cb_ctx)
239 * @beacon_ie: WPS IE for Beacon
240 * @probe_resp_ie: WPS IE for Probe Response
241 * Returns: 0 on success, -1 on failure
243 * This callback is called whenever the WPS IE in Beacon or Probe
244 * Response frames needs to be changed (AP only). Callee is responsible
245 * for freeing the buffers.
247 int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
248 struct wpabuf *probe_resp_ie);
251 * pin_needed_cb - Callback for requesting a PIN
252 * @ctx: Higher layer context data (cb_ctx)
253 * @uuid_e: UUID-E of the unknown Enrollee
254 * @dev: Device Data from the unknown Enrollee
256 * This callback is called whenever an unknown Enrollee requests to use
257 * PIN method and a matching PIN (Device Password) is not found in
260 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
261 const struct wps_device_data *dev);
264 * reg_success_cb - Callback for reporting successful registration
265 * @ctx: Higher layer context data (cb_ctx)
266 * @mac_addr: MAC address of the Enrollee
267 * @uuid_e: UUID-E of the Enrollee
269 * This callback is called whenever an Enrollee completes registration
272 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
276 * set_sel_reg_cb - Callback for reporting selected registrar changes
277 * @ctx: Higher layer context data (cb_ctx)
278 * @sel_reg: Whether the Registrar is selected
279 * @dev_passwd_id: Device Password ID to indicate with method or
280 * specific password the Registrar intends to use
281 * @sel_reg_config_methods: Bit field of active config methods
283 * This callback is called whenever the Selected Registrar state
284 * changes (e.g., a new PIN becomes available or PBC is invoked). This
285 * callback is only used by External Registrar implementation;
286 * set_ie_cb() is used by AP implementation in similar caes, but it
287 * provides the full WPS IE data instead of just the minimal Registrar
290 void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
291 u16 sel_reg_config_methods);
294 * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq
295 * @ctx: Higher layer context data (cb_ctx)
296 * @addr: MAC address of the Enrollee
297 * @uuid_e: UUID of the Enrollee
298 * @pri_dev_type: Primary device type
299 * @config_methods: Config Methods
300 * @dev_password_id: Device Password ID
301 * @request_type: Request Type
302 * @dev_name: Device Name (if available)
304 void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
305 const u8 *pri_dev_type, u16 config_methods,
306 u16 dev_password_id, u8 request_type,
307 const char *dev_name);
310 * cb_ctx: Higher layer context data for Registrar callbacks
315 * skip_cred_build: Do not build credential
317 * This option can be used to disable internal code that builds
318 * Credential attribute into M8 based on the current network
319 * configuration and Enrollee capabilities. The extra_cred data will
320 * then be used as the Credential(s).
325 * extra_cred: Additional Credential attribute(s)
327 * This optional data (set to %NULL to disable) can be used to add
328 * Credential attribute(s) for other networks into M8. If
329 * skip_cred_build is set, this will also override the automatically
330 * generated Credential attribute.
332 const u8 *extra_cred;
335 * extra_cred_len: Length of extra_cred in octets
337 size_t extra_cred_len;
340 * disable_auto_conf - Disable auto-configuration on first registration
342 * By default, the AP that is started in not configured state will
343 * generate a random PSK and move to configured state when the first
344 * registration protocol run is completed successfully. This option can
345 * be used to disable this functionality and leave it up to an external
346 * program to take care of configuration. This requires the extra_cred
347 * to be set with a suitable Credential and skip_cred_build being used.
349 int disable_auto_conf;
352 * static_wep_only - Whether the BSS supports only static WEP
359 * enum wps_event - WPS event types
363 * WPS_EV_M2D - M2D received (Registrar did not know us)
368 * WPS_EV_FAIL - Registration failed
373 * WPS_EV_SUCCESS - Registration succeeded
378 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
380 WPS_EV_PWD_AUTH_FAIL,
383 * WPS_EV_PBC_OVERLAP - PBC session overlap detected
388 * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
393 * WPS_EV_ER_AP_ADD - ER: AP added
398 * WPS_EV_ER_AP_REMOVE - ER: AP removed
403 * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
405 WPS_EV_ER_ENROLLEE_ADD,
408 * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
410 WPS_EV_ER_ENROLLEE_REMOVE,
413 * WPS_EV_ER_AP_SETTINGS - ER: AP Settings learned
415 WPS_EV_ER_AP_SETTINGS
419 * union wps_event_data - WPS event data
421 union wps_event_data {
423 * struct wps_event_m2d - M2D event data
425 struct wps_event_m2d {
427 const u8 *manufacturer;
428 size_t manufacturer_len;
429 const u8 *model_name;
430 size_t model_name_len;
431 const u8 *model_number;
432 size_t model_number_len;
433 const u8 *serial_number;
434 size_t serial_number_len;
437 const u8 *primary_dev_type; /* 8 octets */
443 * struct wps_event_fail - Registration failure information
444 * @msg: enum wps_msg_type
446 struct wps_event_fail {
450 struct wps_event_pwd_auth_fail {
455 struct wps_event_er_ap {
458 const char *friendly_name;
459 const char *manufacturer;
460 const char *manufacturer_url;
461 const char *model_description;
462 const char *model_name;
463 const char *model_number;
464 const char *model_url;
465 const char *serial_number;
467 const u8 *pri_dev_type;
471 struct wps_event_er_enrollee {
477 const u8 *pri_dev_type;
478 const char *dev_name;
479 const char *manufacturer;
480 const char *model_name;
481 const char *model_number;
482 const char *serial_number;
485 struct wps_event_er_ap_settings {
487 const struct wps_credential *cred;
492 * struct upnp_pending_message - Pending PutWLANResponse messages
493 * @next: Pointer to next pending message or %NULL
494 * @addr: NewWLANEventMAC
496 * @type: Message Type
498 struct upnp_pending_message {
499 struct upnp_pending_message *next;
502 enum wps_msg_type type;
506 * struct wps_context - Long term WPS context data
508 * This data is stored at the higher layer Authenticator or Supplicant data
509 * structures and it is maintained over multiple registration protocol runs.
513 * ap - Whether the local end is an access point
518 * registrar - Pointer to WPS registrar data from wps_registrar_init()
520 struct wps_registrar *registrar;
523 * wps_state - Current WPS state
525 enum wps_state wps_state;
528 * ap_setup_locked - Whether AP setup is locked (only used at AP)
540 * This SSID is used by the Registrar to fill in information for
541 * Credentials. In addition, AP uses it when acting as an Enrollee to
542 * notify Registrar of the current configuration.
547 * ssid_len - Length of ssid in octets
552 * dev - Own WPS device data
554 struct wps_device_data dev;
557 * oob_conf - OOB Config data
559 struct oob_conf_data oob_conf;
562 * oob_dev_pw_id - OOB Device password id
567 * dh_ctx - Context data for Diffie-Hellman operation
572 * dh_privkey - Diffie-Hellman private key
574 struct wpabuf *dh_privkey;
577 * dh_pubkey_oob - Diffie-Hellman public key
579 struct wpabuf *dh_pubkey;
582 * config_methods - Enabled configuration methods
584 * Bit field of WPS_CONFIG_*
589 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
594 * auth_types - Authentication types (bit field of WPS_AUTH_*)
599 * network_key - The current Network Key (PSK) or %NULL to generate new
601 * If %NULL, Registrar will generate per-device PSK. In addition, AP
602 * uses this when acting as an Enrollee to notify Registrar of the
603 * current configuration.
605 * When using WPA/WPA2-Person, this key can be either the ASCII
606 * passphrase (8..63 characters) or the 32-octet PSK (64 hex
607 * characters). When this is set to the ASCII passphrase, the PSK can
608 * be provided in the psk buffer and used per-Enrollee to control which
609 * key type is included in the Credential (e.g., to reduce calculation
610 * need on low-powered devices by provisioning PSK while still allowing
611 * other devices to get the passphrase).
616 * network_key_len - Length of network_key in octets
618 size_t network_key_len;
621 * psk - The current network PSK
623 * This optional value can be used to provide the current PSK if
624 * network_key is set to the ASCII passphrase.
629 * psk_set - Whether psk value is set
634 * ap_settings - AP Settings override for M7 (only used at AP)
636 * If %NULL, AP Settings attributes will be generated based on the
637 * current network configuration.
642 * ap_settings_len - Length of ap_settings in octets
644 size_t ap_settings_len;
647 * friendly_name - Friendly Name (required for UPnP)
652 * manufacturer_url - Manufacturer URL (optional for UPnP)
654 char *manufacturer_url;
657 * model_description - Model Description (recommended for UPnP)
659 char *model_description;
662 * model_url - Model URL (optional for UPnP)
667 * upc - Universal Product Code (optional for UPnP)
672 * cred_cb - Callback to notify that new Credentials were received
673 * @ctx: Higher layer context data (cb_ctx)
674 * @cred: The received Credential
675 * Return: 0 on success, -1 on failure
677 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
680 * event_cb - Event callback (state information about progress)
681 * @ctx: Higher layer context data (cb_ctx)
685 void (*event_cb)(void *ctx, enum wps_event event,
686 union wps_event_data *data);
689 * cb_ctx: Higher layer context data for callbacks
693 struct upnp_wps_device_sm *wps_upnp;
695 /* Pending messages from UPnP PutWLANResponse */
696 struct upnp_pending_message *upnp_msgs;
699 struct oob_device_data {
702 void * (*init_func)(struct wps_context *, struct oob_device_data *,
704 struct wpabuf * (*read_func)(void *);
705 int (*write_func)(void *, struct wpabuf *);
706 void (*deinit_func)(void *);
709 struct oob_nfc_device_data {
710 int (*init_func)(char *);
711 void * (*read_func)(size_t *);
712 int (*write_func)(void *, size_t);
713 void (*deinit_func)(void);
716 struct wps_registrar *
717 wps_registrar_init(struct wps_context *wps,
718 const struct wps_registrar_config *cfg);
719 void wps_registrar_deinit(struct wps_registrar *reg);
720 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
721 const u8 *uuid, const u8 *pin, size_t pin_len,
723 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
724 int wps_registrar_wps_cancel(struct wps_registrar *reg);
725 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
726 int wps_registrar_button_pushed(struct wps_registrar *reg);
727 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
728 const struct wpabuf *wps_data,
730 int wps_registrar_update_ie(struct wps_registrar *reg);
731 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
732 char *buf, size_t buflen);
734 unsigned int wps_pin_checksum(unsigned int pin);
735 unsigned int wps_pin_valid(unsigned int pin);
736 unsigned int wps_generate_pin(void);
737 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
739 struct oob_device_data * wps_get_oob_device(char *device_type);
740 struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
741 int wps_get_oob_method(char *method);
742 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
744 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
746 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname,
748 void wps_er_refresh(struct wps_er *er);
749 void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
750 void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
751 u16 sel_reg_config_methods);
752 int wps_er_pbc(struct wps_er *er, const u8 *uuid);
753 int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
755 int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *pin,
756 size_t pin_len, const struct wps_credential *cred);
758 int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
759 char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
761 void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
762 u16 wps_config_methods_str2bin(const char *str);
764 #ifdef CONFIG_WPS_STRICT
765 int wps_validate_beacon(const struct wpabuf *wps_ie);
766 int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe,
768 int wps_validate_probe_req(const struct wpabuf *wps_ie);
769 int wps_validate_assoc_req(const struct wpabuf *wps_ie);
770 int wps_validate_assoc_resp(const struct wpabuf *wps_ie);
771 int wps_validate_m1(const struct wpabuf *tlvs);
772 int wps_validate_m2(const struct wpabuf *tlvs);
773 int wps_validate_m2d(const struct wpabuf *tlvs);
774 int wps_validate_m3(const struct wpabuf *tlvs);
775 int wps_validate_m4(const struct wpabuf *tlvs);
776 int wps_validate_m4_encr(const struct wpabuf *tlvs);
777 int wps_validate_m5(const struct wpabuf *tlvs);
778 int wps_validate_m5_encr(const struct wpabuf *tlvs);
779 int wps_validate_m6(const struct wpabuf *tlvs);
780 int wps_validate_m6_encr(const struct wpabuf *tlvs);
781 int wps_validate_m7(const struct wpabuf *tlvs);
782 int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap);
783 int wps_validate_m8(const struct wpabuf *tlvs);
784 int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap);
785 int wps_validate_wsc_ack(const struct wpabuf *tlvs);
786 int wps_validate_wsc_nack(const struct wpabuf *tlvs);
787 int wps_validate_wsc_done(const struct wpabuf *tlvs);
788 int wps_validate_upnp_set_selected_registrar(const struct wpabuf *tlvs);
789 #else /* CONFIG_WPS_STRICT */
790 static inline int wps_validate_beacon(const struct wpabuf *wps_ie){
794 static inline int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie,
795 int probe, const u8 *addr)
800 static inline int wps_validate_probe_req(const struct wpabuf *wps_ie)
805 static inline int wps_validate_assoc_req(const struct wpabuf *wps_ie)
810 static inline int wps_validate_assoc_resp(const struct wpabuf *wps_ie)
815 static inline int wps_validate_m1(const struct wpabuf *tlvs)
820 static inline int wps_validate_m2(const struct wpabuf *tlvs)
825 static inline int wps_validate_m2d(const struct wpabuf *tlvs)
830 static inline int wps_validate_m3(const struct wpabuf *tlvs)
835 static inline int wps_validate_m4(const struct wpabuf *tlvs)
840 static inline int wps_validate_m4_encr(const struct wpabuf *tlvs)
845 static inline int wps_validate_m5(const struct wpabuf *tlvs)
850 static inline int wps_validate_m5_encr(const struct wpabuf *tlvs)
855 static inline int wps_validate_m6(const struct wpabuf *tlvs)
860 static inline int wps_validate_m6_encr(const struct wpabuf *tlvs)
865 static inline int wps_validate_m7(const struct wpabuf *tlvs)
870 static inline int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap)
875 static inline int wps_validate_m8(const struct wpabuf *tlvs)
880 static inline int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap)
885 static inline int wps_validate_wsc_ack(const struct wpabuf *tlvs)
890 static inline int wps_validate_wsc_nack(const struct wpabuf *tlvs)
895 static inline int wps_validate_wsc_done(const struct wpabuf *tlvs)
900 static inline int wps_validate_upnp_set_selected_registrar(
901 const struct wpabuf *tlvs)
905 #endif /* CONFIG_WPS_STRICT */