WPS: Added support for wildcard SSID matching in ap_scan=2 mode
[libeap.git] / wpa_supplicant / wps_supplicant.c
1 /*
2  * wpa_supplicant / WPS integration
3  * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "includes.h"
16
17 #include "common.h"
18 #include "ieee802_11_defs.h"
19 #include "wpa_common.h"
20 #include "config.h"
21 #include "eap_peer/eap.h"
22 #include "wpa_supplicant_i.h"
23 #include "eloop.h"
24 #include "wpa_ctrl.h"
25 #include "eap_common/eap_wsc_common.h"
26 #include "wps/wps.h"
27 #include "wps/wps_defs.h"
28 #include "wps_supplicant.h"
29
30
31 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
32 static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
33
34
35 int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
36 {
37         eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
38
39         if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
40             !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
41                 wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
42                            "try to associate with the received credential");
43                 wpa_supplicant_deauthenticate(wpa_s,
44                                               WLAN_REASON_DEAUTH_LEAVING);
45                 wpa_s->reassociate = 1;
46                 wpa_supplicant_req_scan(wpa_s, 0, 0);
47                 return 1;
48         }
49
50         return 0;
51 }
52
53
54 static int wpa_supplicant_wps_cred(void *ctx,
55                                    const struct wps_credential *cred)
56 {
57         struct wpa_supplicant *wpa_s = ctx;
58         struct wpa_ssid *ssid = wpa_s->current_ssid;
59
60         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
61
62         if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
63                 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
64                            "on the received credential");
65                 os_free(ssid->eap.identity);
66                 ssid->eap.identity = NULL;
67                 ssid->eap.identity_len = 0;
68                 os_free(ssid->eap.phase1);
69                 ssid->eap.phase1 = NULL;
70                 os_free(ssid->eap.eap_methods);
71                 ssid->eap.eap_methods = NULL;
72         } else {
73                 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
74                            "received credential");
75                 ssid = wpa_config_add_network(wpa_s->conf);
76                 if (ssid == NULL)
77                         return -1;
78         }
79
80         wpa_config_set_network_defaults(ssid);
81
82         os_free(ssid->ssid);
83         ssid->ssid = os_malloc(cred->ssid_len);
84         if (ssid->ssid) {
85                 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
86                 ssid->ssid_len = cred->ssid_len;
87         }
88
89         switch (cred->encr_type) {
90         case WPS_ENCR_NONE:
91                 ssid->pairwise_cipher = ssid->group_cipher = WPA_CIPHER_NONE;
92                 break;
93         case WPS_ENCR_WEP:
94                 ssid->pairwise_cipher = ssid->group_cipher =
95                         WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104;
96                 if (cred->key_len > 0 && cred->key_len <= MAX_WEP_KEY_LEN &&
97                     cred->key_idx < NUM_WEP_KEYS) {
98                         os_memcpy(ssid->wep_key[cred->key_idx], cred->key,
99                                   cred->key_len);
100                         ssid->wep_key_len[cred->key_idx] = cred->key_len;
101                         ssid->wep_tx_keyidx = cred->key_idx;
102                 }
103                 break;
104         case WPS_ENCR_TKIP:
105                 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
106                 ssid->group_cipher = WPA_CIPHER_TKIP;
107                 break;
108         case WPS_ENCR_AES:
109                 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
110                 ssid->group_cipher = WPA_CIPHER_CCMP | WPA_CIPHER_TKIP;
111                 break;
112         }
113
114         switch (cred->auth_type) {
115         case WPS_AUTH_OPEN:
116                 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
117                 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
118                 ssid->proto = 0;
119                 break;
120         case WPS_AUTH_SHARED:
121                 ssid->auth_alg = WPA_AUTH_ALG_SHARED;
122                 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
123                 ssid->proto = 0;
124                 break;
125         case WPS_AUTH_WPAPSK:
126                 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
127                 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
128                 ssid->proto = WPA_PROTO_WPA;
129                 break;
130         case WPS_AUTH_WPA:
131                 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
132                 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
133                 ssid->proto = WPA_PROTO_WPA;
134                 break;
135         case WPS_AUTH_WPA2:
136                 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
137                 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
138                 ssid->proto = WPA_PROTO_RSN;
139                 break;
140         case WPS_AUTH_WPA2PSK:
141                 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
142                 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
143                 ssid->proto = WPA_PROTO_RSN;
144                 break;
145         }
146
147         if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
148                 if (cred->key_len == 2 * PMK_LEN) {
149                         if (hexstr2bin((const char *) cred->key, ssid->psk,
150                                        PMK_LEN)) {
151                                 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
152                                            "Key");
153                                 return -1;
154                         }
155                         ssid->psk_set = 1;
156                 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
157                         os_free(ssid->passphrase);
158                         ssid->passphrase = os_malloc(cred->key_len + 1);
159                         if (ssid->passphrase == NULL)
160                                 return -1;
161                         os_memcpy(ssid->passphrase, cred->key, cred->key_len);
162                         ssid->passphrase[cred->key_len] = '\0';
163                         wpa_config_update_psk(ssid);
164                 } else {
165                         wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
166                                    "length %lu",
167                                    (unsigned long) cred->key_len);
168                         return -1;
169                 }
170         }
171
172 #ifndef CONFIG_NO_CONFIG_WRITE
173         if (wpa_s->conf->update_config &&
174             wpa_config_write(wpa_s->confname, wpa_s->conf)) {
175                 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
176                 return -1;
177         }
178 #endif /* CONFIG_NO_CONFIG_WRITE */
179
180         return 0;
181 }
182
183
184 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
185                                          struct wps_event_m2d *m2d)
186 {
187         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
188                 "dev_password_id=%d config_error=%d",
189                 m2d->dev_password_id, m2d->config_error);
190 }
191
192
193 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
194                                           struct wps_event_fail *fail)
195 {
196         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg);
197         wpas_clear_wps(wpa_s);
198 }
199
200
201 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
202 {
203         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
204 }
205
206
207 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
208                                      union wps_event_data *data)
209 {
210         struct wpa_supplicant *wpa_s = ctx;
211         switch (event) {
212         case WPS_EV_M2D:
213                 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
214                 break;
215         case WPS_EV_FAIL:
216                 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
217                 break;
218         case WPS_EV_SUCCESS:
219                 wpa_supplicant_wps_event_success(wpa_s);
220                 break;
221         }
222 }
223
224
225 u8 wpas_wps_get_req_type(struct wpa_ssid *ssid)
226 {
227         if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
228             eap_is_wps_pin_enrollee(&ssid->eap))
229                 return WPS_REQ_ENROLLEE;
230         else
231                 return WPS_REQ_REGISTRAR;
232 }
233
234
235 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
236 {
237         int id;
238         struct wpa_ssid *ssid;
239
240         eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
241
242         /* Remove any existing WPS network from configuration */
243         ssid = wpa_s->conf->ssid;
244         while (ssid) {
245                 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
246                         if (ssid == wpa_s->current_ssid)
247                                 wpa_s->current_ssid = NULL;
248                         id = ssid->id;
249                 } else
250                         id = -1;
251                 ssid = ssid->next;
252                 if (id >= 0)
253                         wpa_config_remove_network(wpa_s->conf, id);
254         }
255 }
256
257
258 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
259 {
260         struct wpa_supplicant *wpa_s = eloop_ctx;
261         wpa_printf(MSG_DEBUG, "WPS: Requested operation timed out");
262         wpas_clear_wps(wpa_s);
263 }
264
265
266 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
267                                               int registrar, const u8 *bssid)
268 {
269         struct wpa_ssid *ssid;
270
271         ssid = wpa_config_add_network(wpa_s->conf);
272         if (ssid == NULL)
273                 return NULL;
274         wpa_config_set_network_defaults(ssid);
275         if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
276             wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
277             wpa_config_set(ssid, "identity", registrar ?
278                            "\"" WSC_ID_REGISTRAR "\"" :
279                            "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
280                 wpa_config_remove_network(wpa_s->conf, ssid->id);
281                 return NULL;
282         }
283
284         if (bssid) {
285                 size_t i;
286                 struct wpa_scan_res *res;
287
288                 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
289                 ssid->bssid_set = 1;
290
291                 /* Try to get SSID from scan results */
292                 if (wpa_s->scan_res == NULL &&
293                     wpa_supplicant_get_scan_results(wpa_s) < 0)
294                         return ssid; /* Could not find any scan results */
295
296                 for (i = 0; i < wpa_s->scan_res->num; i++) {
297                         const u8 *ie;
298
299                         res = wpa_s->scan_res->res[i];
300                         if (os_memcmp(bssid, res->bssid, ETH_ALEN) != 0)
301                                 continue;
302
303                         ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
304                         if (ie == NULL)
305                                 break;
306                         os_free(ssid->ssid);
307                         ssid->ssid = os_malloc(ie[1]);
308                         if (ssid->ssid == NULL)
309                                 break;
310                         os_memcpy(ssid->ssid, ie + 2, ie[1]);
311                         ssid->ssid_len = ie[1];
312                         break;
313                 }
314         }
315
316         return ssid;
317 }
318
319
320 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
321                              struct wpa_ssid *selected)
322 {
323         struct wpa_ssid *ssid;
324
325         /* Mark all other networks disabled and trigger reassociation */
326         ssid = wpa_s->conf->ssid;
327         while (ssid) {
328                 ssid->disabled = ssid != selected;
329                 ssid = ssid->next;
330         }
331         wpa_s->disconnected = 0;
332         wpa_s->reassociate = 1;
333         wpa_supplicant_req_scan(wpa_s, 0, 0);
334 }
335
336
337 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
338 {
339         struct wpa_ssid *ssid;
340         wpas_clear_wps(wpa_s);
341         ssid = wpas_wps_add_network(wpa_s, 0, bssid);
342         if (ssid == NULL)
343                 return -1;
344         wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
345         eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
346                                wpa_s, NULL);
347         wpas_wps_reassoc(wpa_s, ssid);
348         return 0;
349 }
350
351
352 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
353                        const char *pin)
354 {
355         struct wpa_ssid *ssid;
356         char val[30];
357         unsigned int rpin = 0;
358
359         wpas_clear_wps(wpa_s);
360         ssid = wpas_wps_add_network(wpa_s, 0, bssid);
361         if (ssid == NULL)
362                 return -1;
363         if (pin)
364                 os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
365         else {
366                 rpin = wps_generate_pin();
367                 os_snprintf(val, sizeof(val), "\"pin=%08d\"", rpin);
368         }
369         wpa_config_set(ssid, "phase1", val, 0);
370         eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
371                                wpa_s, NULL);
372         wpas_wps_reassoc(wpa_s, ssid);
373         return rpin;
374 }
375
376
377 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
378                        const char *pin)
379 {
380         struct wpa_ssid *ssid;
381         char val[30];
382
383         if (!pin)
384                 return -1;
385         wpas_clear_wps(wpa_s);
386         ssid = wpas_wps_add_network(wpa_s, 1, bssid);
387         if (ssid == NULL)
388                 return -1;
389         os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
390         wpa_config_set(ssid, "phase1", val, 0);
391         eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
392                                wpa_s, NULL);
393         wpas_wps_reassoc(wpa_s, ssid);
394         return 0;
395 }
396
397
398 int wpas_wps_init(struct wpa_supplicant *wpa_s)
399 {
400         struct wps_context *wps;
401
402         wps = os_zalloc(sizeof(*wps));
403         if (wps == NULL)
404                 return -1;
405
406         wps->cred_cb = wpa_supplicant_wps_cred;
407         wps->event_cb = wpa_supplicant_wps_event;
408         wps->cb_ctx = wpa_s;
409
410         wps->dev.device_name = wpa_s->conf->device_name;
411         wps->dev.manufacturer = wpa_s->conf->manufacturer;
412         wps->dev.model_name = wpa_s->conf->model_name;
413         wps->dev.model_number = wpa_s->conf->model_number;
414         wps->dev.serial_number = wpa_s->conf->serial_number;
415         if (wpa_s->conf->device_type) {
416                 char *pos;
417                 u8 oui[4];
418                 /* <categ>-<OUI>-<subcateg> */
419                 wps->dev.categ = atoi(wpa_s->conf->device_type);
420                 pos = os_strchr(wpa_s->conf->device_type, '-');
421                 if (pos == NULL) {
422                         wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
423                         os_free(wps);
424                         return -1;
425                 }
426                 pos++;
427                 if (hexstr2bin(pos, oui, 4)) {
428                         wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
429                         os_free(wps);
430                         return -1;
431                 }
432                 wps->dev.oui = WPA_GET_BE32(oui);
433                 pos = os_strchr(pos, '-');
434                 if (pos == NULL) {
435                         wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
436                         os_free(wps);
437                         return -1;
438                 }
439                 pos++;
440                 wps->dev.sub_categ = atoi(pos);
441         }
442         wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
443         wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
444         os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
445         os_memcpy(wps->uuid, wpa_s->conf->uuid, 16);
446
447         wpa_s->wps = wps;
448
449         return 0;
450 }
451
452
453 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
454 {
455         eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
456
457         if (wpa_s->wps == NULL)
458                 return;
459
460         os_free(wpa_s->wps->network_key);
461         os_free(wpa_s->wps);
462         wpa_s->wps = NULL;
463 }
464
465
466 int wpas_wps_ssid_bss_match(struct wpa_ssid *ssid, struct wpa_scan_res *bss)
467 {
468         struct wpabuf *wps_ie;
469
470         if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
471                 return -1;
472
473         wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
474         if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
475                 if (!wps_ie) {
476                         wpa_printf(MSG_DEBUG, "   skip - non-WPS AP");
477                         return 0;
478                 }
479
480                 if (!wps_is_selected_pbc_registrar(wps_ie)) {
481                         wpa_printf(MSG_DEBUG, "   skip - WPS AP "
482                                    "without active PBC Registrar");
483                         wpabuf_free(wps_ie);
484                         return 0;
485                 }
486
487                 /* TODO: overlap detection */
488                 wpa_printf(MSG_DEBUG, "   selected based on WPS IE "
489                            "(Active PBC)");
490                 wpabuf_free(wps_ie);
491                 return 1;
492         }
493
494         if (eap_is_wps_pin_enrollee(&ssid->eap)) {
495                 if (!wps_ie) {
496                         wpa_printf(MSG_DEBUG, "   skip - non-WPS AP");
497                         return 0;
498                 }
499
500                 if (!wps_is_selected_pin_registrar(wps_ie)) {
501                         wpa_printf(MSG_DEBUG, "   skip - WPS AP "
502                                    "without active PIN Registrar");
503                         wpabuf_free(wps_ie);
504                         return 0;
505                 }
506                 wpa_printf(MSG_DEBUG, "   selected based on WPS IE "
507                            "(Active PIN)");
508                 wpabuf_free(wps_ie);
509                 return 1;
510         }
511
512         if (wps_ie) {
513                 wpa_printf(MSG_DEBUG, "   selected based on WPS IE");
514                 wpabuf_free(wps_ie);
515                 return 1;
516         }
517
518         return -1;
519 }
520
521
522 int wpas_wps_ssid_wildcard_ok(struct wpa_ssid *ssid,
523                               struct wpa_scan_res *bss)
524 {
525         struct wpabuf *wps_ie = NULL;
526         int ret = 0;
527
528         if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
529                 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
530                 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
531                         /* allow wildcard SSID for WPS PBC */
532                         ret = 1;
533                 }
534         } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
535                 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
536                 if (wps_ie && wps_is_selected_pin_registrar(wps_ie)) {
537                         /* allow wildcard SSID for WPS PIN */
538                         ret = 1;
539                 }
540         }
541
542         if (!ret && ssid->bssid_set &&
543             os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
544                 /* allow wildcard SSID due to hardcoded BSSID match */
545                 ret = 1;
546         }
547
548         wpabuf_free(wps_ie);
549
550         return ret;
551 }
552
553
554 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
555                               struct wpa_scan_res *selected,
556                               struct wpa_ssid *ssid)
557 {
558         const u8 *sel_uuid, *uuid;
559         size_t i;
560         struct wpabuf *wps_ie;
561         int ret = 0;
562
563         if (!eap_is_wps_pbc_enrollee(&ssid->eap))
564                 return 0;
565
566         /* Make sure that only one AP is in active PBC mode */
567         wps_ie = wpa_scan_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
568         if (wps_ie)
569                 sel_uuid = wps_get_uuid_e(wps_ie);
570         else
571                 sel_uuid = NULL;
572         if (!sel_uuid) {
573                 wpa_printf(MSG_DEBUG, "WPS: UUID-E not available for PBC "
574                            "overlap detection");
575                 wpabuf_free(wps_ie);
576                 return 1;
577         }
578
579         for (i = 0; i < wpa_s->scan_res->num; i++) {
580                 struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
581                 struct wpabuf *ie;
582                 if (bss == selected)
583                         continue;
584                 ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
585                 if (!ie)
586                         continue;
587                 if (!wps_is_selected_pbc_registrar(ie)) {
588                         wpabuf_free(ie);
589                         continue;
590                 }
591                 uuid = wps_get_uuid_e(ie);
592                 if (uuid == NULL) {
593                         wpa_printf(MSG_DEBUG, "WPS: UUID-E not available for "
594                                    "PBC overlap detection (other BSS)");
595                         ret = 1;
596                         wpabuf_free(ie);
597                         break;
598                 }
599                 if (os_memcmp(sel_uuid, uuid, 16) != 0) {
600                         ret = 1; /* PBC overlap */
601                         wpabuf_free(ie);
602                         break;
603                 }
604
605                 /* TODO: verify that this is reasonable dual-band situation */
606
607                 wpabuf_free(ie);
608         }
609
610         wpabuf_free(wps_ie);
611
612         return ret;
613 }
614
615
616 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
617 {
618         size_t i;
619
620         if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
621                 return;
622
623         for (i = 0; i < wpa_s->scan_res->num; i++) {
624                 struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
625                 struct wpabuf *ie;
626                 ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
627                 if (!ie)
628                         continue;
629                 if (wps_is_selected_pbc_registrar(ie))
630                         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
631                 else if (wps_is_selected_pin_registrar(ie))
632                         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
633                 else
634                         wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
635                 wpabuf_free(ie);
636                 break;
637         }
638 }
639
640
641 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
642 {
643         struct wpa_ssid *ssid;
644
645         for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
646                 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
647                         return 1;
648         }
649
650         return 0;
651 }