2 * Wi-Fi Protected Setup - Registrar
3 * Copyright (c) 2008-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.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/base64.h"
19 #include "utils/eloop.h"
20 #include "utils/uuid.h"
21 #include "utils/list.h"
22 #include "crypto/crypto.h"
23 #include "crypto/sha256.h"
24 #include "common/ieee802_11_defs.h"
26 #include "wps_dev_attr.h"
28 #include "wps_upnp_i.h"
30 #ifndef CONFIG_WPS_STRICT
31 #define WPS_WORKAROUNDS
32 #endif /* CONFIG_WPS_STRICT */
36 u8 uuid[WPS_UUID_LEN];
40 #define PIN_LOCKED BIT(0)
41 #define PIN_EXPIRES BIT(1)
43 struct os_time expiration;
44 u8 enrollee_addr[ETH_ALEN];
48 static void wps_free_pin(struct wps_uuid_pin *pin)
55 static void wps_remove_pin(struct wps_uuid_pin *pin)
57 dl_list_del(&pin->list);
62 static void wps_free_pins(struct dl_list *pins)
64 struct wps_uuid_pin *pin, *prev;
65 dl_list_for_each_safe(pin, prev, pins, struct wps_uuid_pin, list)
70 struct wps_pbc_session {
71 struct wps_pbc_session *next;
73 u8 uuid_e[WPS_UUID_LEN];
74 struct os_time timestamp;
78 static void wps_free_pbc_sessions(struct wps_pbc_session *pbc)
80 struct wps_pbc_session *prev;
90 struct wps_registrar_device {
91 struct wps_registrar_device *next;
92 struct wps_device_data dev;
93 u8 uuid[WPS_UUID_LEN];
97 struct wps_registrar {
98 struct wps_context *wps;
101 int selected_registrar;
103 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
105 int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
106 struct wpabuf *probe_resp_ie);
107 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
108 const struct wps_device_data *dev);
109 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
111 void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
112 u16 sel_reg_config_methods);
113 void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
114 const u8 *pri_dev_type, u16 config_methods,
115 u16 dev_password_id, u8 request_type,
116 const char *dev_name);
120 struct wps_pbc_session *pbc_sessions;
123 struct wpabuf *extra_cred;
124 int disable_auto_conf;
126 int sel_reg_dev_password_id_override;
127 int sel_reg_config_methods_override;
130 struct wps_registrar_device *devices;
132 int force_pbc_overlap;
134 u8 authorized_macs[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
135 u8 authorized_macs_union[WPS_MAX_AUTHORIZED_MACS][ETH_ALEN];
139 static int wps_set_ie(struct wps_registrar *reg);
140 static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx);
141 static void wps_registrar_set_selected_timeout(void *eloop_ctx,
145 static void wps_registrar_add_authorized_mac(struct wps_registrar *reg,
149 wpa_printf(MSG_DEBUG, "WPS: Add authorized MAC " MACSTR,
151 for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++)
152 if (os_memcmp(reg->authorized_macs[i], addr, ETH_ALEN) == 0) {
153 wpa_printf(MSG_DEBUG, "WPS: Authorized MAC was "
154 "already in the list");
155 return; /* already in list */
157 for (i = WPS_MAX_AUTHORIZED_MACS - 1; i > 0; i--)
158 os_memcpy(reg->authorized_macs[i], reg->authorized_macs[i - 1],
160 os_memcpy(reg->authorized_macs[0], addr, ETH_ALEN);
161 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs",
162 (u8 *) reg->authorized_macs, sizeof(reg->authorized_macs));
166 static void wps_registrar_remove_authorized_mac(struct wps_registrar *reg,
170 wpa_printf(MSG_DEBUG, "WPS: Remove authorized MAC " MACSTR,
172 for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++) {
173 if (os_memcmp(reg->authorized_macs, addr, ETH_ALEN) == 0)
176 if (i == WPS_MAX_AUTHORIZED_MACS) {
177 wpa_printf(MSG_DEBUG, "WPS: Authorized MAC was not in the "
179 return; /* not in the list */
181 for (; i + 1 < WPS_MAX_AUTHORIZED_MACS; i++)
182 os_memcpy(reg->authorized_macs[i], reg->authorized_macs[i + 1],
184 os_memset(reg->authorized_macs[WPS_MAX_AUTHORIZED_MACS - 1], 0,
186 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs",
187 (u8 *) reg->authorized_macs, sizeof(reg->authorized_macs));
191 static void wps_free_devices(struct wps_registrar_device *dev)
193 struct wps_registrar_device *prev;
198 wps_device_data_free(&prev->dev);
204 static struct wps_registrar_device * wps_device_get(struct wps_registrar *reg,
207 struct wps_registrar_device *dev;
209 for (dev = reg->devices; dev; dev = dev->next) {
210 if (os_memcmp(dev->dev.mac_addr, addr, ETH_ALEN) == 0)
217 static void wps_device_clone_data(struct wps_device_data *dst,
218 struct wps_device_data *src)
220 os_memcpy(dst->mac_addr, src->mac_addr, ETH_ALEN);
221 os_memcpy(dst->pri_dev_type, src->pri_dev_type, WPS_DEV_TYPE_LEN);
223 #define WPS_STRDUP(n) \
225 dst->n = src->n ? os_strdup(src->n) : NULL
227 WPS_STRDUP(device_name);
228 WPS_STRDUP(manufacturer);
229 WPS_STRDUP(model_name);
230 WPS_STRDUP(model_number);
231 WPS_STRDUP(serial_number);
236 int wps_device_store(struct wps_registrar *reg,
237 struct wps_device_data *dev, const u8 *uuid)
239 struct wps_registrar_device *d;
241 d = wps_device_get(reg, dev->mac_addr);
243 d = os_zalloc(sizeof(*d));
246 d->next = reg->devices;
250 wps_device_clone_data(&d->dev, dev);
251 os_memcpy(d->uuid, uuid, WPS_UUID_LEN);
257 static void wps_registrar_add_pbc_session(struct wps_registrar *reg,
258 const u8 *addr, const u8 *uuid_e)
260 struct wps_pbc_session *pbc, *prev = NULL;
265 pbc = reg->pbc_sessions;
267 if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
268 os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
270 prev->next = pbc->next;
272 reg->pbc_sessions = pbc->next;
280 pbc = os_zalloc(sizeof(*pbc));
283 os_memcpy(pbc->addr, addr, ETH_ALEN);
285 os_memcpy(pbc->uuid_e, uuid_e, WPS_UUID_LEN);
288 pbc->next = reg->pbc_sessions;
289 reg->pbc_sessions = pbc;
290 pbc->timestamp = now;
292 /* remove entries that have timed out */
297 if (now.sec > pbc->timestamp.sec + WPS_PBC_WALK_TIME) {
299 wps_free_pbc_sessions(pbc);
308 static void wps_registrar_remove_pbc_session(struct wps_registrar *reg,
309 const u8 *addr, const u8 *uuid_e)
311 struct wps_pbc_session *pbc, *prev = NULL;
313 pbc = reg->pbc_sessions;
315 if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
316 os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
318 prev->next = pbc->next;
320 reg->pbc_sessions = pbc->next;
330 int wps_registrar_pbc_overlap(struct wps_registrar *reg,
331 const u8 *addr, const u8 *uuid_e)
334 struct wps_pbc_session *pbc;
339 for (pbc = reg->pbc_sessions; pbc; pbc = pbc->next) {
340 if (now.sec > pbc->timestamp.sec + WPS_PBC_WALK_TIME)
342 if (addr == NULL || os_memcmp(addr, pbc->addr, ETH_ALEN) ||
344 os_memcmp(uuid_e, pbc->uuid_e, WPS_UUID_LEN))
351 return count > 1 ? 1 : 0;
355 static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
357 wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
359 wpabuf_put_be16(msg, ATTR_WPS_STATE);
360 wpabuf_put_be16(msg, 1);
361 wpabuf_put_u8(msg, wps->wps_state);
366 #ifdef CONFIG_WPS_UPNP
367 static void wps_registrar_free_pending_m2(struct wps_context *wps)
369 struct upnp_pending_message *p, *p2, *prev = NULL;
372 if (p->type == WPS_M2 || p->type == WPS_M2D) {
374 wps->upnp_msgs = p->next;
376 prev->next = p->next;
377 wpa_printf(MSG_DEBUG, "WPS UPnP: Drop pending M2/M2D");
380 wpabuf_free(p2->msg);
388 #endif /* CONFIG_WPS_UPNP */
391 static int wps_build_ap_setup_locked(struct wps_context *wps,
394 if (wps->ap_setup_locked) {
395 wpa_printf(MSG_DEBUG, "WPS: * AP Setup Locked");
396 wpabuf_put_be16(msg, ATTR_AP_SETUP_LOCKED);
397 wpabuf_put_be16(msg, 1);
398 wpabuf_put_u8(msg, 1);
404 static int wps_build_selected_registrar(struct wps_registrar *reg,
407 if (!reg->sel_reg_union)
409 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
410 wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR);
411 wpabuf_put_be16(msg, 1);
412 wpabuf_put_u8(msg, 1);
417 static int wps_build_sel_reg_dev_password_id(struct wps_registrar *reg,
420 u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
421 if (!reg->sel_reg_union)
423 if (reg->sel_reg_dev_password_id_override >= 0)
424 id = reg->sel_reg_dev_password_id_override;
425 wpa_printf(MSG_DEBUG, "WPS: * Device Password ID (%d)", id);
426 wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
427 wpabuf_put_be16(msg, 2);
428 wpabuf_put_be16(msg, id);
433 static void wps_set_pushbutton(u16 *methods, u16 conf_methods)
435 *methods |= WPS_CONFIG_PUSHBUTTON;
437 if (conf_methods & WPS_CONFIG_VIRT_PUSHBUTTON)
438 *methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
439 if (conf_methods & WPS_CONFIG_PHY_PUSHBUTTON)
440 *methods |= WPS_CONFIG_PHY_PUSHBUTTON;
441 if ((*methods & WPS_CONFIG_VIRT_PUSHBUTTON) !=
442 WPS_CONFIG_VIRT_PUSHBUTTON ||
443 (*methods & WPS_CONFIG_PHY_PUSHBUTTON) !=
444 WPS_CONFIG_PHY_PUSHBUTTON) {
446 * Required to include virtual/physical flag, but we were not
447 * configured with push button type, so have to default to one
450 *methods |= WPS_CONFIG_PHY_PUSHBUTTON;
452 #endif /* CONFIG_WPS2 */
456 static int wps_build_sel_reg_config_methods(struct wps_registrar *reg,
460 if (!reg->sel_reg_union)
462 methods = reg->wps->config_methods;
463 methods &= ~WPS_CONFIG_PUSHBUTTON;
465 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
466 WPS_CONFIG_PHY_PUSHBUTTON);
467 #endif /* CONFIG_WPS2 */
469 wps_set_pushbutton(&methods, reg->wps->config_methods);
470 if (reg->sel_reg_config_methods_override >= 0)
471 methods = reg->sel_reg_config_methods_override;
472 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar Config Methods (%x)",
474 wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR_CONFIG_METHODS);
475 wpabuf_put_be16(msg, 2);
476 wpabuf_put_be16(msg, methods);
481 static int wps_build_probe_config_methods(struct wps_registrar *reg,
486 * These are the methods that the AP supports as an Enrollee for adding
487 * external Registrars.
489 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
491 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
492 WPS_CONFIG_PHY_PUSHBUTTON);
493 #endif /* CONFIG_WPS2 */
494 wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
495 wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
496 wpabuf_put_be16(msg, 2);
497 wpabuf_put_be16(msg, methods);
502 static int wps_build_config_methods_r(struct wps_registrar *reg,
506 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
508 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
509 WPS_CONFIG_PHY_PUSHBUTTON);
510 #endif /* CONFIG_WPS2 */
512 wps_set_pushbutton(&methods, reg->wps->config_methods);
513 return wps_build_config_methods(msg, methods);
517 const u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count)
522 while (*count < WPS_MAX_AUTHORIZED_MACS) {
523 if (is_zero_ether_addr(reg->authorized_macs_union[*count]))
527 #endif /* CONFIG_WPS2 */
529 return (const u8 *) reg->authorized_macs_union;
534 * wps_registrar_init - Initialize WPS Registrar data
535 * @wps: Pointer to longterm WPS context
536 * @cfg: Registrar configuration
537 * Returns: Pointer to allocated Registrar data or %NULL on failure
539 * This function is used to initialize WPS Registrar functionality. It can be
540 * used for a single Registrar run (e.g., when run in a supplicant) or multiple
541 * runs (e.g., when run as an internal Registrar in an AP). Caller is
542 * responsible for freeing the returned data with wps_registrar_deinit() when
543 * Registrar functionality is not needed anymore.
545 struct wps_registrar *
546 wps_registrar_init(struct wps_context *wps,
547 const struct wps_registrar_config *cfg)
549 struct wps_registrar *reg = os_zalloc(sizeof(*reg));
553 dl_list_init(®->pins);
555 reg->new_psk_cb = cfg->new_psk_cb;
556 reg->set_ie_cb = cfg->set_ie_cb;
557 reg->pin_needed_cb = cfg->pin_needed_cb;
558 reg->reg_success_cb = cfg->reg_success_cb;
559 reg->set_sel_reg_cb = cfg->set_sel_reg_cb;
560 reg->enrollee_seen_cb = cfg->enrollee_seen_cb;
561 reg->cb_ctx = cfg->cb_ctx;
562 reg->skip_cred_build = cfg->skip_cred_build;
563 if (cfg->extra_cred) {
564 reg->extra_cred = wpabuf_alloc_copy(cfg->extra_cred,
565 cfg->extra_cred_len);
566 if (reg->extra_cred == NULL) {
571 reg->disable_auto_conf = cfg->disable_auto_conf;
572 reg->sel_reg_dev_password_id_override = -1;
573 reg->sel_reg_config_methods_override = -1;
574 reg->static_wep_only = cfg->static_wep_only;
576 if (wps_set_ie(reg)) {
577 wps_registrar_deinit(reg);
586 * wps_registrar_deinit - Deinitialize WPS Registrar data
587 * @reg: Registrar data from wps_registrar_init()
589 void wps_registrar_deinit(struct wps_registrar *reg)
593 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
594 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
595 wps_free_pins(®->pins);
596 wps_free_pbc_sessions(reg->pbc_sessions);
597 wpabuf_free(reg->extra_cred);
598 wps_free_devices(reg->devices);
604 * wps_registrar_add_pin - Configure a new PIN for Registrar
605 * @reg: Registrar data from wps_registrar_init()
606 * @addr: Enrollee MAC address or %NULL if not known
607 * @uuid: UUID-E or %NULL for wildcard (any UUID)
608 * @pin: PIN (Device Password)
609 * @pin_len: Length of pin in octets
610 * @timeout: Time (in seconds) when the PIN will be invalidated; 0 = no timeout
611 * Returns: 0 on success, -1 on failure
613 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
614 const u8 *uuid, const u8 *pin, size_t pin_len,
617 struct wps_uuid_pin *p;
619 p = os_zalloc(sizeof(*p));
623 os_memcpy(p->enrollee_addr, addr, ETH_ALEN);
625 p->wildcard_uuid = 1;
627 os_memcpy(p->uuid, uuid, WPS_UUID_LEN);
628 p->pin = os_malloc(pin_len);
629 if (p->pin == NULL) {
633 os_memcpy(p->pin, pin, pin_len);
634 p->pin_len = pin_len;
637 p->flags |= PIN_EXPIRES;
638 os_get_time(&p->expiration);
639 p->expiration.sec += timeout;
642 dl_list_add(®->pins, &p->list);
644 wpa_printf(MSG_DEBUG, "WPS: A new PIN configured (timeout=%d)",
646 wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
647 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
648 reg->selected_registrar = 1;
651 wps_registrar_add_authorized_mac(reg, addr);
653 wps_registrar_add_authorized_mac(
654 reg, (u8 *) "\xff\xff\xff\xff\xff\xff");
655 wps_registrar_selected_registrar_changed(reg);
656 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
657 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
658 wps_registrar_set_selected_timeout,
665 static void wps_registrar_expire_pins(struct wps_registrar *reg)
667 struct wps_uuid_pin *pin, *prev;
671 dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
673 if ((pin->flags & PIN_EXPIRES) &&
674 os_time_before(&pin->expiration, &now)) {
677 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
678 wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID",
679 pin->uuid, WPS_UUID_LEN);
680 if (is_zero_ether_addr(pin->enrollee_addr))
683 addr = pin->enrollee_addr;
684 wps_registrar_remove_authorized_mac(reg, addr);
686 wps_registrar_selected_registrar_changed(reg);
693 * wps_registrar_invalidate_pin - Invalidate a PIN for a specific UUID-E
694 * @reg: Registrar data from wps_registrar_init()
696 * Returns: 0 on success, -1 on failure (e.g., PIN not found)
698 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid)
700 struct wps_uuid_pin *pin, *prev;
702 dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
704 if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
707 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
708 wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
709 pin->uuid, WPS_UUID_LEN);
710 if (is_zero_ether_addr(pin->enrollee_addr))
713 addr = pin->enrollee_addr;
714 wps_registrar_remove_authorized_mac(reg, addr);
716 wps_registrar_selected_registrar_changed(reg);
725 static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
726 const u8 *uuid, size_t *pin_len)
728 struct wps_uuid_pin *pin, *found = NULL;
730 wps_registrar_expire_pins(reg);
732 dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
733 if (!pin->wildcard_uuid &&
734 os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
741 /* Check for wildcard UUIDs since none of the UUID-specific
743 dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
744 if (pin->wildcard_uuid == 1) {
745 wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
746 "PIN. Assigned it for this UUID-E");
747 pin->wildcard_uuid = 2;
748 os_memcpy(pin->uuid, uuid, WPS_UUID_LEN);
759 * Lock the PIN to avoid attacks based on concurrent re-use of the PIN
760 * that could otherwise avoid PIN invalidations.
762 if (found->flags & PIN_LOCKED) {
763 wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
764 "allow concurrent re-use");
767 *pin_len = found->pin_len;
768 found->flags |= PIN_LOCKED;
774 * wps_registrar_unlock_pin - Unlock a PIN for a specific UUID-E
775 * @reg: Registrar data from wps_registrar_init()
777 * Returns: 0 on success, -1 on failure
779 * PINs are locked to enforce only one concurrent use. This function unlocks a
780 * PIN to allow it to be used again. If the specified PIN was configured using
781 * a wildcard UUID, it will be removed instead of allowing multiple uses.
783 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid)
785 struct wps_uuid_pin *pin;
787 dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
788 if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
789 if (pin->wildcard_uuid == 2) {
790 wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
792 return wps_registrar_invalidate_pin(reg, uuid);
794 pin->flags &= ~PIN_LOCKED;
803 static void wps_registrar_stop_pbc(struct wps_registrar *reg)
805 reg->selected_registrar = 0;
807 wps_registrar_selected_registrar_changed(reg);
811 static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx)
813 struct wps_registrar *reg = eloop_ctx;
815 wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
816 wps_pbc_timeout_event(reg->wps);
817 wps_registrar_stop_pbc(reg);
822 * wps_registrar_button_pushed - Notify Registrar that AP button was pushed
823 * @reg: Registrar data from wps_registrar_init()
824 * Returns: 0 on success, -1 on failure
826 * This function is called on an AP when a push button is pushed to activate
827 * PBC mode. The PBC mode will be stopped after walk time (2 minutes) timeout
828 * or when a PBC registration is completed.
830 int wps_registrar_button_pushed(struct wps_registrar *reg)
832 if (wps_registrar_pbc_overlap(reg, NULL, NULL)) {
833 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
835 wps_pbc_overlap_event(reg->wps);
838 wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
839 reg->force_pbc_overlap = 0;
840 reg->selected_registrar = 1;
842 wps_registrar_selected_registrar_changed(reg);
844 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
845 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
851 static void wps_registrar_pbc_completed(struct wps_registrar *reg)
853 wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
854 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
855 wps_registrar_stop_pbc(reg);
859 static void wps_registrar_pin_completed(struct wps_registrar *reg)
861 wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
862 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
863 reg->selected_registrar = 0;
864 wps_registrar_selected_registrar_changed(reg);
869 * wps_registrar_probe_req_rx - Notify Registrar of Probe Request
870 * @reg: Registrar data from wps_registrar_init()
871 * @addr: MAC address of the Probe Request sender
872 * @wps_data: WPS IE contents
874 * This function is called on an AP when a Probe Request with WPS IE is
875 * received. This is used to track PBC mode use and to detect possible overlap
876 * situation with other WPS APs.
878 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
879 const struct wpabuf *wps_data)
881 struct wps_parse_attr attr;
883 wpa_hexdump_buf(MSG_MSGDUMP,
884 "WPS: Probe Request with WPS data received",
887 if (wps_parse_msg(wps_data, &attr) < 0)
890 if (attr.config_methods == NULL) {
891 wpa_printf(MSG_DEBUG, "WPS: No Config Methods attribute in "
896 if (attr.dev_password_id == NULL) {
897 wpa_printf(MSG_DEBUG, "WPS: No Device Password Id attribute "
902 if (reg->enrollee_seen_cb && attr.uuid_e &&
903 attr.primary_dev_type && attr.request_type) {
904 char *dev_name = NULL;
906 dev_name = os_zalloc(attr.dev_name_len + 1);
908 os_memcpy(dev_name, attr.dev_name,
912 reg->enrollee_seen_cb(reg->cb_ctx, addr, attr.uuid_e,
913 attr.primary_dev_type,
914 WPA_GET_BE16(attr.config_methods),
915 WPA_GET_BE16(attr.dev_password_id),
916 *attr.request_type, dev_name);
920 if (WPA_GET_BE16(attr.dev_password_id) != DEV_PW_PUSHBUTTON)
921 return; /* Not PBC */
923 wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
924 MACSTR, MAC2STR(addr));
925 if (attr.uuid_e == NULL) {
926 wpa_printf(MSG_DEBUG, "WPS: Invalid Probe Request WPS IE: No "
931 wps_registrar_add_pbc_session(reg, addr, attr.uuid_e);
932 if (wps_registrar_pbc_overlap(reg, addr, attr.uuid_e)) {
933 wpa_printf(MSG_DEBUG, "WPS: PBC session overlap detected");
934 reg->force_pbc_overlap = 1;
935 wps_pbc_overlap_event(reg->wps);
940 static int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
941 const u8 *psk, size_t psk_len)
943 if (reg->new_psk_cb == NULL)
946 return reg->new_psk_cb(reg->cb_ctx, mac_addr, psk, psk_len);
950 static void wps_cb_pin_needed(struct wps_registrar *reg, const u8 *uuid_e,
951 const struct wps_device_data *dev)
953 if (reg->pin_needed_cb == NULL)
956 reg->pin_needed_cb(reg->cb_ctx, uuid_e, dev);
960 static void wps_cb_reg_success(struct wps_registrar *reg, const u8 *mac_addr,
963 if (reg->reg_success_cb == NULL)
966 reg->reg_success_cb(reg->cb_ctx, mac_addr, uuid_e);
970 static int wps_cb_set_ie(struct wps_registrar *reg, struct wpabuf *beacon_ie,
971 struct wpabuf *probe_resp_ie)
973 return reg->set_ie_cb(reg->cb_ctx, beacon_ie, probe_resp_ie);
977 static void wps_cb_set_sel_reg(struct wps_registrar *reg)
980 if (reg->set_sel_reg_cb == NULL)
983 if (reg->selected_registrar) {
984 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
986 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
987 WPS_CONFIG_PHY_PUSHBUTTON);
988 #endif /* CONFIG_WPS2 */
990 wps_set_pushbutton(&methods, reg->wps->config_methods);
993 wpa_printf(MSG_DEBUG, "WPS: wps_cb_set_sel_reg: sel_reg=%d "
994 "config_methods=0x%x pbc=%d methods=0x%x",
995 reg->selected_registrar, reg->wps->config_methods,
998 reg->set_sel_reg_cb(reg->cb_ctx, reg->selected_registrar,
999 reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT,
1004 static int wps_set_ie(struct wps_registrar *reg)
1006 struct wpabuf *beacon;
1007 struct wpabuf *probe;
1008 const u8 *auth_macs;
1011 if (reg->set_ie_cb == NULL)
1014 beacon = wpabuf_alloc(400);
1017 probe = wpabuf_alloc(500);
1018 if (probe == NULL) {
1019 wpabuf_free(beacon);
1023 auth_macs = wps_authorized_macs(reg, &count);
1025 wpa_printf(MSG_DEBUG, "WPS: Build Beacon IEs");
1027 if (wps_build_version(beacon) ||
1028 wps_build_wps_state(reg->wps, beacon) ||
1029 wps_build_ap_setup_locked(reg->wps, beacon) ||
1030 wps_build_selected_registrar(reg, beacon) ||
1031 wps_build_sel_reg_dev_password_id(reg, beacon) ||
1032 wps_build_sel_reg_config_methods(reg, beacon) ||
1033 wps_build_wfa_ext(beacon, 0, auth_macs, count)) {
1034 wpabuf_free(beacon);
1039 wpa_printf(MSG_DEBUG, "WPS: Build Probe Response IEs");
1041 if (wps_build_version(probe) ||
1042 wps_build_wps_state(reg->wps, probe) ||
1043 wps_build_ap_setup_locked(reg->wps, probe) ||
1044 wps_build_selected_registrar(reg, probe) ||
1045 wps_build_sel_reg_dev_password_id(reg, probe) ||
1046 wps_build_sel_reg_config_methods(reg, probe) ||
1047 wps_build_resp_type(probe, reg->wps->ap ? WPS_RESP_AP :
1048 WPS_RESP_REGISTRAR) ||
1049 wps_build_uuid_e(probe, reg->wps->uuid) ||
1050 wps_build_device_attrs(®->wps->dev, probe) ||
1051 wps_build_probe_config_methods(reg, probe) ||
1052 wps_build_rf_bands(®->wps->dev, probe) ||
1053 wps_build_wfa_ext(probe, 0, auth_macs, count)) {
1054 wpabuf_free(beacon);
1059 beacon = wps_ie_encapsulate(beacon);
1060 probe = wps_ie_encapsulate(probe);
1062 if (!beacon || !probe) {
1063 wpabuf_free(beacon);
1068 if (reg->static_wep_only) {
1070 * Windows XP and Vista clients can get confused about
1071 * EAP-Identity/Request when they probe the network with
1072 * EAPOL-Start. In such a case, they may assume the network is
1073 * using IEEE 802.1X and prompt user for a certificate while
1074 * the correct (non-WPS) behavior would be to ask for the
1075 * static WEP key. As a workaround, use Microsoft Provisioning
1076 * IE to advertise that legacy 802.1X is not supported.
1078 const u8 ms_wps[7] = {
1079 WLAN_EID_VENDOR_SPECIFIC, 5,
1080 /* Microsoft Provisioning IE (00:50:f2:5) */
1081 0x00, 0x50, 0xf2, 5,
1082 0x00 /* no legacy 802.1X or MS WPS */
1084 wpa_printf(MSG_DEBUG, "WPS: Add Microsoft Provisioning IE "
1085 "into Beacon/Probe Response frames");
1086 wpabuf_put_data(beacon, ms_wps, sizeof(ms_wps));
1087 wpabuf_put_data(probe, ms_wps, sizeof(ms_wps));
1090 return wps_cb_set_ie(reg, beacon, probe);
1094 static int wps_get_dev_password(struct wps_data *wps)
1099 os_free(wps->dev_password);
1100 wps->dev_password = NULL;
1103 wpa_printf(MSG_DEBUG, "WPS: Use default PIN for PBC");
1104 pin = (const u8 *) "00000000";
1107 pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
1111 wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
1113 wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
1118 wps->dev_password = os_malloc(pin_len);
1119 if (wps->dev_password == NULL)
1121 os_memcpy(wps->dev_password, pin, pin_len);
1122 wps->dev_password_len = pin_len;
1128 static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
1130 wpa_printf(MSG_DEBUG, "WPS: * UUID-R");
1131 wpabuf_put_be16(msg, ATTR_UUID_R);
1132 wpabuf_put_be16(msg, WPS_UUID_LEN);
1133 wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
1138 static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
1144 if (os_get_random(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
1146 wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
1147 wpa_hexdump(MSG_DEBUG, "WPS: R-S2",
1148 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
1150 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
1151 wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
1152 "R-Hash derivation");
1156 wpa_printf(MSG_DEBUG, "WPS: * R-Hash1");
1157 wpabuf_put_be16(msg, ATTR_R_HASH1);
1158 wpabuf_put_be16(msg, SHA256_MAC_LEN);
1159 hash = wpabuf_put(msg, SHA256_MAC_LEN);
1160 /* R-Hash1 = HMAC_AuthKey(R-S1 || PSK1 || PK_E || PK_R) */
1161 addr[0] = wps->snonce;
1162 len[0] = WPS_SECRET_NONCE_LEN;
1163 addr[1] = wps->psk1;
1164 len[1] = WPS_PSK_LEN;
1165 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1166 len[2] = wpabuf_len(wps->dh_pubkey_e);
1167 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1168 len[3] = wpabuf_len(wps->dh_pubkey_r);
1169 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1170 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", hash, SHA256_MAC_LEN);
1172 wpa_printf(MSG_DEBUG, "WPS: * R-Hash2");
1173 wpabuf_put_be16(msg, ATTR_R_HASH2);
1174 wpabuf_put_be16(msg, SHA256_MAC_LEN);
1175 hash = wpabuf_put(msg, SHA256_MAC_LEN);
1176 /* R-Hash2 = HMAC_AuthKey(R-S2 || PSK2 || PK_E || PK_R) */
1177 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
1178 addr[1] = wps->psk2;
1179 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1180 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", hash, SHA256_MAC_LEN);
1186 static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
1188 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce1");
1189 wpabuf_put_be16(msg, ATTR_R_SNONCE1);
1190 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
1191 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
1196 static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
1198 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce2");
1199 wpabuf_put_be16(msg, ATTR_R_SNONCE2);
1200 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
1201 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
1202 WPS_SECRET_NONCE_LEN);
1207 static int wps_build_cred_network_idx(struct wpabuf *msg,
1208 const struct wps_credential *cred)
1210 wpa_printf(MSG_DEBUG, "WPS: * Network Index");
1211 wpabuf_put_be16(msg, ATTR_NETWORK_INDEX);
1212 wpabuf_put_be16(msg, 1);
1213 wpabuf_put_u8(msg, 1);
1218 static int wps_build_cred_ssid(struct wpabuf *msg,
1219 const struct wps_credential *cred)
1221 wpa_printf(MSG_DEBUG, "WPS: * SSID");
1222 wpabuf_put_be16(msg, ATTR_SSID);
1223 wpabuf_put_be16(msg, cred->ssid_len);
1224 wpabuf_put_data(msg, cred->ssid, cred->ssid_len);
1229 static int wps_build_cred_auth_type(struct wpabuf *msg,
1230 const struct wps_credential *cred)
1232 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
1234 wpabuf_put_be16(msg, ATTR_AUTH_TYPE);
1235 wpabuf_put_be16(msg, 2);
1236 wpabuf_put_be16(msg, cred->auth_type);
1241 static int wps_build_cred_encr_type(struct wpabuf *msg,
1242 const struct wps_credential *cred)
1244 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
1246 wpabuf_put_be16(msg, ATTR_ENCR_TYPE);
1247 wpabuf_put_be16(msg, 2);
1248 wpabuf_put_be16(msg, cred->encr_type);
1253 static int wps_build_cred_network_key(struct wpabuf *msg,
1254 const struct wps_credential *cred)
1256 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%d)",
1257 (int) cred->key_len);
1258 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
1259 wpabuf_put_be16(msg, cred->key_len);
1260 wpabuf_put_data(msg, cred->key, cred->key_len);
1265 static int wps_build_cred_mac_addr(struct wpabuf *msg,
1266 const struct wps_credential *cred)
1268 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (" MACSTR ")",
1269 MAC2STR(cred->mac_addr));
1270 wpabuf_put_be16(msg, ATTR_MAC_ADDR);
1271 wpabuf_put_be16(msg, ETH_ALEN);
1272 wpabuf_put_data(msg, cred->mac_addr, ETH_ALEN);
1277 static int wps_build_credential(struct wpabuf *msg,
1278 const struct wps_credential *cred)
1280 if (wps_build_cred_network_idx(msg, cred) ||
1281 wps_build_cred_ssid(msg, cred) ||
1282 wps_build_cred_auth_type(msg, cred) ||
1283 wps_build_cred_encr_type(msg, cred) ||
1284 wps_build_cred_network_key(msg, cred) ||
1285 wps_build_cred_mac_addr(msg, cred))
1291 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
1293 struct wpabuf *cred;
1295 if (wps->wps->registrar->skip_cred_build)
1296 goto skip_cred_build;
1298 wpa_printf(MSG_DEBUG, "WPS: * Credential");
1299 if (wps->use_cred) {
1300 os_memcpy(&wps->cred, wps->use_cred, sizeof(wps->cred));
1303 os_memset(&wps->cred, 0, sizeof(wps->cred));
1305 os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
1306 wps->cred.ssid_len = wps->wps->ssid_len;
1308 /* Select the best authentication and encryption type */
1309 if (wps->auth_type & WPS_AUTH_WPA2PSK)
1310 wps->auth_type = WPS_AUTH_WPA2PSK;
1311 else if (wps->auth_type & WPS_AUTH_WPAPSK)
1312 wps->auth_type = WPS_AUTH_WPAPSK;
1313 else if (wps->auth_type & WPS_AUTH_OPEN)
1314 wps->auth_type = WPS_AUTH_OPEN;
1315 else if (wps->auth_type & WPS_AUTH_SHARED)
1316 wps->auth_type = WPS_AUTH_SHARED;
1318 wpa_printf(MSG_DEBUG, "WPS: Unsupported auth_type 0x%x",
1322 wps->cred.auth_type = wps->auth_type;
1324 if (wps->auth_type == WPS_AUTH_WPA2PSK ||
1325 wps->auth_type == WPS_AUTH_WPAPSK) {
1326 if (wps->encr_type & WPS_ENCR_AES)
1327 wps->encr_type = WPS_ENCR_AES;
1328 else if (wps->encr_type & WPS_ENCR_TKIP)
1329 wps->encr_type = WPS_ENCR_TKIP;
1331 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1332 "type for WPA/WPA2");
1336 if (wps->encr_type & WPS_ENCR_WEP)
1337 wps->encr_type = WPS_ENCR_WEP;
1338 else if (wps->encr_type & WPS_ENCR_NONE)
1339 wps->encr_type = WPS_ENCR_NONE;
1341 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1342 "type for non-WPA/WPA2 mode");
1346 wps->cred.encr_type = wps->encr_type;
1348 * Set MAC address in the Credential to be the Enrollee's MAC address
1350 os_memcpy(wps->cred.mac_addr, wps->mac_addr_e, ETH_ALEN);
1352 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
1353 !wps->wps->registrar->disable_auto_conf) {
1355 /* Generate a random passphrase */
1356 if (os_get_random(r, sizeof(r)) < 0)
1358 os_free(wps->new_psk);
1359 wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
1360 if (wps->new_psk == NULL)
1362 wps->new_psk_len--; /* remove newline */
1363 while (wps->new_psk_len &&
1364 wps->new_psk[wps->new_psk_len - 1] == '=')
1366 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated passphrase",
1367 wps->new_psk, wps->new_psk_len);
1368 os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
1369 wps->cred.key_len = wps->new_psk_len;
1370 } else if (wps->use_psk_key && wps->wps->psk_set) {
1372 wpa_printf(MSG_DEBUG, "WPS: Use PSK format for Network Key");
1373 wpa_snprintf_hex(hex, sizeof(hex), wps->wps->psk, 32);
1374 os_memcpy(wps->cred.key, hex, 32 * 2);
1375 wps->cred.key_len = 32 * 2;
1376 } else if (wps->wps->network_key) {
1377 os_memcpy(wps->cred.key, wps->wps->network_key,
1378 wps->wps->network_key_len);
1379 wps->cred.key_len = wps->wps->network_key_len;
1380 } else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
1382 /* Generate a random per-device PSK */
1383 os_free(wps->new_psk);
1384 wps->new_psk_len = 32;
1385 wps->new_psk = os_malloc(wps->new_psk_len);
1386 if (wps->new_psk == NULL)
1388 if (os_get_random(wps->new_psk, wps->new_psk_len) < 0) {
1389 os_free(wps->new_psk);
1390 wps->new_psk = NULL;
1393 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
1394 wps->new_psk, wps->new_psk_len);
1395 wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
1397 os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
1398 wps->cred.key_len = wps->new_psk_len * 2;
1402 #ifdef CONFIG_WPS_TESTING_EXTRA_CRED
1403 cred = wpabuf_alloc(200);
1405 struct wps_credential dummy;
1406 wpa_printf(MSG_DEBUG, "WPS: Add dummy credential");
1407 os_memset(&dummy, 0, sizeof(dummy));
1408 os_memcpy(dummy.ssid, "dummy", 5);
1410 dummy.auth_type = WPS_AUTH_WPA2PSK;
1411 dummy.encr_type = WPS_ENCR_AES;
1412 os_memcpy(dummy.key, "dummy psk", 9);
1414 os_memcpy(dummy.mac_addr, wps->mac_addr_e, ETH_ALEN);
1415 wps_build_credential(cred, &dummy);
1416 wpa_hexdump_buf(MSG_DEBUG, "WPS: Dummy Credential", cred);
1418 wpabuf_put_be16(msg, ATTR_CRED);
1419 wpabuf_put_be16(msg, wpabuf_len(cred));
1420 wpabuf_put_buf(msg, cred);
1424 #endif /* CONFIG_WPS_TESTING_EXTRA_CRED */
1426 cred = wpabuf_alloc(200);
1430 if (wps_build_credential(cred, &wps->cred)) {
1435 wpabuf_put_be16(msg, ATTR_CRED);
1436 wpabuf_put_be16(msg, wpabuf_len(cred));
1437 wpabuf_put_buf(msg, cred);
1441 if (wps->wps->registrar->extra_cred) {
1442 wpa_printf(MSG_DEBUG, "WPS: * Credential (pre-configured)");
1443 wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
1450 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
1452 wpa_printf(MSG_DEBUG, "WPS: * AP Settings");
1454 if (wps_build_credential(msg, &wps->cred))
1461 static struct wpabuf * wps_build_m2(struct wps_data *wps)
1465 if (os_get_random(wps->nonce_r, WPS_NONCE_LEN) < 0)
1467 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
1468 wps->nonce_r, WPS_NONCE_LEN);
1469 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
1471 wpa_printf(MSG_DEBUG, "WPS: Building Message M2");
1472 msg = wpabuf_alloc(1000);
1476 if (wps_build_version(msg) ||
1477 wps_build_msg_type(msg, WPS_M2) ||
1478 wps_build_enrollee_nonce(wps, msg) ||
1479 wps_build_registrar_nonce(wps, msg) ||
1480 wps_build_uuid_r(wps, msg) ||
1481 wps_build_public_key(wps, msg) ||
1482 wps_derive_keys(wps) ||
1483 wps_build_auth_type_flags(wps, msg) ||
1484 wps_build_encr_type_flags(wps, msg) ||
1485 wps_build_conn_type_flags(wps, msg) ||
1486 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1487 wps_build_device_attrs(&wps->wps->dev, msg) ||
1488 wps_build_rf_bands(&wps->wps->dev, msg) ||
1489 wps_build_assoc_state(wps, msg) ||
1490 wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
1491 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
1492 wps_build_os_version(&wps->wps->dev, msg) ||
1493 wps_build_wfa_ext(msg, 0, NULL, 0) ||
1494 wps_build_authenticator(wps, msg)) {
1500 wps->state = RECV_M3;
1505 static struct wpabuf * wps_build_m2d(struct wps_data *wps)
1508 u16 err = wps->config_error;
1510 wpa_printf(MSG_DEBUG, "WPS: Building Message M2D");
1511 msg = wpabuf_alloc(1000);
1515 if (wps->wps->ap && wps->wps->ap_setup_locked &&
1516 err == WPS_CFG_NO_ERROR)
1517 err = WPS_CFG_SETUP_LOCKED;
1519 if (wps_build_version(msg) ||
1520 wps_build_msg_type(msg, WPS_M2D) ||
1521 wps_build_enrollee_nonce(wps, msg) ||
1522 wps_build_registrar_nonce(wps, msg) ||
1523 wps_build_uuid_r(wps, msg) ||
1524 wps_build_auth_type_flags(wps, msg) ||
1525 wps_build_encr_type_flags(wps, msg) ||
1526 wps_build_conn_type_flags(wps, msg) ||
1527 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1528 wps_build_device_attrs(&wps->wps->dev, msg) ||
1529 wps_build_rf_bands(&wps->wps->dev, msg) ||
1530 wps_build_assoc_state(wps, msg) ||
1531 wps_build_config_error(msg, err) ||
1532 wps_build_os_version(&wps->wps->dev, msg) ||
1533 wps_build_wfa_ext(msg, 0, NULL, 0)) {
1538 wps->state = RECV_M2D_ACK;
1543 static struct wpabuf * wps_build_m4(struct wps_data *wps)
1545 struct wpabuf *msg, *plain;
1547 wpa_printf(MSG_DEBUG, "WPS: Building Message M4");
1549 wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
1551 plain = wpabuf_alloc(200);
1555 msg = wpabuf_alloc(1000);
1561 if (wps_build_version(msg) ||
1562 wps_build_msg_type(msg, WPS_M4) ||
1563 wps_build_enrollee_nonce(wps, msg) ||
1564 wps_build_r_hash(wps, msg) ||
1565 wps_build_r_snonce1(wps, plain) ||
1566 wps_build_key_wrap_auth(wps, plain) ||
1567 wps_build_encr_settings(wps, msg, plain) ||
1568 wps_build_wfa_ext(msg, 0, NULL, 0) ||
1569 wps_build_authenticator(wps, msg)) {
1576 wps->state = RECV_M5;
1581 static struct wpabuf * wps_build_m6(struct wps_data *wps)
1583 struct wpabuf *msg, *plain;
1585 wpa_printf(MSG_DEBUG, "WPS: Building Message M6");
1587 plain = wpabuf_alloc(200);
1591 msg = wpabuf_alloc(1000);
1597 if (wps_build_version(msg) ||
1598 wps_build_msg_type(msg, WPS_M6) ||
1599 wps_build_enrollee_nonce(wps, msg) ||
1600 wps_build_r_snonce2(wps, plain) ||
1601 wps_build_key_wrap_auth(wps, plain) ||
1602 wps_build_encr_settings(wps, msg, plain) ||
1603 wps_build_wfa_ext(msg, 0, NULL, 0) ||
1604 wps_build_authenticator(wps, msg)) {
1611 wps->wps_pin_revealed = 1;
1612 wps->state = RECV_M7;
1617 static struct wpabuf * wps_build_m8(struct wps_data *wps)
1619 struct wpabuf *msg, *plain;
1621 wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
1623 plain = wpabuf_alloc(500);
1627 msg = wpabuf_alloc(1000);
1633 if (wps_build_version(msg) ||
1634 wps_build_msg_type(msg, WPS_M8) ||
1635 wps_build_enrollee_nonce(wps, msg) ||
1636 ((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
1637 (!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
1638 wps_build_key_wrap_auth(wps, plain) ||
1639 wps_build_encr_settings(wps, msg, plain) ||
1640 wps_build_wfa_ext(msg, 0, NULL, 0) ||
1641 wps_build_authenticator(wps, msg)) {
1648 wps->state = RECV_DONE;
1653 static struct wpabuf * wps_build_wsc_ack(struct wps_data *wps)
1657 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_ACK");
1659 msg = wpabuf_alloc(1000);
1663 if (wps_build_version(msg) ||
1664 wps_build_msg_type(msg, WPS_WSC_ACK) ||
1665 wps_build_enrollee_nonce(wps, msg) ||
1666 wps_build_registrar_nonce(wps, msg) ||
1667 wps_build_wfa_ext(msg, 0, NULL, 0)) {
1676 static struct wpabuf * wps_build_wsc_nack(struct wps_data *wps)
1680 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_NACK");
1682 msg = wpabuf_alloc(1000);
1686 if (wps_build_version(msg) ||
1687 wps_build_msg_type(msg, WPS_WSC_NACK) ||
1688 wps_build_enrollee_nonce(wps, msg) ||
1689 wps_build_registrar_nonce(wps, msg) ||
1690 wps_build_config_error(msg, wps->config_error) ||
1691 wps_build_wfa_ext(msg, 0, NULL, 0)) {
1700 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
1701 enum wsc_op_code *op_code)
1705 #ifdef CONFIG_WPS_UPNP
1706 if (!wps->int_reg && wps->wps->wps_upnp) {
1707 struct upnp_pending_message *p, *prev = NULL;
1708 if (wps->ext_reg > 1)
1709 wps_registrar_free_pending_m2(wps->wps);
1710 p = wps->wps->upnp_msgs;
1711 /* TODO: check pending message MAC address */
1712 while (p && p->next) {
1717 wpa_printf(MSG_DEBUG, "WPS: Use pending message from "
1722 wps->wps->upnp_msgs = NULL;
1729 *op_code = WSC_NACK;
1736 if (wps->ext_reg == 0)
1742 wpa_printf(MSG_DEBUG, "WPS: Using external Registrar, but no "
1743 "pending message available");
1746 #endif /* CONFIG_WPS_UPNP */
1748 switch (wps->state) {
1750 if (wps_get_dev_password(wps) < 0)
1751 msg = wps_build_m2d(wps);
1753 msg = wps_build_m2(wps);
1757 msg = wps_build_m2d(wps);
1761 msg = wps_build_m4(wps);
1765 msg = wps_build_m6(wps);
1769 msg = wps_build_m8(wps);
1773 msg = wps_build_wsc_ack(wps);
1777 msg = wps_build_wsc_nack(wps);
1778 *op_code = WSC_NACK;
1781 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
1782 "a message", wps->state);
1787 if (*op_code == WSC_MSG && msg) {
1788 /* Save a copy of the last message for Authenticator derivation
1790 wpabuf_free(wps->last_msg);
1791 wps->last_msg = wpabuf_dup(msg);
1798 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
1800 if (e_nonce == NULL) {
1801 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
1805 os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
1806 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
1807 wps->nonce_e, WPS_NONCE_LEN);
1813 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
1815 if (r_nonce == NULL) {
1816 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
1820 if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
1821 wpa_printf(MSG_DEBUG, "WPS: Invalid Registrar Nonce received");
1829 static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
1831 if (uuid_e == NULL) {
1832 wpa_printf(MSG_DEBUG, "WPS: No UUID-E received");
1836 os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
1837 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
1843 static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
1845 if (pw_id == NULL) {
1846 wpa_printf(MSG_DEBUG, "WPS: No Device Password ID received");
1850 wps->dev_pw_id = WPA_GET_BE16(pw_id);
1851 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
1857 static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
1859 if (e_hash1 == NULL) {
1860 wpa_printf(MSG_DEBUG, "WPS: No E-Hash1 received");
1864 os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
1865 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
1871 static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
1873 if (e_hash2 == NULL) {
1874 wpa_printf(MSG_DEBUG, "WPS: No E-Hash2 received");
1878 os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
1879 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
1885 static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
1887 u8 hash[SHA256_MAC_LEN];
1891 if (e_snonce1 == NULL) {
1892 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce1 received");
1896 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce1", e_snonce1,
1897 WPS_SECRET_NONCE_LEN);
1899 /* E-Hash1 = HMAC_AuthKey(E-S1 || PSK1 || PK_E || PK_R) */
1900 addr[0] = e_snonce1;
1901 len[0] = WPS_SECRET_NONCE_LEN;
1902 addr[1] = wps->psk1;
1903 len[1] = WPS_PSK_LEN;
1904 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1905 len[2] = wpabuf_len(wps->dh_pubkey_e);
1906 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1907 len[3] = wpabuf_len(wps->dh_pubkey_r);
1908 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1910 if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
1911 wpa_printf(MSG_DEBUG, "WPS: E-Hash1 derived from E-S1 does "
1912 "not match with the pre-committed value");
1913 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1914 wps_pwd_auth_fail_event(wps->wps, 0, 1);
1918 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the first "
1919 "half of the device password");
1925 static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
1927 u8 hash[SHA256_MAC_LEN];
1931 if (e_snonce2 == NULL) {
1932 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce2 received");
1936 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce2", e_snonce2,
1937 WPS_SECRET_NONCE_LEN);
1939 /* E-Hash2 = HMAC_AuthKey(E-S2 || PSK2 || PK_E || PK_R) */
1940 addr[0] = e_snonce2;
1941 len[0] = WPS_SECRET_NONCE_LEN;
1942 addr[1] = wps->psk2;
1943 len[1] = WPS_PSK_LEN;
1944 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1945 len[2] = wpabuf_len(wps->dh_pubkey_e);
1946 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1947 len[3] = wpabuf_len(wps->dh_pubkey_r);
1948 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1950 if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
1951 wpa_printf(MSG_DEBUG, "WPS: E-Hash2 derived from E-S2 does "
1952 "not match with the pre-committed value");
1953 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
1954 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1955 wps_pwd_auth_fail_event(wps->wps, 0, 2);
1959 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the second "
1960 "half of the device password");
1961 wps->wps_pin_revealed = 0;
1962 wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
1968 static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
1970 if (mac_addr == NULL) {
1971 wpa_printf(MSG_DEBUG, "WPS: No MAC Address received");
1975 wpa_printf(MSG_DEBUG, "WPS: Enrollee MAC Address " MACSTR,
1977 os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
1978 os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
1984 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
1987 if (pk == NULL || pk_len == 0) {
1988 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
1992 #ifdef CONFIG_WPS_OOB
1993 if (wps->wps->oob_conf.pubkey_hash != NULL) {
1995 u8 hash[WPS_HASH_LEN];
1998 sha256_vector(1, addr, &pk_len, hash);
2000 wpabuf_head(wps->wps->oob_conf.pubkey_hash),
2001 WPS_OOB_PUBKEY_HASH_LEN) != 0) {
2002 wpa_printf(MSG_ERROR, "WPS: Public Key hash error");
2006 #endif /* CONFIG_WPS_OOB */
2008 wpabuf_free(wps->dh_pubkey_e);
2009 wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
2010 if (wps->dh_pubkey_e == NULL)
2017 static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
2022 wpa_printf(MSG_DEBUG, "WPS: No Authentication Type flags "
2027 auth_types = WPA_GET_BE16(auth);
2029 wpa_printf(MSG_DEBUG, "WPS: Enrollee Authentication Type flags 0x%x",
2031 wps->auth_type = wps->wps->auth_types & auth_types;
2032 if (wps->auth_type == 0) {
2033 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
2034 "authentication types (own 0x%x Enrollee 0x%x)",
2035 wps->wps->auth_types, auth_types);
2036 #ifdef WPS_WORKAROUNDS
2038 * Some deployed implementations seem to advertise incorrect
2039 * information in this attribute. For example, Linksys WRT350N
2040 * seems to have a byteorder bug that breaks this negotiation.
2041 * In order to interoperate with existing implementations,
2042 * assume that the Enrollee supports everything we do.
2044 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
2045 "does not advertise supported authentication types "
2047 wps->auth_type = wps->wps->auth_types;
2048 #else /* WPS_WORKAROUNDS */
2050 #endif /* WPS_WORKAROUNDS */
2057 static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
2062 wpa_printf(MSG_DEBUG, "WPS: No Encryption Type flags "
2067 encr_types = WPA_GET_BE16(encr);
2069 wpa_printf(MSG_DEBUG, "WPS: Enrollee Encryption Type flags 0x%x",
2071 wps->encr_type = wps->wps->encr_types & encr_types;
2072 if (wps->encr_type == 0) {
2073 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
2074 "encryption types (own 0x%x Enrollee 0x%x)",
2075 wps->wps->encr_types, encr_types);
2076 #ifdef WPS_WORKAROUNDS
2078 * Some deployed implementations seem to advertise incorrect
2079 * information in this attribute. For example, Linksys WRT350N
2080 * seems to have a byteorder bug that breaks this negotiation.
2081 * In order to interoperate with existing implementations,
2082 * assume that the Enrollee supports everything we do.
2084 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
2085 "does not advertise supported encryption types "
2087 wps->encr_type = wps->wps->encr_types;
2088 #else /* WPS_WORKAROUNDS */
2090 #endif /* WPS_WORKAROUNDS */
2097 static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
2100 wpa_printf(MSG_DEBUG, "WPS: No Connection Type flags "
2105 wpa_printf(MSG_DEBUG, "WPS: Enrollee Connection Type flags 0x%x",
2112 static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
2116 if (methods == NULL) {
2117 wpa_printf(MSG_DEBUG, "WPS: No Config Methods received");
2121 m = WPA_GET_BE16(methods);
2123 wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x"
2124 "%s%s%s%s%s%s%s%s%s", m,
2125 m & WPS_CONFIG_USBA ? " [USBA]" : "",
2126 m & WPS_CONFIG_ETHERNET ? " [Ethernet]" : "",
2127 m & WPS_CONFIG_LABEL ? " [Label]" : "",
2128 m & WPS_CONFIG_DISPLAY ? " [Display]" : "",
2129 m & WPS_CONFIG_EXT_NFC_TOKEN ? " [Ext NFC Token]" : "",
2130 m & WPS_CONFIG_INT_NFC_TOKEN ? " [Int NFC Token]" : "",
2131 m & WPS_CONFIG_NFC_INTERFACE ? " [NFC]" : "",
2132 m & WPS_CONFIG_PUSHBUTTON ? " [PBC]" : "",
2133 m & WPS_CONFIG_KEYPAD ? " [Keypad]" : "");
2135 if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
2137 * The Enrollee does not have a display so it is unlikely to be
2138 * able to show the passphrase to a user and as such, could
2139 * benefit from receiving PSK to reduce key derivation time.
2141 wpa_printf(MSG_DEBUG, "WPS: Prefer PSK format key due to "
2142 "Enrollee not supporting display");
2143 wps->use_psk_key = 1;
2150 static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
2152 if (state == NULL) {
2153 wpa_printf(MSG_DEBUG, "WPS: No Wi-Fi Protected Setup State "
2158 wpa_printf(MSG_DEBUG, "WPS: Enrollee Wi-Fi Protected Setup State %d",
2165 static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
2169 if (assoc == NULL) {
2170 wpa_printf(MSG_DEBUG, "WPS: No Association State received");
2174 a = WPA_GET_BE16(assoc);
2175 wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a);
2181 static int wps_process_config_error(struct wps_data *wps, const u8 *err)
2186 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received");
2190 e = WPA_GET_BE16(err);
2191 wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e);
2197 static enum wps_process_res wps_process_m1(struct wps_data *wps,
2198 struct wps_parse_attr *attr)
2200 wpa_printf(MSG_DEBUG, "WPS: Received M1");
2202 if (wps->state != RECV_M1) {
2203 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2204 "receiving M1", wps->state);
2208 if (wps_process_uuid_e(wps, attr->uuid_e) ||
2209 wps_process_mac_addr(wps, attr->mac_addr) ||
2210 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
2211 wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
2212 wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
2213 wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
2214 wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
2215 wps_process_config_methods(wps, attr->config_methods) ||
2216 wps_process_wps_state(wps, attr->wps_state) ||
2217 wps_process_device_attrs(&wps->peer_dev, attr) ||
2218 wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
2219 wps_process_assoc_state(wps, attr->assoc_state) ||
2220 wps_process_dev_password_id(wps, attr->dev_password_id) ||
2221 wps_process_config_error(wps, attr->config_error) ||
2222 wps_process_os_version(&wps->peer_dev, attr->os_version))
2225 if (wps->dev_pw_id < 0x10 &&
2226 wps->dev_pw_id != DEV_PW_DEFAULT &&
2227 wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
2228 wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
2229 wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
2230 (wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
2231 !wps->wps->registrar->pbc)) {
2232 wpa_printf(MSG_DEBUG, "WPS: Unsupported Device Password ID %d",
2234 wps->state = SEND_M2D;
2235 return WPS_CONTINUE;
2238 #ifdef CONFIG_WPS_OOB
2239 if (wps->dev_pw_id >= 0x10 &&
2240 wps->dev_pw_id != wps->wps->oob_dev_pw_id) {
2241 wpa_printf(MSG_DEBUG, "WPS: OOB Device Password ID "
2242 "%d mismatch", wps->dev_pw_id);
2243 wps->state = SEND_M2D;
2244 return WPS_CONTINUE;
2246 #endif /* CONFIG_WPS_OOB */
2248 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
2249 if (wps->wps->registrar->force_pbc_overlap ||
2250 wps_registrar_pbc_overlap(wps->wps->registrar,
2251 wps->mac_addr_e, wps->uuid_e)) {
2252 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - deny PBC "
2254 wps->state = SEND_M2D;
2255 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2256 wps_pbc_overlap_event(wps->wps);
2257 wps->wps->registrar->force_pbc_overlap = 1;
2258 return WPS_CONTINUE;
2260 wps_registrar_add_pbc_session(wps->wps->registrar,
2261 wps->mac_addr_e, wps->uuid_e);
2265 #ifdef WPS_WORKAROUNDS
2267 * It looks like Mac OS X 10.6.3 and 10.6.4 do not like Network Key in
2268 * passphrase format. To avoid interop issues, force PSK format to be
2271 if (!wps->use_psk_key &&
2272 wps->peer_dev.manufacturer &&
2273 os_strncmp(wps->peer_dev.manufacturer, "Apple ", 6) == 0 &&
2274 wps->peer_dev.model_name &&
2275 os_strcmp(wps->peer_dev.model_name, "AirPort") == 0) {
2276 wpa_printf(MSG_DEBUG, "WPS: Workaround - Force Network Key in "
2278 wps->use_psk_key = 1;
2280 #endif /* WPS_WORKAROUNDS */
2282 wps->state = SEND_M2;
2283 return WPS_CONTINUE;
2287 static enum wps_process_res wps_process_m3(struct wps_data *wps,
2288 const struct wpabuf *msg,
2289 struct wps_parse_attr *attr)
2291 wpa_printf(MSG_DEBUG, "WPS: Received M3");
2293 if (wps->state != RECV_M3) {
2294 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2295 "receiving M3", wps->state);
2296 wps->state = SEND_WSC_NACK;
2297 return WPS_CONTINUE;
2300 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2301 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2303 wps->state = SEND_WSC_NACK;
2304 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2305 return WPS_CONTINUE;
2308 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2309 wps_process_authenticator(wps, attr->authenticator, msg) ||
2310 wps_process_e_hash1(wps, attr->e_hash1) ||
2311 wps_process_e_hash2(wps, attr->e_hash2)) {
2312 wps->state = SEND_WSC_NACK;
2313 return WPS_CONTINUE;
2316 wps->state = SEND_M4;
2317 return WPS_CONTINUE;
2321 static enum wps_process_res wps_process_m5(struct wps_data *wps,
2322 const struct wpabuf *msg,
2323 struct wps_parse_attr *attr)
2325 struct wpabuf *decrypted;
2326 struct wps_parse_attr eattr;
2328 wpa_printf(MSG_DEBUG, "WPS: Received M5");
2330 if (wps->state != RECV_M5) {
2331 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2332 "receiving M5", wps->state);
2333 wps->state = SEND_WSC_NACK;
2334 return WPS_CONTINUE;
2337 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2338 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2340 wps->state = SEND_WSC_NACK;
2341 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2342 return WPS_CONTINUE;
2345 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2346 wps_process_authenticator(wps, attr->authenticator, msg)) {
2347 wps->state = SEND_WSC_NACK;
2348 return WPS_CONTINUE;
2351 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2352 attr->encr_settings_len);
2353 if (decrypted == NULL) {
2354 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
2355 "Settings attribute");
2356 wps->state = SEND_WSC_NACK;
2357 return WPS_CONTINUE;
2360 if (wps_validate_m5_encr(decrypted) < 0) {
2361 wpabuf_free(decrypted);
2362 wps->state = SEND_WSC_NACK;
2363 return WPS_CONTINUE;
2366 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2368 if (wps_parse_msg(decrypted, &eattr) < 0 ||
2369 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2370 wps_process_e_snonce1(wps, eattr.e_snonce1)) {
2371 wpabuf_free(decrypted);
2372 wps->state = SEND_WSC_NACK;
2373 return WPS_CONTINUE;
2375 wpabuf_free(decrypted);
2377 wps->state = SEND_M6;
2378 return WPS_CONTINUE;
2382 static void wps_sta_cred_cb(struct wps_data *wps)
2385 * Update credential to only include a single authentication and
2386 * encryption type in case the AP configuration includes more than one
2389 if (wps->cred.auth_type & WPS_AUTH_WPA2PSK)
2390 wps->cred.auth_type = WPS_AUTH_WPA2PSK;
2391 else if (wps->cred.auth_type & WPS_AUTH_WPAPSK)
2392 wps->cred.auth_type = WPS_AUTH_WPAPSK;
2393 if (wps->cred.encr_type & WPS_ENCR_AES)
2394 wps->cred.encr_type = WPS_ENCR_AES;
2395 else if (wps->cred.encr_type & WPS_ENCR_TKIP)
2396 wps->cred.encr_type = WPS_ENCR_TKIP;
2397 wpa_printf(MSG_DEBUG, "WPS: Update local configuration based on the "
2398 "AP configuration");
2399 if (wps->wps->cred_cb)
2400 wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
2404 static void wps_cred_update(struct wps_credential *dst,
2405 struct wps_credential *src)
2407 os_memcpy(dst->ssid, src->ssid, sizeof(dst->ssid));
2408 dst->ssid_len = src->ssid_len;
2409 dst->auth_type = src->auth_type;
2410 dst->encr_type = src->encr_type;
2411 dst->key_idx = src->key_idx;
2412 os_memcpy(dst->key, src->key, sizeof(dst->key));
2413 dst->key_len = src->key_len;
2417 static int wps_process_ap_settings_r(struct wps_data *wps,
2418 struct wps_parse_attr *attr)
2420 if (wps->wps->ap || wps->er)
2423 /* AP Settings Attributes in M7 when Enrollee is an AP */
2424 if (wps_process_ap_settings(attr, &wps->cred) < 0)
2427 wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
2429 if (wps->new_ap_settings) {
2430 wpa_printf(MSG_INFO, "WPS: Update AP configuration based on "
2432 wps_cred_update(&wps->cred, wps->new_ap_settings);
2436 * Use the AP PIN only to receive the current AP settings, not
2437 * to reconfigure the AP.
2439 if (wps->ap_settings_cb) {
2440 wps->ap_settings_cb(wps->ap_settings_cb_ctx,
2444 wps_sta_cred_cb(wps);
2450 static enum wps_process_res wps_process_m7(struct wps_data *wps,
2451 const struct wpabuf *msg,
2452 struct wps_parse_attr *attr)
2454 struct wpabuf *decrypted;
2455 struct wps_parse_attr eattr;
2457 wpa_printf(MSG_DEBUG, "WPS: Received M7");
2459 if (wps->state != RECV_M7) {
2460 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2461 "receiving M7", wps->state);
2462 wps->state = SEND_WSC_NACK;
2463 return WPS_CONTINUE;
2466 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2467 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2469 wps->state = SEND_WSC_NACK;
2470 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2471 return WPS_CONTINUE;
2474 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2475 wps_process_authenticator(wps, attr->authenticator, msg)) {
2476 wps->state = SEND_WSC_NACK;
2477 return WPS_CONTINUE;
2480 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2481 attr->encr_settings_len);
2482 if (decrypted == NULL) {
2483 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt Encrypted "
2484 "Settings attribute");
2485 wps->state = SEND_WSC_NACK;
2486 return WPS_CONTINUE;
2489 if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er) < 0) {
2490 wpabuf_free(decrypted);
2491 wps->state = SEND_WSC_NACK;
2492 return WPS_CONTINUE;
2495 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2497 if (wps_parse_msg(decrypted, &eattr) < 0 ||
2498 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2499 wps_process_e_snonce2(wps, eattr.e_snonce2) ||
2500 wps_process_ap_settings_r(wps, &eattr)) {
2501 wpabuf_free(decrypted);
2502 wps->state = SEND_WSC_NACK;
2503 return WPS_CONTINUE;
2506 wpabuf_free(decrypted);
2508 wps->state = SEND_M8;
2509 return WPS_CONTINUE;
2513 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
2514 const struct wpabuf *msg)
2516 struct wps_parse_attr attr;
2517 enum wps_process_res ret = WPS_CONTINUE;
2519 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
2521 if (wps_parse_msg(msg, &attr) < 0)
2524 if (attr.msg_type == NULL) {
2525 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2529 if (*attr.msg_type != WPS_M1 &&
2530 (attr.registrar_nonce == NULL ||
2531 os_memcmp(wps->nonce_r, attr.registrar_nonce,
2532 WPS_NONCE_LEN != 0))) {
2533 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2537 switch (*attr.msg_type) {
2539 if (wps_validate_m1(msg) < 0)
2541 #ifdef CONFIG_WPS_UPNP
2542 if (wps->wps->wps_upnp && attr.mac_addr) {
2543 /* Remove old pending messages when starting new run */
2544 wps_free_pending_msgs(wps->wps->upnp_msgs);
2545 wps->wps->upnp_msgs = NULL;
2547 upnp_wps_device_send_wlan_event(
2548 wps->wps->wps_upnp, attr.mac_addr,
2549 UPNP_WPS_WLANEVENT_TYPE_EAP, msg);
2551 #endif /* CONFIG_WPS_UPNP */
2552 ret = wps_process_m1(wps, &attr);
2555 if (wps_validate_m3(msg) < 0)
2557 ret = wps_process_m3(wps, msg, &attr);
2558 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2559 wps_fail_event(wps->wps, WPS_M3);
2562 if (wps_validate_m5(msg) < 0)
2564 ret = wps_process_m5(wps, msg, &attr);
2565 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2566 wps_fail_event(wps->wps, WPS_M5);
2569 if (wps_validate_m7(msg) < 0)
2571 ret = wps_process_m7(wps, msg, &attr);
2572 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2573 wps_fail_event(wps->wps, WPS_M7);
2576 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
2581 if (ret == WPS_CONTINUE) {
2582 /* Save a copy of the last message for Authenticator derivation
2584 wpabuf_free(wps->last_msg);
2585 wps->last_msg = wpabuf_dup(msg);
2592 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
2593 const struct wpabuf *msg)
2595 struct wps_parse_attr attr;
2597 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
2599 if (wps_parse_msg(msg, &attr) < 0)
2602 if (attr.msg_type == NULL) {
2603 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2607 if (*attr.msg_type != WPS_WSC_ACK) {
2608 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2613 #ifdef CONFIG_WPS_UPNP
2614 if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
2615 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2616 if (wps->wps->upnp_msgs)
2617 return WPS_CONTINUE;
2618 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2619 "external Registrar");
2622 #endif /* CONFIG_WPS_UPNP */
2624 if (attr.registrar_nonce == NULL ||
2625 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2627 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2631 if (attr.enrollee_nonce == NULL ||
2632 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2633 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2637 if (wps->state == RECV_M2D_ACK) {
2638 #ifdef CONFIG_WPS_UPNP
2639 if (wps->wps->wps_upnp &&
2640 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2641 if (wps->wps->upnp_msgs)
2642 return WPS_CONTINUE;
2643 if (wps->ext_reg == 0)
2645 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2646 "external Registrar");
2649 #endif /* CONFIG_WPS_UPNP */
2651 wpa_printf(MSG_DEBUG, "WPS: No more registrars available - "
2652 "terminate negotiation");
2659 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
2660 const struct wpabuf *msg)
2662 struct wps_parse_attr attr;
2665 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
2667 old_state = wps->state;
2668 wps->state = SEND_WSC_NACK;
2670 if (wps_parse_msg(msg, &attr) < 0)
2673 if (attr.msg_type == NULL) {
2674 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2678 if (*attr.msg_type != WPS_WSC_NACK) {
2679 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2684 #ifdef CONFIG_WPS_UPNP
2685 if (wps->wps->wps_upnp && wps->ext_reg) {
2686 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2687 "Registrar terminated by the Enrollee");
2690 #endif /* CONFIG_WPS_UPNP */
2692 if (attr.registrar_nonce == NULL ||
2693 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2695 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2699 if (attr.enrollee_nonce == NULL ||
2700 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2701 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2705 if (attr.config_error == NULL) {
2706 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
2711 wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
2712 "Configuration Error %d", WPA_GET_BE16(attr.config_error));
2714 switch (old_state) {
2716 wps_fail_event(wps->wps, WPS_M2);
2719 wps_fail_event(wps->wps, WPS_M4);
2722 wps_fail_event(wps->wps, WPS_M6);
2725 wps_fail_event(wps->wps, WPS_M8);
2735 static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
2736 const struct wpabuf *msg)
2738 struct wps_parse_attr attr;
2740 wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done");
2742 if (wps->state != RECV_DONE &&
2743 (!wps->wps->wps_upnp || !wps->ext_reg)) {
2744 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2745 "receiving WSC_Done", wps->state);
2749 if (wps_parse_msg(msg, &attr) < 0)
2752 if (attr.msg_type == NULL) {
2753 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2757 if (*attr.msg_type != WPS_WSC_DONE) {
2758 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2763 #ifdef CONFIG_WPS_UPNP
2764 if (wps->wps->wps_upnp && wps->ext_reg) {
2765 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2766 "Registrar completed successfully");
2767 wps_device_store(wps->wps->registrar, &wps->peer_dev,
2771 #endif /* CONFIG_WPS_UPNP */
2773 if (attr.registrar_nonce == NULL ||
2774 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2776 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2780 if (attr.enrollee_nonce == NULL ||
2781 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2782 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2786 wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
2787 wps_device_store(wps->wps->registrar, &wps->peer_dev,
2790 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
2791 wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
2792 struct wps_credential cred;
2794 wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based "
2795 "on first Enrollee connection");
2797 os_memset(&cred, 0, sizeof(cred));
2798 os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
2799 cred.ssid_len = wps->wps->ssid_len;
2800 cred.auth_type = WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK;
2801 cred.encr_type = WPS_ENCR_TKIP | WPS_ENCR_AES;
2802 os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
2803 cred.key_len = wps->new_psk_len;
2805 wps->wps->wps_state = WPS_STATE_CONFIGURED;
2806 wpa_hexdump_ascii_key(MSG_DEBUG,
2807 "WPS: Generated random passphrase",
2808 wps->new_psk, wps->new_psk_len);
2809 if (wps->wps->cred_cb)
2810 wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
2812 os_free(wps->new_psk);
2813 wps->new_psk = NULL;
2816 if (!wps->wps->ap && !wps->er)
2817 wps_sta_cred_cb(wps);
2820 if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
2821 wps->new_psk, wps->new_psk_len)) {
2822 wpa_printf(MSG_DEBUG, "WPS: Failed to configure the "
2825 os_free(wps->new_psk);
2826 wps->new_psk = NULL;
2829 wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e);
2832 wps_registrar_remove_pbc_session(wps->wps->registrar,
2833 wps->mac_addr_e, wps->uuid_e);
2834 wps_registrar_pbc_completed(wps->wps->registrar);
2836 wps_registrar_pin_completed(wps->wps->registrar);
2838 /* TODO: maintain AuthorizedMACs somewhere separately for each ER and
2839 * merge them into APs own list.. */
2841 wps_success_event(wps->wps);
2847 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
2848 enum wsc_op_code op_code,
2849 const struct wpabuf *msg)
2851 enum wps_process_res ret;
2853 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
2855 (unsigned long) wpabuf_len(msg), op_code);
2857 #ifdef CONFIG_WPS_UPNP
2858 if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) {
2859 struct wps_parse_attr attr;
2860 if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type &&
2861 *attr.msg_type == WPS_M3)
2862 wps->ext_reg = 2; /* past M2/M2D phase */
2864 if (wps->ext_reg > 1)
2865 wps_registrar_free_pending_m2(wps->wps);
2866 if (wps->wps->wps_upnp && wps->ext_reg &&
2867 wps->wps->upnp_msgs == NULL &&
2868 (op_code == WSC_MSG || op_code == WSC_Done || op_code == WSC_NACK))
2870 struct wps_parse_attr attr;
2872 if (wps_parse_msg(msg, &attr) < 0 || attr.msg_type == NULL)
2875 type = *attr.msg_type;
2876 wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)"
2877 " to external Registrar for processing", type);
2878 upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
2880 UPNP_WPS_WLANEVENT_TYPE_EAP,
2882 if (op_code == WSC_MSG)
2884 } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
2885 wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using "
2886 "external Registrar");
2887 return WPS_CONTINUE;
2889 #endif /* CONFIG_WPS_UPNP */
2893 return wps_process_wsc_msg(wps, msg);
2895 if (wps_validate_wsc_ack(msg) < 0)
2897 return wps_process_wsc_ack(wps, msg);
2899 if (wps_validate_wsc_nack(msg) < 0)
2901 return wps_process_wsc_nack(wps, msg);
2903 if (wps_validate_wsc_done(msg) < 0)
2905 ret = wps_process_wsc_done(wps, msg);
2906 if (ret == WPS_FAILURE) {
2907 wps->state = SEND_WSC_NACK;
2908 wps_fail_event(wps->wps, WPS_WSC_DONE);
2912 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
2918 int wps_registrar_update_ie(struct wps_registrar *reg)
2920 return wps_set_ie(reg);
2924 static void wps_registrar_set_selected_timeout(void *eloop_ctx,
2927 struct wps_registrar *reg = eloop_ctx;
2929 wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
2930 "unselect internal Registrar");
2931 reg->selected_registrar = 0;
2933 wps_registrar_selected_registrar_changed(reg);
2937 #ifdef CONFIG_WPS_UPNP
2938 static void wps_registrar_sel_reg_add(struct wps_registrar *reg,
2939 struct subscription *s)
2942 wpa_printf(MSG_DEBUG, "WPS: External Registrar selected (dev_pw_id=%d "
2943 "config_methods=0x%x)",
2944 s->dev_password_id, s->config_methods);
2945 reg->sel_reg_union = 1;
2946 if (reg->sel_reg_dev_password_id_override != DEV_PW_PUSHBUTTON)
2947 reg->sel_reg_dev_password_id_override = s->dev_password_id;
2948 if (reg->sel_reg_config_methods_override == -1)
2949 reg->sel_reg_config_methods_override = 0;
2950 reg->sel_reg_config_methods_override |= s->config_methods;
2951 for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++)
2952 if (is_zero_ether_addr(reg->authorized_macs_union[i]))
2954 for (j = 0; i < WPS_MAX_AUTHORIZED_MACS && j < WPS_MAX_AUTHORIZED_MACS;
2956 if (is_zero_ether_addr(s->authorized_macs[j]))
2958 wpa_printf(MSG_DEBUG, "WPS: Add authorized MAC into union: "
2959 MACSTR, MAC2STR(s->authorized_macs[j]));
2960 os_memcpy(reg->authorized_macs_union[i],
2961 s->authorized_macs[j], ETH_ALEN);
2964 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs union",
2965 (u8 *) reg->authorized_macs_union,
2966 sizeof(reg->authorized_macs_union));
2968 #endif /* CONFIG_WPS_UPNP */
2971 static void wps_registrar_sel_reg_union(struct wps_registrar *reg)
2973 #ifdef CONFIG_WPS_UPNP
2974 struct subscription *s;
2976 if (reg->wps->wps_upnp == NULL)
2979 dl_list_for_each(s, ®->wps->wps_upnp->subscriptions,
2980 struct subscription, list) {
2981 struct subscr_addr *sa;
2982 sa = dl_list_first(&s->addr_list, struct subscr_addr, list);
2984 wpa_printf(MSG_DEBUG, "WPS: External Registrar %s:%d",
2985 inet_ntoa(sa->saddr.sin_addr),
2986 ntohs(sa->saddr.sin_port));
2988 if (s->selected_registrar)
2989 wps_registrar_sel_reg_add(reg, s);
2991 wpa_printf(MSG_DEBUG, "WPS: External Registrar not "
2994 #endif /* CONFIG_WPS_UPNP */
2999 * wps_registrar_selected_registrar_changed - SetSelectedRegistrar change
3000 * @reg: Registrar data from wps_registrar_init()
3002 * This function is called when selected registrar state changes, e.g., when an
3003 * AP receives a SetSelectedRegistrar UPnP message.
3005 void wps_registrar_selected_registrar_changed(struct wps_registrar *reg)
3007 wpa_printf(MSG_DEBUG, "WPS: Selected registrar information changed");
3009 reg->sel_reg_union = reg->selected_registrar;
3010 reg->sel_reg_dev_password_id_override = -1;
3011 reg->sel_reg_config_methods_override = -1;
3012 os_memcpy(reg->authorized_macs_union, reg->authorized_macs,
3013 WPS_MAX_AUTHORIZED_MACS * ETH_ALEN);
3014 wpa_hexdump(MSG_DEBUG, "WPS: Authorized MACs union (start with own)",
3015 (u8 *) reg->authorized_macs_union,
3016 sizeof(reg->authorized_macs_union));
3017 if (reg->selected_registrar) {
3020 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
3022 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
3023 WPS_CONFIG_PHY_PUSHBUTTON);
3024 #endif /* CONFIG_WPS2 */
3026 reg->sel_reg_dev_password_id_override =
3028 wps_set_pushbutton(&methods, reg->wps->config_methods);
3030 wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
3031 "(pbc=%d)", reg->pbc);
3032 reg->sel_reg_config_methods_override = methods;
3034 wpa_printf(MSG_DEBUG, "WPS: Internal Registrar not selected");
3036 wps_registrar_sel_reg_union(reg);
3039 wps_cb_set_sel_reg(reg);
3043 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
3044 char *buf, size_t buflen)
3046 struct wps_registrar_device *d;
3049 char devtype[WPS_DEV_TYPE_BUFSIZE];
3051 d = wps_device_get(reg, addr);
3054 if (uuid_bin2str(d->uuid, uuid, sizeof(uuid)))
3057 ret = os_snprintf(buf + len, buflen - len,
3059 "wpsPrimaryDeviceType=%s\n"
3060 "wpsDeviceName=%s\n"
3061 "wpsManufacturer=%s\n"
3063 "wpsModelNumber=%s\n"
3064 "wpsSerialNumber=%s\n",
3066 wps_dev_type_bin2str(d->dev.pri_dev_type, devtype,
3068 d->dev.device_name ? d->dev.device_name : "",
3069 d->dev.manufacturer ? d->dev.manufacturer : "",
3070 d->dev.model_name ? d->dev.model_name : "",
3071 d->dev.model_number ? d->dev.model_number : "",
3072 d->dev.serial_number ? d->dev.serial_number : "");
3073 if (ret < 0 || (size_t) ret >= buflen - len)