wps_supplicant.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  1. /*
  2. * wpa_supplicant / WPS integration
  3. * Copyright (c) 2008-2010, 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 "eloop.h"
  17. #include "uuid.h"
  18. #include "crypto/dh_group5.h"
  19. #include "common/ieee802_11_defs.h"
  20. #include "common/ieee802_11_common.h"
  21. #include "common/wpa_common.h"
  22. #include "common/wpa_ctrl.h"
  23. #include "eap_common/eap_wsc_common.h"
  24. #include "eap_peer/eap.h"
  25. #include "rsn_supp/wpa.h"
  26. #include "config.h"
  27. #include "wpa_supplicant_i.h"
  28. #include "driver_i.h"
  29. #include "notify.h"
  30. #include "blacklist.h"
  31. #include "bss.h"
  32. #include "scan.h"
  33. #include "ap.h"
  34. #include "p2p/p2p.h"
  35. #include "p2p_supplicant.h"
  36. #include "wps_supplicant.h"
  37. #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
  38. #define WPS_PIN_SCAN_IGNORE_SEL_REG 3
  39. #endif /* WPS_PIN_SCAN_IGNORE_SEL_REG */
  40. static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
  41. static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
  42. int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
  43. {
  44. if (!wpa_s->wps_success &&
  45. wpa_s->current_ssid &&
  46. eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
  47. const u8 *bssid = wpa_s->bssid;
  48. if (is_zero_ether_addr(bssid))
  49. bssid = wpa_s->pending_bssid;
  50. wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
  51. " did not succeed - continue trying to find "
  52. "suitable AP", MAC2STR(bssid));
  53. wpa_blacklist_add(wpa_s, bssid);
  54. wpa_supplicant_deauthenticate(wpa_s,
  55. WLAN_REASON_DEAUTH_LEAVING);
  56. wpa_s->reassociate = 1;
  57. wpa_supplicant_req_scan(wpa_s,
  58. wpa_s->blacklist_cleared ? 5 : 0, 0);
  59. wpa_s->blacklist_cleared = 0;
  60. return 1;
  61. }
  62. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  63. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && !wpa_s->wps_success)
  64. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL);
  65. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
  66. !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  67. int disabled = wpa_s->current_ssid->disabled;
  68. wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
  69. "try to associate with the received credential");
  70. wpa_supplicant_deauthenticate(wpa_s,
  71. WLAN_REASON_DEAUTH_LEAVING);
  72. if (disabled) {
  73. wpa_printf(MSG_DEBUG, "WPS: Current network is "
  74. "disabled - wait for user to enable");
  75. return 1;
  76. }
  77. wpa_s->after_wps = 5;
  78. wpa_s->wps_freq = wpa_s->assoc_freq;
  79. wpa_s->reassociate = 1;
  80. wpa_supplicant_req_scan(wpa_s, 0, 0);
  81. return 1;
  82. }
  83. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
  84. wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
  85. "for external credential processing");
  86. wpas_clear_wps(wpa_s);
  87. wpa_supplicant_deauthenticate(wpa_s,
  88. WLAN_REASON_DEAUTH_LEAVING);
  89. return 1;
  90. }
  91. return 0;
  92. }
  93. static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
  94. struct wpa_ssid *ssid,
  95. const struct wps_credential *cred)
  96. {
  97. struct wpa_driver_capa capa;
  98. struct wpa_bss *bss;
  99. const u8 *ie;
  100. struct wpa_ie_data adv;
  101. int wpa2 = 0, ccmp = 0;
  102. /*
  103. * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
  104. * case they are configured for mixed mode operation (WPA+WPA2 and
  105. * TKIP+CCMP). Try to use scan results to figure out whether the AP
  106. * actually supports stronger security and select that if the client
  107. * has support for it, too.
  108. */
  109. if (wpa_drv_get_capa(wpa_s, &capa))
  110. return; /* Unknown what driver supports */
  111. bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len);
  112. if (bss == NULL) {
  113. wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS "
  114. "table - use credential as-is");
  115. return;
  116. }
  117. wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table");
  118. ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  119. if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
  120. wpa2 = 1;
  121. if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
  122. ccmp = 1;
  123. } else {
  124. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  125. if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
  126. adv.pairwise_cipher & WPA_CIPHER_CCMP)
  127. ccmp = 1;
  128. }
  129. if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
  130. (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
  131. /*
  132. * TODO: This could be the initial AP configuration and the
  133. * Beacon contents could change shortly. Should request a new
  134. * scan and delay addition of the network until the updated
  135. * scan results are available.
  136. */
  137. wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
  138. "support - use credential as-is");
  139. return;
  140. }
  141. if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
  142. (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
  143. (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  144. wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
  145. "based on scan results");
  146. if (wpa_s->conf->ap_scan == 1)
  147. ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
  148. else
  149. ssid->pairwise_cipher = WPA_CIPHER_CCMP;
  150. }
  151. if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
  152. (ssid->proto & WPA_PROTO_WPA) &&
  153. (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
  154. wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
  155. "based on scan results");
  156. if (wpa_s->conf->ap_scan == 1)
  157. ssid->proto |= WPA_PROTO_RSN;
  158. else
  159. ssid->proto = WPA_PROTO_RSN;
  160. }
  161. }
  162. static int wpa_supplicant_wps_cred(void *ctx,
  163. const struct wps_credential *cred)
  164. {
  165. struct wpa_supplicant *wpa_s = ctx;
  166. struct wpa_ssid *ssid = wpa_s->current_ssid;
  167. u8 key_idx = 0;
  168. u16 auth_type;
  169. int registrar = 0;
  170. if ((wpa_s->conf->wps_cred_processing == 1 ||
  171. wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
  172. size_t blen = cred->cred_attr_len * 2 + 1;
  173. char *buf = os_malloc(blen);
  174. if (buf) {
  175. wpa_snprintf_hex(buf, blen,
  176. cred->cred_attr, cred->cred_attr_len);
  177. wpa_msg(wpa_s, MSG_INFO, "%s%s",
  178. WPS_EVENT_CRED_RECEIVED, buf);
  179. os_free(buf);
  180. }
  181. wpas_notify_wps_credential(wpa_s, cred);
  182. } else
  183. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
  184. wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
  185. cred->cred_attr, cred->cred_attr_len);
  186. if (wpa_s->conf->wps_cred_processing == 1)
  187. return 0;
  188. wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
  189. wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
  190. cred->auth_type);
  191. wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
  192. wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
  193. wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
  194. cred->key, cred->key_len);
  195. wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
  196. MAC2STR(cred->mac_addr));
  197. auth_type = cred->auth_type;
  198. if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
  199. wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
  200. "auth_type into WPA2PSK");
  201. auth_type = WPS_AUTH_WPA2PSK;
  202. }
  203. if (auth_type != WPS_AUTH_OPEN &&
  204. auth_type != WPS_AUTH_SHARED &&
  205. auth_type != WPS_AUTH_WPAPSK &&
  206. auth_type != WPS_AUTH_WPA2PSK) {
  207. wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
  208. "unsupported authentication type 0x%x",
  209. auth_type);
  210. return 0;
  211. }
  212. if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  213. wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
  214. "on the received credential");
  215. if (ssid->eap.identity &&
  216. ssid->eap.identity_len == WSC_ID_REGISTRAR_LEN &&
  217. os_memcmp(ssid->eap.identity, WSC_ID_REGISTRAR,
  218. WSC_ID_REGISTRAR_LEN) == 0)
  219. registrar = 1;
  220. os_free(ssid->eap.identity);
  221. ssid->eap.identity = NULL;
  222. ssid->eap.identity_len = 0;
  223. os_free(ssid->eap.phase1);
  224. ssid->eap.phase1 = NULL;
  225. os_free(ssid->eap.eap_methods);
  226. ssid->eap.eap_methods = NULL;
  227. if (!ssid->p2p_group)
  228. ssid->temporary = 0;
  229. } else {
  230. wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
  231. "received credential");
  232. ssid = wpa_config_add_network(wpa_s->conf);
  233. if (ssid == NULL)
  234. return -1;
  235. wpas_notify_network_added(wpa_s, ssid);
  236. }
  237. wpa_config_set_network_defaults(ssid);
  238. os_free(ssid->ssid);
  239. ssid->ssid = os_malloc(cred->ssid_len);
  240. if (ssid->ssid) {
  241. os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
  242. ssid->ssid_len = cred->ssid_len;
  243. }
  244. switch (cred->encr_type) {
  245. case WPS_ENCR_NONE:
  246. break;
  247. case WPS_ENCR_WEP:
  248. if (cred->key_len <= 0)
  249. break;
  250. if (cred->key_len != 5 && cred->key_len != 13 &&
  251. cred->key_len != 10 && cred->key_len != 26) {
  252. wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length "
  253. "%lu", (unsigned long) cred->key_len);
  254. return -1;
  255. }
  256. if (cred->key_idx > NUM_WEP_KEYS) {
  257. wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d",
  258. cred->key_idx);
  259. return -1;
  260. }
  261. if (cred->key_idx)
  262. key_idx = cred->key_idx - 1;
  263. if (cred->key_len == 10 || cred->key_len == 26) {
  264. if (hexstr2bin((char *) cred->key,
  265. ssid->wep_key[key_idx],
  266. cred->key_len / 2) < 0) {
  267. wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key "
  268. "%d", key_idx);
  269. return -1;
  270. }
  271. ssid->wep_key_len[key_idx] = cred->key_len / 2;
  272. } else {
  273. os_memcpy(ssid->wep_key[key_idx], cred->key,
  274. cred->key_len);
  275. ssid->wep_key_len[key_idx] = cred->key_len;
  276. }
  277. ssid->wep_tx_keyidx = key_idx;
  278. break;
  279. case WPS_ENCR_TKIP:
  280. ssid->pairwise_cipher = WPA_CIPHER_TKIP;
  281. break;
  282. case WPS_ENCR_AES:
  283. ssid->pairwise_cipher = WPA_CIPHER_CCMP;
  284. break;
  285. }
  286. switch (auth_type) {
  287. case WPS_AUTH_OPEN:
  288. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  289. ssid->key_mgmt = WPA_KEY_MGMT_NONE;
  290. ssid->proto = 0;
  291. #ifdef CONFIG_WPS_REG_DISABLE_OPEN
  292. if (registrar) {
  293. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OPEN_NETWORK
  294. "id=%d - Credentials for an open "
  295. "network disabled by default - use "
  296. "'select_network %d' to enable",
  297. ssid->id, ssid->id);
  298. ssid->disabled = 1;
  299. }
  300. #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
  301. break;
  302. case WPS_AUTH_SHARED:
  303. ssid->auth_alg = WPA_AUTH_ALG_SHARED;
  304. ssid->key_mgmt = WPA_KEY_MGMT_NONE;
  305. ssid->proto = 0;
  306. break;
  307. case WPS_AUTH_WPAPSK:
  308. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  309. ssid->key_mgmt = WPA_KEY_MGMT_PSK;
  310. ssid->proto = WPA_PROTO_WPA;
  311. break;
  312. case WPS_AUTH_WPA:
  313. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  314. ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  315. ssid->proto = WPA_PROTO_WPA;
  316. break;
  317. case WPS_AUTH_WPA2:
  318. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  319. ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
  320. ssid->proto = WPA_PROTO_RSN;
  321. break;
  322. case WPS_AUTH_WPA2PSK:
  323. ssid->auth_alg = WPA_AUTH_ALG_OPEN;
  324. ssid->key_mgmt = WPA_KEY_MGMT_PSK;
  325. ssid->proto = WPA_PROTO_RSN;
  326. break;
  327. }
  328. if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
  329. if (cred->key_len == 2 * PMK_LEN) {
  330. if (hexstr2bin((const char *) cred->key, ssid->psk,
  331. PMK_LEN)) {
  332. wpa_printf(MSG_ERROR, "WPS: Invalid Network "
  333. "Key");
  334. return -1;
  335. }
  336. ssid->psk_set = 1;
  337. ssid->export_keys = 1;
  338. } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
  339. os_free(ssid->passphrase);
  340. ssid->passphrase = os_malloc(cred->key_len + 1);
  341. if (ssid->passphrase == NULL)
  342. return -1;
  343. os_memcpy(ssid->passphrase, cred->key, cred->key_len);
  344. ssid->passphrase[cred->key_len] = '\0';
  345. wpa_config_update_psk(ssid);
  346. ssid->export_keys = 1;
  347. } else {
  348. wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
  349. "length %lu",
  350. (unsigned long) cred->key_len);
  351. return -1;
  352. }
  353. }
  354. wpas_wps_security_workaround(wpa_s, ssid, cred);
  355. #ifndef CONFIG_NO_CONFIG_WRITE
  356. if (wpa_s->conf->update_config &&
  357. wpa_config_write(wpa_s->confname, wpa_s->conf)) {
  358. wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
  359. return -1;
  360. }
  361. #endif /* CONFIG_NO_CONFIG_WRITE */
  362. return 0;
  363. }
  364. static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
  365. struct wps_event_m2d *m2d)
  366. {
  367. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
  368. "dev_password_id=%d config_error=%d",
  369. m2d->dev_password_id, m2d->config_error);
  370. wpas_notify_wps_event_m2d(wpa_s, m2d);
  371. }
  372. static const char * wps_event_fail_reason[NUM_WPS_EI_VALUES] = {
  373. "No Error", /* WPS_EI_NO_ERROR */
  374. "TKIP Only Prohibited", /* WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED */
  375. "WEP Prohibited" /* WPS_EI_SECURITY_WEP_PROHIBITED */
  376. };
  377. static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
  378. struct wps_event_fail *fail)
  379. {
  380. if (fail->error_indication > 0 &&
  381. fail->error_indication < NUM_WPS_EI_VALUES) {
  382. wpa_msg(wpa_s, MSG_INFO,
  383. WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
  384. fail->msg, fail->config_error, fail->error_indication,
  385. wps_event_fail_reason[fail->error_indication]);
  386. if (wpa_s->parent && wpa_s->parent != wpa_s)
  387. wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
  388. "msg=%d config_error=%d reason=%d (%s)",
  389. fail->msg, fail->config_error,
  390. fail->error_indication,
  391. wps_event_fail_reason[fail->error_indication]);
  392. } else {
  393. wpa_msg(wpa_s, MSG_INFO,
  394. WPS_EVENT_FAIL "msg=%d config_error=%d",
  395. fail->msg, fail->config_error);
  396. if (wpa_s->parent && wpa_s->parent != wpa_s)
  397. wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
  398. "msg=%d config_error=%d",
  399. fail->msg, fail->config_error);
  400. }
  401. wpas_clear_wps(wpa_s);
  402. wpas_notify_wps_event_fail(wpa_s, fail);
  403. }
  404. static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
  405. {
  406. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
  407. wpa_s->wps_success = 1;
  408. wpas_notify_wps_event_success(wpa_s);
  409. #ifdef CONFIG_P2P
  410. wpas_p2p_wps_success(wpa_s, wpa_s->bssid, 0);
  411. #endif /* CONFIG_P2P */
  412. }
  413. static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
  414. struct wps_event_er_ap *ap)
  415. {
  416. char uuid_str[100];
  417. char dev_type[WPS_DEV_TYPE_BUFSIZE];
  418. uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
  419. if (ap->pri_dev_type)
  420. wps_dev_type_bin2str(ap->pri_dev_type, dev_type,
  421. sizeof(dev_type));
  422. else
  423. dev_type[0] = '\0';
  424. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR
  425. " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|",
  426. uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state,
  427. ap->friendly_name ? ap->friendly_name : "",
  428. ap->manufacturer ? ap->manufacturer : "",
  429. ap->model_description ? ap->model_description : "",
  430. ap->model_name ? ap->model_name : "",
  431. ap->manufacturer_url ? ap->manufacturer_url : "",
  432. ap->model_url ? ap->model_url : "");
  433. }
  434. static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
  435. struct wps_event_er_ap *ap)
  436. {
  437. char uuid_str[100];
  438. uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
  439. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
  440. }
  441. static void wpa_supplicant_wps_event_er_enrollee_add(
  442. struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
  443. {
  444. char uuid_str[100];
  445. char dev_type[WPS_DEV_TYPE_BUFSIZE];
  446. uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
  447. if (enrollee->pri_dev_type)
  448. wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type,
  449. sizeof(dev_type));
  450. else
  451. dev_type[0] = '\0';
  452. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
  453. " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
  454. "|%s|%s|%s|%s|%s|",
  455. uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
  456. enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
  457. enrollee->dev_name ? enrollee->dev_name : "",
  458. enrollee->manufacturer ? enrollee->manufacturer : "",
  459. enrollee->model_name ? enrollee->model_name : "",
  460. enrollee->model_number ? enrollee->model_number : "",
  461. enrollee->serial_number ? enrollee->serial_number : "");
  462. }
  463. static void wpa_supplicant_wps_event_er_enrollee_remove(
  464. struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
  465. {
  466. char uuid_str[100];
  467. uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
  468. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
  469. uuid_str, MAC2STR(enrollee->mac_addr));
  470. }
  471. static void wpa_supplicant_wps_event_er_ap_settings(
  472. struct wpa_supplicant *wpa_s,
  473. struct wps_event_er_ap_settings *ap_settings)
  474. {
  475. char uuid_str[100];
  476. char key_str[65];
  477. const struct wps_credential *cred = ap_settings->cred;
  478. key_str[0] = '\0';
  479. if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
  480. if (cred->key_len >= 8 && cred->key_len <= 64) {
  481. os_memcpy(key_str, cred->key, cred->key_len);
  482. key_str[cred->key_len] = '\0';
  483. }
  484. }
  485. uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str));
  486. /* Use wpa_msg_ctrl to avoid showing the key in debug log */
  487. wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS
  488. "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x "
  489. "key=%s",
  490. uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len),
  491. cred->auth_type, cred->encr_type, key_str);
  492. }
  493. static void wpa_supplicant_wps_event_er_set_sel_reg(
  494. struct wpa_supplicant *wpa_s,
  495. struct wps_event_er_set_selected_registrar *ev)
  496. {
  497. char uuid_str[100];
  498. uuid_bin2str(ev->uuid, uuid_str, sizeof(uuid_str));
  499. switch (ev->state) {
  500. case WPS_ER_SET_SEL_REG_START:
  501. wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
  502. "uuid=%s state=START sel_reg=%d dev_passwd_id=%u "
  503. "sel_reg_config_methods=0x%x",
  504. uuid_str, ev->sel_reg, ev->dev_passwd_id,
  505. ev->sel_reg_config_methods);
  506. break;
  507. case WPS_ER_SET_SEL_REG_DONE:
  508. wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
  509. "uuid=%s state=DONE", uuid_str);
  510. break;
  511. case WPS_ER_SET_SEL_REG_FAILED:
  512. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_SET_SEL_REG
  513. "uuid=%s state=FAILED", uuid_str);
  514. break;
  515. }
  516. }
  517. static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
  518. union wps_event_data *data)
  519. {
  520. struct wpa_supplicant *wpa_s = ctx;
  521. switch (event) {
  522. case WPS_EV_M2D:
  523. wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
  524. break;
  525. case WPS_EV_FAIL:
  526. wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
  527. break;
  528. case WPS_EV_SUCCESS:
  529. wpa_supplicant_wps_event_success(wpa_s);
  530. break;
  531. case WPS_EV_PWD_AUTH_FAIL:
  532. #ifdef CONFIG_AP
  533. if (wpa_s->ap_iface && data->pwd_auth_fail.enrollee)
  534. wpa_supplicant_ap_pwd_auth_fail(wpa_s);
  535. #endif /* CONFIG_AP */
  536. break;
  537. case WPS_EV_PBC_OVERLAP:
  538. break;
  539. case WPS_EV_PBC_TIMEOUT:
  540. break;
  541. case WPS_EV_ER_AP_ADD:
  542. wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
  543. break;
  544. case WPS_EV_ER_AP_REMOVE:
  545. wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
  546. break;
  547. case WPS_EV_ER_ENROLLEE_ADD:
  548. wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
  549. &data->enrollee);
  550. break;
  551. case WPS_EV_ER_ENROLLEE_REMOVE:
  552. wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
  553. &data->enrollee);
  554. break;
  555. case WPS_EV_ER_AP_SETTINGS:
  556. wpa_supplicant_wps_event_er_ap_settings(wpa_s,
  557. &data->ap_settings);
  558. break;
  559. case WPS_EV_ER_SET_SELECTED_REGISTRAR:
  560. wpa_supplicant_wps_event_er_set_sel_reg(wpa_s,
  561. &data->set_sel_reg);
  562. break;
  563. }
  564. }
  565. enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
  566. {
  567. if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
  568. eap_is_wps_pin_enrollee(&ssid->eap))
  569. return WPS_REQ_ENROLLEE;
  570. else
  571. return WPS_REQ_REGISTRAR;
  572. }
  573. static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
  574. {
  575. int id;
  576. struct wpa_ssid *ssid, *remove_ssid = NULL;
  577. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  578. /* Remove any existing WPS network from configuration */
  579. ssid = wpa_s->conf->ssid;
  580. while (ssid) {
  581. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  582. if (ssid == wpa_s->current_ssid) {
  583. wpa_s->current_ssid = NULL;
  584. if (ssid != NULL)
  585. wpas_notify_network_changed(wpa_s);
  586. }
  587. id = ssid->id;
  588. remove_ssid = ssid;
  589. } else
  590. id = -1;
  591. ssid = ssid->next;
  592. if (id >= 0) {
  593. wpas_notify_network_removed(wpa_s, remove_ssid);
  594. wpa_config_remove_network(wpa_s->conf, id);
  595. }
  596. }
  597. }
  598. static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
  599. {
  600. struct wpa_supplicant *wpa_s = eloop_ctx;
  601. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
  602. "out");
  603. wpas_clear_wps(wpa_s);
  604. }
  605. static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
  606. int registrar, const u8 *bssid)
  607. {
  608. struct wpa_ssid *ssid;
  609. ssid = wpa_config_add_network(wpa_s->conf);
  610. if (ssid == NULL)
  611. return NULL;
  612. wpas_notify_network_added(wpa_s, ssid);
  613. wpa_config_set_network_defaults(ssid);
  614. ssid->temporary = 1;
  615. if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
  616. wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
  617. wpa_config_set(ssid, "identity", registrar ?
  618. "\"" WSC_ID_REGISTRAR "\"" :
  619. "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
  620. wpas_notify_network_removed(wpa_s, ssid);
  621. wpa_config_remove_network(wpa_s->conf, ssid->id);
  622. return NULL;
  623. }
  624. if (bssid) {
  625. #ifndef CONFIG_P2P
  626. struct wpa_bss *bss;
  627. int count = 0;
  628. #endif /* CONFIG_P2P */
  629. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  630. ssid->bssid_set = 1;
  631. /*
  632. * Note: With P2P, the SSID may change at the time the WPS
  633. * provisioning is started, so better not filter the AP based
  634. * on the current SSID in the scan results.
  635. */
  636. #ifndef CONFIG_P2P
  637. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  638. if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0)
  639. continue;
  640. os_free(ssid->ssid);
  641. ssid->ssid = os_malloc(bss->ssid_len);
  642. if (ssid->ssid == NULL)
  643. break;
  644. os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len);
  645. ssid->ssid_len = bss->ssid_len;
  646. wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from "
  647. "scan results",
  648. ssid->ssid, ssid->ssid_len);
  649. count++;
  650. }
  651. if (count > 1) {
  652. wpa_printf(MSG_DEBUG, "WPS: More than one SSID found "
  653. "for the AP; use wildcard");
  654. os_free(ssid->ssid);
  655. ssid->ssid = NULL;
  656. ssid->ssid_len = 0;
  657. }
  658. #endif /* CONFIG_P2P */
  659. }
  660. return ssid;
  661. }
  662. static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
  663. struct wpa_ssid *selected)
  664. {
  665. struct wpa_ssid *ssid;
  666. /* Mark all other networks disabled and trigger reassociation */
  667. ssid = wpa_s->conf->ssid;
  668. while (ssid) {
  669. int was_disabled = ssid->disabled;
  670. ssid->disabled = ssid != selected;
  671. if (was_disabled != ssid->disabled)
  672. wpas_notify_network_enabled_changed(wpa_s, ssid);
  673. ssid = ssid->next;
  674. }
  675. wpa_s->disconnected = 0;
  676. wpa_s->reassociate = 1;
  677. wpa_s->scan_runs = 0;
  678. wpa_s->wps_success = 0;
  679. wpa_s->blacklist_cleared = 0;
  680. wpa_supplicant_req_scan(wpa_s, 0, 0);
  681. }
  682. int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
  683. int p2p_group)
  684. {
  685. struct wpa_ssid *ssid;
  686. wpas_clear_wps(wpa_s);
  687. ssid = wpas_wps_add_network(wpa_s, 0, bssid);
  688. if (ssid == NULL)
  689. return -1;
  690. ssid->temporary = 1;
  691. ssid->p2p_group = p2p_group;
  692. #ifdef CONFIG_P2P
  693. if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
  694. ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
  695. if (ssid->ssid) {
  696. ssid->ssid_len = wpa_s->go_params->ssid_len;
  697. os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
  698. ssid->ssid_len);
  699. wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
  700. "SSID", ssid->ssid, ssid->ssid_len);
  701. }
  702. }
  703. #endif /* CONFIG_P2P */
  704. wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
  705. if (wpa_s->wps_fragment_size)
  706. ssid->eap.fragment_size = wpa_s->wps_fragment_size;
  707. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  708. wpa_s, NULL);
  709. wpas_wps_reassoc(wpa_s, ssid);
  710. return 0;
  711. }
  712. int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
  713. const char *pin, int p2p_group, u16 dev_pw_id)
  714. {
  715. struct wpa_ssid *ssid;
  716. char val[128];
  717. unsigned int rpin = 0;
  718. wpas_clear_wps(wpa_s);
  719. ssid = wpas_wps_add_network(wpa_s, 0, bssid);
  720. if (ssid == NULL)
  721. return -1;
  722. ssid->temporary = 1;
  723. ssid->p2p_group = p2p_group;
  724. #ifdef CONFIG_P2P
  725. if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
  726. ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
  727. if (ssid->ssid) {
  728. ssid->ssid_len = wpa_s->go_params->ssid_len;
  729. os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
  730. ssid->ssid_len);
  731. wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
  732. "SSID", ssid->ssid, ssid->ssid_len);
  733. }
  734. }
  735. #endif /* CONFIG_P2P */
  736. if (pin)
  737. os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u\"",
  738. pin, dev_pw_id);
  739. else {
  740. rpin = wps_generate_pin();
  741. os_snprintf(val, sizeof(val), "\"pin=%08d dev_pw_id=%u\"",
  742. rpin, dev_pw_id);
  743. }
  744. wpa_config_set(ssid, "phase1", val, 0);
  745. if (wpa_s->wps_fragment_size)
  746. ssid->eap.fragment_size = wpa_s->wps_fragment_size;
  747. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  748. wpa_s, NULL);
  749. wpas_wps_reassoc(wpa_s, ssid);
  750. return rpin;
  751. }
  752. /* Cancel the wps pbc/pin requests */
  753. int wpas_wps_cancel(struct wpa_supplicant *wpa_s)
  754. {
  755. #ifdef CONFIG_AP
  756. if (wpa_s->ap_iface) {
  757. wpa_printf(MSG_DEBUG, "WPS: Cancelling in AP mode");
  758. return wpa_supplicant_ap_wps_cancel(wpa_s);
  759. }
  760. #endif /* CONFIG_AP */
  761. if (wpa_s->wpa_state == WPA_SCANNING) {
  762. wpa_printf(MSG_DEBUG, "WPS: Cancel operation - cancel scan");
  763. wpa_supplicant_cancel_scan(wpa_s);
  764. wpas_clear_wps(wpa_s);
  765. } else if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  766. wpa_printf(MSG_DEBUG, "WPS: Cancel operation - "
  767. "deauthenticate");
  768. wpa_supplicant_deauthenticate(wpa_s,
  769. WLAN_REASON_DEAUTH_LEAVING);
  770. wpas_clear_wps(wpa_s);
  771. }
  772. return 0;
  773. }
  774. #ifdef CONFIG_WPS_OOB
  775. int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
  776. char *path, char *method, char *name)
  777. {
  778. struct wps_context *wps = wpa_s->wps;
  779. struct oob_device_data *oob_dev;
  780. oob_dev = wps_get_oob_device(device_type);
  781. if (oob_dev == NULL)
  782. return -1;
  783. oob_dev->device_path = path;
  784. oob_dev->device_name = name;
  785. wps->oob_conf.oob_method = wps_get_oob_method(method);
  786. if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
  787. /*
  788. * Use pre-configured DH keys in order to be able to write the
  789. * key hash into the OOB file.
  790. */
  791. wpabuf_free(wps->dh_pubkey);
  792. wpabuf_free(wps->dh_privkey);
  793. wps->dh_privkey = NULL;
  794. wps->dh_pubkey = NULL;
  795. dh5_free(wps->dh_ctx);
  796. wps->dh_ctx = dh5_init(&wps->dh_privkey, &wps->dh_pubkey);
  797. wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
  798. if (wps->dh_ctx == NULL || wps->dh_pubkey == NULL) {
  799. wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
  800. "Diffie-Hellman handshake");
  801. return -1;
  802. }
  803. }
  804. if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
  805. wpas_clear_wps(wpa_s);
  806. if (wps_process_oob(wps, oob_dev, 0) < 0)
  807. return -1;
  808. if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
  809. wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
  810. wpas_wps_start_pin(wpa_s, NULL,
  811. wpabuf_head(wps->oob_conf.dev_password), 0,
  812. DEV_PW_DEFAULT) < 0)
  813. return -1;
  814. return 0;
  815. }
  816. #endif /* CONFIG_WPS_OOB */
  817. int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
  818. const char *pin, struct wps_new_ap_settings *settings)
  819. {
  820. struct wpa_ssid *ssid;
  821. char val[200];
  822. char *pos, *end;
  823. int res;
  824. if (!pin)
  825. return -1;
  826. wpas_clear_wps(wpa_s);
  827. ssid = wpas_wps_add_network(wpa_s, 1, bssid);
  828. if (ssid == NULL)
  829. return -1;
  830. ssid->temporary = 1;
  831. pos = val;
  832. end = pos + sizeof(val);
  833. res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
  834. if (res < 0 || res >= end - pos)
  835. return -1;
  836. pos += res;
  837. if (settings) {
  838. res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
  839. "new_encr=%s new_key=%s",
  840. settings->ssid_hex, settings->auth,
  841. settings->encr, settings->key_hex);
  842. if (res < 0 || res >= end - pos)
  843. return -1;
  844. pos += res;
  845. }
  846. res = os_snprintf(pos, end - pos, "\"");
  847. if (res < 0 || res >= end - pos)
  848. return -1;
  849. wpa_config_set(ssid, "phase1", val, 0);
  850. if (wpa_s->wps_fragment_size)
  851. ssid->eap.fragment_size = wpa_s->wps_fragment_size;
  852. eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
  853. wpa_s, NULL);
  854. wpas_wps_reassoc(wpa_s, ssid);
  855. return 0;
  856. }
  857. static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
  858. size_t psk_len)
  859. {
  860. wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for "
  861. "STA " MACSTR, MAC2STR(mac_addr));
  862. wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
  863. /* TODO */
  864. return 0;
  865. }
  866. static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
  867. const struct wps_device_data *dev)
  868. {
  869. char uuid[40], txt[400];
  870. int len;
  871. char devtype[WPS_DEV_TYPE_BUFSIZE];
  872. if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
  873. return;
  874. wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
  875. len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
  876. " [%s|%s|%s|%s|%s|%s]",
  877. uuid, MAC2STR(dev->mac_addr), dev->device_name,
  878. dev->manufacturer, dev->model_name,
  879. dev->model_number, dev->serial_number,
  880. wps_dev_type_bin2str(dev->pri_dev_type, devtype,
  881. sizeof(devtype)));
  882. if (len > 0 && len < (int) sizeof(txt))
  883. wpa_printf(MSG_INFO, "%s", txt);
  884. }
  885. static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
  886. u16 sel_reg_config_methods)
  887. {
  888. #ifdef CONFIG_WPS_ER
  889. struct wpa_supplicant *wpa_s = ctx;
  890. if (wpa_s->wps_er == NULL)
  891. return;
  892. wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d "
  893. "dev_password_id=%u sel_reg_config_methods=0x%x",
  894. sel_reg, dev_passwd_id, sel_reg_config_methods);
  895. wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
  896. sel_reg_config_methods);
  897. #endif /* CONFIG_WPS_ER */
  898. }
  899. static u16 wps_fix_config_methods(u16 config_methods)
  900. {
  901. #ifdef CONFIG_WPS2
  902. if ((config_methods &
  903. (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
  904. WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
  905. wpa_printf(MSG_INFO, "WPS: Converting display to "
  906. "virtual_display for WPS 2.0 compliance");
  907. config_methods |= WPS_CONFIG_VIRT_DISPLAY;
  908. }
  909. if ((config_methods &
  910. (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
  911. WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
  912. wpa_printf(MSG_INFO, "WPS: Converting push_button to "
  913. "virtual_push_button for WPS 2.0 compliance");
  914. config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
  915. }
  916. #endif /* CONFIG_WPS2 */
  917. return config_methods;
  918. }
  919. int wpas_wps_init(struct wpa_supplicant *wpa_s)
  920. {
  921. struct wps_context *wps;
  922. struct wps_registrar_config rcfg;
  923. wps = os_zalloc(sizeof(*wps));
  924. if (wps == NULL)
  925. return -1;
  926. wps->cred_cb = wpa_supplicant_wps_cred;
  927. wps->event_cb = wpa_supplicant_wps_event;
  928. wps->cb_ctx = wpa_s;
  929. wps->dev.device_name = wpa_s->conf->device_name;
  930. wps->dev.manufacturer = wpa_s->conf->manufacturer;
  931. wps->dev.model_name = wpa_s->conf->model_name;
  932. wps->dev.model_number = wpa_s->conf->model_number;
  933. wps->dev.serial_number = wpa_s->conf->serial_number;
  934. wps->config_methods =
  935. wps_config_methods_str2bin(wpa_s->conf->config_methods);
  936. if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
  937. (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
  938. wpa_printf(MSG_ERROR, "WPS: Both Label and Display config "
  939. "methods are not allowed at the same time");
  940. os_free(wps);
  941. return -1;
  942. }
  943. wps->config_methods = wps_fix_config_methods(wps->config_methods);
  944. if (wpa_s->conf->device_type &&
  945. wps_dev_type_str2bin(wpa_s->conf->device_type,
  946. wps->dev.pri_dev_type) < 0) {
  947. wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
  948. os_free(wps);
  949. return -1;
  950. }
  951. wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
  952. wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
  953. os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
  954. if (is_nil_uuid(wpa_s->conf->uuid)) {
  955. uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
  956. wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
  957. wps->uuid, WPS_UUID_LEN);
  958. } else
  959. os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  960. wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
  961. wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
  962. os_memset(&rcfg, 0, sizeof(rcfg));
  963. rcfg.new_psk_cb = wpas_wps_new_psk_cb;
  964. rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
  965. rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
  966. rcfg.cb_ctx = wpa_s;
  967. wps->registrar = wps_registrar_init(wps, &rcfg);
  968. if (wps->registrar == NULL) {
  969. wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
  970. os_free(wps);
  971. return -1;
  972. }
  973. wpa_s->wps = wps;
  974. return 0;
  975. }
  976. void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
  977. {
  978. eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
  979. if (wpa_s->wps == NULL)
  980. return;
  981. #ifdef CONFIG_WPS_ER
  982. wps_er_deinit(wpa_s->wps_er, NULL, NULL);
  983. wpa_s->wps_er = NULL;
  984. #endif /* CONFIG_WPS_ER */
  985. wps_registrar_deinit(wpa_s->wps->registrar);
  986. wpabuf_free(wpa_s->wps->dh_pubkey);
  987. wpabuf_free(wpa_s->wps->dh_privkey);
  988. wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
  989. wpabuf_free(wpa_s->wps->oob_conf.dev_password);
  990. os_free(wpa_s->wps->network_key);
  991. os_free(wpa_s->wps);
  992. wpa_s->wps = NULL;
  993. }
  994. int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
  995. struct wpa_ssid *ssid, struct wpa_scan_res *bss)
  996. {
  997. struct wpabuf *wps_ie;
  998. if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
  999. return -1;
  1000. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1001. if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
  1002. if (!wps_ie) {
  1003. wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
  1004. return 0;
  1005. }
  1006. if (!wps_is_selected_pbc_registrar(wps_ie)) {
  1007. wpa_printf(MSG_DEBUG, " skip - WPS AP "
  1008. "without active PBC Registrar");
  1009. wpabuf_free(wps_ie);
  1010. return 0;
  1011. }
  1012. /* TODO: overlap detection */
  1013. wpa_printf(MSG_DEBUG, " selected based on WPS IE "
  1014. "(Active PBC)");
  1015. wpabuf_free(wps_ie);
  1016. return 1;
  1017. }
  1018. if (eap_is_wps_pin_enrollee(&ssid->eap)) {
  1019. if (!wps_ie) {
  1020. wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
  1021. return 0;
  1022. }
  1023. /*
  1024. * Start with WPS APs that advertise our address as an
  1025. * authorized MAC (v2.0) or active PIN Registrar (v1.0) and
  1026. * allow any WPS AP after couple of scans since some APs do not
  1027. * set Selected Registrar attribute properly when using
  1028. * external Registrar.
  1029. */
  1030. if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) {
  1031. if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
  1032. wpa_printf(MSG_DEBUG, " skip - WPS AP "
  1033. "without active PIN Registrar");
  1034. wpabuf_free(wps_ie);
  1035. return 0;
  1036. }
  1037. wpa_printf(MSG_DEBUG, " selected based on WPS IE");
  1038. } else {
  1039. wpa_printf(MSG_DEBUG, " selected based on WPS IE "
  1040. "(Authorized MAC or Active PIN)");
  1041. }
  1042. wpabuf_free(wps_ie);
  1043. return 1;
  1044. }
  1045. if (wps_ie) {
  1046. wpa_printf(MSG_DEBUG, " selected based on WPS IE");
  1047. wpabuf_free(wps_ie);
  1048. return 1;
  1049. }
  1050. return -1;
  1051. }
  1052. int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
  1053. struct wpa_ssid *ssid,
  1054. struct wpa_scan_res *bss)
  1055. {
  1056. struct wpabuf *wps_ie = NULL;
  1057. int ret = 0;
  1058. if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
  1059. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1060. if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
  1061. /* allow wildcard SSID for WPS PBC */
  1062. ret = 1;
  1063. }
  1064. } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
  1065. wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1066. if (wps_ie &&
  1067. (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) ||
  1068. wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
  1069. /* allow wildcard SSID for WPS PIN */
  1070. ret = 1;
  1071. }
  1072. }
  1073. if (!ret && ssid->bssid_set &&
  1074. os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
  1075. /* allow wildcard SSID due to hardcoded BSSID match */
  1076. ret = 1;
  1077. }
  1078. #ifdef CONFIG_WPS_STRICT
  1079. if (wps_ie) {
  1080. if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len >
  1081. 0, bss->bssid) < 0)
  1082. ret = 0;
  1083. if (bss->beacon_ie_len) {
  1084. struct wpabuf *bcn_wps;
  1085. bcn_wps = wpa_scan_get_vendor_ie_multi_beacon(
  1086. bss, WPS_IE_VENDOR_TYPE);
  1087. if (bcn_wps == NULL) {
  1088. wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE "
  1089. "missing from AP Beacon");
  1090. ret = 0;
  1091. } else {
  1092. if (wps_validate_beacon(wps_ie) < 0)
  1093. ret = 0;
  1094. wpabuf_free(bcn_wps);
  1095. }
  1096. }
  1097. }
  1098. #endif /* CONFIG_WPS_STRICT */
  1099. wpabuf_free(wps_ie);
  1100. return ret;
  1101. }
  1102. int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
  1103. struct wpa_bss *selected, struct wpa_ssid *ssid)
  1104. {
  1105. const u8 *sel_uuid, *uuid;
  1106. struct wpabuf *wps_ie;
  1107. int ret = 0;
  1108. struct wpa_bss *bss;
  1109. if (!eap_is_wps_pbc_enrollee(&ssid->eap))
  1110. return 0;
  1111. wpa_printf(MSG_DEBUG, "WPS: Check whether PBC session overlap is "
  1112. "present in scan results; selected BSSID " MACSTR,
  1113. MAC2STR(selected->bssid));
  1114. /* Make sure that only one AP is in active PBC mode */
  1115. wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
  1116. if (wps_ie) {
  1117. sel_uuid = wps_get_uuid_e(wps_ie);
  1118. wpa_hexdump(MSG_DEBUG, "WPS: UUID of the selected BSS",
  1119. sel_uuid, UUID_LEN);
  1120. } else {
  1121. wpa_printf(MSG_DEBUG, "WPS: Selected BSS does not include "
  1122. "WPS IE?!");
  1123. sel_uuid = NULL;
  1124. }
  1125. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  1126. struct wpabuf *ie;
  1127. if (bss == selected)
  1128. continue;
  1129. ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1130. if (!ie)
  1131. continue;
  1132. if (!wps_is_selected_pbc_registrar(ie)) {
  1133. wpabuf_free(ie);
  1134. continue;
  1135. }
  1136. wpa_printf(MSG_DEBUG, "WPS: Another BSS in active PBC mode: "
  1137. MACSTR, MAC2STR(bss->bssid));
  1138. uuid = wps_get_uuid_e(ie);
  1139. wpa_hexdump(MSG_DEBUG, "WPS: UUID of the other BSS",
  1140. uuid, UUID_LEN);
  1141. if (sel_uuid == NULL || uuid == NULL ||
  1142. os_memcmp(sel_uuid, uuid, UUID_LEN) != 0) {
  1143. ret = 1; /* PBC overlap */
  1144. wpa_msg(wpa_s, MSG_INFO, "WPS: PBC overlap detected: "
  1145. MACSTR " and " MACSTR,
  1146. MAC2STR(selected->bssid),
  1147. MAC2STR(bss->bssid));
  1148. wpabuf_free(ie);
  1149. break;
  1150. }
  1151. /* TODO: verify that this is reasonable dual-band situation */
  1152. wpabuf_free(ie);
  1153. }
  1154. wpabuf_free(wps_ie);
  1155. return ret;
  1156. }
  1157. void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
  1158. {
  1159. struct wpa_bss *bss;
  1160. unsigned int pbc = 0, auth = 0, pin = 0, wps = 0;
  1161. if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
  1162. return;
  1163. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  1164. struct wpabuf *ie;
  1165. ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1166. if (!ie)
  1167. continue;
  1168. if (wps_is_selected_pbc_registrar(ie))
  1169. pbc++;
  1170. else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0))
  1171. auth++;
  1172. else if (wps_is_selected_pin_registrar(ie))
  1173. pin++;
  1174. else
  1175. wps++;
  1176. wpabuf_free(ie);
  1177. }
  1178. if (pbc)
  1179. wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
  1180. else if (auth)
  1181. wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_AUTH);
  1182. else if (pin)
  1183. wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
  1184. else if (wps)
  1185. wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
  1186. }
  1187. int wpas_wps_searching(struct wpa_supplicant *wpa_s)
  1188. {
  1189. struct wpa_ssid *ssid;
  1190. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1191. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
  1192. return 1;
  1193. }
  1194. return 0;
  1195. }
  1196. int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
  1197. char *end)
  1198. {
  1199. struct wpabuf *wps_ie;
  1200. int ret;
  1201. wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
  1202. if (wps_ie == NULL)
  1203. return 0;
  1204. ret = wps_attr_text(wps_ie, buf, end);
  1205. wpabuf_free(wps_ie);
  1206. return ret;
  1207. }
  1208. int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter)
  1209. {
  1210. #ifdef CONFIG_WPS_ER
  1211. if (wpa_s->wps_er) {
  1212. wps_er_refresh(wpa_s->wps_er);
  1213. return 0;
  1214. }
  1215. wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter);
  1216. if (wpa_s->wps_er == NULL)
  1217. return -1;
  1218. return 0;
  1219. #else /* CONFIG_WPS_ER */
  1220. return 0;
  1221. #endif /* CONFIG_WPS_ER */
  1222. }
  1223. int wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
  1224. {
  1225. #ifdef CONFIG_WPS_ER
  1226. wps_er_deinit(wpa_s->wps_er, NULL, NULL);
  1227. wpa_s->wps_er = NULL;
  1228. #endif /* CONFIG_WPS_ER */
  1229. return 0;
  1230. }
  1231. #ifdef CONFIG_WPS_ER
  1232. int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr,
  1233. const char *uuid, const char *pin)
  1234. {
  1235. u8 u[UUID_LEN];
  1236. int any = 0;
  1237. if (os_strcmp(uuid, "any") == 0)
  1238. any = 1;
  1239. else if (uuid_str2bin(uuid, u))
  1240. return -1;
  1241. return wps_registrar_add_pin(wpa_s->wps->registrar, addr,
  1242. any ? NULL : u,
  1243. (const u8 *) pin, os_strlen(pin), 300);
  1244. }
  1245. int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid)
  1246. {
  1247. u8 u[UUID_LEN];
  1248. if (uuid_str2bin(uuid, u))
  1249. return -1;
  1250. return wps_er_pbc(wpa_s->wps_er, u);
  1251. }
  1252. int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
  1253. const char *pin)
  1254. {
  1255. u8 u[UUID_LEN];
  1256. if (uuid_str2bin(uuid, u))
  1257. return -1;
  1258. return wps_er_learn(wpa_s->wps_er, u, (const u8 *) pin,
  1259. os_strlen(pin));
  1260. }
  1261. int wpas_wps_er_set_config(struct wpa_supplicant *wpa_s, const char *uuid,
  1262. int id)
  1263. {
  1264. u8 u[UUID_LEN];
  1265. struct wpa_ssid *ssid;
  1266. struct wps_credential cred;
  1267. if (uuid_str2bin(uuid, u))
  1268. return -1;
  1269. ssid = wpa_config_get_network(wpa_s->conf, id);
  1270. if (ssid == NULL || ssid->ssid == NULL)
  1271. return -1;
  1272. os_memset(&cred, 0, sizeof(cred));
  1273. if (ssid->ssid_len > 32)
  1274. return -1;
  1275. os_memcpy(cred.ssid, ssid->ssid, ssid->ssid_len);
  1276. cred.ssid_len = ssid->ssid_len;
  1277. if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
  1278. cred.auth_type = (ssid->proto & WPA_PROTO_RSN) ?
  1279. WPS_AUTH_WPA2PSK : WPS_AUTH_WPAPSK;
  1280. if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
  1281. cred.encr_type = WPS_ENCR_AES;
  1282. else
  1283. cred.encr_type = WPS_ENCR_TKIP;
  1284. if (ssid->passphrase) {
  1285. cred.key_len = os_strlen(ssid->passphrase);
  1286. if (cred.key_len >= 64)
  1287. return -1;
  1288. os_memcpy(cred.key, ssid->passphrase, cred.key_len);
  1289. } else if (ssid->psk_set) {
  1290. cred.key_len = 32;
  1291. os_memcpy(cred.key, ssid->psk, 32);
  1292. } else
  1293. return -1;
  1294. } else {
  1295. cred.auth_type = WPS_AUTH_OPEN;
  1296. cred.encr_type = WPS_ENCR_NONE;
  1297. }
  1298. return wps_er_set_config(wpa_s->wps_er, u, &cred);
  1299. }
  1300. int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid,
  1301. const char *pin, struct wps_new_ap_settings *settings)
  1302. {
  1303. u8 u[UUID_LEN];
  1304. struct wps_credential cred;
  1305. size_t len;
  1306. if (uuid_str2bin(uuid, u))
  1307. return -1;
  1308. if (settings->ssid_hex == NULL || settings->auth == NULL ||
  1309. settings->encr == NULL || settings->key_hex == NULL)
  1310. return -1;
  1311. os_memset(&cred, 0, sizeof(cred));
  1312. len = os_strlen(settings->ssid_hex);
  1313. if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
  1314. hexstr2bin(settings->ssid_hex, cred.ssid, len / 2))
  1315. return -1;
  1316. cred.ssid_len = len / 2;
  1317. len = os_strlen(settings->key_hex);
  1318. if ((len & 1) || len > 2 * sizeof(cred.key) ||
  1319. hexstr2bin(settings->key_hex, cred.key, len / 2))
  1320. return -1;
  1321. cred.key_len = len / 2;
  1322. if (os_strcmp(settings->auth, "OPEN") == 0)
  1323. cred.auth_type = WPS_AUTH_OPEN;
  1324. else if (os_strcmp(settings->auth, "WPAPSK") == 0)
  1325. cred.auth_type = WPS_AUTH_WPAPSK;
  1326. else if (os_strcmp(settings->auth, "WPA2PSK") == 0)
  1327. cred.auth_type = WPS_AUTH_WPA2PSK;
  1328. else
  1329. return -1;
  1330. if (os_strcmp(settings->encr, "NONE") == 0)
  1331. cred.encr_type = WPS_ENCR_NONE;
  1332. else if (os_strcmp(settings->encr, "WEP") == 0)
  1333. cred.encr_type = WPS_ENCR_WEP;
  1334. else if (os_strcmp(settings->encr, "TKIP") == 0)
  1335. cred.encr_type = WPS_ENCR_TKIP;
  1336. else if (os_strcmp(settings->encr, "CCMP") == 0)
  1337. cred.encr_type = WPS_ENCR_AES;
  1338. else
  1339. return -1;
  1340. return wps_er_config(wpa_s->wps_er, u, (const u8 *) pin,
  1341. os_strlen(pin), &cred);
  1342. }
  1343. static void wpas_wps_terminate_cb(void *ctx)
  1344. {
  1345. wpa_printf(MSG_DEBUG, "WPS ER: Terminated");
  1346. eloop_terminate();
  1347. }
  1348. #endif /* CONFIG_WPS_ER */
  1349. int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s)
  1350. {
  1351. #ifdef CONFIG_WPS_ER
  1352. if (wpa_s->wps_er) {
  1353. wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s);
  1354. wpa_s->wps_er = NULL;
  1355. return 1;
  1356. }
  1357. #endif /* CONFIG_WPS_ER */
  1358. return 0;
  1359. }
  1360. int wpas_wps_in_progress(struct wpa_supplicant *wpa_s)
  1361. {
  1362. struct wpa_ssid *ssid;
  1363. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  1364. if (!ssid->disabled && ssid->key_mgmt == WPA_KEY_MGMT_WPS)
  1365. return 1;
  1366. }
  1367. return 0;
  1368. }
  1369. void wpas_wps_update_config(struct wpa_supplicant *wpa_s)
  1370. {
  1371. struct wps_context *wps = wpa_s->wps;
  1372. if (wps == NULL)
  1373. return;
  1374. if (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS) {
  1375. wps->config_methods = wps_config_methods_str2bin(
  1376. wpa_s->conf->config_methods);
  1377. if ((wps->config_methods &
  1378. (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
  1379. (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
  1380. wpa_printf(MSG_ERROR, "WPS: Both Label and Display "
  1381. "config methods are not allowed at the "
  1382. "same time");
  1383. wps->config_methods &= ~WPS_CONFIG_LABEL;
  1384. }
  1385. }
  1386. wps->config_methods = wps_fix_config_methods(wps->config_methods);
  1387. if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) {
  1388. if (wpa_s->conf->device_type &&
  1389. wps_dev_type_str2bin(wpa_s->conf->device_type,
  1390. wps->dev.pri_dev_type) < 0)
  1391. wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
  1392. }
  1393. if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION)
  1394. wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
  1395. if (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID) {
  1396. if (is_nil_uuid(wpa_s->conf->uuid)) {
  1397. uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
  1398. wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC "
  1399. "address", wps->uuid, WPS_UUID_LEN);
  1400. } else
  1401. os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
  1402. }
  1403. if (wpa_s->conf->changed_parameters &
  1404. (CFG_CHANGED_DEVICE_NAME | CFG_CHANGED_WPS_STRING)) {
  1405. /* Update pointers to make sure they refer current values */
  1406. wps->dev.device_name = wpa_s->conf->device_name;
  1407. wps->dev.manufacturer = wpa_s->conf->manufacturer;
  1408. wps->dev.model_name = wpa_s->conf->model_name;
  1409. wps->dev.model_number = wpa_s->conf->model_number;
  1410. wps->dev.serial_number = wpa_s->conf->serial_number;
  1411. }
  1412. }