events.c 60 KB

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