wps_supplicant.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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 "ieee802_11_common.h"
  18. #include "wpa_common.h"
  19. #include "config.h"
  20. #include "eap_peer/eap.h"
  21. #include "wpa_supplicant_i.h"
  22. #include "driver_i.h"
  23. #include "eloop.h"
  24. #include "uuid.h"
  25. #include "wpa_ctrl.h"
  26. #include "notify.h"
  27. #include "eap_common/eap_wsc_common.h"
  28. #include "blacklist.h"
  29. #include "wpa.h"
  30. #include "wps_supplicant.h"
  31. #include "dh_group5.h"
  32. #define WPS_PIN_SCAN_IGNORE_SEL_REG 3
  33. static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
  34. static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
  35. int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
  36. {
  37. if (!wpa_s->wps_success &&
  38. wpa_s->current_ssid &&
  39. eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
  40. const u8 *bssid = wpa_s->bssid;
  41. if (is_zero_ether_addr(bssid))
  42. bssid = wpa_s->pending_bssid;
  43. wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
  44. " did not succeed - continue trying to find "
  45. "suitable AP", MAC2STR(bssid));
  46. wpa_blacklist_add(wpa_s, bssid);
  47. wpa_supplicant_deauthenticate(wpa_s,
  48. WLAN_REASON_DEAUTH_LEAVING);
  49. wpa_s->reassociate = 1;
  50. wpa_supplicant_req_scan(wpa_s,
  51. wpa_s->blacklist_cleared ? 5 : 0, 0);
  52. wpa_s->blacklist_cleared = 0;
  53. return 1;
  54. }
  55. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  56. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
  57. !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  58. wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
  59. "try to associate with the received credential");
  60. wpa_supplicant_deauthenticate(wpa_s,
  61. WLAN_REASON_DEAUTH_LEAVING);
  62. wpa_s->reassociate = 1;
  63. wpa_supplicant_req_scan(wpa_s, 0, 0);
  64. return 1;
  65. }
  66. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
  67. wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
  68. "for external credential processing");
  69. wpas_clear_wps(wpa_s);
  70. wpa_supplicant_deauthenticate(wpa_s,
  71. WLAN_REASON_DEAUTH_LEAVING);
  72. return 1;
  73. }
  74. return 0;
  75. }
  76. static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
  77. struct wpa_ssid *ssid,
  78. const struct wps_credential *cred)
  79. {
  80. struct wpa_driver_capa capa;
  81. size_t i;
  82. struct wpa_scan_res *bss;
  83. const u8 *ie;
  84. struct wpa_ie_data adv;
  85. int wpa2 = 0, ccmp = 0;
  86. /*
  87. * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
  88. * case they are configured for mixed mode operation (WPA+WPA2 and
  89. * TKIP+CCMP). Try to use scan results to figure out whether the AP
  90. * actually supports stronger security and select that if the client
  91. * has support for it, too.
  92. */
  93. if (wpa_drv_get_capa(wpa_s, &capa))
  94. return; /* Unknown what driver supports */
  95. if (wpa_supplicant_get_scan_results(wpa_s) || wpa_s->scan_res == NULL)
  96. return; /* Could not get scan results for checking advertised
  97. * parameters */
  98. for (i = 0; i < wpa_s->scan_res->num; i++) {
  99. bss = wpa_s->scan_res->res[i];
  100. if (os_memcmp(bss->bssid, cred->mac_addr, ETH_ALEN) != 0)
  101. continue;
  102. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  103. if (ie == NULL)
  104. continue;
  105. if (ie[1] != ssid->ssid_len || ssid->ssid == NULL ||
  106. os_memcmp(ie + 2, ssid->ssid, ssid->ssid_len) != 0)
  107. continue;
  108. wpa_printf(MSG_DEBUG, "WPS: AP found from scan results");
  109. break;
  110. }
  111. if (i == wpa_s->scan_res->num) {
  112. wpa_printf(MSG_DEBUG, "WPS: The AP was not found from scan "
  113. "results - use credential as-is");
  114. return;
  115. }
  116. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  117. if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
  118. wpa2 = 1;
  119. if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
  120. ccmp = 1;
  121. } else {
  122. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  123. if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
  124. adv.pairwise_cipher & WPA_CIPHER_CCMP)
  125. ccmp = 1;
  126. }
  127. if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
  128. (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
  129. /*
  130. * TODO: This could be the initial AP configuration and the
  131. * Beacon contents could change shortly. Should request a new
  132. * scan and delay addition of the network until the updated
  133. * scan results are available.
  134. */
  135. wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
  136. "support - use credential as-is");
  137. return;
  138. }
  139. if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
  140. (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
  141. (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  142. wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
  143. "based on scan results");
  144. if (wpa_s->conf->ap_scan == 1)
  145. ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
  146. else
  147. ssid->pairwise_cipher = WPA_CIPHER_CCMP;
  148. }
  149. if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
  150. (ssid->proto & WPA_PROTO_WPA) &&
  151. (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
  152. wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
  153. "based on scan results");
  154. if (wpa_s->conf->ap_scan == 1)
  155. ssid->proto |= WPA_PROTO_RSN;
  156. else
  157. ssid->proto = WPA_PROTO_RSN;
  158. }
  159. }
  160. static int wpa_supplicant_wps_cred(void *ctx,
  161. const struct wps_credential *cred)
  162. {
  163. struct wpa_supplicant *wpa_s = ctx;
  164. struct wpa_ssid *ssid = wpa_s->current_ssid;
  165. u8 key_idx = 0;
  166. u16 auth_type;
  167. if ((wpa_s->conf->wps_cred_processing == 1 ||
  168. wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
  169. size_t blen = cred->cred_attr_len * 2 + 1;
  170. char *buf = os_malloc(blen);
  171. if (buf) {
  172. wpa_snprintf_hex(buf, blen,
  173. cred->cred_attr, cred->cred_attr_len);
  174. wpa_msg(wpa_s, MSG_INFO, "%s%s",
  175. WPS_EVENT_CRED_RECEIVED, buf);
  176. os_free(buf);
  177. }
  178. wpas_notify_wps_credential(wpa_s, cred);
  179. } else
  180. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
  181. wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
  182. cred->cred_attr, cred->cred_attr_len);
  183. if (wpa_s->conf->wps_cred_processing == 1)
  184. return 0;
  185. wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
  186. wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
  187. cred->auth_type);
  188. wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
  189. wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
  190. wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
  191. cred->key, cred->key_len);
  192. wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
  193. MAC2STR(cred->mac_addr));
  194. auth_type = cred->auth_type;
  195. if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
  196. wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
  197. "auth_type into WPA2PSK");
  198. auth_type = WPS_AUTH_WPA2PSK;
  199. }
  200. if (auth_type != WPS_AUTH_OPEN &&
  201. auth_type != WPS_AUTH_SHARED &&
  202. auth_type != WPS_AUTH_WPAPSK &&
  203. auth_type != WPS_AUTH_WPA2PSK) {
  204. wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
  205. "unsupported authentication type 0x%x",
  206. auth_type);
  207. return 0;
  208. }
  209. if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  210. wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
  211. "on the received credential");
  212. os_free(ssid->eap.identity);
  213. ssid->eap.identity = NULL;
  214. ssid->eap.identity_len = 0;
  215. os_free(ssid->eap.phase1);
  216. ssid->eap.phase1 = NULL;
  217. os_free(ssid->eap.eap_methods);
  218. ssid->eap.eap_methods = NULL;
  219. } else {
  220. wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
  221. "received credential");
  222. ssid = wpa_config_add_network(wpa_s->conf);
  223. if (ssid == NULL)
  224. return -1;
  225. wpas_notify_network_added(wpa_s, ssid);
  226. }
  227. wpa_config_set_network_defaults(ssid);
  228. os_free(ssid->ssid);
  229. ssid->ssid = os_malloc(cred->ssid_len);
  230. if (ssid->ssid) {
  231. os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
  232. ssid->ssid_len = cred->ssid_len;
  233. }
  234. switch (cred->encr_type) {
  235. case WPS_ENCR_NONE:
  236. break;
  237. case WPS_ENCR_WEP:
  238. if (cred->key_len <= 0)
  239. break;
  240. if (cred->key_len != 5 && cred->key_len != 13 &&
  241. cred->key_len != 10 && cred->key_len != 26) {
  242. wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length "
  243. "%lu", (unsigned long) cred->key_len);
  244. return -1;
  245. }
  246. if (cred->key_idx > NUM_WEP_KEYS) {
  247. wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d",
  248. cred->key_idx);
  249. return -1;
  250. }
  251. if (cred->key_idx)
  252. key_idx = cred->key_idx - 1;
  253. if (cred->key_len == 10 || cred->key_len == 26) {
  254. if (hexstr2bin((char *) cred->key,
  255. ssid->wep_key[key_idx],
  256. cred->key_len / 2) < 0) {
  257. wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key "
  258. "%d", key_idx);
  259. return -1;
  260. }
  261. ssid->wep_key_len[key_idx] = cred->key_len / 2;
  262. } else {
  263. os_memcpy(ssid->wep_key[key_idx], cred->key,
  264. cred->key_len);
  265. ssid->wep_key_len[key_idx] = cred->key_len;
  266. }
  267. ssid->wep_tx_keyidx = key_idx;
  268. break;
  269. case WPS_ENCR_TKIP:
  270. ssid->pairwise_cipher = WPA_CIPHER_TKIP;
  271. break;
  272. case WPS_ENCR_AES:
  273. ssid->pairwise_cipher = WPA_CIPHER_CCMP;
  274. break;
  275. }
  276. switch (auth_type) {
  277. case WPS_AUTH_OPEN:
  278. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  279. ssid->key_mgmt = WPA_KEY_MGMT_NONE;
  280. ssid->proto = 0;
  281. break;
  282. case WPS_AUTH_SHARED:
  283. ssid->auth_alg = WPA_AUTH_ALG_SHARED;
  284. ssid->key_mgmt = WPA_KEY_MGMT_NONE;
  285. ssid->proto = 0;
  286. break;
  287. case WPS_AUTH_WPAPSK:
  288. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  289. ssid->key_mgmt = WPA_KEY_MGMT_PSK;
  290. ssid->proto = WPA_PROTO_WPA;
  291. break;
  292. case WPS_AUTH_WPA:
  293. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  294. ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  295. ssid->proto = WPA_PROTO_WPA;
  296. break;
  297. case WPS_AUTH_WPA2:
  298. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  299. ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  300. ssid->proto = WPA_PROTO_RSN;
  301. break;
  302. case WPS_AUTH_WPA2PSK:
  303. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  304. ssid->key_mgmt = WPA_KEY_MGMT_PSK;
  305. ssid->proto = WPA_PROTO_RSN;
  306. break;
  307. }
  308. if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
  309. if (cred->key_len == 2 * PMK_LEN) {
  310. if (hexstr2bin((const char *) cred->key, ssid->psk,
  311. PMK_LEN)) {
  312. wpa_printf(MSG_ERROR, "WPS: Invalid Network "
  313. "Key");
  314. return -1;
  315. }
  316. ssid->psk_set = 1;
  317. } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
  318. os_free(ssid->passphrase);
  319. ssid->passphrase = os_malloc(cred->key_len + 1);
  320. if (ssid->passphrase == NULL)
  321. return -1;
  322. os_memcpy(ssid->passphrase, cred->key, cred->key_len);
  323. ssid->passphrase[cred->key_len] = '\0';
  324. wpa_config_update_psk(ssid);
  325. } else {
  326. wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
  327. "length %lu",
  328. (unsigned long) cred->key_len);
  329. return -1;
  330. }
  331. }
  332. wpas_wps_security_workaround(wpa_s, ssid, cred);
  333. #ifndef CONFIG_NO_CONFIG_WRITE
  334. if (wpa_s->conf->update_config &&
  335. wpa_config_write(wpa_s->confname, wpa_s->conf)) {
  336. wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
  337. return -1;
  338. }
  339. #endif /* CONFIG_NO_CONFIG_WRITE */
  340. return 0;
  341. }
  342. static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
  343. struct wps_event_m2d *m2d)
  344. {
  345. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
  346. "dev_password_id=%d config_error=%d",
  347. m2d->dev_password_id, m2d->config_error);
  348. wpas_notify_wps_event_m2d(wpa_s, m2d);
  349. }
  350. static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
  351. struct wps_event_fail *fail)
  352. {
  353. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg);
  354. wpas_clear_wps(wpa_s);
  355. wpas_notify_wps_event_fail(wpa_s, fail);
  356. }
  357. static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
  358. {
  359. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
  360. wpa_s->wps_success = 1;
  361. wpas_notify_wps_event_success(wpa_s);
  362. }
  363. static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
  364. struct wps_event_er_ap *ap)
  365. {
  366. char uuid_str[100];
  367. uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
  368. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s|%s|%s|%s|%s|%s|%s",
  369. uuid_str,
  370. ap->friendly_name ? ap->friendly_name : "",
  371. ap->manufacturer ? ap->manufacturer : "",
  372. ap->model_description ? ap->model_description : "",
  373. ap->model_name ? ap->model_name : "",
  374. ap->manufacturer_url ? ap->manufacturer_url : "",
  375. ap->model_url ? ap->model_url : "");
  376. }
  377. static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
  378. struct wps_event_er_ap *ap)
  379. {
  380. char uuid_str[100];
  381. uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
  382. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
  383. }
  384. static void wpa_supplicant_wps_event_er_enrollee_add(
  385. struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
  386. {
  387. char uuid_str[100];
  388. char dev_type[20];
  389. uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
  390. if (enrollee->pri_dev_type)
  391. os_snprintf(dev_type, sizeof(dev_type), "%u-%08X-%u",
  392. WPA_GET_BE16(enrollee->pri_dev_type),
  393. WPA_GET_BE32(enrollee->pri_dev_type + 2),
  394. WPA_GET_BE16(enrollee->pri_dev_type + 6));
  395. else
  396. dev_type[0] = '\0';
  397. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
  398. " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
  399. "|%s|%s|%s|%s|%s|",
  400. uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
  401. enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
  402. enrollee->dev_name ? enrollee->dev_name : "",
  403. enrollee->manufacturer ? enrollee->manufacturer : "",
  404. enrollee->model_name ? enrollee->model_name : "",
  405. enrollee->model_number ? enrollee->model_number : "",
  406. enrollee->serial_number ? enrollee->serial_number : "");
  407. }
  408. static void wpa_supplicant_wps_event_er_enrollee_remove(
  409. struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
  410. {
  411. char uuid_str[100];
  412. uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
  413. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
  414. uuid_str, MAC2STR(enrollee->mac_addr));
  415. }
  416. static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
  417. union wps_event_data *data)
  418. {
  419. struct wpa_supplicant *wpa_s = ctx;
  420. switch (event) {
  421. case WPS_EV_M2D:
  422. wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
  423. break;
  424. case WPS_EV_FAIL:
  425. wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
  426. break;
  427. case WPS_EV_SUCCESS:
  428. wpa_supplicant_wps_event_success(wpa_s);
  429. break;
  430. case WPS_EV_PWD_AUTH_FAIL:
  431. break;
  432. case WPS_EV_PBC_OVERLAP:
  433. break;
  434. case WPS_EV_PBC_TIMEOUT:
  435. break;
  436. case WPS_EV_ER_AP_ADD:
  437. wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
  438. break;
  439. case WPS_EV_ER_AP_REMOVE:
  440. wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
  441. break;
  442. case WPS_EV_ER_ENROLLEE_ADD:
  443. wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
  444. &data->enrollee);
  445. break;
  446. case WPS_EV_ER_ENROLLEE_REMOVE:
  447. wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
  448. &data->enrollee);
  449. break;
  450. }
  451. }
  452. enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
  453. {
  454. if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
  455. eap_is_wps_pin_enrollee(&ssid->eap))
  456. return WPS_REQ_ENROLLEE;
  457. else
  458. return WPS_REQ_REGISTRAR;
  459. }
  460. static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
  461. {
  462. int id;
  463. struct wpa_ssid *ssid, *remove_ssid = NULL;
  464. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  465. /* Remove any existing WPS network from configuration */
  466. ssid = wpa_s->conf->ssid;
  467. while (ssid) {
  468. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  469. if (ssid == wpa_s->current_ssid) {
  470. wpa_s->current_ssid = NULL;
  471. if (ssid != NULL)
  472. wpas_notify_network_changed(wpa_s);
  473. }
  474. id = ssid->id;
  475. remove_ssid = ssid;
  476. } else
  477. id = -1;
  478. ssid = ssid->next;
  479. if (id >= 0) {
  480. wpas_notify_network_removed(wpa_s, remove_ssid);
  481. wpa_config_remove_network(wpa_s->conf, id);
  482. }
  483. }
  484. }
  485. static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
  486. {
  487. struct wpa_supplicant *wpa_s = eloop_ctx;
  488. wpa_printf(MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
  489. "out");
  490. wpas_clear_wps(wpa_s);
  491. }
  492. static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
  493. int registrar, const u8 *bssid)
  494. {
  495. struct wpa_ssid *ssid;
  496. ssid = wpa_config_add_network(wpa_s->conf);
  497. if (ssid == NULL)
  498. return NULL;
  499. wpas_notify_network_added(wpa_s, ssid);
  500. wpa_config_set_network_defaults(ssid);
  501. if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
  502. wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
  503. wpa_config_set(ssid, "identity", registrar ?
  504. "\"" WSC_ID_REGISTRAR "\"" :
  505. "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
  506. wpas_notify_network_removed(wpa_s, ssid);
  507. wpa_config_remove_network(wpa_s->conf, ssid->id);
  508. return NULL;
  509. }
  510. if (bssid) {
  511. size_t i;
  512. struct wpa_scan_res *res;
  513. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  514. ssid->bssid_set = 1;
  515. /* Try to get SSID from scan results */
  516. if (wpa_s->scan_res == NULL &&
  517. wpa_supplicant_get_scan_results(wpa_s) < 0)
  518. return ssid; /* Could not find any scan results */
  519. for (i = 0; i < wpa_s->scan_res->num; i++) {
  520. const u8 *ie;
  521. res = wpa_s->scan_res->res[i];
  522. if (os_memcmp(bssid, res->bssid, ETH_ALEN) != 0)
  523. continue;
  524. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  525. if (ie == NULL)
  526. break;
  527. os_free(ssid->ssid);
  528. ssid->ssid = os_malloc(ie[1]);
  529. if (ssid->ssid == NULL)
  530. break;
  531. os_memcpy(ssid->ssid, ie + 2, ie[1]);
  532. ssid->ssid_len = ie[1];
  533. break;
  534. }
  535. }
  536. return ssid;
  537. }
  538. static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
  539. struct wpa_ssid *selected)
  540. {
  541. struct wpa_ssid *ssid;
  542. /* Mark all other networks disabled and trigger reassociation */
  543. ssid = wpa_s->conf->ssid;
  544. while (ssid) {
  545. int was_disabled = ssid->disabled;
  546. ssid->disabled = ssid != selected;
  547. if (was_disabled != ssid->disabled)
  548. wpas_notify_network_enabled_changed(wpa_s, ssid);
  549. ssid = ssid->next;
  550. }
  551. wpa_s->disconnected = 0;
  552. wpa_s->reassociate = 1;
  553. wpa_s->scan_runs = 0;
  554. wpa_s->wps_success = 0;
  555. wpa_s->blacklist_cleared = 0;
  556. wpa_supplicant_req_scan(wpa_s, 0, 0);
  557. }
  558. int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
  559. {
  560. struct wpa_ssid *ssid;
  561. wpas_clear_wps(wpa_s);
  562. ssid = wpas_wps_add_network(wpa_s, 0, bssid);
  563. if (ssid == NULL)
  564. return -1;
  565. wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
  566. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  567. wpa_s, NULL);
  568. wpas_wps_reassoc(wpa_s, ssid);
  569. return 0;
  570. }
  571. int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  572. const char *pin)
  573. {
  574. struct wpa_ssid *ssid;
  575. char val[128];
  576. unsigned int rpin = 0;
  577. wpas_clear_wps(wpa_s);
  578. ssid = wpas_wps_add_network(wpa_s, 0, bssid);
  579. if (ssid == NULL)
  580. return -1;
  581. if (pin)
  582. os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
  583. else {
  584. rpin = wps_generate_pin();
  585. os_snprintf(val, sizeof(val), "\"pin=%08d\"", rpin);
  586. }
  587. wpa_config_set(ssid, "phase1", val, 0);
  588. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  589. wpa_s, NULL);
  590. wpas_wps_reassoc(wpa_s, ssid);
  591. return rpin;
  592. }
  593. #ifdef CONFIG_WPS_OOB
  594. int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
  595. char *path, char *method, char *name)
  596. {
  597. struct wps_context *wps = wpa_s->wps;
  598. struct oob_device_data *oob_dev;
  599. oob_dev = wps_get_oob_device(device_type);
  600. if (oob_dev == NULL)
  601. return -1;
  602. oob_dev->device_path = path;
  603. oob_dev->device_name = name;
  604. wps->oob_conf.oob_method = wps_get_oob_method(method);
  605. if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
  606. /*
  607. * Use pre-configured DH keys in order to be able to write the
  608. * key hash into the OOB file.
  609. */
  610. wpabuf_free(wps->dh_pubkey);
  611. wpabuf_free(wps->dh_privkey);
  612. wps->dh_privkey = NULL;
  613. wps->dh_pubkey = NULL;
  614. dh5_free(wps->dh_ctx);
  615. wps->dh_ctx = dh5_init(&wps->dh_privkey, &wps->dh_pubkey);
  616. wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
  617. if (wps->dh_ctx == NULL || wps->dh_pubkey == NULL) {
  618. wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
  619. "Diffie-Hellman handshake");
  620. return -1;
  621. }
  622. }
  623. if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
  624. wpas_clear_wps(wpa_s);
  625. if (wps_process_oob(wps, oob_dev, 0) < 0)
  626. return -1;
  627. if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
  628. wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
  629. wpas_wps_start_pin(wpa_s, NULL,
  630. wpabuf_head(wps->oob_conf.dev_password)) < 0)
  631. return -1;
  632. return 0;
  633. }
  634. #endif /* CONFIG_WPS_OOB */
  635. int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
  636. const char *pin, struct wps_new_ap_settings *settings)
  637. {
  638. struct wpa_ssid *ssid;
  639. char val[200];
  640. char *pos, *end;
  641. int res;
  642. if (!pin)
  643. return -1;
  644. wpas_clear_wps(wpa_s);
  645. ssid = wpas_wps_add_network(wpa_s, 1, bssid);
  646. if (ssid == NULL)
  647. return -1;
  648. pos = val;
  649. end = pos + sizeof(val);
  650. res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
  651. if (res < 0 || res >= end - pos)
  652. return -1;
  653. pos += res;
  654. if (settings) {
  655. res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
  656. "new_encr=%s new_key=%s",
  657. settings->ssid_hex, settings->auth,
  658. settings->encr, settings->key_hex);
  659. if (res < 0 || res >= end - pos)
  660. return -1;
  661. pos += res;
  662. }
  663. res = os_snprintf(pos, end - pos, "\"");
  664. if (res < 0 || res >= end - pos)
  665. return -1;
  666. wpa_config_set(ssid, "phase1", val, 0);
  667. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  668. wpa_s, NULL);
  669. wpas_wps_reassoc(wpa_s, ssid);
  670. return 0;
  671. }
  672. static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
  673. size_t psk_len)
  674. {
  675. wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for "
  676. "STA " MACSTR, MAC2STR(mac_addr));
  677. wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
  678. /* TODO */
  679. return 0;
  680. }
  681. static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
  682. const struct wps_device_data *dev)
  683. {
  684. char uuid[40], txt[400];
  685. int len;
  686. if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
  687. return;
  688. wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
  689. len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
  690. " [%s|%s|%s|%s|%s|%d-%08X-%d]",
  691. uuid, MAC2STR(dev->mac_addr), dev->device_name,
  692. dev->manufacturer, dev->model_name,
  693. dev->model_number, dev->serial_number,
  694. dev->categ, dev->oui, dev->sub_categ);
  695. if (len > 0 && len < (int) sizeof(txt))
  696. wpa_printf(MSG_INFO, "%s", txt);
  697. }
  698. static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
  699. u16 sel_reg_config_methods)
  700. {
  701. #ifdef CONFIG_WPS_ER
  702. struct wpa_supplicant *wpa_s = ctx;
  703. if (wpa_s->wps_er == NULL)
  704. return;
  705. wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
  706. sel_reg_config_methods);
  707. #endif /* CONFIG_WPS_ER */
  708. }
  709. int wpas_wps_init(struct wpa_supplicant *wpa_s)
  710. {
  711. struct wps_context *wps;
  712. struct wps_registrar_config rcfg;
  713. wps = os_zalloc(sizeof(*wps));
  714. if (wps == NULL)
  715. return -1;
  716. wps->cred_cb = wpa_supplicant_wps_cred;
  717. wps->event_cb = wpa_supplicant_wps_event;
  718. wps->cb_ctx = wpa_s;
  719. wps->dev.device_name = wpa_s->conf->device_name;
  720. wps->dev.manufacturer = wpa_s->conf->manufacturer;
  721. wps->dev.model_name = wpa_s->conf->model_name;
  722. wps->dev.model_number = wpa_s->conf->model_number;
  723. wps->dev.serial_number = wpa_s->conf->serial_number;
  724. if (wpa_s->conf->device_type) {
  725. char *pos;
  726. u8 oui[4];
  727. /* <categ>-<OUI>-<subcateg> */
  728. wps->dev.categ = atoi(wpa_s->conf->device_type);
  729. pos = os_strchr(wpa_s->conf->device_type, '-');
  730. if (pos == NULL) {
  731. wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
  732. os_free(wps);
  733. return -1;
  734. }
  735. pos++;
  736. if (hexstr2bin(pos, oui, 4)) {
  737. wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
  738. os_free(wps);
  739. return -1;
  740. }
  741. wps->dev.oui = WPA_GET_BE32(oui);
  742. pos = os_strchr(pos, '-');
  743. if (pos == NULL) {
  744. wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
  745. os_free(wps);
  746. return -1;
  747. }
  748. pos++;
  749. wps->dev.sub_categ = atoi(pos);
  750. }
  751. wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
  752. wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
  753. os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
  754. if (is_nil_uuid(wpa_s->conf->uuid)) {
  755. uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
  756. wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
  757. wps->uuid, WPS_UUID_LEN);
  758. } else
  759. os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  760. wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
  761. wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
  762. os_memset(&rcfg, 0, sizeof(rcfg));
  763. rcfg.new_psk_cb = wpas_wps_new_psk_cb;
  764. rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
  765. rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
  766. rcfg.cb_ctx = wpa_s;
  767. wps->registrar = wps_registrar_init(wps, &rcfg);
  768. if (wps->registrar == NULL) {
  769. wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
  770. os_free(wps);
  771. return -1;
  772. }
  773. wpa_s->wps = wps;
  774. return 0;
  775. }
  776. void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
  777. {
  778. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  779. if (wpa_s->wps == NULL)
  780. return;
  781. wps_registrar_deinit(wpa_s->wps->registrar);
  782. wpabuf_free(wpa_s->wps->dh_pubkey);
  783. wpabuf_free(wpa_s->wps->dh_privkey);
  784. wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
  785. wpabuf_free(wpa_s->wps->oob_conf.dev_password);
  786. os_free(wpa_s->wps->network_key);
  787. os_free(wpa_s->wps);
  788. wpa_s->wps = NULL;
  789. #ifdef CONFIG_WPS_ER
  790. wps_er_deinit(wpa_s->wps_er);
  791. wpa_s->wps_er = NULL;
  792. #endif /* CONFIG_WPS_ER */
  793. }
  794. int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
  795. struct wpa_ssid *ssid, struct wpa_scan_res *bss)
  796. {
  797. struct wpabuf *wps_ie;
  798. if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
  799. return -1;
  800. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  801. if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
  802. if (!wps_ie) {
  803. wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
  804. return 0;
  805. }
  806. if (!wps_is_selected_pbc_registrar(wps_ie)) {
  807. wpa_printf(MSG_DEBUG, " skip - WPS AP "
  808. "without active PBC Registrar");
  809. wpabuf_free(wps_ie);
  810. return 0;
  811. }
  812. /* TODO: overlap detection */
  813. wpa_printf(MSG_DEBUG, " selected based on WPS IE "
  814. "(Active PBC)");
  815. wpabuf_free(wps_ie);
  816. return 1;
  817. }
  818. if (eap_is_wps_pin_enrollee(&ssid->eap)) {
  819. if (!wps_ie) {
  820. wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
  821. return 0;
  822. }
  823. /*
  824. * Start with WPS APs that advertise active PIN Registrar and
  825. * allow any WPS AP after third scan since some APs do not set
  826. * Selected Registrar attribute properly when using external
  827. * Registrar.
  828. */
  829. if (!wps_is_selected_pin_registrar(wps_ie)) {
  830. if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
  831. wpa_printf(MSG_DEBUG, " skip - WPS AP "
  832. "without active PIN Registrar");
  833. wpabuf_free(wps_ie);
  834. return 0;
  835. }
  836. wpa_printf(MSG_DEBUG, " selected based on WPS IE");
  837. } else {
  838. wpa_printf(MSG_DEBUG, " selected based on WPS IE "
  839. "(Active PIN)");
  840. }
  841. wpabuf_free(wps_ie);
  842. return 1;
  843. }
  844. if (wps_ie) {
  845. wpa_printf(MSG_DEBUG, " selected based on WPS IE");
  846. wpabuf_free(wps_ie);
  847. return 1;
  848. }
  849. return -1;
  850. }
  851. int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
  852. struct wpa_ssid *ssid,
  853. struct wpa_scan_res *bss)
  854. {
  855. struct wpabuf *wps_ie = NULL;
  856. int ret = 0;
  857. if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
  858. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  859. if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
  860. /* allow wildcard SSID for WPS PBC */
  861. ret = 1;
  862. }
  863. } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
  864. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  865. if (wps_ie &&
  866. (wps_is_selected_pin_registrar(wps_ie) ||
  867. wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
  868. /* allow wildcard SSID for WPS PIN */
  869. ret = 1;
  870. }
  871. }
  872. if (!ret && ssid->bssid_set &&
  873. os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
  874. /* allow wildcard SSID due to hardcoded BSSID match */
  875. ret = 1;
  876. }
  877. wpabuf_free(wps_ie);
  878. return ret;
  879. }
  880. int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
  881. struct wpa_scan_res *selected,
  882. struct wpa_ssid *ssid)
  883. {
  884. const u8 *sel_uuid, *uuid;
  885. size_t i;
  886. struct wpabuf *wps_ie;
  887. int ret = 0;
  888. if (!eap_is_wps_pbc_enrollee(&ssid->eap))
  889. return 0;
  890. /* Make sure that only one AP is in active PBC mode */
  891. wps_ie = wpa_scan_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
  892. if (wps_ie)
  893. sel_uuid = wps_get_uuid_e(wps_ie);
  894. else
  895. sel_uuid = NULL;
  896. for (i = 0; i < wpa_s->scan_res->num; i++) {
  897. struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
  898. struct wpabuf *ie;
  899. if (bss == selected)
  900. continue;
  901. ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  902. if (!ie)
  903. continue;
  904. if (!wps_is_selected_pbc_registrar(ie)) {
  905. wpabuf_free(ie);
  906. continue;
  907. }
  908. uuid = wps_get_uuid_e(ie);
  909. if (sel_uuid == NULL || uuid == NULL ||
  910. os_memcmp(sel_uuid, uuid, 16) != 0) {
  911. ret = 1; /* PBC overlap */
  912. wpabuf_free(ie);
  913. break;
  914. }
  915. /* TODO: verify that this is reasonable dual-band situation */
  916. wpabuf_free(ie);
  917. }
  918. wpabuf_free(wps_ie);
  919. return ret;
  920. }
  921. void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
  922. {
  923. size_t i;
  924. if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
  925. return;
  926. for (i = 0; i < wpa_s->scan_res->num; i++) {
  927. struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
  928. struct wpabuf *ie;
  929. ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  930. if (!ie)
  931. continue;
  932. if (wps_is_selected_pbc_registrar(ie))
  933. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
  934. else if (wps_is_selected_pin_registrar(ie))
  935. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
  936. else
  937. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
  938. wpabuf_free(ie);
  939. break;
  940. }
  941. }
  942. int wpas_wps_searching(struct wpa_supplicant *wpa_s)
  943. {
  944. struct wpa_ssid *ssid;
  945. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  946. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
  947. return 1;
  948. }
  949. return 0;
  950. }
  951. int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
  952. char *end)
  953. {
  954. struct wpabuf *wps_ie;
  955. int ret;
  956. wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
  957. if (wps_ie == NULL)
  958. return 0;
  959. ret = wps_attr_text(wps_ie, buf, end);
  960. wpabuf_free(wps_ie);
  961. return ret;
  962. }
  963. int wpas_wps_er_start(struct wpa_supplicant *wpa_s)
  964. {
  965. #ifdef CONFIG_WPS_ER
  966. if (wpa_s->wps_er) {
  967. /* TODO: re-send ctrl_iface events for current data? */
  968. return 0;
  969. }
  970. wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname);
  971. if (wpa_s->wps_er == NULL)
  972. return -1;
  973. return 0;
  974. #else /* CONFIG_WPS_ER */
  975. return 0;
  976. #endif /* CONFIG_WPS_ER */
  977. }
  978. int wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
  979. {
  980. #ifdef CONFIG_WPS_ER
  981. wps_er_deinit(wpa_s->wps_er);
  982. wpa_s->wps_er = NULL;
  983. #endif /* CONFIG_WPS_ER */
  984. return 0;
  985. }
  986. #ifdef CONFIG_WPS_ER
  987. int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const char *uuid,
  988. const char *pin)
  989. {
  990. u8 u[UUID_LEN];
  991. int any = 0;
  992. if (os_strcmp(uuid, "any") == 0)
  993. any = 1;
  994. else if (uuid_str2bin(uuid, u))
  995. return -1;
  996. return wps_registrar_add_pin(wpa_s->wps->registrar, any ? NULL : u,
  997. (const u8 *) pin, os_strlen(pin), 300);
  998. }
  999. #endif /* CONFIG_WPS_ER */