wps_supplicant.c 43 KB

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