wps_supplicant.c 15 KB

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