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