wps_supplicant.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. ssid->bssid_set = 1;
  250. /* Try to get SSID from scan results */
  251. if (wpa_s->scan_res == NULL &&
  252. wpa_supplicant_get_scan_results(wpa_s) < 0)
  253. return ssid; /* Could not find any scan results */
  254. for (i = 0; i < wpa_s->scan_res->num; i++) {
  255. const u8 *ie;
  256. res = wpa_s->scan_res->res[i];
  257. if (os_memcmp(bssid, res->bssid, ETH_ALEN) != 0)
  258. continue;
  259. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  260. if (ie == NULL)
  261. break;
  262. os_free(ssid->ssid);
  263. ssid->ssid = os_malloc(ie[1]);
  264. if (ssid->ssid == NULL)
  265. break;
  266. os_memcpy(ssid->ssid, ie + 2, ie[1]);
  267. ssid->ssid_len = ie[1];
  268. break;
  269. }
  270. }
  271. return ssid;
  272. }
  273. static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
  274. struct wpa_ssid *selected)
  275. {
  276. struct wpa_ssid *ssid;
  277. /* Mark all other networks disabled and trigger reassociation */
  278. ssid = wpa_s->conf->ssid;
  279. while (ssid) {
  280. ssid->disabled = ssid != selected;
  281. ssid = ssid->next;
  282. }
  283. wpa_s->disconnected = 0;
  284. wpa_s->reassociate = 1;
  285. wpa_supplicant_req_scan(wpa_s, 0, 0);
  286. }
  287. int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
  288. {
  289. struct wpa_ssid *ssid;
  290. wpas_clear_wps(wpa_s);
  291. ssid = wpas_wps_add_network(wpa_s, 0, bssid);
  292. if (ssid == NULL)
  293. return -1;
  294. wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
  295. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  296. wpa_s, NULL);
  297. wpas_wps_reassoc(wpa_s, ssid);
  298. return 0;
  299. }
  300. int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  301. const char *pin)
  302. {
  303. struct wpa_ssid *ssid;
  304. char val[30];
  305. unsigned int rpin = 0;
  306. wpas_clear_wps(wpa_s);
  307. ssid = wpas_wps_add_network(wpa_s, 0, bssid);
  308. if (ssid == NULL)
  309. return -1;
  310. if (pin)
  311. os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
  312. else {
  313. rpin = wps_generate_pin();
  314. os_snprintf(val, sizeof(val), "\"pin=%08d\"", rpin);
  315. }
  316. wpa_config_set(ssid, "phase1", val, 0);
  317. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  318. wpa_s, NULL);
  319. wpas_wps_reassoc(wpa_s, ssid);
  320. return rpin;
  321. }
  322. int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
  323. const char *pin)
  324. {
  325. struct wpa_ssid *ssid;
  326. char val[30];
  327. if (!pin)
  328. return -1;
  329. wpas_clear_wps(wpa_s);
  330. ssid = wpas_wps_add_network(wpa_s, 1, bssid);
  331. if (ssid == NULL)
  332. return -1;
  333. os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
  334. wpa_config_set(ssid, "phase1", val, 0);
  335. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  336. wpa_s, NULL);
  337. wpas_wps_reassoc(wpa_s, ssid);
  338. return 0;
  339. }
  340. int wpas_wps_init(struct wpa_supplicant *wpa_s)
  341. {
  342. struct wps_context *wps;
  343. wps = os_zalloc(sizeof(*wps));
  344. if (wps == NULL)
  345. return -1;
  346. wps->cred_cb = wpa_supplicant_wps_cred;
  347. wps->event_cb = wpa_supplicant_wps_event;
  348. wps->cb_ctx = wpa_s;
  349. wps->dev.device_name = wpa_s->conf->device_name;
  350. wps->dev.manufacturer = wpa_s->conf->manufacturer;
  351. wps->dev.model_name = wpa_s->conf->model_name;
  352. wps->dev.model_number = wpa_s->conf->model_number;
  353. wps->dev.serial_number = wpa_s->conf->serial_number;
  354. if (wpa_s->conf->device_type) {
  355. char *pos;
  356. u8 oui[4];
  357. /* <categ>-<OUI>-<subcateg> */
  358. wps->dev.categ = atoi(wpa_s->conf->device_type);
  359. pos = os_strchr(wpa_s->conf->device_type, '-');
  360. if (pos == NULL) {
  361. wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
  362. os_free(wps);
  363. return -1;
  364. }
  365. pos++;
  366. if (hexstr2bin(pos, oui, 4)) {
  367. wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
  368. os_free(wps);
  369. return -1;
  370. }
  371. wps->dev.oui = WPA_GET_BE32(oui);
  372. pos = os_strchr(pos, '-');
  373. if (pos == NULL) {
  374. wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
  375. os_free(wps);
  376. return -1;
  377. }
  378. pos++;
  379. wps->dev.sub_categ = atoi(pos);
  380. }
  381. wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
  382. wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
  383. os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
  384. os_memcpy(wps->uuid, wpa_s->conf->uuid, 16);
  385. wpa_s->wps = wps;
  386. return 0;
  387. }
  388. void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
  389. {
  390. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  391. if (wpa_s->wps == NULL)
  392. return;
  393. os_free(wpa_s->wps->network_key);
  394. os_free(wpa_s->wps);
  395. wpa_s->wps = NULL;
  396. }
  397. int wpas_wps_ssid_bss_match(struct wpa_ssid *ssid, struct wpa_scan_res *bss)
  398. {
  399. struct wpabuf *wps_ie;
  400. if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
  401. return -1;
  402. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  403. if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
  404. if (!wps_ie) {
  405. wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
  406. return 0;
  407. }
  408. if (!wps_is_selected_pbc_registrar(wps_ie)) {
  409. wpa_printf(MSG_DEBUG, " skip - WPS AP "
  410. "without active PBC Registrar");
  411. wpabuf_free(wps_ie);
  412. return 0;
  413. }
  414. /* TODO: overlap detection */
  415. wpa_printf(MSG_DEBUG, " selected based on WPS IE "
  416. "(Active PBC)");
  417. wpabuf_free(wps_ie);
  418. return 1;
  419. }
  420. if (eap_is_wps_pin_enrollee(&ssid->eap)) {
  421. if (!wps_ie) {
  422. wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
  423. return 0;
  424. }
  425. if (!wps_is_selected_pin_registrar(wps_ie)) {
  426. wpa_printf(MSG_DEBUG, " skip - WPS AP "
  427. "without active PIN Registrar");
  428. wpabuf_free(wps_ie);
  429. return 0;
  430. }
  431. wpa_printf(MSG_DEBUG, " selected based on WPS IE "
  432. "(Active PIN)");
  433. wpabuf_free(wps_ie);
  434. return 1;
  435. }
  436. if (wps_ie) {
  437. wpa_printf(MSG_DEBUG, " selected based on WPS IE");
  438. wpabuf_free(wps_ie);
  439. return 1;
  440. }
  441. return -1;
  442. }
  443. int wpas_wps_ssid_wildcard_ok(struct wpa_ssid *ssid,
  444. struct wpa_scan_res *bss)
  445. {
  446. struct wpabuf *wps_ie = NULL;
  447. int ret = 0;
  448. if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
  449. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  450. if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
  451. /* allow wildcard SSID for WPS PBC */
  452. ret = 1;
  453. }
  454. } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
  455. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  456. if (wps_ie && wps_is_selected_pin_registrar(wps_ie)) {
  457. /* allow wildcard SSID for WPS PIN */
  458. ret = 1;
  459. }
  460. }
  461. if (!ret && ssid->bssid_set &&
  462. os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
  463. /* allow wildcard SSID due to hardcoded BSSID match */
  464. ret = 1;
  465. }
  466. wpabuf_free(wps_ie);
  467. return ret;
  468. }
  469. int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
  470. struct wpa_scan_res *selected,
  471. struct wpa_ssid *ssid)
  472. {
  473. const u8 *sel_uuid, *uuid;
  474. size_t i;
  475. struct wpabuf *wps_ie;
  476. int ret = 0;
  477. if (!eap_is_wps_pbc_enrollee(&ssid->eap))
  478. return 0;
  479. /* Make sure that only one AP is in active PBC mode */
  480. wps_ie = wpa_scan_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
  481. if (wps_ie)
  482. sel_uuid = wps_get_uuid_e(wps_ie);
  483. else
  484. sel_uuid = NULL;
  485. if (!sel_uuid) {
  486. wpa_printf(MSG_DEBUG, "WPS: UUID-E not available for PBC "
  487. "overlap detection");
  488. wpabuf_free(wps_ie);
  489. return 1;
  490. }
  491. for (i = 0; i < wpa_s->scan_res->num; i++) {
  492. struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
  493. struct wpabuf *ie;
  494. if (bss == selected)
  495. continue;
  496. ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  497. if (!ie)
  498. continue;
  499. if (!wps_is_selected_pbc_registrar(ie)) {
  500. wpabuf_free(ie);
  501. continue;
  502. }
  503. uuid = wps_get_uuid_e(ie);
  504. if (uuid == NULL) {
  505. wpa_printf(MSG_DEBUG, "WPS: UUID-E not available for "
  506. "PBC overlap detection (other BSS)");
  507. ret = 1;
  508. wpabuf_free(ie);
  509. break;
  510. }
  511. if (os_memcmp(sel_uuid, uuid, 16) != 0) {
  512. ret = 1; /* PBC overlap */
  513. wpabuf_free(ie);
  514. break;
  515. }
  516. /* TODO: verify that this is reasonable dual-band situation */
  517. wpabuf_free(ie);
  518. }
  519. wpabuf_free(wps_ie);
  520. return ret;
  521. }
  522. void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
  523. {
  524. size_t i;
  525. if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
  526. return;
  527. for (i = 0; i < wpa_s->scan_res->num; i++) {
  528. struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
  529. struct wpabuf *ie;
  530. ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  531. if (!ie)
  532. continue;
  533. if (wps_is_selected_pbc_registrar(ie))
  534. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
  535. else if (wps_is_selected_pin_registrar(ie))
  536. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
  537. else
  538. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
  539. wpabuf_free(ie);
  540. break;
  541. }
  542. }
  543. int wpas_wps_searching(struct wpa_supplicant *wpa_s)
  544. {
  545. struct wpa_ssid *ssid;
  546. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  547. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
  548. return 1;
  549. }
  550. return 0;
  551. }