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 for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++)
150 if (os_memcmp(reg->authorized_macs[i], addr, ETH_ALEN) == 0)
151 return; /* already in list */
152 for (i = WPS_MAX_AUTHORIZED_MACS - 1; i > 0; i--)
153 os_memcpy(reg->authorized_macs[i], reg->authorized_macs[i - 1],
155 os_memcpy(reg->authorized_macs[0], addr, ETH_ALEN);
159 static void wps_registrar_remove_authorized_mac(struct wps_registrar *reg,
163 for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++) {
164 if (os_memcmp(reg->authorized_macs, addr, ETH_ALEN) == 0)
167 if (i == WPS_MAX_AUTHORIZED_MACS)
168 return; /* not in the list */
169 for (; i + 1 < WPS_MAX_AUTHORIZED_MACS; i++)
170 os_memcpy(reg->authorized_macs[i], reg->authorized_macs[i + 1],
172 os_memset(reg->authorized_macs[WPS_MAX_AUTHORIZED_MACS - 1], 0,
177 static void wps_free_devices(struct wps_registrar_device *dev)
179 struct wps_registrar_device *prev;
184 wps_device_data_free(&prev->dev);
190 static struct wps_registrar_device * wps_device_get(struct wps_registrar *reg,
193 struct wps_registrar_device *dev;
195 for (dev = reg->devices; dev; dev = dev->next) {
196 if (os_memcmp(dev->dev.mac_addr, addr, ETH_ALEN) == 0)
203 static void wps_device_clone_data(struct wps_device_data *dst,
204 struct wps_device_data *src)
206 os_memcpy(dst->mac_addr, src->mac_addr, ETH_ALEN);
207 os_memcpy(dst->pri_dev_type, src->pri_dev_type, WPS_DEV_TYPE_LEN);
209 #define WPS_STRDUP(n) \
211 dst->n = src->n ? os_strdup(src->n) : NULL
213 WPS_STRDUP(device_name);
214 WPS_STRDUP(manufacturer);
215 WPS_STRDUP(model_name);
216 WPS_STRDUP(model_number);
217 WPS_STRDUP(serial_number);
222 int wps_device_store(struct wps_registrar *reg,
223 struct wps_device_data *dev, const u8 *uuid)
225 struct wps_registrar_device *d;
227 d = wps_device_get(reg, dev->mac_addr);
229 d = os_zalloc(sizeof(*d));
232 d->next = reg->devices;
236 wps_device_clone_data(&d->dev, dev);
237 os_memcpy(d->uuid, uuid, WPS_UUID_LEN);
243 static void wps_registrar_add_pbc_session(struct wps_registrar *reg,
244 const u8 *addr, const u8 *uuid_e)
246 struct wps_pbc_session *pbc, *prev = NULL;
251 pbc = reg->pbc_sessions;
253 if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
254 os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
256 prev->next = pbc->next;
258 reg->pbc_sessions = pbc->next;
266 pbc = os_zalloc(sizeof(*pbc));
269 os_memcpy(pbc->addr, addr, ETH_ALEN);
271 os_memcpy(pbc->uuid_e, uuid_e, WPS_UUID_LEN);
274 pbc->next = reg->pbc_sessions;
275 reg->pbc_sessions = pbc;
276 pbc->timestamp = now;
278 /* remove entries that have timed out */
283 if (now.sec > pbc->timestamp.sec + WPS_PBC_WALK_TIME) {
285 wps_free_pbc_sessions(pbc);
294 static void wps_registrar_remove_pbc_session(struct wps_registrar *reg,
295 const u8 *addr, const u8 *uuid_e)
297 struct wps_pbc_session *pbc, *prev = NULL;
299 pbc = reg->pbc_sessions;
301 if (os_memcmp(pbc->addr, addr, ETH_ALEN) == 0 &&
302 os_memcmp(pbc->uuid_e, uuid_e, WPS_UUID_LEN) == 0) {
304 prev->next = pbc->next;
306 reg->pbc_sessions = pbc->next;
316 static int wps_registrar_pbc_overlap(struct wps_registrar *reg,
317 const u8 *addr, const u8 *uuid_e)
320 struct wps_pbc_session *pbc;
325 for (pbc = reg->pbc_sessions; pbc; pbc = pbc->next) {
326 if (now.sec > pbc->timestamp.sec + WPS_PBC_WALK_TIME)
328 if (addr == NULL || os_memcmp(addr, pbc->addr, ETH_ALEN) ||
330 os_memcmp(uuid_e, pbc->uuid_e, WPS_UUID_LEN))
337 return count > 1 ? 1 : 0;
341 static int wps_build_wps_state(struct wps_context *wps, struct wpabuf *msg)
343 wpa_printf(MSG_DEBUG, "WPS: * Wi-Fi Protected Setup State (%d)",
345 wpabuf_put_be16(msg, ATTR_WPS_STATE);
346 wpabuf_put_be16(msg, 1);
347 wpabuf_put_u8(msg, wps->wps_state);
352 #ifdef CONFIG_WPS_UPNP
353 static void wps_registrar_free_pending_m2(struct wps_context *wps)
355 struct upnp_pending_message *p, *p2, *prev = NULL;
358 if (p->type == WPS_M2 || p->type == WPS_M2D) {
360 wps->upnp_msgs = p->next;
362 prev->next = p->next;
363 wpa_printf(MSG_DEBUG, "WPS UPnP: Drop pending M2/M2D");
366 wpabuf_free(p2->msg);
374 #endif /* CONFIG_WPS_UPNP */
377 static int wps_build_ap_setup_locked(struct wps_context *wps,
380 if (wps->ap_setup_locked) {
381 wpa_printf(MSG_DEBUG, "WPS: * AP Setup Locked");
382 wpabuf_put_be16(msg, ATTR_AP_SETUP_LOCKED);
383 wpabuf_put_be16(msg, 1);
384 wpabuf_put_u8(msg, 1);
390 static int wps_build_selected_registrar(struct wps_registrar *reg,
393 if (!reg->sel_reg_union)
395 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar");
396 wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR);
397 wpabuf_put_be16(msg, 1);
398 wpabuf_put_u8(msg, 1);
403 static int wps_build_sel_reg_dev_password_id(struct wps_registrar *reg,
406 u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
407 if (!reg->sel_reg_union)
409 if (reg->sel_reg_dev_password_id_override >= 0)
410 id = reg->sel_reg_dev_password_id_override;
411 wpa_printf(MSG_DEBUG, "WPS: * Device Password ID (%d)", id);
412 wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
413 wpabuf_put_be16(msg, 2);
414 wpabuf_put_be16(msg, id);
419 static void wps_set_pushbutton(u16 *methods, u16 conf_methods)
421 *methods |= WPS_CONFIG_PUSHBUTTON;
423 if (conf_methods & WPS_CONFIG_VIRT_PUSHBUTTON)
424 *methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
425 if (conf_methods & WPS_CONFIG_PHY_PUSHBUTTON)
426 *methods |= WPS_CONFIG_PHY_PUSHBUTTON;
427 if ((*methods & WPS_CONFIG_VIRT_PUSHBUTTON) !=
428 WPS_CONFIG_VIRT_PUSHBUTTON ||
429 (*methods & WPS_CONFIG_PHY_PUSHBUTTON) !=
430 WPS_CONFIG_PHY_PUSHBUTTON) {
432 * Required to include virtual/physical flag, but we were not
433 * configured with push button type, so have to default to one
436 *methods |= WPS_CONFIG_PHY_PUSHBUTTON;
438 #endif /* CONFIG_WPS2 */
442 static int wps_build_sel_reg_config_methods(struct wps_registrar *reg,
446 if (!reg->sel_reg_union)
448 methods = reg->wps->config_methods;
449 methods &= ~WPS_CONFIG_PUSHBUTTON;
451 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
452 WPS_CONFIG_PHY_PUSHBUTTON);
453 #endif /* CONFIG_WPS2 */
455 wps_set_pushbutton(&methods, reg->wps->config_methods);
456 if (reg->sel_reg_config_methods_override >= 0)
457 methods = reg->sel_reg_config_methods_override;
458 wpa_printf(MSG_DEBUG, "WPS: * Selected Registrar Config Methods (%x)",
460 wpabuf_put_be16(msg, ATTR_SELECTED_REGISTRAR_CONFIG_METHODS);
461 wpabuf_put_be16(msg, 2);
462 wpabuf_put_be16(msg, methods);
467 static int wps_build_probe_config_methods(struct wps_registrar *reg,
472 * These are the methods that the AP supports as an Enrollee for adding
473 * external Registrars.
475 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
477 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
478 WPS_CONFIG_PHY_PUSHBUTTON);
479 #endif /* CONFIG_WPS2 */
480 wpa_printf(MSG_DEBUG, "WPS: * Config Methods (%x)", methods);
481 wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
482 wpabuf_put_be16(msg, 2);
483 wpabuf_put_be16(msg, methods);
488 static int wps_build_config_methods_r(struct wps_registrar *reg,
492 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
494 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
495 WPS_CONFIG_PHY_PUSHBUTTON);
496 #endif /* CONFIG_WPS2 */
498 wps_set_pushbutton(&methods, reg->wps->config_methods);
499 return wps_build_config_methods(msg, methods);
503 int wps_build_authorized_macs(struct wps_registrar *reg, struct wpabuf *msg)
508 while (count < WPS_MAX_AUTHORIZED_MACS) {
509 if (is_zero_ether_addr(reg->authorized_macs_union[count]))
517 wpa_printf(MSG_DEBUG, "WPS: * AuthorizedMACs (count=%d)", count);
518 wpabuf_put_be16(msg, ATTR_AUTHORIZED_MACS);
519 wpabuf_put_be16(msg, count * ETH_ALEN);
520 wpabuf_put_data(msg, reg->authorized_macs_union, count * ETH_ALEN);
521 #endif /* CONFIG_WPS2 */
528 * wps_registrar_init - Initialize WPS Registrar data
529 * @wps: Pointer to longterm WPS context
530 * @cfg: Registrar configuration
531 * Returns: Pointer to allocated Registrar data or %NULL on failure
533 * This function is used to initialize WPS Registrar functionality. It can be
534 * used for a single Registrar run (e.g., when run in a supplicant) or multiple
535 * runs (e.g., when run as an internal Registrar in an AP). Caller is
536 * responsible for freeing the returned data with wps_registrar_deinit() when
537 * Registrar functionality is not needed anymore.
539 struct wps_registrar *
540 wps_registrar_init(struct wps_context *wps,
541 const struct wps_registrar_config *cfg)
543 struct wps_registrar *reg = os_zalloc(sizeof(*reg));
547 dl_list_init(®->pins);
549 reg->new_psk_cb = cfg->new_psk_cb;
550 reg->set_ie_cb = cfg->set_ie_cb;
551 reg->pin_needed_cb = cfg->pin_needed_cb;
552 reg->reg_success_cb = cfg->reg_success_cb;
553 reg->set_sel_reg_cb = cfg->set_sel_reg_cb;
554 reg->enrollee_seen_cb = cfg->enrollee_seen_cb;
555 reg->cb_ctx = cfg->cb_ctx;
556 reg->skip_cred_build = cfg->skip_cred_build;
557 if (cfg->extra_cred) {
558 reg->extra_cred = wpabuf_alloc_copy(cfg->extra_cred,
559 cfg->extra_cred_len);
560 if (reg->extra_cred == NULL) {
565 reg->disable_auto_conf = cfg->disable_auto_conf;
566 reg->sel_reg_dev_password_id_override = -1;
567 reg->sel_reg_config_methods_override = -1;
568 reg->static_wep_only = cfg->static_wep_only;
570 if (wps_set_ie(reg)) {
571 wps_registrar_deinit(reg);
580 * wps_registrar_deinit - Deinitialize WPS Registrar data
581 * @reg: Registrar data from wps_registrar_init()
583 void wps_registrar_deinit(struct wps_registrar *reg)
587 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
588 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
589 wps_free_pins(®->pins);
590 wps_free_pbc_sessions(reg->pbc_sessions);
591 wpabuf_free(reg->extra_cred);
592 wps_free_devices(reg->devices);
598 * wps_registrar_add_pin - Configure a new PIN for Registrar
599 * @reg: Registrar data from wps_registrar_init()
600 * @addr: Enrollee MAC address or %NULL if not known
601 * @uuid: UUID-E or %NULL for wildcard (any UUID)
602 * @pin: PIN (Device Password)
603 * @pin_len: Length of pin in octets
604 * @timeout: Time (in seconds) when the PIN will be invalidated; 0 = no timeout
605 * Returns: 0 on success, -1 on failure
607 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
608 const u8 *uuid, const u8 *pin, size_t pin_len,
611 struct wps_uuid_pin *p;
613 p = os_zalloc(sizeof(*p));
617 os_memcpy(p->enrollee_addr, addr, ETH_ALEN);
619 p->wildcard_uuid = 1;
621 os_memcpy(p->uuid, uuid, WPS_UUID_LEN);
622 p->pin = os_malloc(pin_len);
623 if (p->pin == NULL) {
627 os_memcpy(p->pin, pin, pin_len);
628 p->pin_len = pin_len;
631 p->flags |= PIN_EXPIRES;
632 os_get_time(&p->expiration);
633 p->expiration.sec += timeout;
636 dl_list_add(®->pins, &p->list);
638 wpa_printf(MSG_DEBUG, "WPS: A new PIN configured (timeout=%d)",
640 wpa_hexdump(MSG_DEBUG, "WPS: UUID", uuid, WPS_UUID_LEN);
641 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: PIN", pin, pin_len);
642 reg->selected_registrar = 1;
645 wps_registrar_add_authorized_mac(reg, addr);
647 wps_registrar_add_authorized_mac(
648 reg, (u8 *) "\xff\xff\xff\xff\xff\xff");
649 wps_registrar_selected_registrar_changed(reg);
650 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
651 eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
652 wps_registrar_set_selected_timeout,
659 static void wps_registrar_expire_pins(struct wps_registrar *reg)
661 struct wps_uuid_pin *pin, *prev;
665 dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
667 if ((pin->flags & PIN_EXPIRES) &&
668 os_time_before(&pin->expiration, &now)) {
671 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
672 wpa_hexdump(MSG_DEBUG, "WPS: Expired PIN for UUID",
673 pin->uuid, WPS_UUID_LEN);
674 if (is_zero_ether_addr(pin->enrollee_addr))
677 addr = pin->enrollee_addr;
678 wps_registrar_remove_authorized_mac(reg, addr);
680 wps_registrar_selected_registrar_changed(reg);
687 * wps_registrar_invalidate_pin - Invalidate a PIN for a specific UUID-E
688 * @reg: Registrar data from wps_registrar_init()
690 * Returns: 0 on success, -1 on failure (e.g., PIN not found)
692 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid)
694 struct wps_uuid_pin *pin, *prev;
696 dl_list_for_each_safe(pin, prev, ®->pins, struct wps_uuid_pin, list)
698 if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
701 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
702 wpa_hexdump(MSG_DEBUG, "WPS: Invalidated PIN for UUID",
703 pin->uuid, WPS_UUID_LEN);
704 if (is_zero_ether_addr(pin->enrollee_addr))
707 addr = pin->enrollee_addr;
708 wps_registrar_remove_authorized_mac(reg, addr);
710 wps_registrar_selected_registrar_changed(reg);
719 static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
720 const u8 *uuid, size_t *pin_len)
722 struct wps_uuid_pin *pin, *found = NULL;
724 wps_registrar_expire_pins(reg);
726 dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
727 if (!pin->wildcard_uuid &&
728 os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
735 /* Check for wildcard UUIDs since none of the UUID-specific
737 dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
738 if (pin->wildcard_uuid == 1) {
739 wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
740 "PIN. Assigned it for this UUID-E");
741 pin->wildcard_uuid = 2;
742 os_memcpy(pin->uuid, uuid, WPS_UUID_LEN);
753 * Lock the PIN to avoid attacks based on concurrent re-use of the PIN
754 * that could otherwise avoid PIN invalidations.
756 if (found->flags & PIN_LOCKED) {
757 wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
758 "allow concurrent re-use");
761 *pin_len = found->pin_len;
762 found->flags |= PIN_LOCKED;
768 * wps_registrar_unlock_pin - Unlock a PIN for a specific UUID-E
769 * @reg: Registrar data from wps_registrar_init()
771 * Returns: 0 on success, -1 on failure
773 * PINs are locked to enforce only one concurrent use. This function unlocks a
774 * PIN to allow it to be used again. If the specified PIN was configured using
775 * a wildcard UUID, it will be removed instead of allowing multiple uses.
777 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid)
779 struct wps_uuid_pin *pin;
781 dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
782 if (os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
783 if (pin->wildcard_uuid == 2) {
784 wpa_printf(MSG_DEBUG, "WPS: Invalidating used "
786 return wps_registrar_invalidate_pin(reg, uuid);
788 pin->flags &= ~PIN_LOCKED;
797 static void wps_registrar_stop_pbc(struct wps_registrar *reg)
799 reg->selected_registrar = 0;
801 wps_registrar_selected_registrar_changed(reg);
805 static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx)
807 struct wps_registrar *reg = eloop_ctx;
809 wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
810 wps_pbc_timeout_event(reg->wps);
811 wps_registrar_stop_pbc(reg);
816 * wps_registrar_button_pushed - Notify Registrar that AP button was pushed
817 * @reg: Registrar data from wps_registrar_init()
818 * Returns: 0 on success, -1 on failure
820 * This function is called on an AP when a push button is pushed to activate
821 * PBC mode. The PBC mode will be stopped after walk time (2 minutes) timeout
822 * or when a PBC registration is completed.
824 int wps_registrar_button_pushed(struct wps_registrar *reg)
826 if (wps_registrar_pbc_overlap(reg, NULL, NULL)) {
827 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
829 wps_pbc_overlap_event(reg->wps);
832 wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
833 reg->force_pbc_overlap = 0;
834 reg->selected_registrar = 1;
836 wps_registrar_selected_registrar_changed(reg);
838 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
839 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
845 static void wps_registrar_pbc_completed(struct wps_registrar *reg)
847 wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
848 eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
849 wps_registrar_stop_pbc(reg);
853 static void wps_registrar_pin_completed(struct wps_registrar *reg)
855 wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
856 eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
857 reg->selected_registrar = 0;
858 wps_registrar_selected_registrar_changed(reg);
863 * wps_registrar_probe_req_rx - Notify Registrar of Probe Request
864 * @reg: Registrar data from wps_registrar_init()
865 * @addr: MAC address of the Probe Request sender
866 * @wps_data: WPS IE contents
868 * This function is called on an AP when a Probe Request with WPS IE is
869 * received. This is used to track PBC mode use and to detect possible overlap
870 * situation with other WPS APs.
872 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
873 const struct wpabuf *wps_data)
875 struct wps_parse_attr attr;
877 wpa_hexdump_buf(MSG_MSGDUMP,
878 "WPS: Probe Request with WPS data received",
881 if (wps_parse_msg(wps_data, &attr) < 0)
884 if (attr.config_methods == NULL) {
885 wpa_printf(MSG_DEBUG, "WPS: No Config Methods attribute in "
890 if (attr.dev_password_id == NULL) {
891 wpa_printf(MSG_DEBUG, "WPS: No Device Password Id attribute "
896 if (reg->enrollee_seen_cb && attr.uuid_e &&
897 attr.primary_dev_type && attr.request_type) {
898 char *dev_name = NULL;
900 dev_name = os_zalloc(attr.dev_name_len + 1);
902 os_memcpy(dev_name, attr.dev_name,
906 reg->enrollee_seen_cb(reg->cb_ctx, addr, attr.uuid_e,
907 attr.primary_dev_type,
908 WPA_GET_BE16(attr.config_methods),
909 WPA_GET_BE16(attr.dev_password_id),
910 *attr.request_type, dev_name);
914 if (WPA_GET_BE16(attr.dev_password_id) != DEV_PW_PUSHBUTTON)
915 return; /* Not PBC */
917 wpa_printf(MSG_DEBUG, "WPS: Probe Request for PBC received from "
918 MACSTR, MAC2STR(addr));
919 if (attr.uuid_e == NULL) {
920 wpa_printf(MSG_DEBUG, "WPS: Invalid Probe Request WPS IE: No "
925 wps_registrar_add_pbc_session(reg, addr, attr.uuid_e);
926 if (wps_registrar_pbc_overlap(reg, addr, attr.uuid_e)) {
927 wpa_printf(MSG_DEBUG, "WPS: PBC session overlap detected");
928 reg->force_pbc_overlap = 1;
929 wps_pbc_overlap_event(reg->wps);
934 static int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
935 const u8 *psk, size_t psk_len)
937 if (reg->new_psk_cb == NULL)
940 return reg->new_psk_cb(reg->cb_ctx, mac_addr, psk, psk_len);
944 static void wps_cb_pin_needed(struct wps_registrar *reg, const u8 *uuid_e,
945 const struct wps_device_data *dev)
947 if (reg->pin_needed_cb == NULL)
950 reg->pin_needed_cb(reg->cb_ctx, uuid_e, dev);
954 static void wps_cb_reg_success(struct wps_registrar *reg, const u8 *mac_addr,
957 if (reg->reg_success_cb == NULL)
960 reg->reg_success_cb(reg->cb_ctx, mac_addr, uuid_e);
964 static int wps_cb_set_ie(struct wps_registrar *reg, struct wpabuf *beacon_ie,
965 struct wpabuf *probe_resp_ie)
967 return reg->set_ie_cb(reg->cb_ctx, beacon_ie, probe_resp_ie);
971 static void wps_cb_set_sel_reg(struct wps_registrar *reg)
974 if (reg->set_sel_reg_cb == NULL)
977 if (reg->selected_registrar) {
978 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
980 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
981 WPS_CONFIG_PHY_PUSHBUTTON);
982 #endif /* CONFIG_WPS2 */
984 wps_set_pushbutton(&methods, reg->wps->config_methods);
987 wpa_printf(MSG_DEBUG, "WPS: wps_cb_set_sel_reg: sel_reg=%d "
988 "config_methods=0x%x pbc=%d methods=0x%x",
989 reg->selected_registrar, reg->wps->config_methods,
992 reg->set_sel_reg_cb(reg->cb_ctx, reg->selected_registrar,
993 reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT,
998 static int wps_set_ie(struct wps_registrar *reg)
1000 struct wpabuf *beacon;
1001 struct wpabuf *probe;
1003 if (reg->set_ie_cb == NULL)
1006 beacon = wpabuf_alloc(400);
1009 probe = wpabuf_alloc(500);
1010 if (probe == NULL) {
1011 wpabuf_free(beacon);
1015 wpa_printf(MSG_DEBUG, "WPS: Build Beacon IEs");
1017 if (wps_build_version(beacon) ||
1018 wps_build_wps_state(reg->wps, beacon) ||
1019 wps_build_ap_setup_locked(reg->wps, beacon) ||
1020 wps_build_selected_registrar(reg, beacon) ||
1021 wps_build_sel_reg_dev_password_id(reg, beacon) ||
1022 wps_build_sel_reg_config_methods(reg, beacon) ||
1023 wps_build_version2(beacon) ||
1024 wps_build_authorized_macs(reg, beacon)) {
1025 wpabuf_free(beacon);
1030 wpa_printf(MSG_DEBUG, "WPS: Build Probe Response IEs");
1032 if (wps_build_version(probe) ||
1033 wps_build_wps_state(reg->wps, probe) ||
1034 wps_build_ap_setup_locked(reg->wps, probe) ||
1035 wps_build_selected_registrar(reg, probe) ||
1036 wps_build_sel_reg_dev_password_id(reg, probe) ||
1037 wps_build_sel_reg_config_methods(reg, probe) ||
1038 wps_build_resp_type(probe, reg->wps->ap ? WPS_RESP_AP :
1039 WPS_RESP_REGISTRAR) ||
1040 wps_build_uuid_e(probe, reg->wps->uuid) ||
1041 wps_build_device_attrs(®->wps->dev, probe) ||
1042 wps_build_probe_config_methods(reg, probe) ||
1043 wps_build_rf_bands(®->wps->dev, probe) ||
1044 wps_build_version2(probe) ||
1045 wps_build_authorized_macs(reg, probe)) {
1046 wpabuf_free(beacon);
1051 beacon = wps_ie_encapsulate(beacon);
1052 probe = wps_ie_encapsulate(probe);
1054 if (!beacon || !probe) {
1055 wpabuf_free(beacon);
1060 if (reg->static_wep_only) {
1062 * Windows XP and Vista clients can get confused about
1063 * EAP-Identity/Request when they probe the network with
1064 * EAPOL-Start. In such a case, they may assume the network is
1065 * using IEEE 802.1X and prompt user for a certificate while
1066 * the correct (non-WPS) behavior would be to ask for the
1067 * static WEP key. As a workaround, use Microsoft Provisioning
1068 * IE to advertise that legacy 802.1X is not supported.
1070 const u8 ms_wps[7] = {
1071 WLAN_EID_VENDOR_SPECIFIC, 5,
1072 /* Microsoft Provisioning IE (00:50:f2:5) */
1073 0x00, 0x50, 0xf2, 5,
1074 0x00 /* no legacy 802.1X or MS WPS */
1076 wpa_printf(MSG_DEBUG, "WPS: Add Microsoft Provisioning IE "
1077 "into Beacon/Probe Response frames");
1078 wpabuf_put_data(beacon, ms_wps, sizeof(ms_wps));
1079 wpabuf_put_data(probe, ms_wps, sizeof(ms_wps));
1082 return wps_cb_set_ie(reg, beacon, probe);
1086 static int wps_get_dev_password(struct wps_data *wps)
1091 os_free(wps->dev_password);
1092 wps->dev_password = NULL;
1095 wpa_printf(MSG_DEBUG, "WPS: Use default PIN for PBC");
1096 pin = (const u8 *) "00000000";
1099 pin = wps_registrar_get_pin(wps->wps->registrar, wps->uuid_e,
1103 wpa_printf(MSG_DEBUG, "WPS: No Device Password available for "
1105 wps_cb_pin_needed(wps->wps->registrar, wps->uuid_e,
1110 wps->dev_password = os_malloc(pin_len);
1111 if (wps->dev_password == NULL)
1113 os_memcpy(wps->dev_password, pin, pin_len);
1114 wps->dev_password_len = pin_len;
1120 static int wps_build_uuid_r(struct wps_data *wps, struct wpabuf *msg)
1122 wpa_printf(MSG_DEBUG, "WPS: * UUID-R");
1123 wpabuf_put_be16(msg, ATTR_UUID_R);
1124 wpabuf_put_be16(msg, WPS_UUID_LEN);
1125 wpabuf_put_data(msg, wps->uuid_r, WPS_UUID_LEN);
1130 static int wps_build_r_hash(struct wps_data *wps, struct wpabuf *msg)
1136 if (os_get_random(wps->snonce, 2 * WPS_SECRET_NONCE_LEN) < 0)
1138 wpa_hexdump(MSG_DEBUG, "WPS: R-S1", wps->snonce, WPS_SECRET_NONCE_LEN);
1139 wpa_hexdump(MSG_DEBUG, "WPS: R-S2",
1140 wps->snonce + WPS_SECRET_NONCE_LEN, WPS_SECRET_NONCE_LEN);
1142 if (wps->dh_pubkey_e == NULL || wps->dh_pubkey_r == NULL) {
1143 wpa_printf(MSG_DEBUG, "WPS: DH public keys not available for "
1144 "R-Hash derivation");
1148 wpa_printf(MSG_DEBUG, "WPS: * R-Hash1");
1149 wpabuf_put_be16(msg, ATTR_R_HASH1);
1150 wpabuf_put_be16(msg, SHA256_MAC_LEN);
1151 hash = wpabuf_put(msg, SHA256_MAC_LEN);
1152 /* R-Hash1 = HMAC_AuthKey(R-S1 || PSK1 || PK_E || PK_R) */
1153 addr[0] = wps->snonce;
1154 len[0] = WPS_SECRET_NONCE_LEN;
1155 addr[1] = wps->psk1;
1156 len[1] = WPS_PSK_LEN;
1157 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1158 len[2] = wpabuf_len(wps->dh_pubkey_e);
1159 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1160 len[3] = wpabuf_len(wps->dh_pubkey_r);
1161 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1162 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash1", hash, SHA256_MAC_LEN);
1164 wpa_printf(MSG_DEBUG, "WPS: * R-Hash2");
1165 wpabuf_put_be16(msg, ATTR_R_HASH2);
1166 wpabuf_put_be16(msg, SHA256_MAC_LEN);
1167 hash = wpabuf_put(msg, SHA256_MAC_LEN);
1168 /* R-Hash2 = HMAC_AuthKey(R-S2 || PSK2 || PK_E || PK_R) */
1169 addr[0] = wps->snonce + WPS_SECRET_NONCE_LEN;
1170 addr[1] = wps->psk2;
1171 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1172 wpa_hexdump(MSG_DEBUG, "WPS: R-Hash2", hash, SHA256_MAC_LEN);
1178 static int wps_build_r_snonce1(struct wps_data *wps, struct wpabuf *msg)
1180 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce1");
1181 wpabuf_put_be16(msg, ATTR_R_SNONCE1);
1182 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
1183 wpabuf_put_data(msg, wps->snonce, WPS_SECRET_NONCE_LEN);
1188 static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
1190 wpa_printf(MSG_DEBUG, "WPS: * R-SNonce2");
1191 wpabuf_put_be16(msg, ATTR_R_SNONCE2);
1192 wpabuf_put_be16(msg, WPS_SECRET_NONCE_LEN);
1193 wpabuf_put_data(msg, wps->snonce + WPS_SECRET_NONCE_LEN,
1194 WPS_SECRET_NONCE_LEN);
1199 static int wps_build_cred_network_idx(struct wpabuf *msg,
1200 const struct wps_credential *cred)
1202 wpa_printf(MSG_DEBUG, "WPS: * Network Index");
1203 wpabuf_put_be16(msg, ATTR_NETWORK_INDEX);
1204 wpabuf_put_be16(msg, 1);
1205 wpabuf_put_u8(msg, 1);
1210 static int wps_build_cred_ssid(struct wpabuf *msg,
1211 const struct wps_credential *cred)
1213 wpa_printf(MSG_DEBUG, "WPS: * SSID");
1214 wpabuf_put_be16(msg, ATTR_SSID);
1215 wpabuf_put_be16(msg, cred->ssid_len);
1216 wpabuf_put_data(msg, cred->ssid, cred->ssid_len);
1221 static int wps_build_cred_auth_type(struct wpabuf *msg,
1222 const struct wps_credential *cred)
1224 wpa_printf(MSG_DEBUG, "WPS: * Authentication Type (0x%x)",
1226 wpabuf_put_be16(msg, ATTR_AUTH_TYPE);
1227 wpabuf_put_be16(msg, 2);
1228 wpabuf_put_be16(msg, cred->auth_type);
1233 static int wps_build_cred_encr_type(struct wpabuf *msg,
1234 const struct wps_credential *cred)
1236 wpa_printf(MSG_DEBUG, "WPS: * Encryption Type (0x%x)",
1238 wpabuf_put_be16(msg, ATTR_ENCR_TYPE);
1239 wpabuf_put_be16(msg, 2);
1240 wpabuf_put_be16(msg, cred->encr_type);
1245 static int wps_build_cred_network_key(struct wpabuf *msg,
1246 const struct wps_credential *cred)
1248 wpa_printf(MSG_DEBUG, "WPS: * Network Key (len=%d)",
1249 (int) cred->key_len);
1250 wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
1251 wpabuf_put_be16(msg, cred->key_len);
1252 wpabuf_put_data(msg, cred->key, cred->key_len);
1257 static int wps_build_cred_mac_addr(struct wpabuf *msg,
1258 const struct wps_credential *cred)
1260 wpa_printf(MSG_DEBUG, "WPS: * MAC Address (" MACSTR ")",
1261 MAC2STR(cred->mac_addr));
1262 wpabuf_put_be16(msg, ATTR_MAC_ADDR);
1263 wpabuf_put_be16(msg, ETH_ALEN);
1264 wpabuf_put_data(msg, cred->mac_addr, ETH_ALEN);
1269 static int wps_build_credential(struct wpabuf *msg,
1270 const struct wps_credential *cred)
1272 if (wps_build_cred_network_idx(msg, cred) ||
1273 wps_build_cred_ssid(msg, cred) ||
1274 wps_build_cred_auth_type(msg, cred) ||
1275 wps_build_cred_encr_type(msg, cred) ||
1276 wps_build_cred_network_key(msg, cred) ||
1277 wps_build_cred_mac_addr(msg, cred))
1283 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
1285 struct wpabuf *cred;
1287 if (wps->wps->registrar->skip_cred_build)
1288 goto skip_cred_build;
1290 wpa_printf(MSG_DEBUG, "WPS: * Credential");
1291 if (wps->use_cred) {
1292 os_memcpy(&wps->cred, wps->use_cred, sizeof(wps->cred));
1295 os_memset(&wps->cred, 0, sizeof(wps->cred));
1297 os_memcpy(wps->cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
1298 wps->cred.ssid_len = wps->wps->ssid_len;
1300 /* Select the best authentication and encryption type */
1301 if (wps->auth_type & WPS_AUTH_WPA2PSK)
1302 wps->auth_type = WPS_AUTH_WPA2PSK;
1303 else if (wps->auth_type & WPS_AUTH_WPAPSK)
1304 wps->auth_type = WPS_AUTH_WPAPSK;
1305 else if (wps->auth_type & WPS_AUTH_OPEN)
1306 wps->auth_type = WPS_AUTH_OPEN;
1307 else if (wps->auth_type & WPS_AUTH_SHARED)
1308 wps->auth_type = WPS_AUTH_SHARED;
1310 wpa_printf(MSG_DEBUG, "WPS: Unsupported auth_type 0x%x",
1314 wps->cred.auth_type = wps->auth_type;
1316 if (wps->auth_type == WPS_AUTH_WPA2PSK ||
1317 wps->auth_type == WPS_AUTH_WPAPSK) {
1318 if (wps->encr_type & WPS_ENCR_AES)
1319 wps->encr_type = WPS_ENCR_AES;
1320 else if (wps->encr_type & WPS_ENCR_TKIP)
1321 wps->encr_type = WPS_ENCR_TKIP;
1323 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1324 "type for WPA/WPA2");
1328 if (wps->encr_type & WPS_ENCR_WEP)
1329 wps->encr_type = WPS_ENCR_WEP;
1330 else if (wps->encr_type & WPS_ENCR_NONE)
1331 wps->encr_type = WPS_ENCR_NONE;
1333 wpa_printf(MSG_DEBUG, "WPS: No suitable encryption "
1334 "type for non-WPA/WPA2 mode");
1338 wps->cred.encr_type = wps->encr_type;
1340 * Set MAC address in the Credential to be the Enrollee's MAC address
1342 os_memcpy(wps->cred.mac_addr, wps->mac_addr_e, ETH_ALEN);
1344 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->wps->ap &&
1345 !wps->wps->registrar->disable_auto_conf) {
1347 /* Generate a random passphrase */
1348 if (os_get_random(r, sizeof(r)) < 0)
1350 os_free(wps->new_psk);
1351 wps->new_psk = base64_encode(r, sizeof(r), &wps->new_psk_len);
1352 if (wps->new_psk == NULL)
1354 wps->new_psk_len--; /* remove newline */
1355 while (wps->new_psk_len &&
1356 wps->new_psk[wps->new_psk_len - 1] == '=')
1358 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Generated passphrase",
1359 wps->new_psk, wps->new_psk_len);
1360 os_memcpy(wps->cred.key, wps->new_psk, wps->new_psk_len);
1361 wps->cred.key_len = wps->new_psk_len;
1362 } else if (wps->use_psk_key && wps->wps->psk_set) {
1364 wpa_printf(MSG_DEBUG, "WPS: Use PSK format for Network Key");
1365 wpa_snprintf_hex(hex, sizeof(hex), wps->wps->psk, 32);
1366 os_memcpy(wps->cred.key, hex, 32 * 2);
1367 wps->cred.key_len = 32 * 2;
1368 } else if (wps->wps->network_key) {
1369 os_memcpy(wps->cred.key, wps->wps->network_key,
1370 wps->wps->network_key_len);
1371 wps->cred.key_len = wps->wps->network_key_len;
1372 } else if (wps->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
1374 /* Generate a random per-device PSK */
1375 os_free(wps->new_psk);
1376 wps->new_psk_len = 32;
1377 wps->new_psk = os_malloc(wps->new_psk_len);
1378 if (wps->new_psk == NULL)
1380 if (os_get_random(wps->new_psk, wps->new_psk_len) < 0) {
1381 os_free(wps->new_psk);
1382 wps->new_psk = NULL;
1385 wpa_hexdump_key(MSG_DEBUG, "WPS: Generated per-device PSK",
1386 wps->new_psk, wps->new_psk_len);
1387 wpa_snprintf_hex(hex, sizeof(hex), wps->new_psk,
1389 os_memcpy(wps->cred.key, hex, wps->new_psk_len * 2);
1390 wps->cred.key_len = wps->new_psk_len * 2;
1394 #ifdef CONFIG_WPS_TESTING_EXTRA_CRED
1395 cred = wpabuf_alloc(200);
1397 struct wps_credential dummy;
1398 wpa_printf(MSG_DEBUG, "WPS: Add dummy credential");
1399 os_memset(&dummy, 0, sizeof(dummy));
1400 os_memcpy(dummy.ssid, "dummy", 5);
1402 dummy.auth_type = WPS_AUTH_WPA2PSK;
1403 dummy.encr_type = WPS_ENCR_AES;
1404 os_memcpy(dummy.key, "dummy psk", 9);
1406 os_memcpy(dummy.mac_addr, wps->mac_addr_e, ETH_ALEN);
1407 wps_build_credential(cred, &dummy);
1408 wpa_hexdump_buf(MSG_DEBUG, "WPS: Dummy Credential", cred);
1410 wpabuf_put_be16(msg, ATTR_CRED);
1411 wpabuf_put_be16(msg, wpabuf_len(cred));
1412 wpabuf_put_buf(msg, cred);
1416 #endif /* CONFIG_WPS_TESTING_EXTRA_CRED */
1418 cred = wpabuf_alloc(200);
1422 if (wps_build_credential(cred, &wps->cred)) {
1427 wpabuf_put_be16(msg, ATTR_CRED);
1428 wpabuf_put_be16(msg, wpabuf_len(cred));
1429 wpabuf_put_buf(msg, cred);
1433 if (wps->wps->registrar->extra_cred) {
1434 wpa_printf(MSG_DEBUG, "WPS: * Credential (pre-configured)");
1435 wpabuf_put_buf(msg, wps->wps->registrar->extra_cred);
1442 static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
1444 wpa_printf(MSG_DEBUG, "WPS: * AP Settings");
1446 if (wps_build_credential(msg, &wps->cred))
1453 static struct wpabuf * wps_build_m2(struct wps_data *wps)
1457 if (os_get_random(wps->nonce_r, WPS_NONCE_LEN) < 0)
1459 wpa_hexdump(MSG_DEBUG, "WPS: Registrar Nonce",
1460 wps->nonce_r, WPS_NONCE_LEN);
1461 wpa_hexdump(MSG_DEBUG, "WPS: UUID-R", wps->uuid_r, WPS_UUID_LEN);
1463 wpa_printf(MSG_DEBUG, "WPS: Building Message M2");
1464 msg = wpabuf_alloc(1000);
1468 if (wps_build_version(msg) ||
1469 wps_build_msg_type(msg, WPS_M2) ||
1470 wps_build_enrollee_nonce(wps, msg) ||
1471 wps_build_registrar_nonce(wps, msg) ||
1472 wps_build_uuid_r(wps, msg) ||
1473 wps_build_public_key(wps, msg) ||
1474 wps_derive_keys(wps) ||
1475 wps_build_auth_type_flags(wps, msg) ||
1476 wps_build_encr_type_flags(wps, msg) ||
1477 wps_build_conn_type_flags(wps, msg) ||
1478 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1479 wps_build_device_attrs(&wps->wps->dev, msg) ||
1480 wps_build_rf_bands(&wps->wps->dev, msg) ||
1481 wps_build_assoc_state(wps, msg) ||
1482 wps_build_config_error(msg, WPS_CFG_NO_ERROR) ||
1483 wps_build_dev_password_id(msg, wps->dev_pw_id) ||
1484 wps_build_os_version(&wps->wps->dev, msg) ||
1485 wps_build_version2(msg) ||
1486 wps_build_authenticator(wps, msg)) {
1492 wps->state = RECV_M3;
1497 static struct wpabuf * wps_build_m2d(struct wps_data *wps)
1500 u16 err = wps->config_error;
1502 wpa_printf(MSG_DEBUG, "WPS: Building Message M2D");
1503 msg = wpabuf_alloc(1000);
1507 if (wps->wps->ap && wps->wps->ap_setup_locked &&
1508 err == WPS_CFG_NO_ERROR)
1509 err = WPS_CFG_SETUP_LOCKED;
1511 if (wps_build_version(msg) ||
1512 wps_build_msg_type(msg, WPS_M2D) ||
1513 wps_build_enrollee_nonce(wps, msg) ||
1514 wps_build_registrar_nonce(wps, msg) ||
1515 wps_build_uuid_r(wps, msg) ||
1516 wps_build_auth_type_flags(wps, msg) ||
1517 wps_build_encr_type_flags(wps, msg) ||
1518 wps_build_conn_type_flags(wps, msg) ||
1519 wps_build_config_methods_r(wps->wps->registrar, msg) ||
1520 wps_build_device_attrs(&wps->wps->dev, msg) ||
1521 wps_build_rf_bands(&wps->wps->dev, msg) ||
1522 wps_build_assoc_state(wps, msg) ||
1523 wps_build_config_error(msg, err) ||
1524 wps_build_os_version(&wps->wps->dev, msg) ||
1525 wps_build_version2(msg)) {
1530 wps->state = RECV_M2D_ACK;
1535 static struct wpabuf * wps_build_m4(struct wps_data *wps)
1537 struct wpabuf *msg, *plain;
1539 wpa_printf(MSG_DEBUG, "WPS: Building Message M4");
1541 wps_derive_psk(wps, wps->dev_password, wps->dev_password_len);
1543 plain = wpabuf_alloc(200);
1547 msg = wpabuf_alloc(1000);
1553 if (wps_build_version(msg) ||
1554 wps_build_msg_type(msg, WPS_M4) ||
1555 wps_build_enrollee_nonce(wps, msg) ||
1556 wps_build_r_hash(wps, msg) ||
1557 wps_build_r_snonce1(wps, plain) ||
1558 wps_build_key_wrap_auth(wps, plain) ||
1559 wps_build_encr_settings(wps, msg, plain) ||
1560 wps_build_version2(msg) ||
1561 wps_build_authenticator(wps, msg)) {
1568 wps->state = RECV_M5;
1573 static struct wpabuf * wps_build_m6(struct wps_data *wps)
1575 struct wpabuf *msg, *plain;
1577 wpa_printf(MSG_DEBUG, "WPS: Building Message M6");
1579 plain = wpabuf_alloc(200);
1583 msg = wpabuf_alloc(1000);
1589 if (wps_build_version(msg) ||
1590 wps_build_msg_type(msg, WPS_M6) ||
1591 wps_build_enrollee_nonce(wps, msg) ||
1592 wps_build_r_snonce2(wps, plain) ||
1593 wps_build_key_wrap_auth(wps, plain) ||
1594 wps_build_encr_settings(wps, msg, plain) ||
1595 wps_build_version2(msg) ||
1596 wps_build_authenticator(wps, msg)) {
1603 wps->wps_pin_revealed = 1;
1604 wps->state = RECV_M7;
1609 static struct wpabuf * wps_build_m8(struct wps_data *wps)
1611 struct wpabuf *msg, *plain;
1613 wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
1615 plain = wpabuf_alloc(500);
1619 msg = wpabuf_alloc(1000);
1625 if (wps_build_version(msg) ||
1626 wps_build_msg_type(msg, WPS_M8) ||
1627 wps_build_enrollee_nonce(wps, msg) ||
1628 ((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
1629 (!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
1630 wps_build_key_wrap_auth(wps, plain) ||
1631 wps_build_encr_settings(wps, msg, plain) ||
1632 wps_build_version2(msg) ||
1633 wps_build_authenticator(wps, msg)) {
1640 wps->state = RECV_DONE;
1645 static struct wpabuf * wps_build_wsc_ack(struct wps_data *wps)
1649 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_ACK");
1651 msg = wpabuf_alloc(1000);
1655 if (wps_build_version(msg) ||
1656 wps_build_msg_type(msg, WPS_WSC_ACK) ||
1657 wps_build_enrollee_nonce(wps, msg) ||
1658 wps_build_registrar_nonce(wps, msg) ||
1659 wps_build_version2(msg)) {
1668 static struct wpabuf * wps_build_wsc_nack(struct wps_data *wps)
1672 wpa_printf(MSG_DEBUG, "WPS: Building Message WSC_NACK");
1674 msg = wpabuf_alloc(1000);
1678 if (wps_build_version(msg) ||
1679 wps_build_msg_type(msg, WPS_WSC_NACK) ||
1680 wps_build_enrollee_nonce(wps, msg) ||
1681 wps_build_registrar_nonce(wps, msg) ||
1682 wps_build_config_error(msg, wps->config_error) ||
1683 wps_build_version2(msg)) {
1692 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
1693 enum wsc_op_code *op_code)
1697 #ifdef CONFIG_WPS_UPNP
1698 if (!wps->int_reg && wps->wps->wps_upnp) {
1699 struct upnp_pending_message *p, *prev = NULL;
1700 if (wps->ext_reg > 1)
1701 wps_registrar_free_pending_m2(wps->wps);
1702 p = wps->wps->upnp_msgs;
1703 /* TODO: check pending message MAC address */
1704 while (p && p->next) {
1709 wpa_printf(MSG_DEBUG, "WPS: Use pending message from "
1714 wps->wps->upnp_msgs = NULL;
1721 *op_code = WSC_NACK;
1728 if (wps->ext_reg == 0)
1734 wpa_printf(MSG_DEBUG, "WPS: Using external Registrar, but no "
1735 "pending message available");
1738 #endif /* CONFIG_WPS_UPNP */
1740 switch (wps->state) {
1742 if (wps_get_dev_password(wps) < 0)
1743 msg = wps_build_m2d(wps);
1745 msg = wps_build_m2(wps);
1749 msg = wps_build_m2d(wps);
1753 msg = wps_build_m4(wps);
1757 msg = wps_build_m6(wps);
1761 msg = wps_build_m8(wps);
1765 msg = wps_build_wsc_ack(wps);
1769 msg = wps_build_wsc_nack(wps);
1770 *op_code = WSC_NACK;
1773 wpa_printf(MSG_DEBUG, "WPS: Unsupported state %d for building "
1774 "a message", wps->state);
1779 if (*op_code == WSC_MSG && msg) {
1780 /* Save a copy of the last message for Authenticator derivation
1782 wpabuf_free(wps->last_msg);
1783 wps->last_msg = wpabuf_dup(msg);
1790 static int wps_process_enrollee_nonce(struct wps_data *wps, const u8 *e_nonce)
1792 if (e_nonce == NULL) {
1793 wpa_printf(MSG_DEBUG, "WPS: No Enrollee Nonce received");
1797 os_memcpy(wps->nonce_e, e_nonce, WPS_NONCE_LEN);
1798 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Nonce",
1799 wps->nonce_e, WPS_NONCE_LEN);
1805 static int wps_process_registrar_nonce(struct wps_data *wps, const u8 *r_nonce)
1807 if (r_nonce == NULL) {
1808 wpa_printf(MSG_DEBUG, "WPS: No Registrar Nonce received");
1812 if (os_memcmp(wps->nonce_r, r_nonce, WPS_NONCE_LEN) != 0) {
1813 wpa_printf(MSG_DEBUG, "WPS: Invalid Registrar Nonce received");
1821 static int wps_process_uuid_e(struct wps_data *wps, const u8 *uuid_e)
1823 if (uuid_e == NULL) {
1824 wpa_printf(MSG_DEBUG, "WPS: No UUID-E received");
1828 os_memcpy(wps->uuid_e, uuid_e, WPS_UUID_LEN);
1829 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", wps->uuid_e, WPS_UUID_LEN);
1835 static int wps_process_dev_password_id(struct wps_data *wps, const u8 *pw_id)
1837 if (pw_id == NULL) {
1838 wpa_printf(MSG_DEBUG, "WPS: No Device Password ID received");
1842 wps->dev_pw_id = WPA_GET_BE16(pw_id);
1843 wpa_printf(MSG_DEBUG, "WPS: Device Password ID %d", wps->dev_pw_id);
1849 static int wps_process_e_hash1(struct wps_data *wps, const u8 *e_hash1)
1851 if (e_hash1 == NULL) {
1852 wpa_printf(MSG_DEBUG, "WPS: No E-Hash1 received");
1856 os_memcpy(wps->peer_hash1, e_hash1, WPS_HASH_LEN);
1857 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash1", wps->peer_hash1, WPS_HASH_LEN);
1863 static int wps_process_e_hash2(struct wps_data *wps, const u8 *e_hash2)
1865 if (e_hash2 == NULL) {
1866 wpa_printf(MSG_DEBUG, "WPS: No E-Hash2 received");
1870 os_memcpy(wps->peer_hash2, e_hash2, WPS_HASH_LEN);
1871 wpa_hexdump(MSG_DEBUG, "WPS: E-Hash2", wps->peer_hash2, WPS_HASH_LEN);
1877 static int wps_process_e_snonce1(struct wps_data *wps, const u8 *e_snonce1)
1879 u8 hash[SHA256_MAC_LEN];
1883 if (e_snonce1 == NULL) {
1884 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce1 received");
1888 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce1", e_snonce1,
1889 WPS_SECRET_NONCE_LEN);
1891 /* E-Hash1 = HMAC_AuthKey(E-S1 || PSK1 || PK_E || PK_R) */
1892 addr[0] = e_snonce1;
1893 len[0] = WPS_SECRET_NONCE_LEN;
1894 addr[1] = wps->psk1;
1895 len[1] = WPS_PSK_LEN;
1896 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1897 len[2] = wpabuf_len(wps->dh_pubkey_e);
1898 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1899 len[3] = wpabuf_len(wps->dh_pubkey_r);
1900 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1902 if (os_memcmp(wps->peer_hash1, hash, WPS_HASH_LEN) != 0) {
1903 wpa_printf(MSG_DEBUG, "WPS: E-Hash1 derived from E-S1 does "
1904 "not match with the pre-committed value");
1905 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1906 wps_pwd_auth_fail_event(wps->wps, 0, 1);
1910 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the first "
1911 "half of the device password");
1917 static int wps_process_e_snonce2(struct wps_data *wps, const u8 *e_snonce2)
1919 u8 hash[SHA256_MAC_LEN];
1923 if (e_snonce2 == NULL) {
1924 wpa_printf(MSG_DEBUG, "WPS: No E-SNonce2 received");
1928 wpa_hexdump_key(MSG_DEBUG, "WPS: E-SNonce2", e_snonce2,
1929 WPS_SECRET_NONCE_LEN);
1931 /* E-Hash2 = HMAC_AuthKey(E-S2 || PSK2 || PK_E || PK_R) */
1932 addr[0] = e_snonce2;
1933 len[0] = WPS_SECRET_NONCE_LEN;
1934 addr[1] = wps->psk2;
1935 len[1] = WPS_PSK_LEN;
1936 addr[2] = wpabuf_head(wps->dh_pubkey_e);
1937 len[2] = wpabuf_len(wps->dh_pubkey_e);
1938 addr[3] = wpabuf_head(wps->dh_pubkey_r);
1939 len[3] = wpabuf_len(wps->dh_pubkey_r);
1940 hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 4, addr, len, hash);
1942 if (os_memcmp(wps->peer_hash2, hash, WPS_HASH_LEN) != 0) {
1943 wpa_printf(MSG_DEBUG, "WPS: E-Hash2 derived from E-S2 does "
1944 "not match with the pre-committed value");
1945 wps_registrar_invalidate_pin(wps->wps->registrar, wps->uuid_e);
1946 wps->config_error = WPS_CFG_DEV_PASSWORD_AUTH_FAILURE;
1947 wps_pwd_auth_fail_event(wps->wps, 0, 2);
1951 wpa_printf(MSG_DEBUG, "WPS: Enrollee proved knowledge of the second "
1952 "half of the device password");
1953 wps->wps_pin_revealed = 0;
1954 wps_registrar_unlock_pin(wps->wps->registrar, wps->uuid_e);
1960 static int wps_process_mac_addr(struct wps_data *wps, const u8 *mac_addr)
1962 if (mac_addr == NULL) {
1963 wpa_printf(MSG_DEBUG, "WPS: No MAC Address received");
1967 wpa_printf(MSG_DEBUG, "WPS: Enrollee MAC Address " MACSTR,
1969 os_memcpy(wps->mac_addr_e, mac_addr, ETH_ALEN);
1970 os_memcpy(wps->peer_dev.mac_addr, mac_addr, ETH_ALEN);
1976 static int wps_process_pubkey(struct wps_data *wps, const u8 *pk,
1979 if (pk == NULL || pk_len == 0) {
1980 wpa_printf(MSG_DEBUG, "WPS: No Public Key received");
1984 #ifdef CONFIG_WPS_OOB
1985 if (wps->wps->oob_conf.pubkey_hash != NULL) {
1987 u8 hash[WPS_HASH_LEN];
1990 sha256_vector(1, addr, &pk_len, hash);
1992 wpabuf_head(wps->wps->oob_conf.pubkey_hash),
1993 WPS_OOB_PUBKEY_HASH_LEN) != 0) {
1994 wpa_printf(MSG_ERROR, "WPS: Public Key hash error");
1998 #endif /* CONFIG_WPS_OOB */
2000 wpabuf_free(wps->dh_pubkey_e);
2001 wps->dh_pubkey_e = wpabuf_alloc_copy(pk, pk_len);
2002 if (wps->dh_pubkey_e == NULL)
2009 static int wps_process_auth_type_flags(struct wps_data *wps, const u8 *auth)
2014 wpa_printf(MSG_DEBUG, "WPS: No Authentication Type flags "
2019 auth_types = WPA_GET_BE16(auth);
2021 wpa_printf(MSG_DEBUG, "WPS: Enrollee Authentication Type flags 0x%x",
2023 wps->auth_type = wps->wps->auth_types & auth_types;
2024 if (wps->auth_type == 0) {
2025 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
2026 "authentication types (own 0x%x Enrollee 0x%x)",
2027 wps->wps->auth_types, auth_types);
2028 #ifdef WPS_WORKAROUNDS
2030 * Some deployed implementations seem to advertise incorrect
2031 * information in this attribute. For example, Linksys WRT350N
2032 * seems to have a byteorder bug that breaks this negotiation.
2033 * In order to interoperate with existing implementations,
2034 * assume that the Enrollee supports everything we do.
2036 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
2037 "does not advertise supported authentication types "
2039 wps->auth_type = wps->wps->auth_types;
2040 #else /* WPS_WORKAROUNDS */
2042 #endif /* WPS_WORKAROUNDS */
2049 static int wps_process_encr_type_flags(struct wps_data *wps, const u8 *encr)
2054 wpa_printf(MSG_DEBUG, "WPS: No Encryption Type flags "
2059 encr_types = WPA_GET_BE16(encr);
2061 wpa_printf(MSG_DEBUG, "WPS: Enrollee Encryption Type flags 0x%x",
2063 wps->encr_type = wps->wps->encr_types & encr_types;
2064 if (wps->encr_type == 0) {
2065 wpa_printf(MSG_DEBUG, "WPS: No match in supported "
2066 "encryption types (own 0x%x Enrollee 0x%x)",
2067 wps->wps->encr_types, encr_types);
2068 #ifdef WPS_WORKAROUNDS
2070 * Some deployed implementations seem to advertise incorrect
2071 * information in this attribute. For example, Linksys WRT350N
2072 * seems to have a byteorder bug that breaks this negotiation.
2073 * In order to interoperate with existing implementations,
2074 * assume that the Enrollee supports everything we do.
2076 wpa_printf(MSG_DEBUG, "WPS: Workaround - assume Enrollee "
2077 "does not advertise supported encryption types "
2079 wps->encr_type = wps->wps->encr_types;
2080 #else /* WPS_WORKAROUNDS */
2082 #endif /* WPS_WORKAROUNDS */
2089 static int wps_process_conn_type_flags(struct wps_data *wps, const u8 *conn)
2092 wpa_printf(MSG_DEBUG, "WPS: No Connection Type flags "
2097 wpa_printf(MSG_DEBUG, "WPS: Enrollee Connection Type flags 0x%x",
2104 static int wps_process_config_methods(struct wps_data *wps, const u8 *methods)
2108 if (methods == NULL) {
2109 wpa_printf(MSG_DEBUG, "WPS: No Config Methods received");
2113 m = WPA_GET_BE16(methods);
2115 wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x"
2116 "%s%s%s%s%s%s%s%s%s", m,
2117 m & WPS_CONFIG_USBA ? " [USBA]" : "",
2118 m & WPS_CONFIG_ETHERNET ? " [Ethernet]" : "",
2119 m & WPS_CONFIG_LABEL ? " [Label]" : "",
2120 m & WPS_CONFIG_DISPLAY ? " [Display]" : "",
2121 m & WPS_CONFIG_EXT_NFC_TOKEN ? " [Ext NFC Token]" : "",
2122 m & WPS_CONFIG_INT_NFC_TOKEN ? " [Int NFC Token]" : "",
2123 m & WPS_CONFIG_NFC_INTERFACE ? " [NFC]" : "",
2124 m & WPS_CONFIG_PUSHBUTTON ? " [PBC]" : "",
2125 m & WPS_CONFIG_KEYPAD ? " [Keypad]" : "");
2127 if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
2129 * The Enrollee does not have a display so it is unlikely to be
2130 * able to show the passphrase to a user and as such, could
2131 * benefit from receiving PSK to reduce key derivation time.
2133 wpa_printf(MSG_DEBUG, "WPS: Prefer PSK format key due to "
2134 "Enrollee not supporting display");
2135 wps->use_psk_key = 1;
2142 static int wps_process_wps_state(struct wps_data *wps, const u8 *state)
2144 if (state == NULL) {
2145 wpa_printf(MSG_DEBUG, "WPS: No Wi-Fi Protected Setup State "
2150 wpa_printf(MSG_DEBUG, "WPS: Enrollee Wi-Fi Protected Setup State %d",
2157 static int wps_process_assoc_state(struct wps_data *wps, const u8 *assoc)
2161 if (assoc == NULL) {
2162 wpa_printf(MSG_DEBUG, "WPS: No Association State received");
2166 a = WPA_GET_BE16(assoc);
2167 wpa_printf(MSG_DEBUG, "WPS: Enrollee Association State %d", a);
2173 static int wps_process_config_error(struct wps_data *wps, const u8 *err)
2178 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error received");
2182 e = WPA_GET_BE16(err);
2183 wpa_printf(MSG_DEBUG, "WPS: Enrollee Configuration Error %d", e);
2189 static enum wps_process_res wps_process_m1(struct wps_data *wps,
2190 struct wps_parse_attr *attr)
2192 wpa_printf(MSG_DEBUG, "WPS: Received M1");
2194 if (wps->state != RECV_M1) {
2195 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2196 "receiving M1", wps->state);
2200 if (wps_process_uuid_e(wps, attr->uuid_e) ||
2201 wps_process_mac_addr(wps, attr->mac_addr) ||
2202 wps_process_enrollee_nonce(wps, attr->enrollee_nonce) ||
2203 wps_process_pubkey(wps, attr->public_key, attr->public_key_len) ||
2204 wps_process_auth_type_flags(wps, attr->auth_type_flags) ||
2205 wps_process_encr_type_flags(wps, attr->encr_type_flags) ||
2206 wps_process_conn_type_flags(wps, attr->conn_type_flags) ||
2207 wps_process_config_methods(wps, attr->config_methods) ||
2208 wps_process_wps_state(wps, attr->wps_state) ||
2209 wps_process_device_attrs(&wps->peer_dev, attr) ||
2210 wps_process_rf_bands(&wps->peer_dev, attr->rf_bands) ||
2211 wps_process_assoc_state(wps, attr->assoc_state) ||
2212 wps_process_dev_password_id(wps, attr->dev_password_id) ||
2213 wps_process_config_error(wps, attr->config_error) ||
2214 wps_process_os_version(&wps->peer_dev, attr->os_version))
2217 if (wps->dev_pw_id < 0x10 &&
2218 wps->dev_pw_id != DEV_PW_DEFAULT &&
2219 wps->dev_pw_id != DEV_PW_USER_SPECIFIED &&
2220 wps->dev_pw_id != DEV_PW_MACHINE_SPECIFIED &&
2221 wps->dev_pw_id != DEV_PW_REGISTRAR_SPECIFIED &&
2222 (wps->dev_pw_id != DEV_PW_PUSHBUTTON ||
2223 !wps->wps->registrar->pbc)) {
2224 wpa_printf(MSG_DEBUG, "WPS: Unsupported Device Password ID %d",
2226 wps->state = SEND_M2D;
2227 return WPS_CONTINUE;
2230 #ifdef CONFIG_WPS_OOB
2231 if (wps->dev_pw_id >= 0x10 &&
2232 wps->dev_pw_id != wps->wps->oob_dev_pw_id) {
2233 wpa_printf(MSG_DEBUG, "WPS: OOB Device Password ID "
2234 "%d mismatch", wps->dev_pw_id);
2235 wps->state = SEND_M2D;
2236 return WPS_CONTINUE;
2238 #endif /* CONFIG_WPS_OOB */
2240 if (wps->dev_pw_id == DEV_PW_PUSHBUTTON) {
2241 if (wps->wps->registrar->force_pbc_overlap ||
2242 wps_registrar_pbc_overlap(wps->wps->registrar,
2243 wps->mac_addr_e, wps->uuid_e)) {
2244 wpa_printf(MSG_DEBUG, "WPS: PBC overlap - deny PBC "
2246 wps->state = SEND_M2D;
2247 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2248 wps_pbc_overlap_event(wps->wps);
2249 wps->wps->registrar->force_pbc_overlap = 1;
2250 return WPS_CONTINUE;
2252 wps_registrar_add_pbc_session(wps->wps->registrar,
2253 wps->mac_addr_e, wps->uuid_e);
2257 #ifdef WPS_WORKAROUNDS
2259 * It looks like Mac OS X 10.6.3 and 10.6.4 do not like Network Key in
2260 * passphrase format. To avoid interop issues, force PSK format to be
2263 if (!wps->use_psk_key &&
2264 wps->peer_dev.manufacturer &&
2265 os_strncmp(wps->peer_dev.manufacturer, "Apple ", 6) == 0 &&
2266 wps->peer_dev.model_name &&
2267 os_strcmp(wps->peer_dev.model_name, "AirPort") == 0) {
2268 wpa_printf(MSG_DEBUG, "WPS: Workaround - Force Network Key in "
2270 wps->use_psk_key = 1;
2272 #endif /* WPS_WORKAROUNDS */
2274 wps->state = SEND_M2;
2275 return WPS_CONTINUE;
2279 static enum wps_process_res wps_process_m3(struct wps_data *wps,
2280 const struct wpabuf *msg,
2281 struct wps_parse_attr *attr)
2283 wpa_printf(MSG_DEBUG, "WPS: Received M3");
2285 if (wps->state != RECV_M3) {
2286 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2287 "receiving M3", wps->state);
2288 wps->state = SEND_WSC_NACK;
2289 return WPS_CONTINUE;
2292 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2293 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2295 wps->state = SEND_WSC_NACK;
2296 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2297 return WPS_CONTINUE;
2300 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2301 wps_process_authenticator(wps, attr->authenticator, msg) ||
2302 wps_process_e_hash1(wps, attr->e_hash1) ||
2303 wps_process_e_hash2(wps, attr->e_hash2)) {
2304 wps->state = SEND_WSC_NACK;
2305 return WPS_CONTINUE;
2308 wps->state = SEND_M4;
2309 return WPS_CONTINUE;
2313 static enum wps_process_res wps_process_m5(struct wps_data *wps,
2314 const struct wpabuf *msg,
2315 struct wps_parse_attr *attr)
2317 struct wpabuf *decrypted;
2318 struct wps_parse_attr eattr;
2320 wpa_printf(MSG_DEBUG, "WPS: Received M5");
2322 if (wps->state != RECV_M5) {
2323 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2324 "receiving M5", wps->state);
2325 wps->state = SEND_WSC_NACK;
2326 return WPS_CONTINUE;
2329 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2330 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2332 wps->state = SEND_WSC_NACK;
2333 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2334 return WPS_CONTINUE;
2337 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2338 wps_process_authenticator(wps, attr->authenticator, msg)) {
2339 wps->state = SEND_WSC_NACK;
2340 return WPS_CONTINUE;
2343 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2344 attr->encr_settings_len);
2345 if (decrypted == NULL) {
2346 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypted Encrypted "
2347 "Settings attribute");
2348 wps->state = SEND_WSC_NACK;
2349 return WPS_CONTINUE;
2352 if (wps_validate_m5_encr(decrypted) < 0) {
2353 wpabuf_free(decrypted);
2354 wps->state = SEND_WSC_NACK;
2355 return WPS_CONTINUE;
2358 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2360 if (wps_parse_msg(decrypted, &eattr) < 0 ||
2361 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2362 wps_process_e_snonce1(wps, eattr.e_snonce1)) {
2363 wpabuf_free(decrypted);
2364 wps->state = SEND_WSC_NACK;
2365 return WPS_CONTINUE;
2367 wpabuf_free(decrypted);
2369 wps->state = SEND_M6;
2370 return WPS_CONTINUE;
2374 static void wps_sta_cred_cb(struct wps_data *wps)
2377 * Update credential to only include a single authentication and
2378 * encryption type in case the AP configuration includes more than one
2381 if (wps->cred.auth_type & WPS_AUTH_WPA2PSK)
2382 wps->cred.auth_type = WPS_AUTH_WPA2PSK;
2383 else if (wps->cred.auth_type & WPS_AUTH_WPAPSK)
2384 wps->cred.auth_type = WPS_AUTH_WPAPSK;
2385 if (wps->cred.encr_type & WPS_ENCR_AES)
2386 wps->cred.encr_type = WPS_ENCR_AES;
2387 else if (wps->cred.encr_type & WPS_ENCR_TKIP)
2388 wps->cred.encr_type = WPS_ENCR_TKIP;
2389 wpa_printf(MSG_DEBUG, "WPS: Update local configuration based on the "
2390 "AP configuration");
2391 if (wps->wps->cred_cb)
2392 wps->wps->cred_cb(wps->wps->cb_ctx, &wps->cred);
2396 static void wps_cred_update(struct wps_credential *dst,
2397 struct wps_credential *src)
2399 os_memcpy(dst->ssid, src->ssid, sizeof(dst->ssid));
2400 dst->ssid_len = src->ssid_len;
2401 dst->auth_type = src->auth_type;
2402 dst->encr_type = src->encr_type;
2403 dst->key_idx = src->key_idx;
2404 os_memcpy(dst->key, src->key, sizeof(dst->key));
2405 dst->key_len = src->key_len;
2409 static int wps_process_ap_settings_r(struct wps_data *wps,
2410 struct wps_parse_attr *attr)
2412 if (wps->wps->ap || wps->er)
2415 /* AP Settings Attributes in M7 when Enrollee is an AP */
2416 if (wps_process_ap_settings(attr, &wps->cred) < 0)
2419 wpa_printf(MSG_INFO, "WPS: Received old AP configuration from AP");
2421 if (wps->new_ap_settings) {
2422 wpa_printf(MSG_INFO, "WPS: Update AP configuration based on "
2424 wps_cred_update(&wps->cred, wps->new_ap_settings);
2428 * Use the AP PIN only to receive the current AP settings, not
2429 * to reconfigure the AP.
2431 if (wps->ap_settings_cb) {
2432 wps->ap_settings_cb(wps->ap_settings_cb_ctx,
2436 wps_sta_cred_cb(wps);
2442 static enum wps_process_res wps_process_m7(struct wps_data *wps,
2443 const struct wpabuf *msg,
2444 struct wps_parse_attr *attr)
2446 struct wpabuf *decrypted;
2447 struct wps_parse_attr eattr;
2449 wpa_printf(MSG_DEBUG, "WPS: Received M7");
2451 if (wps->state != RECV_M7) {
2452 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2453 "receiving M7", wps->state);
2454 wps->state = SEND_WSC_NACK;
2455 return WPS_CONTINUE;
2458 if (wps->pbc && wps->wps->registrar->force_pbc_overlap) {
2459 wpa_printf(MSG_DEBUG, "WPS: Reject negotiation due to PBC "
2461 wps->state = SEND_WSC_NACK;
2462 wps->config_error = WPS_CFG_MULTIPLE_PBC_DETECTED;
2463 return WPS_CONTINUE;
2466 if (wps_process_registrar_nonce(wps, attr->registrar_nonce) ||
2467 wps_process_authenticator(wps, attr->authenticator, msg)) {
2468 wps->state = SEND_WSC_NACK;
2469 return WPS_CONTINUE;
2472 decrypted = wps_decrypt_encr_settings(wps, attr->encr_settings,
2473 attr->encr_settings_len);
2474 if (decrypted == NULL) {
2475 wpa_printf(MSG_DEBUG, "WPS: Failed to decrypt Encrypted "
2476 "Settings attribute");
2477 wps->state = SEND_WSC_NACK;
2478 return WPS_CONTINUE;
2481 if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er) < 0) {
2482 wpabuf_free(decrypted);
2483 wps->state = SEND_WSC_NACK;
2484 return WPS_CONTINUE;
2487 wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
2489 if (wps_parse_msg(decrypted, &eattr) < 0 ||
2490 wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
2491 wps_process_e_snonce2(wps, eattr.e_snonce2) ||
2492 wps_process_ap_settings_r(wps, &eattr)) {
2493 wpabuf_free(decrypted);
2494 wps->state = SEND_WSC_NACK;
2495 return WPS_CONTINUE;
2498 wpabuf_free(decrypted);
2500 wps->state = SEND_M8;
2501 return WPS_CONTINUE;
2505 static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
2506 const struct wpabuf *msg)
2508 struct wps_parse_attr attr;
2509 enum wps_process_res ret = WPS_CONTINUE;
2511 wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");
2513 if (wps_parse_msg(msg, &attr) < 0)
2516 if (attr.msg_type == NULL) {
2517 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2521 if (*attr.msg_type != WPS_M1 &&
2522 (attr.registrar_nonce == NULL ||
2523 os_memcmp(wps->nonce_r, attr.registrar_nonce,
2524 WPS_NONCE_LEN != 0))) {
2525 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2529 switch (*attr.msg_type) {
2531 if (wps_validate_m1(msg) < 0)
2533 #ifdef CONFIG_WPS_UPNP
2534 if (wps->wps->wps_upnp && attr.mac_addr) {
2535 /* Remove old pending messages when starting new run */
2536 wps_free_pending_msgs(wps->wps->upnp_msgs);
2537 wps->wps->upnp_msgs = NULL;
2539 upnp_wps_device_send_wlan_event(
2540 wps->wps->wps_upnp, attr.mac_addr,
2541 UPNP_WPS_WLANEVENT_TYPE_EAP, msg);
2543 #endif /* CONFIG_WPS_UPNP */
2544 ret = wps_process_m1(wps, &attr);
2547 if (wps_validate_m3(msg) < 0)
2549 ret = wps_process_m3(wps, msg, &attr);
2550 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2551 wps_fail_event(wps->wps, WPS_M3);
2554 if (wps_validate_m5(msg) < 0)
2556 ret = wps_process_m5(wps, msg, &attr);
2557 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2558 wps_fail_event(wps->wps, WPS_M5);
2561 if (wps_validate_m7(msg) < 0)
2563 ret = wps_process_m7(wps, msg, &attr);
2564 if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
2565 wps_fail_event(wps->wps, WPS_M7);
2568 wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
2573 if (ret == WPS_CONTINUE) {
2574 /* Save a copy of the last message for Authenticator derivation
2576 wpabuf_free(wps->last_msg);
2577 wps->last_msg = wpabuf_dup(msg);
2584 static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
2585 const struct wpabuf *msg)
2587 struct wps_parse_attr attr;
2589 wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");
2591 if (wps_parse_msg(msg, &attr) < 0)
2594 if (attr.msg_type == NULL) {
2595 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2599 if (*attr.msg_type != WPS_WSC_ACK) {
2600 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2605 #ifdef CONFIG_WPS_UPNP
2606 if (wps->wps->wps_upnp && wps->ext_reg && wps->state == RECV_M2D_ACK &&
2607 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2608 if (wps->wps->upnp_msgs)
2609 return WPS_CONTINUE;
2610 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2611 "external Registrar");
2614 #endif /* CONFIG_WPS_UPNP */
2616 if (attr.registrar_nonce == NULL ||
2617 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2619 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2623 if (attr.enrollee_nonce == NULL ||
2624 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2625 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2629 if (wps->state == RECV_M2D_ACK) {
2630 #ifdef CONFIG_WPS_UPNP
2631 if (wps->wps->wps_upnp &&
2632 upnp_wps_subscribers(wps->wps->wps_upnp)) {
2633 if (wps->wps->upnp_msgs)
2634 return WPS_CONTINUE;
2635 if (wps->ext_reg == 0)
2637 wpa_printf(MSG_DEBUG, "WPS: Wait for response from an "
2638 "external Registrar");
2641 #endif /* CONFIG_WPS_UPNP */
2643 wpa_printf(MSG_DEBUG, "WPS: No more registrars available - "
2644 "terminate negotiation");
2651 static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
2652 const struct wpabuf *msg)
2654 struct wps_parse_attr attr;
2657 wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
2659 old_state = wps->state;
2660 wps->state = SEND_WSC_NACK;
2662 if (wps_parse_msg(msg, &attr) < 0)
2665 if (attr.msg_type == NULL) {
2666 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2670 if (*attr.msg_type != WPS_WSC_NACK) {
2671 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2676 #ifdef CONFIG_WPS_UPNP
2677 if (wps->wps->wps_upnp && wps->ext_reg) {
2678 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2679 "Registrar terminated by the Enrollee");
2682 #endif /* CONFIG_WPS_UPNP */
2684 if (attr.registrar_nonce == NULL ||
2685 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2687 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2691 if (attr.enrollee_nonce == NULL ||
2692 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2693 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2697 if (attr.config_error == NULL) {
2698 wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
2703 wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
2704 "Configuration Error %d", WPA_GET_BE16(attr.config_error));
2706 switch (old_state) {
2708 wps_fail_event(wps->wps, WPS_M2);
2711 wps_fail_event(wps->wps, WPS_M4);
2714 wps_fail_event(wps->wps, WPS_M6);
2717 wps_fail_event(wps->wps, WPS_M8);
2727 static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
2728 const struct wpabuf *msg)
2730 struct wps_parse_attr attr;
2732 wpa_printf(MSG_DEBUG, "WPS: Received WSC_Done");
2734 if (wps->state != RECV_DONE &&
2735 (!wps->wps->wps_upnp || !wps->ext_reg)) {
2736 wpa_printf(MSG_DEBUG, "WPS: Unexpected state (%d) for "
2737 "receiving WSC_Done", wps->state);
2741 if (wps_parse_msg(msg, &attr) < 0)
2744 if (attr.msg_type == NULL) {
2745 wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
2749 if (*attr.msg_type != WPS_WSC_DONE) {
2750 wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
2755 #ifdef CONFIG_WPS_UPNP
2756 if (wps->wps->wps_upnp && wps->ext_reg) {
2757 wpa_printf(MSG_DEBUG, "WPS: Negotiation using external "
2758 "Registrar completed successfully");
2759 wps_device_store(wps->wps->registrar, &wps->peer_dev,
2763 #endif /* CONFIG_WPS_UPNP */
2765 if (attr.registrar_nonce == NULL ||
2766 os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
2768 wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
2772 if (attr.enrollee_nonce == NULL ||
2773 os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
2774 wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
2778 wpa_printf(MSG_DEBUG, "WPS: Negotiation completed successfully");
2779 wps_device_store(wps->wps->registrar, &wps->peer_dev,
2782 if (wps->wps->wps_state == WPS_STATE_NOT_CONFIGURED && wps->new_psk &&
2783 wps->wps->ap && !wps->wps->registrar->disable_auto_conf) {
2784 struct wps_credential cred;
2786 wpa_printf(MSG_DEBUG, "WPS: Moving to Configured state based "
2787 "on first Enrollee connection");
2789 os_memset(&cred, 0, sizeof(cred));
2790 os_memcpy(cred.ssid, wps->wps->ssid, wps->wps->ssid_len);
2791 cred.ssid_len = wps->wps->ssid_len;
2792 cred.auth_type = WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK;
2793 cred.encr_type = WPS_ENCR_TKIP | WPS_ENCR_AES;
2794 os_memcpy(cred.key, wps->new_psk, wps->new_psk_len);
2795 cred.key_len = wps->new_psk_len;
2797 wps->wps->wps_state = WPS_STATE_CONFIGURED;
2798 wpa_hexdump_ascii_key(MSG_DEBUG,
2799 "WPS: Generated random passphrase",
2800 wps->new_psk, wps->new_psk_len);
2801 if (wps->wps->cred_cb)
2802 wps->wps->cred_cb(wps->wps->cb_ctx, &cred);
2804 os_free(wps->new_psk);
2805 wps->new_psk = NULL;
2808 if (!wps->wps->ap && !wps->er)
2809 wps_sta_cred_cb(wps);
2812 if (wps_cb_new_psk(wps->wps->registrar, wps->mac_addr_e,
2813 wps->new_psk, wps->new_psk_len)) {
2814 wpa_printf(MSG_DEBUG, "WPS: Failed to configure the "
2817 os_free(wps->new_psk);
2818 wps->new_psk = NULL;
2821 wps_cb_reg_success(wps->wps->registrar, wps->mac_addr_e, wps->uuid_e);
2824 wps_registrar_remove_pbc_session(wps->wps->registrar,
2825 wps->mac_addr_e, wps->uuid_e);
2826 wps_registrar_pbc_completed(wps->wps->registrar);
2828 wps_registrar_pin_completed(wps->wps->registrar);
2830 /* TODO: maintain AuthorizedMACs somewhere separately for each ER and
2831 * merge them into APs own list.. */
2833 wps_success_event(wps->wps);
2839 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
2840 enum wsc_op_code op_code,
2841 const struct wpabuf *msg)
2843 enum wps_process_res ret;
2845 wpa_printf(MSG_DEBUG, "WPS: Processing received message (len=%lu "
2847 (unsigned long) wpabuf_len(msg), op_code);
2849 #ifdef CONFIG_WPS_UPNP
2850 if (wps->wps->wps_upnp && op_code == WSC_MSG && wps->ext_reg == 1) {
2851 struct wps_parse_attr attr;
2852 if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type &&
2853 *attr.msg_type == WPS_M3)
2854 wps->ext_reg = 2; /* past M2/M2D phase */
2856 if (wps->ext_reg > 1)
2857 wps_registrar_free_pending_m2(wps->wps);
2858 if (wps->wps->wps_upnp && wps->ext_reg &&
2859 wps->wps->upnp_msgs == NULL &&
2860 (op_code == WSC_MSG || op_code == WSC_Done || op_code == WSC_NACK))
2862 struct wps_parse_attr attr;
2864 if (wps_parse_msg(msg, &attr) < 0 || attr.msg_type == NULL)
2867 type = *attr.msg_type;
2868 wpa_printf(MSG_DEBUG, "WPS: Sending received message (type %d)"
2869 " to external Registrar for processing", type);
2870 upnp_wps_device_send_wlan_event(wps->wps->wps_upnp,
2872 UPNP_WPS_WLANEVENT_TYPE_EAP,
2874 if (op_code == WSC_MSG)
2876 } else if (wps->wps->wps_upnp && wps->ext_reg && op_code == WSC_MSG) {
2877 wpa_printf(MSG_DEBUG, "WPS: Skip internal processing - using "
2878 "external Registrar");
2879 return WPS_CONTINUE;
2881 #endif /* CONFIG_WPS_UPNP */
2885 return wps_process_wsc_msg(wps, msg);
2887 if (wps_validate_wsc_ack(msg) < 0)
2889 return wps_process_wsc_ack(wps, msg);
2891 if (wps_validate_wsc_nack(msg) < 0)
2893 return wps_process_wsc_nack(wps, msg);
2895 if (wps_validate_wsc_done(msg) < 0)
2897 ret = wps_process_wsc_done(wps, msg);
2898 if (ret == WPS_FAILURE) {
2899 wps->state = SEND_WSC_NACK;
2900 wps_fail_event(wps->wps, WPS_WSC_DONE);
2904 wpa_printf(MSG_DEBUG, "WPS: Unsupported op_code %d", op_code);
2910 int wps_registrar_update_ie(struct wps_registrar *reg)
2912 return wps_set_ie(reg);
2916 static void wps_registrar_set_selected_timeout(void *eloop_ctx,
2919 struct wps_registrar *reg = eloop_ctx;
2921 wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
2922 "unselect internal Registrar");
2923 reg->selected_registrar = 0;
2925 wps_registrar_selected_registrar_changed(reg);
2929 #ifdef CONFIG_WPS_UPNP
2930 static void wps_registrar_sel_reg_add(struct wps_registrar *reg,
2931 struct subscription *s)
2934 wpa_printf(MSG_DEBUG, "WPS: External Registrar selected (dev_pw_id=%d "
2935 "config_methods=0x%x)",
2936 s->dev_password_id, s->config_methods);
2937 reg->sel_reg_union = 1;
2938 if (reg->sel_reg_dev_password_id_override != DEV_PW_PUSHBUTTON)
2939 reg->sel_reg_dev_password_id_override = s->dev_password_id;
2940 if (reg->sel_reg_config_methods_override == -1)
2941 reg->sel_reg_config_methods_override = 0;
2942 reg->sel_reg_config_methods_override |= s->config_methods;
2943 for (i = 0; i < WPS_MAX_AUTHORIZED_MACS; i++)
2944 if (is_zero_ether_addr(reg->authorized_macs_union[i]))
2946 for (j = 0; i < WPS_MAX_AUTHORIZED_MACS && j < WPS_MAX_AUTHORIZED_MACS;
2948 if (is_zero_ether_addr(s->authorized_macs[j]))
2950 os_memcpy(reg->authorized_macs_union[i],
2951 s->authorized_macs[j], ETH_ALEN);
2955 #endif /* CONFIG_WPS_UPNP */
2958 static void wps_registrar_sel_reg_union(struct wps_registrar *reg)
2960 #ifdef CONFIG_WPS_UPNP
2961 struct subscription *s;
2963 if (reg->wps->wps_upnp == NULL)
2966 dl_list_for_each(s, ®->wps->wps_upnp->subscriptions,
2967 struct subscription, list) {
2968 struct subscr_addr *sa;
2969 sa = dl_list_first(&s->addr_list, struct subscr_addr, list);
2971 wpa_printf(MSG_DEBUG, "WPS: External Registrar %s:%d",
2972 inet_ntoa(sa->saddr.sin_addr),
2973 ntohs(sa->saddr.sin_port));
2975 if (s->selected_registrar)
2976 wps_registrar_sel_reg_add(reg, s);
2978 wpa_printf(MSG_DEBUG, "WPS: External Registrar not "
2981 #endif /* CONFIG_WPS_UPNP */
2986 * wps_registrar_selected_registrar_changed - SetSelectedRegistrar change
2987 * @reg: Registrar data from wps_registrar_init()
2989 * This function is called when selected registrar state changes, e.g., when an
2990 * AP receives a SetSelectedRegistrar UPnP message.
2992 void wps_registrar_selected_registrar_changed(struct wps_registrar *reg)
2994 wpa_printf(MSG_DEBUG, "WPS: Selected registrar information changed");
2996 reg->sel_reg_union = reg->selected_registrar;
2997 reg->sel_reg_dev_password_id_override = -1;
2998 reg->sel_reg_config_methods_override = -1;
2999 os_memcpy(reg->authorized_macs_union, reg->authorized_macs,
3000 WPS_MAX_AUTHORIZED_MACS * ETH_ALEN);
3001 if (reg->selected_registrar) {
3004 methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
3006 methods &= ~(WPS_CONFIG_VIRT_PUSHBUTTON |
3007 WPS_CONFIG_PHY_PUSHBUTTON);
3008 #endif /* CONFIG_WPS2 */
3010 reg->sel_reg_dev_password_id_override =
3012 wps_set_pushbutton(&methods, reg->wps->config_methods);
3014 wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
3015 "(pbc=%d)", reg->pbc);
3016 reg->sel_reg_config_methods_override = methods;
3018 wpa_printf(MSG_DEBUG, "WPS: Internal Registrar not selected");
3020 wps_registrar_sel_reg_union(reg);
3023 wps_cb_set_sel_reg(reg);
3027 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
3028 char *buf, size_t buflen)
3030 struct wps_registrar_device *d;
3033 char devtype[WPS_DEV_TYPE_BUFSIZE];
3035 d = wps_device_get(reg, addr);
3038 if (uuid_bin2str(d->uuid, uuid, sizeof(uuid)))
3041 ret = os_snprintf(buf + len, buflen - len,
3043 "wpsPrimaryDeviceType=%s\n"
3044 "wpsDeviceName=%s\n"
3045 "wpsManufacturer=%s\n"
3047 "wpsModelNumber=%s\n"
3048 "wpsSerialNumber=%s\n",
3050 wps_dev_type_bin2str(d->dev.pri_dev_type, devtype,
3052 d->dev.device_name ? d->dev.device_name : "",
3053 d->dev.manufacturer ? d->dev.manufacturer : "",
3054 d->dev.model_name ? d->dev.model_name : "",
3055 d->dev.model_number ? d->dev.model_number : "",
3056 d->dev.serial_number ? d->dev.serial_number : "");
3057 if (ret < 0 || (size_t) ret >= buflen - len)