2 * Wi-Fi Protected Setup - Registrar
3 * Copyright (c) 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.
20 #include "ieee802_11_defs.h"
23 #include "wps_dev_attr.h"
28 struct wps_uuid_pin *next;
29 u8 uuid[WPS_UUID_LEN];
37 static void wps_free_pin(struct wps_uuid_pin *pin)
44 static void wps_free_pins(struct wps_uuid_pin *pins)
46 struct wps_uuid_pin *pin, *prev;
57 struct wps_pbc_session {
58 struct wps_pbc_session *next;
60 u8 uuid_e[WPS_UUID_LEN];
61 struct os_time timestamp;
65 static void wps_free_pbc_sessions(struct wps_pbc_session *pbc)
67 struct wps_pbc_session *prev;
77 struct wps_registrar {
78 struct wps_context *wps;
81 int selected_registrar;
83 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
85 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
86 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
87 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
88 const struct wps_device_data *dev);
89 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
93 struct wps_uuid_pin *pins;
94 struct wps_pbc_session *pbc_sessions;
97 struct wpabuf *extra_cred;
98 int disable_auto_conf;
99 int sel_reg_dev_password_id_override;
100 int sel_reg_config_methods_override;
104 static int wps_set_ie(struct wps_registrar *reg);
105 static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx);
106 static void wps_registrar_set_selected_timeout(void *eloop_ctx,
110 static void wps_registrar_add_pbc_session(struct wps_registrar *reg,
111 const u8 *addr, const u8 *uuid_e)
113 struct wps_pbc_session *pbc, *prev = NULL;
118 pbc = reg->pbc_sessions;
120 if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
121 os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
123 prev->next = pbc->next;
125 reg->pbc_sessions = pbc->next;
133 pbc = os_zalloc(sizeof(*pbc));
136 os_memcpy(pbc->addr, addr, ETH_ALEN);
138 os_memcpy(pbc->uuid_e, uuid_e, WPS_UUID_LEN);
141 pbc->next = reg->pbc_sessions;
142 reg->pbc_sessions = pbc;
143 pbc->timestamp = now;
145 /* remove entries that have timed out */
150 if (now.sec > pbc->timestamp.sec + WPS_PBC_WALK_TIME) {
152 wps_free_pbc_sessions(pbc);
161 static void wps_registrar_remove_pbc_session(struct wps_registrar *reg,
162 const u8 *addr, const u8 *uuid_e)
164 struct wps_pbc_session *pbc, *prev = NULL;
166 pbc = reg->pbc_sessions;
168 if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
169 os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
171 prev->next = pbc->next;
173 reg->pbc_sessions = pbc->next;
183 static int wps_registrar_pbc_overlap(struct wps_registrar *reg,
184 const u8 *addr, const u8 *uuid_e)
187 struct wps_pbc_session *pbc;
192 for (pbc = reg->pbc_sessions; pbc; pbc = pbc->next) {
193 if (now.sec > pbc->timestamp.sec + WPS_PBC_WALK_TIME)
195 if (addr == NULL || os_memcmp(addr, pbc->addr, ETH_ALEN) ||
197 os_memcmp(uuid_e, pbc->uuid_e, WPS_UUID_LEN))
204 return count > 1 ? 1 : 0;
208 static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
210 wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
212 wpabuf_put_be16(msg, ATTR_WPS_STATE);
213 wpabuf_put_be16(msg, 1);
214 wpabuf_put_u8(msg, wps->wps_state);
219 static int wps_build_ap_setup_locked(struct wps_context *wps,
222 if (wps->ap_setup_locked) {
223 wpa_printf(MSG_DEBUG, "WPS: * AP Setup Locked");
224 wpabuf_put_be16(msg, ATTR_AP_SETUP_LOCKED);
225 wpabuf_put_be16(msg, 1);
226 wpabuf_put_u8(msg, 1);
232 static int wps_build_selected_registrar(struct wps_registrar *reg,
235 if (!reg->selected_registrar)
237 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
238 wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR);
239 wpabuf_put_be16(msg, 1);
240 wpabuf_put_u8(msg, 1);
245 static int wps_build_sel_reg_dev_password_id(struct wps_registrar *reg,
248 u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
249 if (!reg->selected_registrar)
251 if (reg->sel_reg_dev_password_id_override >= 0)
252 id = reg->sel_reg_dev_password_id_override;
253 wpa_printf(MSG_DEBUG, "WPS: * Device Password ID (%d)", id);
254 wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
255 wpabuf_put_be16(msg, 2);
256 wpabuf_put_be16(msg, id);
261 static int wps_build_sel_reg_config_methods(struct wps_registrar *reg,
265 if (!reg->selected_registrar)
267 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
269 methods |= WPS_CONFIG_PUSHBUTTON;
270 if (reg->sel_reg_config_methods_override >= 0)
271 methods = reg->sel_reg_config_methods_override;
272 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar Config Methods (%x)",
274 wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR_CONFIG_METHODS);
275 wpabuf_put_be16(msg, 2);
276 wpabuf_put_be16(msg, methods);
281 static int wps_build_probe_config_methods(struct wps_registrar *reg,
286 wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
287 wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
288 wpabuf_put_be16(msg, 2);
289 wpabuf_put_be16(msg, methods);
294 static int wps_build_config_methods_r(struct wps_registrar *reg,
298 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
300 methods |= WPS_CONFIG_PUSHBUTTON;
301 return wps_build_config_methods(msg, methods);
305 static int wps_build_resp_type(struct wps_registrar *reg, struct wpabuf *msg)
307 u8 resp = reg->wps->ap ? WPS_RESP_AP : WPS_RESP_REGISTRAR;
308 wpa_printf(MSG_DEBUG, "WPS: * Response Type (%d)", resp);
309 wpabuf_put_be16(msg, ATTR_RESPONSE_TYPE);
310 wpabuf_put_be16(msg, 1);
311 wpabuf_put_u8(msg, resp);
317 * wps_registrar_init - Initialize WPS Registrar data
318 * @wps: Pointer to longterm WPS context
319 * @cfg: Registrar configuration
320 * Returns: Pointer to allocated Registrar data or %NULL on failure
322 * This function is used to initialize WPS Registrar functionality. It can be
323 * used for a single Registrar run (e.g., when run in a supplicant) or multiple
324 * runs (e.g., when run as an internal Registrar in an AP). Caller is
325 * responsible for freeing the returned data with wps_registrar_deinit() when
326 * Registrar functionality is not needed anymore.
328 struct wps_registrar *
329 wps_registrar_init(struct wps_context *wps,
330 const struct wps_registrar_config *cfg)
332 struct wps_registrar *reg = os_zalloc(sizeof(*reg));
337 reg->new_psk_cb = cfg->new_psk_cb;
338 reg->set_ie_cb = cfg->set_ie_cb;
339 reg->pin_needed_cb = cfg->pin_needed_cb;
340 reg->reg_success_cb = cfg->reg_success_cb;
341 reg->cb_ctx = cfg->cb_ctx;
342 reg->skip_cred_build = cfg->skip_cred_build;
343 if (cfg->extra_cred) {
344 reg->extra_cred = wpabuf_alloc_copy(cfg->extra_cred,
345 cfg->extra_cred_len);
346 if (reg->extra_cred == NULL) {
351 reg->disable_auto_conf = cfg->disable_auto_conf;
352 reg->sel_reg_dev_password_id_override = -1;
354 if (wps_set_ie(reg)) {
355 wps_registrar_deinit(reg);
364 * wps_registrar_deinit - Deinitialize WPS Registrar data
365 * @reg: Registrar data from wps_registrar_init()
367 void wps_registrar_deinit(struct wps_registrar *reg)
371 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
372 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
373 wps_free_pins(reg->pins);
374 wps_free_pbc_sessions(reg->pbc_sessions);
375 wpabuf_free(reg->extra_cred);
381 * wps_registrar_add_pin - Configure a new PIN for Registrar
382 * @reg: Registrar data from wps_registrar_init()
383 * @uuid: UUID-E or %NULL for wildcard (any UUID)
384 * @pin: PIN (Device Password)
385 * @pin_len: Length of pin in octets
386 * Returns: 0 on success, -1 on failure
388 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
389 const u8 *pin, size_t pin_len)
391 struct wps_uuid_pin *p;
393 p = os_zalloc(sizeof(*p));
397 p->wildcard_uuid = 1;
399 os_memcpy(p->uuid, uuid, WPS_UUID_LEN);
400 p->pin = os_malloc(pin_len);
401 if (p->pin == NULL) {
405 os_memcpy(p->pin, pin, pin_len);
406 p->pin_len = pin_len;
411 wpa_printf(MSG_DEBUG, "WPS: A new PIN configured");
412 wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
413 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
414 reg->selected_registrar = 1;
423 * wps_registrar_invalidate_pin - Invalidate a PIN for a specific UUID-E
424 * @reg: Registrar data from wps_registrar_init()
426 * Returns: 0 on success, -1 on failure (e.g., PIN not found)
428 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid)
430 struct wps_uuid_pin *pin, *prev;
435 if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
437 reg->pins = pin->next;
439 prev->next = pin->next;
440 wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
441 pin->uuid, WPS_UUID_LEN);
453 static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
454 const u8 *uuid, size_t *pin_len)
456 struct wps_uuid_pin *pin;
460 if (!pin->wildcard_uuid &&
461 os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0)
467 /* Check for wildcard UUIDs since none of the UUID-specific
471 if (pin->wildcard_uuid == 1) {
472 wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
473 "PIN. Assigned it for this UUID-E");
474 pin->wildcard_uuid = 2;
475 os_memcpy(pin->uuid, uuid, WPS_UUID_LEN);
486 * Lock the PIN to avoid attacks based on concurrent re-use of the PIN
487 * that could otherwise avoid PIN invalidations.
490 wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
491 "allow concurrent re-use");
494 *pin_len = pin->pin_len;
501 * wps_registrar_unlock_pin - Unlock a PIN for a specific UUID-E
502 * @reg: Registrar data from wps_registrar_init()
504 * Returns: 0 on success, -1 on failure
506 * PINs are locked to enforce only one concurrent use. This function unlocks a
507 * PIN to allow it to be used again. If the specified PIN was configured using
508 * a wildcard UUID, it will be removed instead of allowing multiple uses.
510 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid)
512 struct wps_uuid_pin *pin;
516 if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
517 if (pin->wildcard_uuid == 2) {
518 wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
520 return wps_registrar_invalidate_pin(reg, uuid);
532 static void wps_registrar_stop_pbc(struct wps_registrar *reg)
534 reg->selected_registrar = 0;
540 static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx)
542 struct wps_registrar *reg = eloop_ctx;
544 wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
545 wps_registrar_stop_pbc(reg);
550 * wps_registrar_button_pushed - Notify Registrar that AP button was pushed
551 * @reg: Registrar data from wps_registrar_init()
552 * Returns: 0 on success, -1 on failure
554 * This function is called on an AP when a push button is pushed to activate
555 * PBC mode. The PBC mode will be stopped after walk time (2 minutes) timeout
556 * or when a PBC registration is completed.
558 int wps_registrar_button_pushed(struct wps_registrar *reg)
560 if (wps_registrar_pbc_overlap(reg, NULL, NULL)) {
561 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
565 wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
566 reg->selected_registrar = 1;
570 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
571 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
577 static void wps_registrar_pbc_completed(struct wps_registrar *reg)
579 wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
580 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
581 wps_registrar_stop_pbc(reg);
586 * wps_registrar_probe_req_rx - Notify Registrar of Probe Request
587 * @reg: Registrar data from wps_registrar_init()
588 * @addr: MAC address of the Probe Request sender
589 * @wps_data: WPS IE contents
591 * This function is called on an AP when a Probe Request with WPS IE is
592 * received. This is used to track PBC mode use and to detect possible overlap
593 * situation with other WPS APs.
595 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
596 const struct wpabuf *wps_data)
598 struct wps_parse_attr attr;
601 wpa_hexdump_buf(MSG_MSGDUMP,
602 "WPS: Probe Request with WPS data received",
605 if (wps_parse_msg(wps_data, &attr) < 0 ||
606 attr.version == NULL || *attr.version != WPS_VERSION) {
607 wpa_printf(MSG_DEBUG, "WPS: Unsupported ProbeReq WPS IE "
608 "version 0x%x", attr.version ? *attr.version : 0);
612 if (attr.config_methods == NULL) {
613 wpa_printf(MSG_DEBUG, "WPS: No Config Methods attribute in "
618 methods = WPA_GET_BE16(attr.config_methods);
619 if (!(methods & WPS_CONFIG_PUSHBUTTON))
620 return; /* Not PBC */
622 wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
623 MACSTR, MAC2STR(addr));
625 wps_registrar_add_pbc_session(reg, addr, attr.uuid_e);
629 static int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
630 const u8 *psk, size_t psk_len)
632 if (reg->new_psk_cb == NULL)
635 return reg->new_psk_cb(reg->cb_ctx, mac_addr, psk, psk_len);
639 static void wps_cb_pin_needed(struct wps_registrar *reg, const u8 *uuid_e,
640 const struct wps_device_data *dev)
642 if (reg->pin_needed_cb == NULL)
645 reg->pin_needed_cb(reg->cb_ctx, uuid_e, dev);
649 static void wps_cb_reg_success(struct wps_registrar *reg, const u8 *mac_addr,
652 if (reg->reg_success_cb == NULL)
655 reg->reg_success_cb(reg->cb_ctx, mac_addr, uuid_e);
659 static int wps_cb_set_ie(struct wps_registrar *reg,
660 const struct wpabuf *beacon_ie,
661 const struct wpabuf *probe_resp_ie)
663 if (reg->set_ie_cb == NULL)
666 return reg->set_ie_cb(reg->cb_ctx, wpabuf_head(beacon_ie),
667 wpabuf_len(beacon_ie),
668 wpabuf_head(probe_resp_ie),
669 wpabuf_len(probe_resp_ie));
673 /* Encapsulate WPS IE data with one (or more, if needed) IE headers */
674 static struct wpabuf * wps_ie_encapsulate(struct wpabuf *data)
679 ie = wpabuf_alloc(wpabuf_len(data) + 100);
685 pos = wpabuf_head(data);
686 end = pos + wpabuf_len(data);
689 size_t frag_len = end - pos;
692 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
693 wpabuf_put_u8(ie, 4 + frag_len);
694 wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
695 wpabuf_put_data(ie, pos, frag_len);
705 static int wps_set_ie(struct wps_registrar *reg)
707 struct wpabuf *beacon;
708 struct wpabuf *probe;
711 wpa_printf(MSG_DEBUG, "WPS: Build Beacon and Probe Response IEs");
713 beacon = wpabuf_alloc(300);
716 probe = wpabuf_alloc(400);
722 if (wps_build_version(beacon) ||
723 wps_build_wps_state(reg->wps, beacon) ||
724 wps_build_ap_setup_locked(reg->wps, beacon) ||
725 wps_build_selected_registrar(reg, beacon) ||
726 wps_build_sel_reg_dev_password_id(reg, beacon) ||
727 wps_build_sel_reg_config_methods(reg, beacon) ||
728 wps_build_version(probe) ||
729 wps_build_wps_state(reg->wps, probe) ||
730 wps_build_ap_setup_locked(reg->wps, probe) ||
731 wps_build_selected_registrar(reg, probe) ||
732 wps_build_sel_reg_dev_password_id(reg, probe) ||
733 wps_build_sel_reg_config_methods(reg, probe) ||
734 wps_build_resp_type(reg, probe) ||
735 wps_build_uuid_e(probe, reg->wps->uuid) ||
736 wps_build_device_attrs(®->wps->dev, probe) ||
737 wps_build_probe_config_methods(reg, probe) ||
738 wps_build_rf_bands(®->wps->dev, probe)) {
744 beacon = wps_ie_encapsulate(beacon);
745 probe = wps_ie_encapsulate(probe);
747 if (!beacon || !probe) {
753 ret = wps_cb_set_ie(reg, beacon, probe);
761 static int wps_get_dev_password(struct wps_data *wps)
766 os_free(wps->dev_password);
767 wps->dev_password = NULL;
770 wpa_printf(MSG_DEBUG, "WPS: Use default PIN for PBC");
771 pin = (const u8 *) "00000000";
774 pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
778 wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
780 wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
785 wps->dev_password = os_malloc(pin_len);
786 if (wps->dev_password == NULL)
788 os_memcpy(wps->dev_password, pin, pin_len);
789 wps->dev_password_len = pin_len;
795 static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
797 wpa_printf(MSG_DEBUG, "WPS: * UUID-R");
798 wpabuf_put_be16(msg, ATTR_UUID_R);
799 wpabuf_put_be16(msg, WPS_UUID_LEN);
800 wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
805 static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
811 if (os_get_random(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
813 wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
814 wpa_hexdump(MSG_DEBUG, "WPS: R-S2",
815 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
817 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
818 wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
819 "R-Hash derivation");
823 wpa_printf(MSG_DEBUG, "WPS: * R-Hash1");
824 wpabuf_put_be16(msg, ATTR_R_HASH1);
825 wpabuf_put_be16(msg, SHA256_MAC_LEN);
826 hash = wpabuf_put(msg, SHA256_MAC_LEN);
827 /* R-Hash1 = HMAC_AuthKey(R-S1 || PSK1 || PK_E || PK_R) */
828 addr[0] = wps->snonce;
829 len[0] = WPS_SECRET_NONCE_LEN;
831 len[1] = WPS_PSK_LEN;
832 addr[2] = wpabuf_head(wps->dh_pubkey_e);
833 len[2] = wpabuf_len(wps->dh_pubkey_e);
834 addr[3] = wpabuf_head(wps->dh_pubkey_r);
835 len[3] = wpabuf_len(wps->dh_pubkey_r);
836 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
837 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", hash, SHA256_MAC_LEN);
839 wpa_printf(MSG_DEBUG, "WPS: * R-Hash2");
840 wpabuf_put_be16(msg, ATTR_R_HASH2);
841 wpabuf_put_be16(msg, SHA256_MAC_LEN);
842 hash = wpabuf_put(msg, SHA256_MAC_LEN);
843 /* R-Hash2 = HMAC_AuthKey(R-S2 || PSK2 || PK_E || PK_R) */
844 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
846 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
847 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", hash, SHA256_MAC_LEN);
853 static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
855 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce1");
856 wpabuf_put_be16(msg, ATTR_R_SNONCE1);
857 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
858 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
863 static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
865 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce2");
866 wpabuf_put_be16(msg, ATTR_R_SNONCE2);
867 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
868 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
869 WPS_SECRET_NONCE_LEN);
874 static int wps_build_cred_network_idx(struct wpabuf *msg,
875 struct wps_credential *cred)
877 wpa_printf(MSG_DEBUG, "WPS: * Network Index");
878 wpabuf_put_be16(msg, ATTR_NETWORK_INDEX);
879 wpabuf_put_be16(msg, 1);
880 wpabuf_put_u8(msg, 1);
885 static int wps_build_cred_ssid(struct wpabuf *msg,
886 struct wps_credential *cred)
888 wpa_printf(MSG_DEBUG, "WPS: * SSID");
889 wpabuf_put_be16(msg, ATTR_SSID);
890 wpabuf_put_be16(msg, cred->ssid_len);
891 wpabuf_put_data(msg, cred->ssid, cred->ssid_len);
896 static int wps_build_cred_auth_type(struct wpabuf *msg,
897 struct wps_credential *cred)
899 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
901 wpabuf_put_be16(msg, ATTR_AUTH_TYPE);
902 wpabuf_put_be16(msg, 2);
903 wpabuf_put_be16(msg, cred->auth_type);
908 static int wps_build_cred_encr_type(struct wpabuf *msg,
909 struct wps_credential *cred)
911 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
913 wpabuf_put_be16(msg, ATTR_ENCR_TYPE);
914 wpabuf_put_be16(msg, 2);
915 wpabuf_put_be16(msg, cred->encr_type);
920 static int wps_build_cred_network_key(struct wpabuf *msg,
921 struct wps_credential *cred)
923 wpa_printf(MSG_DEBUG, "WPS: * Network Key");
924 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
925 wpabuf_put_be16(msg, cred->key_len);
926 wpabuf_put_data(msg, cred->key, cred->key_len);
931 static int wps_build_cred_mac_addr(struct wpabuf *msg,
932 struct wps_credential *cred)
934 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (" MACSTR ")",
935 MAC2STR(cred->mac_addr));
936 wpabuf_put_be16(msg, ATTR_MAC_ADDR);
937 wpabuf_put_be16(msg, ETH_ALEN);
938 wpabuf_put_data(msg, cred->mac_addr, ETH_ALEN);
943 static int wps_build_credential(struct wpabuf *msg,
944 struct wps_credential *cred)
946 if (wps_build_cred_network_idx(msg, cred) ||
947 wps_build_cred_ssid(msg, cred) ||
948 wps_build_cred_auth_type(msg, cred) ||
949 wps_build_cred_encr_type(msg, cred) ||
950 wps_build_cred_network_key(msg, cred) ||
951 wps_build_cred_mac_addr(msg, cred))
957 static int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
961 if (wps->wps->registrar->skip_cred_build)
962 goto skip_cred_build;
964 wpa_printf(MSG_DEBUG, "WPS: * Credential");
965 os_memset(&wps->cred, 0, sizeof(wps->cred));
967 os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
968 wps->cred.ssid_len = wps->wps->ssid_len;
970 /* Select the best authentication and encryption type */
971 if (wps->auth_type & WPS_AUTH_WPA2PSK)
972 wps->auth_type = WPS_AUTH_WPA2PSK;
973 else if (wps->auth_type & WPS_AUTH_WPAPSK)
974 wps->auth_type = WPS_AUTH_WPAPSK;
975 else if (wps->auth_type & WPS_AUTH_OPEN)
976 wps->auth_type = WPS_AUTH_OPEN;
977 else if (wps->auth_type & WPS_AUTH_SHARED)
978 wps->auth_type = WPS_AUTH_SHARED;
980 wpa_printf(MSG_DEBUG, "WPS: Unsupported auth_type 0x%x",
984 wps->cred.auth_type = wps->auth_type;
986 if (wps->auth_type == WPS_AUTH_WPA2PSK ||
987 wps->auth_type == WPS_AUTH_WPAPSK) {
988 if (wps->encr_type & WPS_ENCR_AES)
989 wps->encr_type = WPS_ENCR_AES;
990 else if (wps->encr_type & WPS_ENCR_TKIP)
991 wps->encr_type = WPS_ENCR_TKIP;
993 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
994 "type for WPA/WPA2");
998 if (wps->encr_type & WPS_ENCR_WEP)
999 wps->encr_type = WPS_ENCR_WEP;
1000 else if (wps->encr_type & WPS_ENCR_NONE)
1001 wps->encr_type = WPS_ENCR_NONE;
1003 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1004 "type for non-WPA/WPA2 mode");
1008 wps->cred.encr_type = wps->encr_type;
1009 /* Set MAC address in the Credential to be the AP's address (BSSID) */
1010 os_memcpy(wps->cred.mac_addr, wps->wps->dev.mac_addr, ETH_ALEN);
1012 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
1013 !wps->wps->registrar->disable_auto_conf) {
1015 /* Generate a random passphrase */
1016 if (os_get_random(r, sizeof(r)) < 0)
1018 os_free(wps->new_psk);
1019 wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
1020 if (wps->new_psk == NULL)
1022 wps->new_psk_len--; /* remove newline */
1023 while (wps->new_psk_len &&
1024 wps->new_psk[wps->new_psk_len - 1] == '=')
1026 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated passphrase",
1027 wps->new_psk, wps->new_psk_len);
1028 os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
1029 wps->cred.key_len = wps->new_psk_len;
1030 } else if (wps->wps->network_key) {
1031 os_memcpy(wps->cred.key, wps->wps->network_key,
1032 wps->wps->network_key_len);
1033 wps->cred.key_len = wps->wps->network_key_len;
1034 } else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
1036 /* Generate a random per-device PSK */
1037 os_free(wps->new_psk);
1038 wps->new_psk_len = 32;
1039 wps->new_psk = os_malloc(wps->new_psk_len);
1040 if (wps->new_psk == NULL)
1042 if (os_get_random(wps->new_psk, wps->new_psk_len) < 0) {
1043 os_free(wps->new_psk);
1044 wps->new_psk = NULL;
1047 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
1048 wps->new_psk, wps->new_psk_len);
1049 wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
1051 os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
1052 wps->cred.key_len = wps->new_psk_len * 2;
1055 cred = wpabuf_alloc(200);
1059 if (wps_build_credential(cred, &wps->cred)) {
1064 wpabuf_put_be16(msg, ATTR_CRED);
1065 wpabuf_put_be16(msg, wpabuf_len(cred));
1066 wpabuf_put_buf(msg, cred);
1070 if (wps->wps->registrar->extra_cred) {
1071 wpa_printf(MSG_DEBUG, "WPS: * Credential (pre-configured)");
1072 wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
1079 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
1081 wpa_printf(MSG_DEBUG, "WPS: * AP Settings");
1083 if (wps_build_credential(msg, &wps->cred))
1090 static struct wpabuf * wps_build_m2(struct wps_data *wps)
1094 if (os_get_random(wps->nonce_r, WPS_NONCE_LEN) < 0)
1096 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
1097 wps->nonce_r, WPS_NONCE_LEN);
1098 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
1100 wpa_printf(MSG_DEBUG, "WPS: Building Message M2");
1101 msg = wpabuf_alloc(1000);
1105 if (wps_build_version(msg) ||
1106 wps_build_msg_type(msg, WPS_M2) ||
1107 wps_build_enrollee_nonce(wps, msg) ||
1108 wps_build_registrar_nonce(wps, msg) ||
1109 wps_build_uuid_r(wps, msg) ||
1110 wps_build_public_key(wps, msg) ||
1111 wps_derive_keys(wps) ||
1112 wps_build_auth_type_flags(wps, msg) ||
1113 wps_build_encr_type_flags(wps, msg) ||
1114 wps_build_conn_type_flags(wps, msg) ||
1115 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1116 wps_build_device_attrs(&wps->wps->dev, msg) ||
1117 wps_build_rf_bands(&wps->wps->dev, msg) ||
1118 wps_build_assoc_state(wps, msg) ||
1119 wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
1120 wps_build_dev_password_id(msg, DEV_PW_DEFAULT) ||
1121 wps_build_os_version(&wps->wps->dev, msg) ||
1122 wps_build_authenticator(wps, msg)) {
1127 wps->state = RECV_M3;
1132 static struct wpabuf * wps_build_m2d(struct wps_data *wps)
1135 u16 err = WPS_CFG_NO_ERROR;
1137 wpa_printf(MSG_DEBUG, "WPS: Building Message M2D");
1138 msg = wpabuf_alloc(1000);
1142 if (wps->wps->ap && wps->wps->ap_setup_locked)
1143 err = WPS_CFG_SETUP_LOCKED;
1145 if (wps_build_version(msg) ||
1146 wps_build_msg_type(msg, WPS_M2D) ||
1147 wps_build_enrollee_nonce(wps, msg) ||
1148 wps_build_registrar_nonce(wps, msg) ||
1149 wps_build_uuid_r(wps, msg) ||
1150 wps_build_auth_type_flags(wps, msg) ||
1151 wps_build_encr_type_flags(wps, msg) ||
1152 wps_build_conn_type_flags(wps, msg) ||
1153 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1154 wps_build_device_attrs(&wps->wps->dev, msg) ||
1155 wps_build_rf_bands(&wps->wps->dev, msg) ||
1156 wps_build_assoc_state(wps, msg) ||
1157 wps_build_config_error(msg, err) ||
1158 wps_build_os_version(&wps->wps->dev, msg)) {
1163 wps->state = RECV_M2D_ACK;
1168 static struct wpabuf * wps_build_m4(struct wps_data *wps)
1170 struct wpabuf *msg, *plain;
1172 wpa_printf(MSG_DEBUG, "WPS: Building Message M4");
1174 wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
1176 plain = wpabuf_alloc(200);
1180 msg = wpabuf_alloc(1000);
1186 if (wps_build_version(msg) ||
1187 wps_build_msg_type(msg, WPS_M4) ||
1188 wps_build_enrollee_nonce(wps, msg) ||
1189 wps_build_r_hash(wps, msg) ||
1190 wps_build_r_snonce1(wps, plain) ||
1191 wps_build_key_wrap_auth(wps, plain) ||
1192 wps_build_encr_settings(wps, msg, plain) ||
1193 wps_build_authenticator(wps, msg)) {
1200 wps->state = RECV_M5;
1205 static struct wpabuf * wps_build_m6(struct wps_data *wps)
1207 struct wpabuf *msg, *plain;
1209 wpa_printf(MSG_DEBUG, "WPS: Building Message M6");
1211 plain = wpabuf_alloc(200);
1215 msg = wpabuf_alloc(1000);
1221 if (wps_build_version(msg) ||
1222 wps_build_msg_type(msg, WPS_M6) ||
1223 wps_build_enrollee_nonce(wps, msg) ||
1224 wps_build_r_snonce2(wps, plain) ||
1225 wps_build_key_wrap_auth(wps, plain) ||
1226 wps_build_encr_settings(wps, msg, plain) ||
1227 wps_build_authenticator(wps, msg)) {
1234 wps->wps_pin_revealed = 1;
1235 wps->state = RECV_M7;
1240 static struct wpabuf * wps_build_m8(struct wps_data *wps)
1242 struct wpabuf *msg, *plain;
1244 wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
1246 plain = wpabuf_alloc(500);
1250 msg = wpabuf_alloc(1000);
1256 if (wps_build_version(msg) ||
1257 wps_build_msg_type(msg, WPS_M8) ||
1258 wps_build_enrollee_nonce(wps, msg) ||
1259 (wps->wps->ap && wps_build_cred(wps, plain)) ||
1260 (!wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
1261 wps_build_key_wrap_auth(wps, plain) ||
1262 wps_build_encr_settings(wps, msg, plain) ||
1263 wps_build_authenticator(wps, msg)) {
1270 wps->state = RECV_DONE;
1275 static struct wpabuf * wps_build_wsc_ack(struct wps_data *wps)
1279 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_ACK");
1281 msg = wpabuf_alloc(1000);
1285 if (wps_build_version(msg) ||
1286 wps_build_msg_type(msg, WPS_WSC_ACK) ||
1287 wps_build_enrollee_nonce(wps, msg) ||
1288 wps_build_registrar_nonce(wps, msg)) {
1297 static struct wpabuf * wps_build_wsc_nack(struct wps_data *wps)
1301 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_NACK");
1303 msg = wpabuf_alloc(1000);
1307 if (wps_build_version(msg) ||
1308 wps_build_msg_type(msg, WPS_WSC_NACK) ||
1309 wps_build_enrollee_nonce(wps, msg) ||
1310 wps_build_registrar_nonce(wps, msg) ||
1311 wps_build_config_error(msg, wps->config_error)) {
1320 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
1321 enum wsc_op_code *op_code)
1325 #ifdef CONFIG_WPS_UPNP
1326 if (wps->wps->wps_upnp && wps->wps->upnp_msg) {
1327 wpa_printf(MSG_DEBUG, "WPS: Use pending message from UPnP");
1328 msg = wps->wps->upnp_msg;
1329 wps->wps->upnp_msg = NULL;
1330 *op_code = WSC_MSG; /* FIX: ack/nack */
1335 wpa_printf(MSG_DEBUG, "WPS: Using external Registrar, but no "
1336 "pending message available");
1339 #endif /* CONFIG_WPS_UPNP */
1341 switch (wps->state) {
1343 if (wps_get_dev_password(wps) < 0)
1344 msg = wps_build_m2d(wps);
1346 msg = wps_build_m2(wps);
1350 msg = wps_build_m2d(wps);
1354 msg = wps_build_m4(wps);
1358 msg = wps_build_m6(wps);
1362 msg = wps_build_m8(wps);
1366 msg = wps_build_wsc_ack(wps);
1370 msg = wps_build_wsc_nack(wps);
1371 *op_code = WSC_NACK;
1374 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
1375 "a message", wps->state);
1380 if (*op_code == WSC_MSG && msg) {
1381 /* Save a copy of the last message for Authenticator derivation
1383 wpabuf_free(wps->last_msg);
1384 wps->last_msg = wpabuf_dup(msg);
1391 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
1393 if (e_nonce == NULL) {
1394 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
1398 os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
1399 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
1400 wps->nonce_e, WPS_NONCE_LEN);
1406 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
1408 if (r_nonce == NULL) {
1409 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
1413 if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
1414 wpa_printf(MSG_DEBUG, "WPS: Invalid Registrar Nonce received");
1422 static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
1424 if (uuid_e == NULL) {
1425 wpa_printf(MSG_DEBUG, "WPS: No UUID-E received");
1429 os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
1430 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
1436 static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
1438 if (pw_id == NULL) {
1439 wpa_printf(MSG_DEBUG, "WPS: No Device Password ID received");
1443 wps->dev_pw_id = WPA_GET_BE16(pw_id);
1444 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
1450 static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
1452 if (e_hash1 == NULL) {
1453 wpa_printf(MSG_DEBUG, "WPS: No E-Hash1 received");
1457 os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
1458 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
1464 static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
1466 if (e_hash2 == NULL) {
1467 wpa_printf(MSG_DEBUG, "WPS: No E-Hash2 received");
1471 os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
1472 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
1478 static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
1480 u8 hash[SHA256_MAC_LEN];
1484 if (e_snonce1 == NULL) {
1485 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce1 received");
1489 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce1", e_snonce1,
1490 WPS_SECRET_NONCE_LEN);
1492 /* E-Hash1 = HMAC_AuthKey(E-S1 || PSK1 || PK_E || PK_R) */
1493 addr[0] = e_snonce1;
1494 len[0] = WPS_SECRET_NONCE_LEN;
1495 addr[1] = wps->psk1;
1496 len[1] = WPS_PSK_LEN;
1497 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1498 len[2] = wpabuf_len(wps->dh_pubkey_e);
1499 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1500 len[3] = wpabuf_len(wps->dh_pubkey_r);
1501 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1503 if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
1504 wpa_printf(MSG_DEBUG, "WPS: E-Hash1 derived from E-S1 does "
1505 "not match with the pre-committed value");
1506 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1507 wps_pwd_auth_fail_event(wps->wps, 0, 1);
1511 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the first "
1512 "half of the device password");
1518 static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
1520 u8 hash[SHA256_MAC_LEN];
1524 if (e_snonce2 == NULL) {
1525 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce2 received");
1529 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce2", e_snonce2,
1530 WPS_SECRET_NONCE_LEN);
1532 /* E-Hash2 = HMAC_AuthKey(E-S2 || PSK2 || PK_E || PK_R) */
1533 addr[0] = e_snonce2;
1534 len[0] = WPS_SECRET_NONCE_LEN;
1535 addr[1] = wps->psk2;
1536 len[1] = WPS_PSK_LEN;
1537 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1538 len[2] = wpabuf_len(wps->dh_pubkey_e);
1539 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1540 len[3] = wpabuf_len(wps->dh_pubkey_r);
1541 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1543 if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
1544 wpa_printf(MSG_DEBUG, "WPS: E-Hash2 derived from E-S2 does "
1545 "not match with the pre-committed value");
1546 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
1547 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1548 wps_pwd_auth_fail_event(wps->wps, 0, 2);
1552 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the second "
1553 "half of the device password");
1554 wps->wps_pin_revealed = 0;
1555 wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
1561 static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
1563 if (mac_addr == NULL) {
1564 wpa_printf(MSG_DEBUG, "WPS: No MAC Address received");
1568 wpa_printf(MSG_DEBUG, "WPS: Enrollee MAC Address " MACSTR,
1570 os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
1571 os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
1577 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
1580 if (pk == NULL || pk_len == 0) {
1581 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
1585 wpabuf_free(wps->dh_pubkey_e);
1586 wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
1587 if (wps->dh_pubkey_e == NULL)
1594 static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
1599 wpa_printf(MSG_DEBUG, "WPS: No Authentication Type flags "
1604 auth_types = WPA_GET_BE16(auth);
1606 wpa_printf(MSG_DEBUG, "WPS: Enrollee Authentication Type flags 0x%x",
1608 wps->auth_type = wps->wps->auth_types & auth_types;
1609 if (wps->auth_type == 0) {
1610 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
1611 "authentication types (own 0x%x Enrollee 0x%x)",
1612 wps->wps->auth_types, auth_types);
1620 static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
1625 wpa_printf(MSG_DEBUG, "WPS: No Encryption Type flags "
1630 encr_types = WPA_GET_BE16(encr);
1632 wpa_printf(MSG_DEBUG, "WPS: Enrollee Encryption Type flags 0x%x",
1634 wps->encr_type = wps->wps->encr_types & encr_types;
1635 if (wps->encr_type == 0) {
1636 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
1637 "encryption types");
1645 static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
1648 wpa_printf(MSG_DEBUG, "WPS: No Connection Type flags "
1653 wpa_printf(MSG_DEBUG, "WPS: Enrollee Connection Type flags 0x%x",
1660 static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
1664 if (methods == NULL) {
1665 wpa_printf(MSG_DEBUG, "WPS: No Config Methods received");
1669 m = WPA_GET_BE16(methods);
1671 wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x", m);
1677 static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
1679 if (state == NULL) {
1680 wpa_printf(MSG_DEBUG, "WPS: No Wi-Fi Protected Setup State "
1685 wpa_printf(MSG_DEBUG, "WPS: Enrollee Wi-Fi Protected Setup State %d",
1692 static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
1696 if (assoc == NULL) {
1697 wpa_printf(MSG_DEBUG, "WPS: No Association State received");
1701 a = WPA_GET_BE16(assoc);
1702 wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a);
1708 static int wps_process_config_error(struct wps_data *wps, const u8 *err)
1713 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received");
1717 e = WPA_GET_BE16(err);
1718 wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e);
1724 static enum wps_process_res wps_process_m1(struct wps_data *wps,
1725 struct wps_parse_attr *attr)
1727 wpa_printf(MSG_DEBUG, "WPS: Received M1");
1729 if (wps->state != RECV_M1) {
1730 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1731 "receiving M1", wps->state);
1735 if (wps_process_uuid_e(wps, attr->uuid_e) ||
1736 wps_process_mac_addr(wps, attr->mac_addr) ||
1737 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
1738 wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
1739 wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
1740 wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
1741 wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
1742 wps_process_config_methods(wps, attr->config_methods) ||
1743 wps_process_wps_state(wps, attr->wps_state) ||
1744 wps_process_device_attrs(&wps->peer_dev, attr) ||
1745 wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
1746 wps_process_assoc_state(wps, attr->assoc_state) ||
1747 wps_process_dev_password_id(wps, attr->dev_password_id) ||
1748 wps_process_config_error(wps, attr->config_error) ||
1749 wps_process_os_version(&wps->peer_dev, attr->os_version))
1752 if (wps->dev_pw_id != DEV_PW_DEFAULT &&
1753 wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
1754 wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
1755 wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
1756 (wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
1757 !wps->wps->registrar->pbc)) {
1758 wpa_printf(MSG_DEBUG, "WPS: Unsupported Device Password ID %d",
1760 wps->state = SEND_M2D;
1761 return WPS_CONTINUE;
1764 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
1765 if (wps_registrar_pbc_overlap(wps->wps->registrar,
1766 wps->mac_addr_e, wps->uuid_e)) {
1767 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - deny PBC "
1769 wps->state = SEND_M2D;
1770 return WPS_CONTINUE;
1772 wps_registrar_add_pbc_session(wps->wps->registrar,
1773 wps->mac_addr_e, wps->uuid_e);
1777 wps->state = SEND_M2;
1778 return WPS_CONTINUE;
1782 static enum wps_process_res wps_process_m3(struct wps_data *wps,
1783 const struct wpabuf *msg,
1784 struct wps_parse_attr *attr)
1786 wpa_printf(MSG_DEBUG, "WPS: Received M3");
1788 if (wps->state != RECV_M3) {
1789 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1790 "receiving M3", wps->state);
1791 wps->state = SEND_WSC_NACK;
1792 return WPS_CONTINUE;
1795 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
1796 wps_process_authenticator(wps, attr->authenticator, msg) ||
1797 wps_process_e_hash1(wps, attr->e_hash1) ||
1798 wps_process_e_hash2(wps, attr->e_hash2)) {
1799 wps->state = SEND_WSC_NACK;
1800 return WPS_CONTINUE;
1803 wps->state = SEND_M4;
1804 return WPS_CONTINUE;
1808 static enum wps_process_res wps_process_m5(struct wps_data *wps,
1809 const struct wpabuf *msg,
1810 struct wps_parse_attr *attr)
1812 struct wpabuf *decrypted;
1813 struct wps_parse_attr eattr;
1815 wpa_printf(MSG_DEBUG, "WPS: Received M5");
1817 if (wps->state != RECV_M5) {
1818 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1819 "receiving M5", wps->state);
1820 wps->state = SEND_WSC_NACK;
1821 return WPS_CONTINUE;
1824 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
1825 wps_process_authenticator(wps, attr->authenticator, msg)) {
1826 wps->state = SEND_WSC_NACK;
1827 return WPS_CONTINUE;
1830 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1831 attr->encr_settings_len);
1832 if (decrypted == NULL) {
1833 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1834 "Settings attribute");
1835 wps->state = SEND_WSC_NACK;
1836 return WPS_CONTINUE;
1839 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1841 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1842 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1843 wps_process_e_snonce1(wps, eattr.e_snonce1)) {
1844 wpabuf_free(decrypted);
1845 wps->state = SEND_WSC_NACK;
1846 return WPS_CONTINUE;
1848 wpabuf_free(decrypted);
1850 wps->state = SEND_M6;
1851 return WPS_CONTINUE;
1855 static int wps_process_ap_settings_r(struct wps_data *wps,
1856 struct wps_parse_attr *attr)
1861 /* AP Settings Attributes in M7 when Enrollee is an AP */
1862 if (wps_process_ap_settings(attr, &wps->cred) < 0)
1865 wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
1868 * TODO: Provide access to AP settings and allow changes before sending
1869 * out M8. For now, just copy the settings unchanged into M8.
1876 static enum wps_process_res wps_process_m7(struct wps_data *wps,
1877 const struct wpabuf *msg,
1878 struct wps_parse_attr *attr)
1880 struct wpabuf *decrypted;
1881 struct wps_parse_attr eattr;
1883 wpa_printf(MSG_DEBUG, "WPS: Received M7");
1885 if (wps->state != RECV_M7) {
1886 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
1887 "receiving M7", wps->state);
1888 wps->state = SEND_WSC_NACK;
1889 return WPS_CONTINUE;
1892 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
1893 wps_process_authenticator(wps, attr->authenticator, msg)) {
1894 wps->state = SEND_WSC_NACK;
1895 return WPS_CONTINUE;
1898 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
1899 attr->encr_settings_len);
1900 if (decrypted == NULL) {
1901 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
1902 "Settings attribute");
1903 wps->state = SEND_WSC_NACK;
1904 return WPS_CONTINUE;
1907 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
1909 if (wps_parse_msg(decrypted, &eattr) < 0 ||
1910 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
1911 wps_process_e_snonce2(wps, eattr.e_snonce2) ||
1912 wps_process_ap_settings_r(wps, &eattr)) {
1913 wpabuf_free(decrypted);
1914 wps->state = SEND_WSC_NACK;
1915 return WPS_CONTINUE;
1918 wpabuf_free(decrypted);
1920 wps->state = SEND_M8;
1921 return WPS_CONTINUE;
1925 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
1926 const struct wpabuf *msg)
1928 struct wps_parse_attr attr;
1929 enum wps_process_res ret = WPS_CONTINUE;
1931 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
1933 if (wps_parse_msg(msg, &attr) < 0)
1936 if (attr.version == NULL || *attr.version != WPS_VERSION) {
1937 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
1938 attr.version ? *attr.version : 0);
1942 if (attr.msg_type == NULL) {
1943 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
1947 if (*attr.msg_type != WPS_M1 &&
1948 (attr.registrar_nonce == NULL ||
1949 os_memcmp(wps->nonce_r, attr.registrar_nonce,
1950 WPS_NONCE_LEN != 0))) {
1951 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
1955 switch (*attr.msg_type) {
1957 #ifdef CONFIG_WPS_UPNP
1958 if (wps->wps->wps_upnp && attr.mac_addr) {
1959 /* Remove old pending messages when starting new run */
1960 wpabuf_free(wps->wps->upnp_msg);
1961 wps->wps->upnp_msg = NULL;
1963 upnp_wps_device_send_wlan_event(
1964 wps->wps->wps_upnp, attr.mac_addr,
1965 UPNP_WPS_WLANEVENT_TYPE_EAP, msg);
1967 #endif /* CONFIG_WPS_UPNP */
1968 ret = wps_process_m1(wps, &attr);
1971 ret = wps_process_m3(wps, msg, &attr);
1972 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1973 wps_fail_event(wps->wps, WPS_M3);
1976 ret = wps_process_m5(wps, msg, &attr);
1977 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1978 wps_fail_event(wps->wps, WPS_M5);
1981 ret = wps_process_m7(wps, msg, &attr);
1982 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
1983 wps_fail_event(wps->wps, WPS_M7);
1986 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
1991 if (ret == WPS_CONTINUE) {
1992 /* Save a copy of the last message for Authenticator derivation
1994 wpabuf_free(wps->last_msg);
1995 wps->last_msg = wpabuf_dup(msg);
2002 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
2003 const struct wpabuf *msg)
2005 struct wps_parse_attr attr;
2007 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
2009 if (wps_parse_msg(msg, &attr) < 0)
2012 if (attr.version == NULL || *attr.version != WPS_VERSION) {
2013 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2014 attr.version ? *attr.version : 0);
2018 if (attr.msg_type == NULL) {
2019 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2023 if (*attr.msg_type != WPS_WSC_ACK) {
2024 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2029 #ifdef CONFIG_WPS_UPNP
2030 if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
2031 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2032 if (wps->wps->upnp_msg)
2033 return WPS_CONTINUE;
2034 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2035 "external Registrar");
2038 #endif /* CONFIG_WPS_UPNP */
2040 if (attr.registrar_nonce == NULL ||
2041 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2043 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2047 if (attr.enrollee_nonce == NULL ||
2048 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2049 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2053 if (wps->state == RECV_M2D_ACK) {
2054 #ifdef CONFIG_WPS_UPNP
2055 if (wps->wps->wps_upnp &&
2056 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2057 if (wps->wps->upnp_msg)
2058 return WPS_CONTINUE;
2059 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2060 "external Registrar");
2063 #endif /* CONFIG_WPS_UPNP */
2065 wpa_printf(MSG_DEBUG, "WPS: No more registrars available - "
2066 "terminate negotiation");
2073 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
2074 const struct wpabuf *msg)
2076 struct wps_parse_attr attr;
2079 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
2081 old_state = wps->state;
2082 wps->state = SEND_WSC_NACK;
2084 if (wps_parse_msg(msg, &attr) < 0)
2087 if (attr.version == NULL || *attr.version != WPS_VERSION) {
2088 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2089 attr.version ? *attr.version : 0);
2093 if (attr.msg_type == NULL) {
2094 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2098 if (*attr.msg_type != WPS_WSC_NACK) {
2099 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2104 #ifdef CONFIG_WPS_UPNP
2105 if (wps->wps->wps_upnp && wps->ext_reg) {
2106 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2107 "Registrar terminated by the Enrollee");
2110 #endif /* CONFIG_WPS_UPNP */
2112 if (attr.registrar_nonce == NULL ||
2113 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2115 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2119 if (attr.enrollee_nonce == NULL ||
2120 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2121 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2125 if (attr.config_error == NULL) {
2126 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
2131 wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
2132 "Configuration Error %d", WPA_GET_BE16(attr.config_error));
2134 switch (old_state) {
2136 wps_fail_event(wps->wps, WPS_M2);
2139 wps_fail_event(wps->wps, WPS_M4);
2142 wps_fail_event(wps->wps, WPS_M6);
2145 wps_fail_event(wps->wps, WPS_M8);
2155 static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
2156 const struct wpabuf *msg)
2158 struct wps_parse_attr attr;
2160 wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done");
2162 if (wps->state != RECV_DONE &&
2163 (!wps->wps->wps_upnp || !wps->ext_reg)) {
2164 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2165 "receiving WSC_Done", wps->state);
2169 if (wps_parse_msg(msg, &attr) < 0)
2172 if (attr.version == NULL || *attr.version != WPS_VERSION) {
2173 wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
2174 attr.version ? *attr.version : 0);
2178 if (attr.msg_type == NULL) {
2179 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2183 if (*attr.msg_type != WPS_WSC_DONE) {
2184 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2189 #ifdef CONFIG_WPS_UPNP
2190 if (wps->wps->wps_upnp && wps->ext_reg) {
2191 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2192 "Registrar completed successfully");
2195 #endif /* CONFIG_WPS_UPNP */
2197 if (attr.registrar_nonce == NULL ||
2198 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2200 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2204 if (attr.enrollee_nonce == NULL ||
2205 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2206 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2210 wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
2212 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
2213 wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
2214 struct wps_credential cred;
2216 wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based "
2217 "on first Enrollee connection");
2219 os_memset(&cred, 0, sizeof(cred));
2220 os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
2221 cred.ssid_len = wps->wps->ssid_len;
2222 cred.auth_type = WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK;
2223 cred.encr_type = WPS_ENCR_TKIP | WPS_ENCR_AES;
2224 os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
2225 cred.key_len = wps->new_psk_len;
2227 wps->wps->wps_state = WPS_STATE_CONFIGURED;
2228 wpa_hexdump_ascii_key(MSG_DEBUG,
2229 "WPS: Generated random passphrase",
2230 wps->new_psk, wps->new_psk_len);
2231 if (wps->wps->cred_cb)
2232 wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
2234 os_free(wps->new_psk);
2235 wps->new_psk = NULL;
2238 if (!wps->wps->ap) {
2239 wpa_printf(MSG_DEBUG, "WPS: Update local configuration based "
2240 "on the modified AP configuration");
2241 if (wps->wps->cred_cb)
2242 wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
2246 if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
2247 wps->new_psk, wps->new_psk_len)) {
2248 wpa_printf(MSG_DEBUG, "WPS: Failed to configure the "
2251 os_free(wps->new_psk);
2252 wps->new_psk = NULL;
2255 wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e);
2258 wps_registrar_remove_pbc_session(wps->wps->registrar,
2259 wps->mac_addr_e, wps->uuid_e);
2260 wps_registrar_pbc_completed(wps->wps->registrar);
2263 wps_success_event(wps->wps);
2269 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
2270 enum wsc_op_code op_code,
2271 const struct wpabuf *msg)
2273 enum wps_process_res ret;
2275 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
2277 (unsigned long) wpabuf_len(msg), op_code);
2279 #ifdef CONFIG_WPS_UPNP
2280 if (wps->wps->wps_upnp && wps->ext_reg && wps->wps->upnp_msg == NULL &&
2281 (op_code == WSC_MSG || op_code == WSC_Done)) {
2282 struct wps_parse_attr attr;
2284 if (wps_parse_msg(msg, &attr) < 0 || attr.msg_type == NULL)
2287 type = *attr.msg_type;
2288 wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)"
2289 " to external Registrar for processing", type);
2290 upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
2292 UPNP_WPS_WLANEVENT_TYPE_EAP,
2294 if (op_code == WSC_MSG)
2296 } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
2297 wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using "
2298 "external Registrar");
2299 return WPS_CONTINUE;
2301 #endif /* CONFIG_WPS_UPNP */
2305 return wps_process_wsc_msg(wps, msg);
2307 return wps_process_wsc_ack(wps, msg);
2309 return wps_process_wsc_nack(wps, msg);
2311 ret = wps_process_wsc_done(wps, msg);
2312 if (ret == WPS_FAILURE) {
2313 wps->state = SEND_WSC_NACK;
2314 wps_fail_event(wps->wps, WPS_WSC_DONE);
2318 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
2324 int wps_registrar_update_ie(struct wps_registrar *reg)
2326 return wps_set_ie(reg);
2330 static void wps_registrar_set_selected_timeout(void *eloop_ctx,
2333 struct wps_registrar *reg = eloop_ctx;
2335 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar timed out - "
2336 "unselect Registrar");
2337 reg->selected_registrar = 0;
2339 reg->sel_reg_dev_password_id_override = -1;
2340 reg->sel_reg_config_methods_override = -1;
2346 * wps_registrar_set_selected_registrar - Notification of SetSelectedRegistrar
2347 * @reg: Registrar data from wps_registrar_init()
2348 * @msg: Received message from SetSelectedRegistrar
2349 * @msg_len: Length of msg in octets
2350 * Returns: 0 on success, -1 on failure
2352 * This function is called when an AP receives a SetSelectedRegistrar UPnP
2355 int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
2356 const struct wpabuf *msg)
2358 struct wps_parse_attr attr;
2360 wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
2363 if (wps_parse_msg(msg, &attr) < 0 ||
2364 attr.version == NULL || *attr.version != WPS_VERSION) {
2365 wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
2366 "version 0x%x", attr.version ? *attr.version : 0);
2370 if (attr.selected_registrar == NULL ||
2371 *attr.selected_registrar == 0) {
2372 wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
2373 "Selected Registrar");
2374 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg,
2376 wps_registrar_set_selected_timeout(reg, NULL);
2380 reg->selected_registrar = 1;
2381 reg->sel_reg_dev_password_id_override = attr.dev_password_id ?
2382 WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
2383 reg->sel_reg_config_methods_override = attr.sel_reg_config_methods ?
2384 WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
2387 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
2388 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
2389 wps_registrar_set_selected_timeout,