events.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2011, 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 "eapol_supp/eapol_supp_sm.h"
  17. #include "rsn_supp/wpa.h"
  18. #include "eloop.h"
  19. #include "config.h"
  20. #include "l2_packet/l2_packet.h"
  21. #include "wpa_supplicant_i.h"
  22. #include "driver_i.h"
  23. #include "pcsc_funcs.h"
  24. #include "rsn_supp/preauth.h"
  25. #include "rsn_supp/pmksa_cache.h"
  26. #include "common/wpa_ctrl.h"
  27. #include "eap_peer/eap.h"
  28. #include "ap/hostapd.h"
  29. #include "p2p/p2p.h"
  30. #include "notify.h"
  31. #include "common/ieee802_11_defs.h"
  32. #include "common/ieee802_11_common.h"
  33. #include "crypto/random.h"
  34. #include "blacklist.h"
  35. #include "wpas_glue.h"
  36. #include "wps_supplicant.h"
  37. #include "ibss_rsn.h"
  38. #include "sme.h"
  39. #include "p2p_supplicant.h"
  40. #include "bgscan.h"
  41. #include "ap.h"
  42. #include "bss.h"
  43. #include "mlme.h"
  44. #include "scan.h"
  45. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  46. {
  47. struct wpa_ssid *ssid, *old_ssid;
  48. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  49. return 0;
  50. wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
  51. "information");
  52. ssid = wpa_supplicant_get_ssid(wpa_s);
  53. if (ssid == NULL) {
  54. wpa_msg(wpa_s, MSG_INFO,
  55. "No network configuration found for the current AP");
  56. return -1;
  57. }
  58. if (ssid->disabled) {
  59. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
  60. return -1;
  61. }
  62. wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
  63. "current AP");
  64. if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  65. WPA_KEY_MGMT_WPA_NONE |
  66. WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
  67. WPA_KEY_MGMT_PSK_SHA256 |
  68. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  69. u8 wpa_ie[80];
  70. size_t wpa_ie_len = sizeof(wpa_ie);
  71. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  72. wpa_ie, &wpa_ie_len);
  73. } else {
  74. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  75. }
  76. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  77. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  78. old_ssid = wpa_s->current_ssid;
  79. wpa_s->current_ssid = ssid;
  80. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  81. wpa_supplicant_initiate_eapol(wpa_s);
  82. if (old_ssid != wpa_s->current_ssid)
  83. wpas_notify_network_changed(wpa_s);
  84. return 0;
  85. }
  86. static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
  87. void *sock_ctx)
  88. {
  89. struct wpa_supplicant *wpa_s = eloop_ctx;
  90. if (wpa_s->countermeasures) {
  91. wpa_s->countermeasures = 0;
  92. wpa_drv_set_countermeasures(wpa_s, 0);
  93. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  94. wpa_supplicant_req_scan(wpa_s, 0, 0);
  95. }
  96. }
  97. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  98. {
  99. int bssid_changed;
  100. #ifdef CONFIG_IBSS_RSN
  101. ibss_rsn_deinit(wpa_s->ibss_rsn);
  102. wpa_s->ibss_rsn = NULL;
  103. #endif /* CONFIG_IBSS_RSN */
  104. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  105. return;
  106. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  107. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  108. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  109. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  110. wpa_s->current_bss = NULL;
  111. wpa_s->assoc_freq = 0;
  112. if (bssid_changed)
  113. wpas_notify_bssid_changed(wpa_s);
  114. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  115. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  116. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  117. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  118. wpa_s->ap_ies_from_associnfo = 0;
  119. }
  120. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  121. {
  122. struct wpa_ie_data ie;
  123. int pmksa_set = -1;
  124. size_t i;
  125. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  126. ie.pmkid == NULL)
  127. return;
  128. for (i = 0; i < ie.num_pmkid; i++) {
  129. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  130. ie.pmkid + i * PMKID_LEN,
  131. NULL, NULL, 0);
  132. if (pmksa_set == 0) {
  133. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  134. break;
  135. }
  136. }
  137. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
  138. "PMKSA cache", pmksa_set == 0 ? "" : "not ");
  139. }
  140. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  141. union wpa_event_data *data)
  142. {
  143. if (data == NULL) {
  144. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
  145. "event");
  146. return;
  147. }
  148. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  149. " index=%d preauth=%d",
  150. MAC2STR(data->pmkid_candidate.bssid),
  151. data->pmkid_candidate.index,
  152. data->pmkid_candidate.preauth);
  153. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  154. data->pmkid_candidate.index,
  155. data->pmkid_candidate.preauth);
  156. }
  157. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  158. {
  159. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  160. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  161. return 0;
  162. #ifdef IEEE8021X_EAPOL
  163. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  164. wpa_s->current_ssid &&
  165. !(wpa_s->current_ssid->eapol_flags &
  166. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  167. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  168. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  169. * plaintext or static WEP keys). */
  170. return 0;
  171. }
  172. #endif /* IEEE8021X_EAPOL */
  173. return 1;
  174. }
  175. /**
  176. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  177. * @wpa_s: pointer to wpa_supplicant data
  178. * @ssid: Configuration data for the network
  179. * Returns: 0 on success, -1 on failure
  180. *
  181. * This function is called when starting authentication with a network that is
  182. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  183. */
  184. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  185. struct wpa_ssid *ssid)
  186. {
  187. #ifdef IEEE8021X_EAPOL
  188. int aka = 0, sim = 0, type;
  189. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  190. return 0;
  191. if (ssid->eap.eap_methods == NULL) {
  192. sim = 1;
  193. aka = 1;
  194. } else {
  195. struct eap_method_type *eap = ssid->eap.eap_methods;
  196. while (eap->vendor != EAP_VENDOR_IETF ||
  197. eap->method != EAP_TYPE_NONE) {
  198. if (eap->vendor == EAP_VENDOR_IETF) {
  199. if (eap->method == EAP_TYPE_SIM)
  200. sim = 1;
  201. else if (eap->method == EAP_TYPE_AKA)
  202. aka = 1;
  203. }
  204. eap++;
  205. }
  206. }
  207. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  208. sim = 0;
  209. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  210. aka = 0;
  211. if (!sim && !aka) {
  212. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
  213. "use SIM, but neither EAP-SIM nor EAP-AKA are "
  214. "enabled");
  215. return 0;
  216. }
  217. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
  218. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  219. if (sim && aka)
  220. type = SCARD_TRY_BOTH;
  221. else if (aka)
  222. type = SCARD_USIM_ONLY;
  223. else
  224. type = SCARD_GSM_SIM_ONLY;
  225. wpa_s->scard = scard_init(type);
  226. if (wpa_s->scard == NULL) {
  227. wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
  228. "(pcsc-lite)");
  229. return -1;
  230. }
  231. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  232. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  233. #endif /* IEEE8021X_EAPOL */
  234. return 0;
  235. }
  236. #ifndef CONFIG_NO_SCAN_PROCESSING
  237. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  238. struct wpa_ssid *ssid)
  239. {
  240. int i, privacy = 0;
  241. if (ssid->mixed_cell)
  242. return 1;
  243. #ifdef CONFIG_WPS
  244. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  245. return 1;
  246. #endif /* CONFIG_WPS */
  247. for (i = 0; i < NUM_WEP_KEYS; i++) {
  248. if (ssid->wep_key_len[i]) {
  249. privacy = 1;
  250. break;
  251. }
  252. }
  253. #ifdef IEEE8021X_EAPOL
  254. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  255. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  256. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  257. privacy = 1;
  258. #endif /* IEEE8021X_EAPOL */
  259. if (bss->caps & IEEE80211_CAP_PRIVACY)
  260. return privacy;
  261. return !privacy;
  262. }
  263. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  264. struct wpa_ssid *ssid,
  265. struct wpa_scan_res *bss)
  266. {
  267. struct wpa_ie_data ie;
  268. int proto_match = 0;
  269. const u8 *rsn_ie, *wpa_ie;
  270. int ret;
  271. int wep_ok;
  272. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  273. if (ret >= 0)
  274. return ret;
  275. /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
  276. wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
  277. (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  278. ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
  279. (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
  280. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  281. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  282. proto_match++;
  283. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  284. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
  285. "failed");
  286. break;
  287. }
  288. if (wep_ok &&
  289. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  290. {
  291. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  292. "in RSN IE");
  293. return 1;
  294. }
  295. if (!(ie.proto & ssid->proto)) {
  296. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
  297. "mismatch");
  298. break;
  299. }
  300. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  301. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
  302. "cipher mismatch");
  303. break;
  304. }
  305. if (!(ie.group_cipher & ssid->group_cipher)) {
  306. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
  307. "cipher mismatch");
  308. break;
  309. }
  310. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  311. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
  312. "mismatch");
  313. break;
  314. }
  315. #ifdef CONFIG_IEEE80211W
  316. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  317. ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
  318. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
  319. "frame protection");
  320. break;
  321. }
  322. #endif /* CONFIG_IEEE80211W */
  323. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
  324. return 1;
  325. }
  326. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  327. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  328. proto_match++;
  329. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  330. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
  331. "failed");
  332. break;
  333. }
  334. if (wep_ok &&
  335. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  336. {
  337. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  338. "in WPA IE");
  339. return 1;
  340. }
  341. if (!(ie.proto & ssid->proto)) {
  342. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
  343. "mismatch");
  344. break;
  345. }
  346. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  347. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
  348. "cipher mismatch");
  349. break;
  350. }
  351. if (!(ie.group_cipher & ssid->group_cipher)) {
  352. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
  353. "cipher mismatch");
  354. break;
  355. }
  356. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  357. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
  358. "mismatch");
  359. break;
  360. }
  361. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
  362. return 1;
  363. }
  364. if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
  365. wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
  366. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
  367. return 0;
  368. }
  369. if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
  370. wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
  371. return 1;
  372. }
  373. wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
  374. "WPA/WPA2");
  375. return 0;
  376. }
  377. static int freq_allowed(int *freqs, int freq)
  378. {
  379. int i;
  380. if (freqs == NULL)
  381. return 1;
  382. for (i = 0; freqs[i]; i++)
  383. if (freqs[i] == freq)
  384. return 1;
  385. return 0;
  386. }
  387. static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
  388. int i, struct wpa_scan_res *bss,
  389. struct wpa_ssid *group)
  390. {
  391. const u8 *ssid_;
  392. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  393. int wpa;
  394. struct wpa_blacklist *e;
  395. const u8 *ie;
  396. struct wpa_ssid *ssid;
  397. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  398. ssid_ = ie ? ie + 2 : (u8 *) "";
  399. ssid_len = ie ? ie[1] : 0;
  400. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  401. wpa_ie_len = ie ? ie[1] : 0;
  402. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  403. rsn_ie_len = ie ? ie[1] : 0;
  404. wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  405. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
  406. i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
  407. wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
  408. wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
  409. e = wpa_blacklist_get(wpa_s, bss->bssid);
  410. if (e) {
  411. int limit = 1;
  412. if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
  413. /*
  414. * When only a single network is enabled, we can
  415. * trigger blacklisting on the first failure. This
  416. * should not be done with multiple enabled networks to
  417. * avoid getting forced to move into a worse ESS on
  418. * single error if there are no other BSSes of the
  419. * current ESS.
  420. */
  421. limit = 0;
  422. }
  423. if (e->count > limit) {
  424. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  425. "(count=%d limit=%d)", e->count, limit);
  426. return NULL;
  427. }
  428. }
  429. if (ssid_len == 0) {
  430. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
  431. return NULL;
  432. }
  433. wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
  434. for (ssid = group; ssid; ssid = ssid->pnext) {
  435. int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
  436. if (ssid->disabled) {
  437. wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
  438. continue;
  439. }
  440. #ifdef CONFIG_WPS
  441. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
  442. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  443. "(WPS)");
  444. continue;
  445. }
  446. if (wpa && ssid->ssid_len == 0 &&
  447. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  448. check_ssid = 0;
  449. if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  450. /* Only allow wildcard SSID match if an AP
  451. * advertises active WPS operation that matches
  452. * with our mode. */
  453. check_ssid = 1;
  454. if (ssid->ssid_len == 0 &&
  455. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  456. check_ssid = 0;
  457. }
  458. #endif /* CONFIG_WPS */
  459. if (check_ssid &&
  460. (ssid_len != ssid->ssid_len ||
  461. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  462. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
  463. continue;
  464. }
  465. if (ssid->bssid_set &&
  466. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
  467. wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
  468. continue;
  469. }
  470. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  471. continue;
  472. if (!wpa &&
  473. !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  474. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  475. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
  476. wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
  477. "not allowed");
  478. continue;
  479. }
  480. if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) {
  481. wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
  482. "mismatch");
  483. continue;
  484. }
  485. if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) {
  486. wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
  487. "network");
  488. continue;
  489. }
  490. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  491. wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
  492. "allowed");
  493. continue;
  494. }
  495. #ifdef CONFIG_P2P
  496. /*
  497. * TODO: skip the AP if its P2P IE has Group Formation
  498. * bit set in the P2P Group Capability Bitmap and we
  499. * are not in Group Formation with that device.
  500. */
  501. #endif /* CONFIG_P2P */
  502. /* Matching configuration found */
  503. return ssid;
  504. }
  505. /* No matching configuration found */
  506. return NULL;
  507. }
  508. static struct wpa_bss *
  509. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  510. struct wpa_scan_results *scan_res,
  511. struct wpa_ssid *group,
  512. struct wpa_ssid **selected_ssid)
  513. {
  514. size_t i;
  515. wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
  516. group->priority);
  517. for (i = 0; i < scan_res->num; i++) {
  518. struct wpa_scan_res *bss = scan_res->res[i];
  519. const u8 *ie, *ssid;
  520. u8 ssid_len;
  521. *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
  522. if (!*selected_ssid)
  523. continue;
  524. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  525. ssid = ie ? ie + 2 : (u8 *) "";
  526. ssid_len = ie ? ie[1] : 0;
  527. wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
  528. " ssid='%s'",
  529. MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
  530. return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
  531. }
  532. return NULL;
  533. }
  534. static struct wpa_bss *
  535. wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  536. struct wpa_scan_results *scan_res,
  537. struct wpa_ssid **selected_ssid)
  538. {
  539. struct wpa_bss *selected = NULL;
  540. int prio;
  541. while (selected == NULL) {
  542. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  543. selected = wpa_supplicant_select_bss(
  544. wpa_s, scan_res, wpa_s->conf->pssid[prio],
  545. selected_ssid);
  546. if (selected)
  547. break;
  548. }
  549. if (selected == NULL && wpa_s->blacklist) {
  550. wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
  551. "blacklist and try again");
  552. wpa_blacklist_clear(wpa_s);
  553. wpa_s->blacklist_cleared++;
  554. } else if (selected == NULL)
  555. break;
  556. }
  557. return selected;
  558. }
  559. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  560. int timeout_sec, int timeout_usec)
  561. {
  562. if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
  563. /*
  564. * No networks are enabled; short-circuit request so
  565. * we don't wait timeout seconds before transitioning
  566. * to INACTIVE state.
  567. */
  568. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  569. return;
  570. }
  571. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  572. }
  573. void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  574. struct wpa_bss *selected,
  575. struct wpa_ssid *ssid)
  576. {
  577. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  578. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  579. "PBC session overlap");
  580. #ifdef CONFIG_P2P
  581. if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
  582. return;
  583. #endif /* CONFIG_P2P */
  584. #ifdef CONFIG_WPS
  585. wpas_wps_cancel(wpa_s);
  586. #endif /* CONFIG_WPS */
  587. return;
  588. }
  589. /*
  590. * Do not trigger new association unless the BSSID has changed or if
  591. * reassociation is requested. If we are in process of associating with
  592. * the selected BSSID, do not trigger new attempt.
  593. */
  594. if (wpa_s->reassociate ||
  595. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  596. ((wpa_s->wpa_state != WPA_ASSOCIATING &&
  597. wpa_s->wpa_state != WPA_AUTHENTICATING) ||
  598. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  599. 0))) {
  600. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  601. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  602. return;
  603. }
  604. wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
  605. "reassociate: %d selected: "MACSTR " bssid: " MACSTR
  606. " pending: " MACSTR " wpa_state: %s",
  607. wpa_s->reassociate, MAC2STR(selected->bssid),
  608. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  609. wpa_supplicant_state_txt(wpa_s->wpa_state));
  610. wpa_supplicant_associate(wpa_s, selected, ssid);
  611. } else {
  612. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
  613. "selected AP");
  614. }
  615. }
  616. static struct wpa_ssid *
  617. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  618. {
  619. int prio;
  620. struct wpa_ssid *ssid;
  621. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  622. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  623. {
  624. if (ssid->disabled)
  625. continue;
  626. if (ssid->mode == IEEE80211_MODE_IBSS ||
  627. ssid->mode == IEEE80211_MODE_AP)
  628. return ssid;
  629. }
  630. }
  631. return NULL;
  632. }
  633. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  634. * on BSS added and BSS changed events */
  635. static void wpa_supplicant_rsn_preauth_scan_results(
  636. struct wpa_supplicant *wpa_s)
  637. {
  638. struct wpa_bss *bss;
  639. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  640. return;
  641. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  642. const u8 *ssid, *rsn;
  643. ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  644. if (ssid == NULL)
  645. continue;
  646. rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  647. if (rsn == NULL)
  648. continue;
  649. rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
  650. }
  651. }
  652. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  653. struct wpa_bss *selected,
  654. struct wpa_ssid *ssid,
  655. struct wpa_scan_results *scan_res)
  656. {
  657. size_t i;
  658. struct wpa_scan_res *current_bss = NULL;
  659. int min_diff;
  660. if (wpa_s->reassociate)
  661. return 1; /* explicit request to reassociate */
  662. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  663. return 1; /* we are not associated; continue */
  664. if (wpa_s->current_ssid == NULL)
  665. return 1; /* unknown current SSID */
  666. if (wpa_s->current_ssid != ssid)
  667. return 1; /* different network block */
  668. for (i = 0; i < scan_res->num; i++) {
  669. struct wpa_scan_res *res = scan_res->res[i];
  670. const u8 *ie;
  671. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  672. continue;
  673. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  674. if (ie == NULL)
  675. continue;
  676. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  677. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  678. continue;
  679. current_bss = res;
  680. break;
  681. }
  682. if (!current_bss)
  683. return 1; /* current BSS not seen in scan results */
  684. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  685. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  686. MAC2STR(current_bss->bssid), current_bss->level);
  687. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  688. MAC2STR(selected->bssid), selected->level);
  689. if (wpa_s->current_ssid->bssid_set &&
  690. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  691. 0) {
  692. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  693. "has preferred BSSID");
  694. return 1;
  695. }
  696. min_diff = 2;
  697. if (current_bss->level < 0) {
  698. if (current_bss->level < -85)
  699. min_diff = 1;
  700. else if (current_bss->level < -80)
  701. min_diff = 2;
  702. else if (current_bss->level < -75)
  703. min_diff = 3;
  704. else if (current_bss->level < -70)
  705. min_diff = 4;
  706. else
  707. min_diff = 5;
  708. }
  709. if (abs(current_bss->level - selected->level) < min_diff) {
  710. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  711. "in signal level");
  712. return 0;
  713. }
  714. return 1;
  715. }
  716. /* Return < 0 if no scan results could be fetched. */
  717. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  718. union wpa_event_data *data)
  719. {
  720. struct wpa_bss *selected;
  721. struct wpa_ssid *ssid = NULL;
  722. struct wpa_scan_results *scan_res;
  723. int ap = 0;
  724. #ifdef CONFIG_AP
  725. if (wpa_s->ap_iface)
  726. ap = 1;
  727. #endif /* CONFIG_AP */
  728. wpa_supplicant_notify_scanning(wpa_s, 0);
  729. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  730. data ? &data->scan_info :
  731. NULL, 1);
  732. if (scan_res == NULL) {
  733. if (wpa_s->conf->ap_scan == 2 || ap)
  734. return -1;
  735. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  736. "scanning again");
  737. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  738. return -1;
  739. }
  740. #ifndef CONFIG_NO_RANDOM_POOL
  741. size_t i, num;
  742. num = scan_res->num;
  743. if (num > 10)
  744. num = 10;
  745. for (i = 0; i < num; i++) {
  746. u8 buf[5];
  747. struct wpa_scan_res *res = scan_res->res[i];
  748. buf[0] = res->bssid[5];
  749. buf[1] = res->qual & 0xff;
  750. buf[2] = res->noise & 0xff;
  751. buf[3] = res->level & 0xff;
  752. buf[4] = res->tsf & 0xff;
  753. random_add_randomness(buf, sizeof(buf));
  754. }
  755. #endif /* CONFIG_NO_RANDOM_POOL */
  756. if (wpa_s->scan_res_handler) {
  757. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  758. struct wpa_scan_results *scan_res);
  759. scan_res_handler = wpa_s->scan_res_handler;
  760. wpa_s->scan_res_handler = NULL;
  761. scan_res_handler(wpa_s, scan_res);
  762. wpa_scan_results_free(scan_res);
  763. return 0;
  764. }
  765. if (ap) {
  766. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  767. #ifdef CONFIG_AP
  768. if (wpa_s->ap_iface->scan_cb)
  769. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  770. #endif /* CONFIG_AP */
  771. wpa_scan_results_free(scan_res);
  772. return 0;
  773. }
  774. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  775. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  776. wpas_notify_scan_results(wpa_s);
  777. wpas_notify_scan_done(wpa_s, 1);
  778. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  779. wpa_scan_results_free(scan_res);
  780. return 0;
  781. }
  782. if (wpa_s->disconnected) {
  783. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  784. wpa_scan_results_free(scan_res);
  785. return 0;
  786. }
  787. if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
  788. wpa_scan_results_free(scan_res);
  789. return 0;
  790. }
  791. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  792. if (selected) {
  793. int skip;
  794. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  795. scan_res);
  796. wpa_scan_results_free(scan_res);
  797. if (skip)
  798. return 0;
  799. wpa_supplicant_connect(wpa_s, selected, ssid);
  800. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  801. } else {
  802. wpa_scan_results_free(scan_res);
  803. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  804. ssid = wpa_supplicant_pick_new_network(wpa_s);
  805. if (ssid) {
  806. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  807. wpa_supplicant_associate(wpa_s, NULL, ssid);
  808. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  809. } else {
  810. int timeout_sec = wpa_s->scan_interval;
  811. int timeout_usec = 0;
  812. #ifdef CONFIG_P2P
  813. if (wpa_s->p2p_in_provisioning) {
  814. /*
  815. * Use shorter wait during P2P Provisioning
  816. * state to speed up group formation.
  817. */
  818. timeout_sec = 0;
  819. timeout_usec = 250000;
  820. }
  821. #endif /* CONFIG_P2P */
  822. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  823. timeout_usec);
  824. }
  825. }
  826. return 0;
  827. }
  828. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  829. union wpa_event_data *data)
  830. {
  831. const char *rn, *rn2;
  832. struct wpa_supplicant *ifs;
  833. if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
  834. /*
  835. * If no scan results could be fetched, then no need to
  836. * notify those interfaces that did not actually request
  837. * this scan.
  838. */
  839. return;
  840. }
  841. /*
  842. * Check other interfaces to see if they have the same radio-name. If
  843. * so, they get updated with this same scan info.
  844. */
  845. if (!wpa_s->driver->get_radio_name)
  846. return;
  847. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  848. if (rn == NULL || rn[0] == '\0')
  849. return;
  850. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  851. "sharing same radio (%s) in event_scan_results", rn);
  852. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  853. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  854. continue;
  855. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  856. if (rn2 && os_strcmp(rn, rn2) == 0) {
  857. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  858. "sibling", ifs->ifname);
  859. _wpa_supplicant_event_scan_results(ifs, data);
  860. }
  861. }
  862. }
  863. #endif /* CONFIG_NO_SCAN_PROCESSING */
  864. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  865. union wpa_event_data *data)
  866. {
  867. int l, len, found = 0, wpa_found, rsn_found;
  868. const u8 *p;
  869. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  870. if (data->assoc_info.req_ies)
  871. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  872. data->assoc_info.req_ies_len);
  873. if (data->assoc_info.resp_ies) {
  874. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  875. data->assoc_info.resp_ies_len);
  876. #ifdef CONFIG_TDLS
  877. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  878. data->assoc_info.resp_ies_len);
  879. #endif /* CONFIG_TDLS */
  880. }
  881. if (data->assoc_info.beacon_ies)
  882. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  883. data->assoc_info.beacon_ies,
  884. data->assoc_info.beacon_ies_len);
  885. if (data->assoc_info.freq)
  886. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  887. data->assoc_info.freq);
  888. p = data->assoc_info.req_ies;
  889. l = data->assoc_info.req_ies_len;
  890. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  891. while (p && l >= 2) {
  892. len = p[1] + 2;
  893. if (len > l) {
  894. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  895. p, l);
  896. break;
  897. }
  898. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  899. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  900. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  901. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  902. break;
  903. found = 1;
  904. wpa_find_assoc_pmkid(wpa_s);
  905. break;
  906. }
  907. l -= len;
  908. p += len;
  909. }
  910. if (!found && data->assoc_info.req_ies)
  911. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  912. #ifdef CONFIG_IEEE80211R
  913. #ifdef CONFIG_SME
  914. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  915. u8 bssid[ETH_ALEN];
  916. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  917. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  918. data->assoc_info.resp_ies,
  919. data->assoc_info.resp_ies_len,
  920. bssid) < 0) {
  921. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  922. "Reassociation Response failed");
  923. wpa_supplicant_deauthenticate(
  924. wpa_s, WLAN_REASON_INVALID_IE);
  925. return -1;
  926. }
  927. }
  928. p = data->assoc_info.resp_ies;
  929. l = data->assoc_info.resp_ies_len;
  930. #ifdef CONFIG_WPS_STRICT
  931. if (p && wpa_s->current_ssid &&
  932. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  933. struct wpabuf *wps;
  934. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  935. if (wps == NULL) {
  936. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  937. "include WPS IE in (Re)Association Response");
  938. return -1;
  939. }
  940. if (wps_validate_assoc_resp(wps) < 0) {
  941. wpabuf_free(wps);
  942. wpa_supplicant_deauthenticate(
  943. wpa_s, WLAN_REASON_INVALID_IE);
  944. return -1;
  945. }
  946. wpabuf_free(wps);
  947. }
  948. #endif /* CONFIG_WPS_STRICT */
  949. /* Go through the IEs and make a copy of the MDIE, if present. */
  950. while (p && l >= 2) {
  951. len = p[1] + 2;
  952. if (len > l) {
  953. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  954. p, l);
  955. break;
  956. }
  957. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  958. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  959. wpa_s->sme.ft_used = 1;
  960. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  961. MOBILITY_DOMAIN_ID_LEN);
  962. break;
  963. }
  964. l -= len;
  965. p += len;
  966. }
  967. #endif /* CONFIG_SME */
  968. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  969. data->assoc_info.resp_ies_len);
  970. #endif /* CONFIG_IEEE80211R */
  971. /* WPA/RSN IE from Beacon/ProbeResp */
  972. p = data->assoc_info.beacon_ies;
  973. l = data->assoc_info.beacon_ies_len;
  974. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  975. */
  976. wpa_found = rsn_found = 0;
  977. while (p && l >= 2) {
  978. len = p[1] + 2;
  979. if (len > l) {
  980. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  981. p, l);
  982. break;
  983. }
  984. if (!wpa_found &&
  985. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  986. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  987. wpa_found = 1;
  988. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  989. }
  990. if (!rsn_found &&
  991. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  992. rsn_found = 1;
  993. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  994. }
  995. l -= len;
  996. p += len;
  997. }
  998. if (!wpa_found && data->assoc_info.beacon_ies)
  999. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1000. if (!rsn_found && data->assoc_info.beacon_ies)
  1001. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1002. if (wpa_found || rsn_found)
  1003. wpa_s->ap_ies_from_associnfo = 1;
  1004. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1005. wpa_s->assoc_freq != data->assoc_info.freq) {
  1006. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1007. "%u to %u MHz",
  1008. wpa_s->assoc_freq, data->assoc_info.freq);
  1009. wpa_supplicant_update_scan_results(wpa_s);
  1010. }
  1011. wpa_s->assoc_freq = data->assoc_info.freq;
  1012. return 0;
  1013. }
  1014. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1015. union wpa_event_data *data)
  1016. {
  1017. u8 bssid[ETH_ALEN];
  1018. int ft_completed;
  1019. int bssid_changed;
  1020. struct wpa_driver_capa capa;
  1021. #ifdef CONFIG_AP
  1022. if (wpa_s->ap_iface) {
  1023. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1024. data->assoc_info.addr,
  1025. data->assoc_info.req_ies,
  1026. data->assoc_info.req_ies_len,
  1027. data->assoc_info.reassoc);
  1028. return;
  1029. }
  1030. #endif /* CONFIG_AP */
  1031. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1032. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1033. return;
  1034. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1035. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  1036. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  1037. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  1038. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1039. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  1040. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1041. MACSTR, MAC2STR(bssid));
  1042. random_add_randomness(bssid, ETH_ALEN);
  1043. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1044. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1045. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1046. if (bssid_changed)
  1047. wpas_notify_bssid_changed(wpa_s);
  1048. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1049. wpa_clear_keys(wpa_s, bssid);
  1050. }
  1051. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1052. wpa_supplicant_disassociate(
  1053. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1054. return;
  1055. }
  1056. if (wpa_s->current_ssid) {
  1057. struct wpa_bss *bss = NULL;
  1058. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1059. if (ssid->ssid_len > 0)
  1060. bss = wpa_bss_get(wpa_s, bssid,
  1061. ssid->ssid, ssid->ssid_len);
  1062. if (!bss)
  1063. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1064. if (bss)
  1065. wpa_s->current_bss = bss;
  1066. }
  1067. }
  1068. #ifdef CONFIG_SME
  1069. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1070. wpa_s->sme.prev_bssid_set = 1;
  1071. #endif /* CONFIG_SME */
  1072. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1073. if (wpa_s->current_ssid) {
  1074. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1075. * initialized before association, but for other modes,
  1076. * initialize PC/SC here, if the current configuration needs
  1077. * smartcard or SIM/USIM. */
  1078. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1079. }
  1080. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1081. if (wpa_s->l2)
  1082. l2_packet_notify_auth_start(wpa_s->l2);
  1083. /*
  1084. * Set portEnabled first to FALSE in order to get EAP state machine out
  1085. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1086. * state machine may transit to AUTHENTICATING state based on obsolete
  1087. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1088. * AUTHENTICATED without ever giving chance to EAP state machine to
  1089. * reset the state.
  1090. */
  1091. if (!ft_completed) {
  1092. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1093. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1094. }
  1095. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1096. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1097. /* 802.1X::portControl = Auto */
  1098. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1099. wpa_s->eapol_received = 0;
  1100. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1101. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1102. (wpa_s->current_ssid &&
  1103. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1104. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1105. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1106. } else if (!ft_completed) {
  1107. /* Timeout for receiving the first EAPOL packet */
  1108. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1109. }
  1110. wpa_supplicant_cancel_scan(wpa_s);
  1111. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1112. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1113. /*
  1114. * We are done; the driver will take care of RSN 4-way
  1115. * handshake.
  1116. */
  1117. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1118. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1119. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1120. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1121. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1122. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1123. /*
  1124. * The driver will take care of RSN 4-way handshake, so we need
  1125. * to allow EAPOL supplicant to complete its work without
  1126. * waiting for WPA supplicant.
  1127. */
  1128. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1129. } else if (ft_completed) {
  1130. /*
  1131. * FT protocol completed - make sure EAPOL state machine ends
  1132. * up in authenticated.
  1133. */
  1134. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1135. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1136. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1137. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1138. }
  1139. if (wpa_s->pending_eapol_rx) {
  1140. struct os_time now, age;
  1141. os_get_time(&now);
  1142. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1143. if (age.sec == 0 && age.usec < 100000 &&
  1144. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1145. 0) {
  1146. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1147. "frame that was received just before "
  1148. "association notification");
  1149. wpa_supplicant_rx_eapol(
  1150. wpa_s, wpa_s->pending_eapol_rx_src,
  1151. wpabuf_head(wpa_s->pending_eapol_rx),
  1152. wpabuf_len(wpa_s->pending_eapol_rx));
  1153. }
  1154. wpabuf_free(wpa_s->pending_eapol_rx);
  1155. wpa_s->pending_eapol_rx = NULL;
  1156. }
  1157. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1158. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1159. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1160. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1161. /* Set static WEP keys again */
  1162. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1163. }
  1164. #ifdef CONFIG_IBSS_RSN
  1165. if (wpa_s->current_ssid &&
  1166. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1167. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1168. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1169. wpa_s->ibss_rsn == NULL) {
  1170. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1171. if (!wpa_s->ibss_rsn) {
  1172. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1173. wpa_supplicant_deauthenticate(
  1174. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1175. return;
  1176. }
  1177. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1178. }
  1179. #endif /* CONFIG_IBSS_RSN */
  1180. }
  1181. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1182. u16 reason_code)
  1183. {
  1184. const u8 *bssid;
  1185. int authenticating;
  1186. u8 prev_pending_bssid[ETH_ALEN];
  1187. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1188. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1189. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1190. /*
  1191. * At least Host AP driver and a Prism3 card seemed to be
  1192. * generating streams of disconnected events when configuring
  1193. * IBSS for WPA-None. Ignore them for now.
  1194. */
  1195. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1196. "IBSS/WPA-None mode");
  1197. return;
  1198. }
  1199. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1200. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1201. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1202. "pre-shared key may be incorrect");
  1203. }
  1204. if (!wpa_s->auto_reconnect_disabled ||
  1205. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1206. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
  1207. "reconnect (wps=%d)",
  1208. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
  1209. if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1210. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1211. } else {
  1212. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
  1213. "try to re-connect");
  1214. wpa_s->reassociate = 0;
  1215. wpa_s->disconnected = 1;
  1216. }
  1217. bssid = wpa_s->bssid;
  1218. if (is_zero_ether_addr(bssid))
  1219. bssid = wpa_s->pending_bssid;
  1220. wpas_connection_failed(wpa_s, bssid);
  1221. wpa_sm_notify_disassoc(wpa_s->wpa);
  1222. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1223. " reason=%d",
  1224. MAC2STR(bssid), reason_code);
  1225. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1226. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1227. wpa_s->keys_cleared = 0;
  1228. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1229. }
  1230. wpa_supplicant_mark_disassoc(wpa_s);
  1231. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1232. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1233. }
  1234. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1235. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1236. void *sock_ctx)
  1237. {
  1238. struct wpa_supplicant *wpa_s = eloop_ctx;
  1239. if (!wpa_s->pending_mic_error_report)
  1240. return;
  1241. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1242. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1243. wpa_s->pending_mic_error_report = 0;
  1244. }
  1245. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1246. static void
  1247. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1248. union wpa_event_data *data)
  1249. {
  1250. int pairwise;
  1251. struct os_time t;
  1252. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1253. pairwise = (data && data->michael_mic_failure.unicast);
  1254. os_get_time(&t);
  1255. if ((wpa_s->last_michael_mic_error &&
  1256. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1257. wpa_s->pending_mic_error_report) {
  1258. if (wpa_s->pending_mic_error_report) {
  1259. /*
  1260. * Send the pending MIC error report immediately since
  1261. * we are going to start countermeasures and AP better
  1262. * do the same.
  1263. */
  1264. wpa_sm_key_request(wpa_s->wpa, 1,
  1265. wpa_s->pending_mic_error_pairwise);
  1266. }
  1267. /* Send the new MIC error report immediately since we are going
  1268. * to start countermeasures and AP better do the same.
  1269. */
  1270. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1271. /* initialize countermeasures */
  1272. wpa_s->countermeasures = 1;
  1273. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1274. /*
  1275. * Need to wait for completion of request frame. We do not get
  1276. * any callback for the message completion, so just wait a
  1277. * short while and hope for the best. */
  1278. os_sleep(0, 10000);
  1279. wpa_drv_set_countermeasures(wpa_s, 1);
  1280. wpa_supplicant_deauthenticate(wpa_s,
  1281. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1282. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1283. wpa_s, NULL);
  1284. eloop_register_timeout(60, 0,
  1285. wpa_supplicant_stop_countermeasures,
  1286. wpa_s, NULL);
  1287. /* TODO: mark the AP rejected for 60 second. STA is
  1288. * allowed to associate with another AP.. */
  1289. } else {
  1290. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1291. if (wpa_s->mic_errors_seen) {
  1292. /*
  1293. * Reduce the effectiveness of Michael MIC error
  1294. * reports as a means for attacking against TKIP if
  1295. * more than one MIC failure is noticed with the same
  1296. * PTK. We delay the transmission of the reports by a
  1297. * random time between 0 and 60 seconds in order to
  1298. * force the attacker wait 60 seconds before getting
  1299. * the information on whether a frame resulted in a MIC
  1300. * failure.
  1301. */
  1302. u8 rval[4];
  1303. int sec;
  1304. if (os_get_random(rval, sizeof(rval)) < 0)
  1305. sec = os_random() % 60;
  1306. else
  1307. sec = WPA_GET_BE32(rval) % 60;
  1308. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1309. "report %d seconds", sec);
  1310. wpa_s->pending_mic_error_report = 1;
  1311. wpa_s->pending_mic_error_pairwise = pairwise;
  1312. eloop_cancel_timeout(
  1313. wpa_supplicant_delayed_mic_error_report,
  1314. wpa_s, NULL);
  1315. eloop_register_timeout(
  1316. sec, os_random() % 1000000,
  1317. wpa_supplicant_delayed_mic_error_report,
  1318. wpa_s, NULL);
  1319. } else {
  1320. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1321. }
  1322. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1323. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1324. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1325. }
  1326. wpa_s->last_michael_mic_error = t.sec;
  1327. wpa_s->mic_errors_seen++;
  1328. }
  1329. #ifdef CONFIG_TERMINATE_ONLASTIF
  1330. static int any_interfaces(struct wpa_supplicant *head)
  1331. {
  1332. struct wpa_supplicant *wpa_s;
  1333. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1334. if (!wpa_s->interface_removed)
  1335. return 1;
  1336. return 0;
  1337. }
  1338. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1339. static void
  1340. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1341. union wpa_event_data *data)
  1342. {
  1343. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1344. return;
  1345. switch (data->interface_status.ievent) {
  1346. case EVENT_INTERFACE_ADDED:
  1347. if (!wpa_s->interface_removed)
  1348. break;
  1349. wpa_s->interface_removed = 0;
  1350. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1351. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1352. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1353. "driver after interface was added");
  1354. }
  1355. break;
  1356. case EVENT_INTERFACE_REMOVED:
  1357. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1358. wpa_s->interface_removed = 1;
  1359. wpa_supplicant_mark_disassoc(wpa_s);
  1360. l2_packet_deinit(wpa_s->l2);
  1361. wpa_s->l2 = NULL;
  1362. #ifdef CONFIG_IBSS_RSN
  1363. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1364. wpa_s->ibss_rsn = NULL;
  1365. #endif /* CONFIG_IBSS_RSN */
  1366. #ifdef CONFIG_TERMINATE_ONLASTIF
  1367. /* check if last interface */
  1368. if (!any_interfaces(wpa_s->global->ifaces))
  1369. eloop_terminate();
  1370. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1371. break;
  1372. }
  1373. }
  1374. #ifdef CONFIG_PEERKEY
  1375. static void
  1376. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1377. union wpa_event_data *data)
  1378. {
  1379. if (data == NULL)
  1380. return;
  1381. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1382. }
  1383. #endif /* CONFIG_PEERKEY */
  1384. #ifdef CONFIG_TDLS
  1385. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1386. union wpa_event_data *data)
  1387. {
  1388. if (data == NULL)
  1389. return;
  1390. switch (data->tdls.oper) {
  1391. case TDLS_REQUEST_SETUP:
  1392. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1393. break;
  1394. case TDLS_REQUEST_TEARDOWN:
  1395. /* request from driver to add FTIE */
  1396. wpa_tdls_recv_teardown_notify(wpa_s->wpa, data->tdls.peer,
  1397. data->tdls.reason_code);
  1398. break;
  1399. }
  1400. }
  1401. #endif /* CONFIG_TDLS */
  1402. #ifdef CONFIG_IEEE80211R
  1403. static void
  1404. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1405. union wpa_event_data *data)
  1406. {
  1407. if (data == NULL)
  1408. return;
  1409. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1410. data->ft_ies.ies_len,
  1411. data->ft_ies.ft_action,
  1412. data->ft_ies.target_ap,
  1413. data->ft_ies.ric_ies,
  1414. data->ft_ies.ric_ies_len) < 0) {
  1415. /* TODO: prevent MLME/driver from trying to associate? */
  1416. }
  1417. }
  1418. #endif /* CONFIG_IEEE80211R */
  1419. #ifdef CONFIG_IBSS_RSN
  1420. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1421. union wpa_event_data *data)
  1422. {
  1423. struct wpa_ssid *ssid;
  1424. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1425. return;
  1426. if (data == NULL)
  1427. return;
  1428. ssid = wpa_s->current_ssid;
  1429. if (ssid == NULL)
  1430. return;
  1431. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1432. return;
  1433. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1434. }
  1435. #endif /* CONFIG_IBSS_RSN */
  1436. #ifdef CONFIG_IEEE80211R
  1437. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1438. size_t len)
  1439. {
  1440. const u8 *sta_addr, *target_ap_addr;
  1441. u16 status;
  1442. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1443. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1444. return; /* only SME case supported for now */
  1445. if (len < 1 + 2 * ETH_ALEN + 2)
  1446. return;
  1447. if (data[0] != 2)
  1448. return; /* Only FT Action Response is supported for now */
  1449. sta_addr = data + 1;
  1450. target_ap_addr = data + 1 + ETH_ALEN;
  1451. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1452. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1453. MACSTR " TargetAP " MACSTR " status %u",
  1454. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1455. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1456. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1457. " in FT Action Response", MAC2STR(sta_addr));
  1458. return;
  1459. }
  1460. if (status) {
  1461. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1462. "failure (status code %d)", status);
  1463. /* TODO: report error to FT code(?) */
  1464. return;
  1465. }
  1466. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1467. len - (1 + 2 * ETH_ALEN + 2), 1,
  1468. target_ap_addr, NULL, 0) < 0)
  1469. return;
  1470. #ifdef CONFIG_SME
  1471. {
  1472. struct wpa_bss *bss;
  1473. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1474. if (bss)
  1475. wpa_s->sme.freq = bss->freq;
  1476. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1477. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1478. WLAN_AUTH_FT);
  1479. }
  1480. #endif /* CONFIG_SME */
  1481. }
  1482. #endif /* CONFIG_IEEE80211R */
  1483. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1484. struct unprot_deauth *e)
  1485. {
  1486. #ifdef CONFIG_IEEE80211W
  1487. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1488. "dropped: " MACSTR " -> " MACSTR
  1489. " (reason code %u)",
  1490. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1491. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1492. #endif /* CONFIG_IEEE80211W */
  1493. }
  1494. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1495. struct unprot_disassoc *e)
  1496. {
  1497. #ifdef CONFIG_IEEE80211W
  1498. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1499. "dropped: " MACSTR " -> " MACSTR
  1500. " (reason code %u)",
  1501. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1502. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1503. #endif /* CONFIG_IEEE80211W */
  1504. }
  1505. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1506. union wpa_event_data *data)
  1507. {
  1508. struct wpa_supplicant *wpa_s = ctx;
  1509. u16 reason_code = 0;
  1510. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1511. event != EVENT_INTERFACE_ENABLED &&
  1512. event != EVENT_INTERFACE_STATUS) {
  1513. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
  1514. "disabled", event);
  1515. return;
  1516. }
  1517. wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
  1518. event, wpa_s->ifname);
  1519. switch (event) {
  1520. case EVENT_AUTH:
  1521. sme_event_auth(wpa_s, data);
  1522. break;
  1523. case EVENT_ASSOC:
  1524. wpa_supplicant_event_assoc(wpa_s, data);
  1525. break;
  1526. case EVENT_DISASSOC:
  1527. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1528. if (data) {
  1529. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1530. data->disassoc_info.reason_code);
  1531. if (data->disassoc_info.addr)
  1532. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1533. MAC2STR(data->disassoc_info.addr));
  1534. }
  1535. #ifdef CONFIG_AP
  1536. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1537. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1538. data->disassoc_info.addr);
  1539. break;
  1540. }
  1541. #endif /* CONFIG_AP */
  1542. if (data) {
  1543. reason_code = data->disassoc_info.reason_code;
  1544. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1545. data->disassoc_info.ie,
  1546. data->disassoc_info.ie_len);
  1547. #ifdef CONFIG_P2P
  1548. wpas_p2p_disassoc_notif(
  1549. wpa_s, data->disassoc_info.addr, reason_code,
  1550. data->disassoc_info.ie,
  1551. data->disassoc_info.ie_len);
  1552. #endif /* CONFIG_P2P */
  1553. }
  1554. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1555. sme_event_disassoc(wpa_s, data);
  1556. /* fall through */
  1557. case EVENT_DEAUTH:
  1558. if (event == EVENT_DEAUTH) {
  1559. wpa_dbg(wpa_s, MSG_DEBUG,
  1560. "Deauthentication notification");
  1561. if (data) {
  1562. reason_code = data->deauth_info.reason_code;
  1563. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1564. data->deauth_info.reason_code);
  1565. if (data->deauth_info.addr) {
  1566. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1567. MACSTR,
  1568. MAC2STR(data->deauth_info.
  1569. addr));
  1570. }
  1571. wpa_hexdump(MSG_DEBUG,
  1572. "Deauthentication frame IE(s)",
  1573. data->deauth_info.ie,
  1574. data->deauth_info.ie_len);
  1575. #ifdef CONFIG_P2P
  1576. wpas_p2p_deauth_notif(
  1577. wpa_s, data->deauth_info.addr,
  1578. reason_code,
  1579. data->deauth_info.ie,
  1580. data->deauth_info.ie_len);
  1581. #endif /* CONFIG_P2P */
  1582. }
  1583. }
  1584. #ifdef CONFIG_AP
  1585. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1586. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1587. data->deauth_info.addr);
  1588. break;
  1589. }
  1590. #endif /* CONFIG_AP */
  1591. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1592. break;
  1593. case EVENT_MICHAEL_MIC_FAILURE:
  1594. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1595. break;
  1596. #ifndef CONFIG_NO_SCAN_PROCESSING
  1597. case EVENT_SCAN_RESULTS:
  1598. wpa_supplicant_event_scan_results(wpa_s, data);
  1599. break;
  1600. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1601. case EVENT_ASSOCINFO:
  1602. wpa_supplicant_event_associnfo(wpa_s, data);
  1603. break;
  1604. case EVENT_INTERFACE_STATUS:
  1605. wpa_supplicant_event_interface_status(wpa_s, data);
  1606. break;
  1607. case EVENT_PMKID_CANDIDATE:
  1608. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1609. break;
  1610. #ifdef CONFIG_PEERKEY
  1611. case EVENT_STKSTART:
  1612. wpa_supplicant_event_stkstart(wpa_s, data);
  1613. break;
  1614. #endif /* CONFIG_PEERKEY */
  1615. #ifdef CONFIG_TDLS
  1616. case EVENT_TDLS:
  1617. wpa_supplicant_event_tdls(wpa_s, data);
  1618. break;
  1619. #endif /* CONFIG_TDLS */
  1620. #ifdef CONFIG_IEEE80211R
  1621. case EVENT_FT_RESPONSE:
  1622. wpa_supplicant_event_ft_response(wpa_s, data);
  1623. break;
  1624. #endif /* CONFIG_IEEE80211R */
  1625. #ifdef CONFIG_IBSS_RSN
  1626. case EVENT_IBSS_RSN_START:
  1627. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1628. break;
  1629. #endif /* CONFIG_IBSS_RSN */
  1630. case EVENT_ASSOC_REJECT:
  1631. if (data->assoc_reject.bssid)
  1632. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1633. "bssid=" MACSTR " status_code=%u",
  1634. MAC2STR(data->assoc_reject.bssid),
  1635. data->assoc_reject.status_code);
  1636. else
  1637. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1638. "status_code=%u",
  1639. data->assoc_reject.status_code);
  1640. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1641. sme_event_assoc_reject(wpa_s, data);
  1642. break;
  1643. case EVENT_AUTH_TIMED_OUT:
  1644. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1645. sme_event_auth_timed_out(wpa_s, data);
  1646. break;
  1647. case EVENT_ASSOC_TIMED_OUT:
  1648. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1649. sme_event_assoc_timed_out(wpa_s, data);
  1650. break;
  1651. #ifdef CONFIG_AP
  1652. case EVENT_TX_STATUS:
  1653. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  1654. " type=%d stype=%d",
  1655. MAC2STR(data->tx_status.dst),
  1656. data->tx_status.type, data->tx_status.stype);
  1657. if (wpa_s->ap_iface == NULL) {
  1658. #ifdef CONFIG_P2P
  1659. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1660. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1661. wpas_send_action_tx_status(
  1662. wpa_s, data->tx_status.dst,
  1663. data->tx_status.data,
  1664. data->tx_status.data_len,
  1665. data->tx_status.ack ?
  1666. P2P_SEND_ACTION_SUCCESS :
  1667. P2P_SEND_ACTION_NO_ACK);
  1668. #endif /* CONFIG_P2P */
  1669. break;
  1670. }
  1671. #ifdef CONFIG_P2P
  1672. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  1673. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  1674. /*
  1675. * Catch TX status events for Action frames we sent via group
  1676. * interface in GO mode.
  1677. */
  1678. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1679. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1680. os_memcmp(wpa_s->parent->pending_action_dst,
  1681. data->tx_status.dst, ETH_ALEN) == 0) {
  1682. wpas_send_action_tx_status(
  1683. wpa_s->parent, data->tx_status.dst,
  1684. data->tx_status.data,
  1685. data->tx_status.data_len,
  1686. data->tx_status.ack ?
  1687. P2P_SEND_ACTION_SUCCESS :
  1688. P2P_SEND_ACTION_NO_ACK);
  1689. break;
  1690. }
  1691. #endif /* CONFIG_P2P */
  1692. switch (data->tx_status.type) {
  1693. case WLAN_FC_TYPE_MGMT:
  1694. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1695. data->tx_status.data_len,
  1696. data->tx_status.stype,
  1697. data->tx_status.ack);
  1698. break;
  1699. case WLAN_FC_TYPE_DATA:
  1700. ap_tx_status(wpa_s, data->tx_status.dst,
  1701. data->tx_status.data,
  1702. data->tx_status.data_len,
  1703. data->tx_status.ack);
  1704. break;
  1705. }
  1706. break;
  1707. case EVENT_RX_FROM_UNKNOWN:
  1708. if (wpa_s->ap_iface == NULL)
  1709. break;
  1710. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1711. data->rx_from_unknown.len);
  1712. break;
  1713. case EVENT_RX_MGMT:
  1714. if (wpa_s->ap_iface == NULL) {
  1715. #ifdef CONFIG_P2P
  1716. u16 fc, stype;
  1717. const struct ieee80211_mgmt *mgmt;
  1718. mgmt = (const struct ieee80211_mgmt *)
  1719. data->rx_mgmt.frame;
  1720. fc = le_to_host16(mgmt->frame_control);
  1721. stype = WLAN_FC_GET_STYPE(fc);
  1722. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  1723. data->rx_mgmt.frame_len > 24) {
  1724. const u8 *src = mgmt->sa;
  1725. const u8 *ie = mgmt->u.probe_req.variable;
  1726. size_t ie_len = data->rx_mgmt.frame_len -
  1727. (mgmt->u.probe_req.variable -
  1728. data->rx_mgmt.frame);
  1729. wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
  1730. break;
  1731. }
  1732. #endif /* CONFIG_P2P */
  1733. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  1734. "management frame in non-AP mode");
  1735. break;
  1736. }
  1737. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1738. break;
  1739. #endif /* CONFIG_AP */
  1740. case EVENT_RX_ACTION:
  1741. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1742. " Category=%u DataLen=%d freq=%d MHz",
  1743. MAC2STR(data->rx_action.sa),
  1744. data->rx_action.category, (int) data->rx_action.len,
  1745. data->rx_action.freq);
  1746. #ifdef CONFIG_IEEE80211R
  1747. if (data->rx_action.category == WLAN_ACTION_FT) {
  1748. ft_rx_action(wpa_s, data->rx_action.data,
  1749. data->rx_action.len);
  1750. break;
  1751. }
  1752. #endif /* CONFIG_IEEE80211R */
  1753. #ifdef CONFIG_IEEE80211W
  1754. #ifdef CONFIG_SME
  1755. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  1756. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  1757. data->rx_action.data,
  1758. data->rx_action.len);
  1759. break;
  1760. }
  1761. #endif /* CONFIG_SME */
  1762. #endif /* CONFIG_IEEE80211W */
  1763. #ifdef CONFIG_P2P
  1764. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  1765. data->rx_action.sa,
  1766. data->rx_action.bssid,
  1767. data->rx_action.category,
  1768. data->rx_action.data,
  1769. data->rx_action.len, data->rx_action.freq);
  1770. #endif /* CONFIG_P2P */
  1771. break;
  1772. case EVENT_RX_PROBE_REQ:
  1773. if (data->rx_probe_req.sa == NULL ||
  1774. data->rx_probe_req.ie == NULL)
  1775. break;
  1776. #ifdef CONFIG_AP
  1777. if (wpa_s->ap_iface) {
  1778. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  1779. data->rx_probe_req.sa,
  1780. data->rx_probe_req.ie,
  1781. data->rx_probe_req.ie_len);
  1782. break;
  1783. }
  1784. #endif /* CONFIG_AP */
  1785. #ifdef CONFIG_P2P
  1786. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  1787. data->rx_probe_req.ie,
  1788. data->rx_probe_req.ie_len);
  1789. #endif /* CONFIG_P2P */
  1790. break;
  1791. #ifdef CONFIG_P2P
  1792. case EVENT_REMAIN_ON_CHANNEL:
  1793. wpas_p2p_remain_on_channel_cb(
  1794. wpa_s, data->remain_on_channel.freq,
  1795. data->remain_on_channel.duration);
  1796. break;
  1797. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  1798. wpas_p2p_cancel_remain_on_channel_cb(
  1799. wpa_s, data->remain_on_channel.freq);
  1800. break;
  1801. case EVENT_P2P_DEV_FOUND: {
  1802. struct p2p_peer_info peer_info;
  1803. os_memset(&peer_info, 0, sizeof(peer_info));
  1804. if (data->p2p_dev_found.dev_addr)
  1805. os_memcpy(peer_info.p2p_device_addr,
  1806. data->p2p_dev_found.dev_addr, ETH_ALEN);
  1807. if (data->p2p_dev_found.pri_dev_type)
  1808. os_memcpy(peer_info.pri_dev_type,
  1809. data->p2p_dev_found.pri_dev_type,
  1810. sizeof(peer_info.pri_dev_type));
  1811. if (data->p2p_dev_found.dev_name)
  1812. os_strlcpy(peer_info.device_name,
  1813. data->p2p_dev_found.dev_name,
  1814. sizeof(peer_info.device_name));
  1815. peer_info.config_methods = data->p2p_dev_found.config_methods;
  1816. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  1817. peer_info.group_capab = data->p2p_dev_found.group_capab;
  1818. /*
  1819. * FIX: new_device=1 is not necessarily correct. We should
  1820. * maintain a P2P peer database in wpa_supplicant and update
  1821. * this information based on whether the peer is truly new.
  1822. */
  1823. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  1824. break;
  1825. }
  1826. case EVENT_P2P_GO_NEG_REQ_RX:
  1827. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  1828. data->p2p_go_neg_req_rx.dev_passwd_id);
  1829. break;
  1830. case EVENT_P2P_GO_NEG_COMPLETED:
  1831. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  1832. break;
  1833. case EVENT_P2P_PROV_DISC_REQUEST:
  1834. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  1835. data->p2p_prov_disc_req.config_methods,
  1836. data->p2p_prov_disc_req.dev_addr,
  1837. data->p2p_prov_disc_req.pri_dev_type,
  1838. data->p2p_prov_disc_req.dev_name,
  1839. data->p2p_prov_disc_req.supp_config_methods,
  1840. data->p2p_prov_disc_req.dev_capab,
  1841. data->p2p_prov_disc_req.group_capab);
  1842. break;
  1843. case EVENT_P2P_PROV_DISC_RESPONSE:
  1844. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  1845. data->p2p_prov_disc_resp.config_methods);
  1846. break;
  1847. case EVENT_P2P_SD_REQUEST:
  1848. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  1849. data->p2p_sd_req.sa,
  1850. data->p2p_sd_req.dialog_token,
  1851. data->p2p_sd_req.update_indic,
  1852. data->p2p_sd_req.tlvs,
  1853. data->p2p_sd_req.tlvs_len);
  1854. break;
  1855. case EVENT_P2P_SD_RESPONSE:
  1856. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  1857. data->p2p_sd_resp.update_indic,
  1858. data->p2p_sd_resp.tlvs,
  1859. data->p2p_sd_resp.tlvs_len);
  1860. break;
  1861. #endif /* CONFIG_P2P */
  1862. #ifdef CONFIG_CLIENT_MLME
  1863. case EVENT_MLME_RX: {
  1864. struct ieee80211_rx_status rx_status;
  1865. os_memset(&rx_status, 0, sizeof(rx_status));
  1866. rx_status.freq = data->mlme_rx.freq;
  1867. rx_status.channel = data->mlme_rx.channel;
  1868. rx_status.ssi = data->mlme_rx.ssi;
  1869. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1870. &rx_status);
  1871. break;
  1872. }
  1873. #endif /* CONFIG_CLIENT_MLME */
  1874. case EVENT_EAPOL_RX:
  1875. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1876. data->eapol_rx.data,
  1877. data->eapol_rx.data_len);
  1878. break;
  1879. case EVENT_SIGNAL_CHANGE:
  1880. bgscan_notify_signal_change(
  1881. wpa_s, data->signal_change.above_threshold,
  1882. data->signal_change.current_signal,
  1883. data->signal_change.current_noise,
  1884. data->signal_change.current_txrate);
  1885. break;
  1886. case EVENT_INTERFACE_ENABLED:
  1887. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  1888. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1889. #ifdef CONFIG_AP
  1890. if (!wpa_s->ap_iface) {
  1891. wpa_supplicant_set_state(wpa_s,
  1892. WPA_DISCONNECTED);
  1893. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1894. } else
  1895. wpa_supplicant_set_state(wpa_s,
  1896. WPA_COMPLETED);
  1897. #else /* CONFIG_AP */
  1898. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1899. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1900. #endif /* CONFIG_AP */
  1901. }
  1902. break;
  1903. case EVENT_INTERFACE_DISABLED:
  1904. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  1905. wpa_supplicant_mark_disassoc(wpa_s);
  1906. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1907. break;
  1908. case EVENT_CHANNEL_LIST_CHANGED:
  1909. if (wpa_s->drv_priv == NULL)
  1910. break; /* Ignore event during drv initialization */
  1911. #ifdef CONFIG_P2P
  1912. wpas_p2p_update_channel_list(wpa_s);
  1913. #endif /* CONFIG_P2P */
  1914. break;
  1915. case EVENT_INTERFACE_UNAVAILABLE:
  1916. #ifdef CONFIG_P2P
  1917. wpas_p2p_interface_unavailable(wpa_s);
  1918. #endif /* CONFIG_P2P */
  1919. break;
  1920. case EVENT_BEST_CHANNEL:
  1921. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  1922. "(%d %d %d)",
  1923. data->best_chan.freq_24, data->best_chan.freq_5,
  1924. data->best_chan.freq_overall);
  1925. wpa_s->best_24_freq = data->best_chan.freq_24;
  1926. wpa_s->best_5_freq = data->best_chan.freq_5;
  1927. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  1928. #ifdef CONFIG_P2P
  1929. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  1930. data->best_chan.freq_5,
  1931. data->best_chan.freq_overall);
  1932. #endif /* CONFIG_P2P */
  1933. break;
  1934. case EVENT_UNPROT_DEAUTH:
  1935. wpa_supplicant_event_unprot_deauth(wpa_s,
  1936. &data->unprot_deauth);
  1937. break;
  1938. case EVENT_UNPROT_DISASSOC:
  1939. wpa_supplicant_event_unprot_disassoc(wpa_s,
  1940. &data->unprot_disassoc);
  1941. break;
  1942. case EVENT_STATION_LOW_ACK:
  1943. #ifdef CONFIG_AP
  1944. if (wpa_s->ap_iface && data)
  1945. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  1946. data->low_ack.addr);
  1947. #endif /* CONFIG_AP */
  1948. break;
  1949. case EVENT_IBSS_PEER_LOST:
  1950. #ifdef CONFIG_IBSS_RSN
  1951. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  1952. #endif /* CONFIG_IBSS_RSN */
  1953. break;
  1954. default:
  1955. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  1956. break;
  1957. }
  1958. }