events.c 60 KB

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