events.c 60 KB

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