87
100
int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
89
int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
90
const u8 *probe_resp_ie, size_t probe_resp_ie_len);
102
int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
103
struct wpabuf *probe_resp_ie);
91
104
void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
92
105
const struct wps_device_data *dev);
93
106
void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
94
107
const u8 *uuid_e);
108
void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
109
u16 sel_reg_config_methods);
110
void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
111
const u8 *pri_dev_type, u16 config_methods,
112
u16 dev_password_id, u8 request_type,
113
const char *dev_name);
97
struct wps_uuid_pin *pins;
98
117
struct wps_pbc_session *pbc_sessions;
100
119
int skip_cred_build;
101
120
struct wpabuf *extra_cred;
102
121
int disable_auto_conf;
103
123
int sel_reg_dev_password_id_override;
104
124
int sel_reg_config_methods_override;
105
125
int static_wep_only;
127
struct wps_registrar_device *devices;
107
129
int force_pbc_overlap;
114
136
void *timeout_ctx);
139
static void wps_free_devices(struct wps_registrar_device *dev)
141
struct wps_registrar_device *prev;
146
wps_device_data_free(&prev->dev);
152
static struct wps_registrar_device * wps_device_get(struct wps_registrar *reg,
155
struct wps_registrar_device *dev;
157
for (dev = reg->devices; dev; dev = dev->next) {
158
if (os_memcmp(dev->dev.mac_addr, addr, ETH_ALEN) == 0)
165
static void wps_device_clone_data(struct wps_device_data *dst,
166
struct wps_device_data *src)
168
os_memcpy(dst->mac_addr, src->mac_addr, ETH_ALEN);
169
os_memcpy(dst->pri_dev_type, src->pri_dev_type, WPS_DEV_TYPE_LEN);
171
#define WPS_STRDUP(n) \
173
dst->n = src->n ? os_strdup(src->n) : NULL
175
WPS_STRDUP(device_name);
176
WPS_STRDUP(manufacturer);
177
WPS_STRDUP(model_name);
178
WPS_STRDUP(model_number);
179
WPS_STRDUP(serial_number);
184
int wps_device_store(struct wps_registrar *reg,
185
struct wps_device_data *dev, const u8 *uuid)
187
struct wps_registrar_device *d;
189
d = wps_device_get(reg, dev->mac_addr);
191
d = os_zalloc(sizeof(*d));
194
d->next = reg->devices;
198
wps_device_clone_data(&d->dev, dev);
199
os_memcpy(d->uuid, uuid, WPS_UUID_LEN);
117
205
static void wps_registrar_add_pbc_session(struct wps_registrar *reg,
118
206
const u8 *addr, const u8 *uuid_e)
527
594
static const u8 * wps_registrar_get_pin(struct wps_registrar *reg,
528
595
const u8 *uuid, size_t *pin_len)
530
struct wps_uuid_pin *pin;
597
struct wps_uuid_pin *pin, *found = NULL;
532
599
wps_registrar_expire_pins(reg);
601
dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
536
602
if (!pin->wildcard_uuid &&
537
os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0)
603
os_memcmp(pin->uuid, uuid, WPS_UUID_LEN) == 0) {
543
610
/* Check for wildcard UUIDs since none of the UUID-specific
544
611
* PINs matched */
612
dl_list_for_each(pin, ®->pins, struct wps_uuid_pin, list) {
547
613
if (pin->wildcard_uuid == 1) {
548
614
wpa_printf(MSG_DEBUG, "WPS: Found a wildcard "
549
615
"PIN. Assigned it for this UUID-E");
550
616
pin->wildcard_uuid = 2;
551
617
os_memcpy(pin->uuid, uuid, WPS_UUID_LEN);
562
628
* Lock the PIN to avoid attacks based on concurrent re-use of the PIN
563
629
* that could otherwise avoid PIN invalidations.
565
if (pin->flags & PIN_LOCKED) {
631
if (found->flags & PIN_LOCKED) {
566
632
wpa_printf(MSG_DEBUG, "WPS: Selected PIN locked - do not "
567
633
"allow concurrent re-use");
570
*pin_len = pin->pin_len;
571
pin->flags |= PIN_LOCKED;
636
*pin_len = found->pin_len;
637
found->flags |= PIN_LOCKED;
757
static int wps_cb_set_ie(struct wps_registrar *reg,
758
const struct wpabuf *beacon_ie,
759
const struct wpabuf *probe_resp_ie)
761
if (reg->set_ie_cb == NULL)
764
return reg->set_ie_cb(reg->cb_ctx, wpabuf_head(beacon_ie),
765
wpabuf_len(beacon_ie),
766
wpabuf_head(probe_resp_ie),
767
wpabuf_len(probe_resp_ie));
844
static int wps_cb_set_ie(struct wps_registrar *reg, struct wpabuf *beacon_ie,
845
struct wpabuf *probe_resp_ie)
847
return reg->set_ie_cb(reg->cb_ctx, beacon_ie, probe_resp_ie);
851
static void wps_cb_set_sel_reg(struct wps_registrar *reg)
854
if (reg->set_sel_reg_cb == NULL)
857
if (reg->selected_registrar) {
858
methods = reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
860
methods |= WPS_CONFIG_PUSHBUTTON;
863
reg->set_sel_reg_cb(reg->cb_ctx, reg->selected_registrar,
864
reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT,
1848
1974
m = WPA_GET_BE16(methods);
1850
wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x", m);
1976
wpa_printf(MSG_DEBUG, "WPS: Enrollee Config Methods 0x%x"
1977
"%s%s%s%s%s%s%s%s%s", m,
1978
m & WPS_CONFIG_USBA ? " [USBA]" : "",
1979
m & WPS_CONFIG_ETHERNET ? " [Ethernet]" : "",
1980
m & WPS_CONFIG_LABEL ? " [Label]" : "",
1981
m & WPS_CONFIG_DISPLAY ? " [Display]" : "",
1982
m & WPS_CONFIG_EXT_NFC_TOKEN ? " [Ext NFC Token]" : "",
1983
m & WPS_CONFIG_INT_NFC_TOKEN ? " [Int NFC Token]" : "",
1984
m & WPS_CONFIG_NFC_INTERFACE ? " [NFC]" : "",
1985
m & WPS_CONFIG_PUSHBUTTON ? " [PBC]" : "",
1986
m & WPS_CONFIG_KEYPAD ? " [Keypad]" : "");
1988
if (!(m & WPS_CONFIG_DISPLAY) && !wps->use_psk_key) {
1990
* The Enrollee does not have a display so it is unlikely to be
1991
* able to show the passphrase to a user and as such, could
1992
* benefit from receiving PSK to reduce key derivation time.
1994
wpa_printf(MSG_DEBUG, "WPS: Prefer PSK format key due to "
1995
"Enrollee not supporting display");
1996
wps->use_psk_key = 1;
2581
2776
struct wps_registrar *reg = eloop_ctx;
2583
wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar timed out - "
2584
"unselect Registrar");
2778
wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
2779
"unselect internal Registrar");
2585
2780
reg->selected_registrar = 0;
2587
reg->sel_reg_dev_password_id_override = -1;
2588
reg->sel_reg_config_methods_override = -1;
2782
wps_registrar_selected_registrar_changed(reg);
2786
#ifdef CONFIG_WPS_UPNP
2787
static void wps_registrar_sel_reg_add(struct wps_registrar *reg,
2788
struct subscription *s)
2790
wpa_printf(MSG_DEBUG, "WPS: External Registrar selected (dev_pw_id=%d "
2791
"config_methods=0x%x)",
2792
s->dev_password_id, s->config_methods);
2793
reg->sel_reg_union = 1;
2794
if (reg->sel_reg_dev_password_id_override != DEV_PW_PUSHBUTTON)
2795
reg->sel_reg_dev_password_id_override = s->dev_password_id;
2796
if (reg->sel_reg_config_methods_override == -1)
2797
reg->sel_reg_config_methods_override = 0;
2798
reg->sel_reg_config_methods_override |= s->config_methods;
2800
#endif /* CONFIG_WPS_UPNP */
2803
static void wps_registrar_sel_reg_union(struct wps_registrar *reg)
2805
#ifdef CONFIG_WPS_UPNP
2806
struct subscription *s;
2808
if (reg->wps->wps_upnp == NULL)
2811
dl_list_for_each(s, ®->wps->wps_upnp->subscriptions,
2812
struct subscription, list) {
2813
struct subscr_addr *sa;
2814
sa = dl_list_first(&s->addr_list, struct subscr_addr, list);
2816
wpa_printf(MSG_DEBUG, "WPS: External Registrar %s:%d",
2817
inet_ntoa(sa->saddr.sin_addr),
2818
ntohs(sa->saddr.sin_port));
2820
if (s->selected_registrar)
2821
wps_registrar_sel_reg_add(reg, s);
2823
wpa_printf(MSG_DEBUG, "WPS: External Registrar not "
2826
#endif /* CONFIG_WPS_UPNP */
2594
* wps_registrar_set_selected_registrar - Notification of SetSelectedRegistrar
2831
* wps_registrar_selected_registrar_changed - SetSelectedRegistrar change
2595
2832
* @reg: Registrar data from wps_registrar_init()
2596
* @msg: Received message from SetSelectedRegistrar
2597
* Returns: 0 on success, -1 on failure
2599
* This function is called when an AP receives a SetSelectedRegistrar UPnP
2834
* This function is called when selected registrar state changes, e.g., when an
2835
* AP receives a SetSelectedRegistrar UPnP message.
2602
int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
2603
const struct wpabuf *msg)
2837
void wps_registrar_selected_registrar_changed(struct wps_registrar *reg)
2605
struct wps_parse_attr attr;
2607
wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
2610
if (wps_parse_msg(msg, &attr) < 0)
2612
if (!wps_version_supported(attr.version)) {
2613
wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
2614
"version 0x%x", attr.version ? *attr.version : 0);
2618
if (attr.selected_registrar == NULL ||
2619
*attr.selected_registrar == 0) {
2620
wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
2621
"Selected Registrar");
2622
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg,
2624
wps_registrar_set_selected_timeout(reg, NULL);
2628
reg->selected_registrar = 1;
2629
reg->sel_reg_dev_password_id_override = attr.dev_password_id ?
2630
WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
2631
reg->sel_reg_config_methods_override = attr.sel_reg_config_methods ?
2632
WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
2839
wpa_printf(MSG_DEBUG, "WPS: Selected registrar information changed");
2841
reg->sel_reg_union = reg->selected_registrar;
2842
reg->sel_reg_dev_password_id_override = -1;
2843
reg->sel_reg_config_methods_override = -1;
2844
if (reg->selected_registrar) {
2845
reg->sel_reg_config_methods_override =
2846
reg->wps->config_methods & ~WPS_CONFIG_PUSHBUTTON;
2848
reg->sel_reg_dev_password_id_override =
2850
reg->sel_reg_config_methods_override |=
2851
WPS_CONFIG_PUSHBUTTON;
2853
wpa_printf(MSG_DEBUG, "WPS: Internal Registrar selected "
2854
"(pbc=%d)", reg->pbc);
2856
wpa_printf(MSG_DEBUG, "WPS: Internal Registrar not selected");
2858
wps_registrar_sel_reg_union(reg);
2633
2860
wps_set_ie(reg);
2635
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
2636
eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
2637
wps_registrar_set_selected_timeout,
2861
wps_cb_set_sel_reg(reg);
2865
int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
2866
char *buf, size_t buflen)
2868
struct wps_registrar_device *d;
2871
char devtype[WPS_DEV_TYPE_BUFSIZE];
2873
d = wps_device_get(reg, addr);
2876
if (uuid_bin2str(d->uuid, uuid, sizeof(uuid)))
2879
ret = os_snprintf(buf + len, buflen - len,
2881
"wpsPrimaryDeviceType=%s\n"
2882
"wpsDeviceName=%s\n"
2883
"wpsManufacturer=%s\n"
2885
"wpsModelNumber=%s\n"
2886
"wpsSerialNumber=%s\n",
2888
wps_dev_type_bin2str(d->dev.pri_dev_type, devtype,
2890
d->dev.device_name ? d->dev.device_name : "",
2891
d->dev.manufacturer ? d->dev.manufacturer : "",
2892
d->dev.model_name ? d->dev.model_name : "",
2893
d->dev.model_number ? d->dev.model_number : "",
2894
d->dev.serial_number ? d->dev.serial_number : "");
2895
if (ret < 0 || (size_t) ret >= buflen - len)