wps_supplicant.c 16 KB

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