events.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2010, 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 "notify.h"
  30. #include "common/ieee802_11_defs.h"
  31. #include "blacklist.h"
  32. #include "wpas_glue.h"
  33. #include "wps_supplicant.h"
  34. #include "ibss_rsn.h"
  35. #include "sme.h"
  36. #include "bgscan.h"
  37. #include "ap.h"
  38. #include "bss.h"
  39. #include "mlme.h"
  40. #include "scan.h"
  41. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  42. {
  43. struct wpa_ssid *ssid, *old_ssid;
  44. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  45. return 0;
  46. wpa_printf(MSG_DEBUG, "Select network based on association "
  47. "information");
  48. ssid = wpa_supplicant_get_ssid(wpa_s);
  49. if (ssid == NULL) {
  50. wpa_printf(MSG_INFO, "No network configuration found for the "
  51. "current AP");
  52. return -1;
  53. }
  54. if (ssid->disabled) {
  55. wpa_printf(MSG_DEBUG, "Selected network is disabled");
  56. return -1;
  57. }
  58. wpa_printf(MSG_DEBUG, "Network configuration found for the current "
  59. "AP");
  60. if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  61. WPA_KEY_MGMT_WPA_NONE |
  62. WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
  63. WPA_KEY_MGMT_PSK_SHA256 |
  64. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  65. u8 wpa_ie[80];
  66. size_t wpa_ie_len = sizeof(wpa_ie);
  67. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  68. wpa_ie, &wpa_ie_len);
  69. } else {
  70. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  71. }
  72. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  73. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  74. old_ssid = wpa_s->current_ssid;
  75. wpa_s->current_ssid = ssid;
  76. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  77. wpa_supplicant_initiate_eapol(wpa_s);
  78. if (old_ssid != wpa_s->current_ssid)
  79. wpas_notify_network_changed(wpa_s);
  80. return 0;
  81. }
  82. static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
  83. void *sock_ctx)
  84. {
  85. struct wpa_supplicant *wpa_s = eloop_ctx;
  86. if (wpa_s->countermeasures) {
  87. wpa_s->countermeasures = 0;
  88. wpa_drv_set_countermeasures(wpa_s, 0);
  89. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  90. wpa_supplicant_req_scan(wpa_s, 0, 0);
  91. }
  92. }
  93. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  94. {
  95. int bssid_changed;
  96. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  97. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  98. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  99. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  100. wpa_s->current_bss = NULL;
  101. if (bssid_changed)
  102. wpas_notify_bssid_changed(wpa_s);
  103. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  104. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  105. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  106. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  107. wpa_s->ap_ies_from_associnfo = 0;
  108. }
  109. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  110. {
  111. struct wpa_ie_data ie;
  112. int pmksa_set = -1;
  113. size_t i;
  114. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  115. ie.pmkid == NULL)
  116. return;
  117. for (i = 0; i < ie.num_pmkid; i++) {
  118. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  119. ie.pmkid + i * PMKID_LEN,
  120. NULL, NULL, 0);
  121. if (pmksa_set == 0) {
  122. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  123. break;
  124. }
  125. }
  126. wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
  127. "cache", pmksa_set == 0 ? "" : "not ");
  128. }
  129. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  130. union wpa_event_data *data)
  131. {
  132. if (data == NULL) {
  133. wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
  134. return;
  135. }
  136. wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  137. " index=%d preauth=%d",
  138. MAC2STR(data->pmkid_candidate.bssid),
  139. data->pmkid_candidate.index,
  140. data->pmkid_candidate.preauth);
  141. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  142. data->pmkid_candidate.index,
  143. data->pmkid_candidate.preauth);
  144. }
  145. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  146. {
  147. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  148. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  149. return 0;
  150. #ifdef IEEE8021X_EAPOL
  151. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  152. wpa_s->current_ssid &&
  153. !(wpa_s->current_ssid->eapol_flags &
  154. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  155. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  156. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  157. * plaintext or static WEP keys). */
  158. return 0;
  159. }
  160. #endif /* IEEE8021X_EAPOL */
  161. return 1;
  162. }
  163. /**
  164. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  165. * @wpa_s: pointer to wpa_supplicant data
  166. * @ssid: Configuration data for the network
  167. * Returns: 0 on success, -1 on failure
  168. *
  169. * This function is called when starting authentication with a network that is
  170. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  171. */
  172. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  173. struct wpa_ssid *ssid)
  174. {
  175. #ifdef IEEE8021X_EAPOL
  176. int aka = 0, sim = 0, type;
  177. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  178. return 0;
  179. if (ssid->eap.eap_methods == NULL) {
  180. sim = 1;
  181. aka = 1;
  182. } else {
  183. struct eap_method_type *eap = ssid->eap.eap_methods;
  184. while (eap->vendor != EAP_VENDOR_IETF ||
  185. eap->method != EAP_TYPE_NONE) {
  186. if (eap->vendor == EAP_VENDOR_IETF) {
  187. if (eap->method == EAP_TYPE_SIM)
  188. sim = 1;
  189. else if (eap->method == EAP_TYPE_AKA)
  190. aka = 1;
  191. }
  192. eap++;
  193. }
  194. }
  195. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  196. sim = 0;
  197. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  198. aka = 0;
  199. if (!sim && !aka) {
  200. wpa_printf(MSG_DEBUG, "Selected network is configured to use "
  201. "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
  202. return 0;
  203. }
  204. wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
  205. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  206. if (sim && aka)
  207. type = SCARD_TRY_BOTH;
  208. else if (aka)
  209. type = SCARD_USIM_ONLY;
  210. else
  211. type = SCARD_GSM_SIM_ONLY;
  212. wpa_s->scard = scard_init(type);
  213. if (wpa_s->scard == NULL) {
  214. wpa_printf(MSG_WARNING, "Failed to initialize SIM "
  215. "(pcsc-lite)");
  216. return -1;
  217. }
  218. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  219. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  220. #endif /* IEEE8021X_EAPOL */
  221. return 0;
  222. }
  223. #ifndef CONFIG_NO_SCAN_PROCESSING
  224. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  225. struct wpa_ssid *ssid)
  226. {
  227. int i, privacy = 0;
  228. if (ssid->mixed_cell)
  229. return 1;
  230. #ifdef CONFIG_WPS
  231. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  232. return 1;
  233. #endif /* CONFIG_WPS */
  234. for (i = 0; i < NUM_WEP_KEYS; i++) {
  235. if (ssid->wep_key_len[i]) {
  236. privacy = 1;
  237. break;
  238. }
  239. }
  240. #ifdef IEEE8021X_EAPOL
  241. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  242. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  243. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  244. privacy = 1;
  245. #endif /* IEEE8021X_EAPOL */
  246. if (bss->caps & IEEE80211_CAP_PRIVACY)
  247. return privacy;
  248. return !privacy;
  249. }
  250. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  251. struct wpa_ssid *ssid,
  252. struct wpa_scan_res *bss)
  253. {
  254. struct wpa_ie_data ie;
  255. int proto_match = 0;
  256. const u8 *rsn_ie, *wpa_ie;
  257. int ret;
  258. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  259. if (ret >= 0)
  260. return ret;
  261. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  262. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  263. proto_match++;
  264. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  265. wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
  266. break;
  267. }
  268. if (!(ie.proto & ssid->proto)) {
  269. wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
  270. "mismatch");
  271. break;
  272. }
  273. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  274. wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
  275. "mismatch");
  276. break;
  277. }
  278. if (!(ie.group_cipher & ssid->group_cipher)) {
  279. wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
  280. "mismatch");
  281. break;
  282. }
  283. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  284. wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
  285. "mismatch");
  286. break;
  287. }
  288. #ifdef CONFIG_IEEE80211W
  289. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  290. ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
  291. wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
  292. "protection");
  293. break;
  294. }
  295. #endif /* CONFIG_IEEE80211W */
  296. wpa_printf(MSG_DEBUG, " selected based on RSN IE");
  297. return 1;
  298. }
  299. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  300. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  301. proto_match++;
  302. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  303. wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
  304. break;
  305. }
  306. if (!(ie.proto & ssid->proto)) {
  307. wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
  308. "mismatch");
  309. break;
  310. }
  311. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  312. wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
  313. "mismatch");
  314. break;
  315. }
  316. if (!(ie.group_cipher & ssid->group_cipher)) {
  317. wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
  318. "mismatch");
  319. break;
  320. }
  321. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  322. wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
  323. "mismatch");
  324. break;
  325. }
  326. wpa_printf(MSG_DEBUG, " selected based on WPA IE");
  327. return 1;
  328. }
  329. if (proto_match == 0)
  330. wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
  331. return 0;
  332. }
  333. static int freq_allowed(int *freqs, int freq)
  334. {
  335. int i;
  336. if (freqs == NULL)
  337. return 1;
  338. for (i = 0; freqs[i]; i++)
  339. if (freqs[i] == freq)
  340. return 1;
  341. return 0;
  342. }
  343. static struct wpa_bss *
  344. wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
  345. struct wpa_scan_results *scan_res,
  346. struct wpa_ssid *group,
  347. struct wpa_ssid **selected_ssid)
  348. {
  349. struct wpa_ssid *ssid;
  350. struct wpa_scan_res *bss;
  351. size_t i;
  352. struct wpa_blacklist *e;
  353. const u8 *ie;
  354. wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
  355. for (i = 0; i < scan_res->num; i++) {
  356. const u8 *ssid_;
  357. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  358. bss = scan_res->res[i];
  359. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  360. ssid_ = ie ? ie + 2 : (u8 *) "";
  361. ssid_len = ie ? ie[1] : 0;
  362. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  363. wpa_ie_len = ie ? ie[1] : 0;
  364. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  365. rsn_ie_len = ie ? ie[1] : 0;
  366. wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  367. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
  368. (int) i, MAC2STR(bss->bssid),
  369. wpa_ssid_txt(ssid_, ssid_len),
  370. wpa_ie_len, rsn_ie_len, bss->caps);
  371. e = wpa_blacklist_get(wpa_s, bss->bssid);
  372. if (e && e->count > 1) {
  373. wpa_printf(MSG_DEBUG, " skip - blacklisted");
  374. continue;
  375. }
  376. if (ssid_len == 0) {
  377. wpa_printf(MSG_DEBUG, " skip - SSID not known");
  378. continue;
  379. }
  380. if (wpa_ie_len == 0 && rsn_ie_len == 0) {
  381. wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE");
  382. continue;
  383. }
  384. for (ssid = group; ssid; ssid = ssid->pnext) {
  385. int check_ssid = 1;
  386. if (ssid->disabled) {
  387. wpa_printf(MSG_DEBUG, " skip - disabled");
  388. continue;
  389. }
  390. #ifdef CONFIG_WPS
  391. if (ssid->ssid_len == 0 &&
  392. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  393. check_ssid = 0;
  394. #endif /* CONFIG_WPS */
  395. if (check_ssid &&
  396. (ssid_len != ssid->ssid_len ||
  397. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  398. wpa_printf(MSG_DEBUG, " skip - "
  399. "SSID mismatch");
  400. continue;
  401. }
  402. if (ssid->bssid_set &&
  403. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
  404. {
  405. wpa_printf(MSG_DEBUG, " skip - "
  406. "BSSID mismatch");
  407. continue;
  408. }
  409. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  410. continue;
  411. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  412. wpa_printf(MSG_DEBUG, " skip - "
  413. "frequency not allowed");
  414. continue;
  415. }
  416. wpa_printf(MSG_DEBUG, " selected WPA AP "
  417. MACSTR " ssid='%s'",
  418. MAC2STR(bss->bssid),
  419. wpa_ssid_txt(ssid_, ssid_len));
  420. *selected_ssid = ssid;
  421. return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
  422. }
  423. }
  424. return NULL;
  425. }
  426. static struct wpa_bss *
  427. wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
  428. struct wpa_scan_results *scan_res,
  429. struct wpa_ssid *group,
  430. struct wpa_ssid **selected_ssid)
  431. {
  432. struct wpa_ssid *ssid;
  433. struct wpa_scan_res *bss;
  434. size_t i;
  435. struct wpa_blacklist *e;
  436. const u8 *ie;
  437. wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
  438. for (i = 0; i < scan_res->num; i++) {
  439. const u8 *ssid_;
  440. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  441. bss = scan_res->res[i];
  442. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  443. ssid_ = ie ? ie + 2 : (u8 *) "";
  444. ssid_len = ie ? ie[1] : 0;
  445. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  446. wpa_ie_len = ie ? ie[1] : 0;
  447. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  448. rsn_ie_len = ie ? ie[1] : 0;
  449. wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  450. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
  451. (int) i, MAC2STR(bss->bssid),
  452. wpa_ssid_txt(ssid_, ssid_len),
  453. wpa_ie_len, rsn_ie_len, bss->caps);
  454. e = wpa_blacklist_get(wpa_s, bss->bssid);
  455. if (e && e->count > 1) {
  456. wpa_printf(MSG_DEBUG, " skip - blacklisted");
  457. continue;
  458. }
  459. if (ssid_len == 0) {
  460. wpa_printf(MSG_DEBUG, " skip - SSID not known");
  461. continue;
  462. }
  463. for (ssid = group; ssid; ssid = ssid->pnext) {
  464. int check_ssid = ssid->ssid_len != 0;
  465. if (ssid->disabled) {
  466. wpa_printf(MSG_DEBUG, " skip - disabled");
  467. continue;
  468. }
  469. #ifdef CONFIG_WPS
  470. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  471. /* Only allow wildcard SSID match if an AP
  472. * advertises active WPS operation that matches
  473. * with our mode. */
  474. check_ssid = 1;
  475. if (ssid->ssid_len == 0 &&
  476. wpas_wps_ssid_wildcard_ok(wpa_s, ssid,
  477. bss))
  478. check_ssid = 0;
  479. }
  480. #endif /* CONFIG_WPS */
  481. if (check_ssid &&
  482. (ssid_len != ssid->ssid_len ||
  483. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  484. wpa_printf(MSG_DEBUG, " skip - "
  485. "SSID mismatch");
  486. continue;
  487. }
  488. if (ssid->bssid_set &&
  489. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
  490. {
  491. wpa_printf(MSG_DEBUG, " skip - "
  492. "BSSID mismatch");
  493. continue;
  494. }
  495. if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  496. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  497. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
  498. {
  499. wpa_printf(MSG_DEBUG, " skip - "
  500. "non-WPA network not allowed");
  501. continue;
  502. }
  503. if ((ssid->key_mgmt &
  504. (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
  505. WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK |
  506. WPA_KEY_MGMT_IEEE8021X_SHA256 |
  507. WPA_KEY_MGMT_PSK_SHA256)) &&
  508. (wpa_ie_len != 0 || rsn_ie_len != 0)) {
  509. wpa_printf(MSG_DEBUG, " skip - "
  510. "WPA network");
  511. continue;
  512. }
  513. if (!wpa_supplicant_match_privacy(bss, ssid)) {
  514. wpa_printf(MSG_DEBUG, " skip - "
  515. "privacy mismatch");
  516. continue;
  517. }
  518. if (bss->caps & IEEE80211_CAP_IBSS) {
  519. wpa_printf(MSG_DEBUG, " skip - "
  520. "IBSS (adhoc) network");
  521. continue;
  522. }
  523. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  524. wpa_printf(MSG_DEBUG, " skip - "
  525. "frequency not allowed");
  526. continue;
  527. }
  528. wpa_printf(MSG_DEBUG, " selected non-WPA AP "
  529. MACSTR " ssid='%s'",
  530. MAC2STR(bss->bssid),
  531. wpa_ssid_txt(ssid_, ssid_len));
  532. *selected_ssid = ssid;
  533. return wpa_bss_get(wpa_s, bss->bssid, ssid_, ssid_len);
  534. }
  535. }
  536. return NULL;
  537. }
  538. static struct wpa_bss *
  539. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  540. struct wpa_scan_results *scan_res,
  541. struct wpa_ssid *group,
  542. struct wpa_ssid **selected_ssid)
  543. {
  544. struct wpa_bss *selected;
  545. wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
  546. group->priority);
  547. /* First, try to find WPA-enabled AP */
  548. selected = wpa_supplicant_select_bss_wpa(wpa_s, scan_res, group,
  549. selected_ssid);
  550. if (selected)
  551. return selected;
  552. /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
  553. * allows this. */
  554. return wpa_supplicant_select_bss_non_wpa(wpa_s, scan_res, group,
  555. selected_ssid);
  556. }
  557. static struct wpa_bss *
  558. wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  559. struct wpa_scan_results *scan_res,
  560. struct wpa_ssid **selected_ssid)
  561. {
  562. struct wpa_bss *selected = NULL;
  563. int prio;
  564. while (selected == NULL) {
  565. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  566. selected = wpa_supplicant_select_bss(
  567. wpa_s, scan_res, wpa_s->conf->pssid[prio],
  568. selected_ssid);
  569. if (selected)
  570. break;
  571. }
  572. if (selected == NULL && wpa_s->blacklist) {
  573. wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
  574. "and try again");
  575. wpa_blacklist_clear(wpa_s);
  576. wpa_s->blacklist_cleared++;
  577. } else if (selected == NULL)
  578. break;
  579. }
  580. return selected;
  581. }
  582. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  583. int timeout_sec, int timeout_usec)
  584. {
  585. if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
  586. /*
  587. * Quick recovery if the initial scan results were not
  588. * complete when fetched before the first scan request.
  589. */
  590. wpa_s->scan_res_tried++;
  591. timeout_sec = 0;
  592. timeout_usec = 0;
  593. } else if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
  594. /*
  595. * No networks are enabled; short-circuit request so
  596. * we don't wait timeout seconds before transitioning
  597. * to INACTIVE state.
  598. */
  599. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  600. return;
  601. }
  602. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  603. }
  604. void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  605. struct wpa_bss *selected,
  606. struct wpa_ssid *ssid)
  607. {
  608. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  609. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  610. "PBC session overlap");
  611. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  612. return;
  613. }
  614. /*
  615. * Do not trigger new association unless the BSSID has changed or if
  616. * reassociation is requested. If we are in process of associating with
  617. * the selected BSSID, do not trigger new attempt.
  618. */
  619. if (wpa_s->reassociate ||
  620. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  621. (wpa_s->wpa_state != WPA_ASSOCIATING ||
  622. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  623. 0))) {
  624. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  625. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  626. return;
  627. }
  628. wpa_supplicant_associate(wpa_s, selected, ssid);
  629. } else {
  630. wpa_printf(MSG_DEBUG, "Already associated with the selected "
  631. "AP");
  632. }
  633. }
  634. static struct wpa_ssid *
  635. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  636. {
  637. int prio;
  638. struct wpa_ssid *ssid;
  639. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  640. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  641. {
  642. if (ssid->disabled)
  643. continue;
  644. if (ssid->mode == IEEE80211_MODE_IBSS ||
  645. ssid->mode == IEEE80211_MODE_AP)
  646. return ssid;
  647. }
  648. }
  649. return NULL;
  650. }
  651. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  652. * on BSS added and BSS changed events */
  653. static void wpa_supplicant_rsn_preauth_scan_results(
  654. struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
  655. {
  656. int i;
  657. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  658. return;
  659. for (i = scan_res->num - 1; i >= 0; i--) {
  660. const u8 *ssid, *rsn;
  661. struct wpa_scan_res *r;
  662. r = scan_res->res[i];
  663. ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
  664. if (ssid == NULL)
  665. continue;
  666. rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
  667. if (rsn == NULL)
  668. continue;
  669. rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
  670. }
  671. }
  672. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  673. struct wpa_bss *selected,
  674. struct wpa_ssid *ssid,
  675. struct wpa_scan_results *scan_res)
  676. {
  677. size_t i;
  678. struct wpa_scan_res *current_bss = NULL;
  679. int min_diff;
  680. if (wpa_s->reassociate)
  681. return 1; /* explicit request to reassociate */
  682. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  683. return 1; /* we are not associated; continue */
  684. if (wpa_s->current_ssid == NULL)
  685. return 1; /* unknown current SSID */
  686. if (wpa_s->current_ssid != ssid)
  687. return 1; /* different network block */
  688. for (i = 0; i < scan_res->num; i++) {
  689. struct wpa_scan_res *res = scan_res->res[i];
  690. const u8 *ie;
  691. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  692. continue;
  693. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  694. if (ie == NULL)
  695. continue;
  696. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  697. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  698. continue;
  699. current_bss = res;
  700. break;
  701. }
  702. if (!current_bss)
  703. return 1; /* current BSS not seen in scan results */
  704. wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
  705. wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  706. MAC2STR(current_bss->bssid), current_bss->level);
  707. wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  708. MAC2STR(selected->bssid), selected->level);
  709. if (wpa_s->current_ssid->bssid_set &&
  710. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  711. 0) {
  712. wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
  713. "preferred BSSID");
  714. return 1;
  715. }
  716. min_diff = 2;
  717. if (current_bss->level < 0) {
  718. if (current_bss->level < -85)
  719. min_diff = 1;
  720. else if (current_bss->level < -80)
  721. min_diff = 2;
  722. else if (current_bss->level < -75)
  723. min_diff = 3;
  724. else if (current_bss->level < -70)
  725. min_diff = 4;
  726. else
  727. min_diff = 5;
  728. }
  729. if (abs(current_bss->level - selected->level) < min_diff) {
  730. wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
  731. "signal level");
  732. return 0;
  733. }
  734. return 1;
  735. }
  736. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  737. union wpa_event_data *data)
  738. {
  739. struct wpa_bss *selected;
  740. struct wpa_ssid *ssid = NULL;
  741. struct wpa_scan_results *scan_res;
  742. wpa_supplicant_notify_scanning(wpa_s, 0);
  743. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  744. data ? &data->scan_info :
  745. NULL, 1);
  746. if (scan_res == NULL) {
  747. if (wpa_s->conf->ap_scan == 2)
  748. return;
  749. wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
  750. "scanning again");
  751. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  752. return;
  753. }
  754. if (wpa_s->scan_res_handler) {
  755. wpa_s->scan_res_handler(wpa_s, scan_res);
  756. wpa_s->scan_res_handler = NULL;
  757. wpa_scan_results_free(scan_res);
  758. return;
  759. }
  760. /*
  761. * Don't post the results if this was the initial cached
  762. * and there were no results.
  763. */
  764. if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 &&
  765. scan_res->num == 0) {
  766. wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are "
  767. "empty - not posting");
  768. } else {
  769. wpa_printf(MSG_DEBUG, "New scan results available");
  770. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  771. wpas_notify_scan_results(wpa_s);
  772. }
  773. wpas_notify_scan_done(wpa_s, 1);
  774. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  775. wpa_scan_results_free(scan_res);
  776. return;
  777. }
  778. if (wpa_s->disconnected) {
  779. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  780. wpa_scan_results_free(scan_res);
  781. return;
  782. }
  783. if (bgscan_notify_scan(wpa_s) == 1) {
  784. wpa_scan_results_free(scan_res);
  785. return;
  786. }
  787. wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
  788. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  789. if (selected) {
  790. int skip;
  791. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  792. scan_res);
  793. wpa_scan_results_free(scan_res);
  794. if (skip)
  795. return;
  796. wpa_supplicant_connect(wpa_s, selected, ssid);
  797. } else {
  798. wpa_scan_results_free(scan_res);
  799. wpa_printf(MSG_DEBUG, "No suitable network found");
  800. ssid = wpa_supplicant_pick_new_network(wpa_s);
  801. if (ssid) {
  802. wpa_printf(MSG_DEBUG, "Setup a new network");
  803. wpa_supplicant_associate(wpa_s, NULL, ssid);
  804. } else {
  805. int timeout_sec = 5;
  806. int timeout_usec = 0;
  807. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  808. timeout_usec);
  809. }
  810. }
  811. }
  812. #endif /* CONFIG_NO_SCAN_PROCESSING */
  813. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  814. union wpa_event_data *data)
  815. {
  816. int l, len, found = 0, wpa_found, rsn_found;
  817. const u8 *p;
  818. wpa_printf(MSG_DEBUG, "Association info event");
  819. if (data->assoc_info.req_ies)
  820. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  821. data->assoc_info.req_ies_len);
  822. if (data->assoc_info.resp_ies)
  823. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  824. data->assoc_info.resp_ies_len);
  825. if (data->assoc_info.beacon_ies)
  826. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  827. data->assoc_info.beacon_ies,
  828. data->assoc_info.beacon_ies_len);
  829. if (data->assoc_info.freq)
  830. wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
  831. p = data->assoc_info.req_ies;
  832. l = data->assoc_info.req_ies_len;
  833. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  834. while (p && l >= 2) {
  835. len = p[1] + 2;
  836. if (len > l) {
  837. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  838. p, l);
  839. break;
  840. }
  841. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  842. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  843. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  844. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  845. break;
  846. found = 1;
  847. wpa_find_assoc_pmkid(wpa_s);
  848. break;
  849. }
  850. l -= len;
  851. p += len;
  852. }
  853. if (!found && data->assoc_info.req_ies)
  854. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  855. #ifdef CONFIG_IEEE80211R
  856. #ifdef CONFIG_SME
  857. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  858. u8 bssid[ETH_ALEN];
  859. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  860. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  861. data->assoc_info.resp_ies,
  862. data->assoc_info.resp_ies_len,
  863. bssid) < 0) {
  864. wpa_printf(MSG_DEBUG, "FT: Validation of "
  865. "Reassociation Response failed");
  866. wpa_supplicant_deauthenticate(
  867. wpa_s, WLAN_REASON_INVALID_IE);
  868. return -1;
  869. }
  870. }
  871. p = data->assoc_info.resp_ies;
  872. l = data->assoc_info.resp_ies_len;
  873. /* Go through the IEs and make a copy of the MDIE, if present. */
  874. while (p && l >= 2) {
  875. len = p[1] + 2;
  876. if (len > l) {
  877. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  878. p, l);
  879. break;
  880. }
  881. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  882. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  883. wpa_s->sme.ft_used = 1;
  884. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  885. MOBILITY_DOMAIN_ID_LEN);
  886. break;
  887. }
  888. l -= len;
  889. p += len;
  890. }
  891. #endif /* CONFIG_SME */
  892. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  893. data->assoc_info.resp_ies_len);
  894. #endif /* CONFIG_IEEE80211R */
  895. /* WPA/RSN IE from Beacon/ProbeResp */
  896. p = data->assoc_info.beacon_ies;
  897. l = data->assoc_info.beacon_ies_len;
  898. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  899. */
  900. wpa_found = rsn_found = 0;
  901. while (p && l >= 2) {
  902. len = p[1] + 2;
  903. if (len > l) {
  904. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  905. p, l);
  906. break;
  907. }
  908. if (!wpa_found &&
  909. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  910. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  911. wpa_found = 1;
  912. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  913. }
  914. if (!rsn_found &&
  915. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  916. rsn_found = 1;
  917. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  918. }
  919. l -= len;
  920. p += len;
  921. }
  922. if (!wpa_found && data->assoc_info.beacon_ies)
  923. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  924. if (!rsn_found && data->assoc_info.beacon_ies)
  925. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  926. if (wpa_found || rsn_found)
  927. wpa_s->ap_ies_from_associnfo = 1;
  928. wpa_s->assoc_freq = data->assoc_info.freq;
  929. return 0;
  930. }
  931. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  932. union wpa_event_data *data)
  933. {
  934. u8 bssid[ETH_ALEN];
  935. int ft_completed;
  936. int bssid_changed;
  937. struct wpa_driver_capa capa;
  938. #ifdef CONFIG_AP
  939. if (wpa_s->ap_iface) {
  940. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  941. data->assoc_info.addr,
  942. data->assoc_info.req_ies,
  943. data->assoc_info.req_ies_len);
  944. return;
  945. }
  946. #endif /* CONFIG_AP */
  947. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  948. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  949. return;
  950. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  951. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  952. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  953. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  954. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  955. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  956. wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  957. MACSTR, MAC2STR(bssid));
  958. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  959. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  960. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  961. if (bssid_changed)
  962. wpas_notify_bssid_changed(wpa_s);
  963. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  964. wpa_clear_keys(wpa_s, bssid);
  965. }
  966. if (wpa_supplicant_select_config(wpa_s) < 0) {
  967. wpa_supplicant_disassociate(
  968. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  969. return;
  970. }
  971. if (wpa_s->current_ssid) {
  972. struct wpa_bss *bss = NULL;
  973. struct wpa_ssid *ssid = wpa_s->current_ssid;
  974. if (ssid->ssid_len > 0)
  975. bss = wpa_bss_get(wpa_s, bssid,
  976. ssid->ssid, ssid->ssid_len);
  977. if (!bss)
  978. bss = wpa_bss_get_bssid(wpa_s, bssid);
  979. if (bss)
  980. wpa_s->current_bss = bss;
  981. }
  982. }
  983. #ifdef CONFIG_SME
  984. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  985. wpa_s->sme.prev_bssid_set = 1;
  986. #endif /* CONFIG_SME */
  987. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  988. if (wpa_s->current_ssid) {
  989. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  990. * initialized before association, but for other modes,
  991. * initialize PC/SC here, if the current configuration needs
  992. * smartcard or SIM/USIM. */
  993. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  994. }
  995. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  996. l2_packet_notify_auth_start(wpa_s->l2);
  997. /*
  998. * Set portEnabled first to FALSE in order to get EAP state machine out
  999. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1000. * state machine may transit to AUTHENTICATING state based on obsolete
  1001. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1002. * AUTHENTICATED without ever giving chance to EAP state machine to
  1003. * reset the state.
  1004. */
  1005. if (!ft_completed) {
  1006. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1007. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1008. }
  1009. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1010. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1011. /* 802.1X::portControl = Auto */
  1012. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1013. wpa_s->eapol_received = 0;
  1014. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1015. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1016. (wpa_s->current_ssid &&
  1017. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1018. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1019. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1020. } else if (!ft_completed) {
  1021. /* Timeout for receiving the first EAPOL packet */
  1022. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1023. }
  1024. wpa_supplicant_cancel_scan(wpa_s);
  1025. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1026. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1027. /*
  1028. * We are done; the driver will take care of RSN 4-way
  1029. * handshake.
  1030. */
  1031. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1032. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1033. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1034. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1035. }
  1036. if (wpa_s->pending_eapol_rx) {
  1037. struct os_time now, age;
  1038. os_get_time(&now);
  1039. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1040. if (age.sec == 0 && age.usec < 100000 &&
  1041. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1042. 0) {
  1043. wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
  1044. "that was received just before association "
  1045. "notification");
  1046. wpa_supplicant_rx_eapol(
  1047. wpa_s, wpa_s->pending_eapol_rx_src,
  1048. wpabuf_head(wpa_s->pending_eapol_rx),
  1049. wpabuf_len(wpa_s->pending_eapol_rx));
  1050. }
  1051. wpabuf_free(wpa_s->pending_eapol_rx);
  1052. wpa_s->pending_eapol_rx = NULL;
  1053. }
  1054. #ifdef CONFIG_BGSCAN
  1055. if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
  1056. bgscan_deinit(wpa_s);
  1057. if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
  1058. if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
  1059. wpa_printf(MSG_DEBUG, "Failed to initialize "
  1060. "bgscan");
  1061. /*
  1062. * Live without bgscan; it is only used as a
  1063. * roaming optimization, so the initial
  1064. * connection is not affected.
  1065. */
  1066. } else
  1067. wpa_s->bgscan_ssid = wpa_s->current_ssid;
  1068. } else
  1069. wpa_s->bgscan_ssid = NULL;
  1070. }
  1071. #endif /* CONFIG_BGSCAN */
  1072. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1073. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1074. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1075. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1076. /* Set static WEP keys again */
  1077. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1078. }
  1079. }
  1080. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1081. u16 reason_code)
  1082. {
  1083. const u8 *bssid;
  1084. #ifdef CONFIG_SME
  1085. int authenticating;
  1086. u8 prev_pending_bssid[ETH_ALEN];
  1087. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1088. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1089. #endif /* CONFIG_SME */
  1090. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1091. /*
  1092. * At least Host AP driver and a Prism3 card seemed to be
  1093. * generating streams of disconnected events when configuring
  1094. * IBSS for WPA-None. Ignore them for now.
  1095. */
  1096. wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
  1097. "IBSS/WPA-None mode");
  1098. return;
  1099. }
  1100. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1101. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1102. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1103. "pre-shared key may be incorrect");
  1104. }
  1105. if (wpa_s->wpa_state >= WPA_ASSOCIATED)
  1106. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1107. bssid = wpa_s->bssid;
  1108. if (is_zero_ether_addr(bssid))
  1109. bssid = wpa_s->pending_bssid;
  1110. wpa_blacklist_add(wpa_s, bssid);
  1111. wpa_sm_notify_disassoc(wpa_s->wpa);
  1112. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1113. " reason=%d",
  1114. MAC2STR(bssid), reason_code);
  1115. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1116. wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
  1117. wpa_s->keys_cleared = 0;
  1118. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1119. }
  1120. wpa_supplicant_mark_disassoc(wpa_s);
  1121. bgscan_deinit(wpa_s);
  1122. #ifdef CONFIG_SME
  1123. if (authenticating &&
  1124. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
  1125. /*
  1126. * mac80211-workaround to force deauth on failed auth cmd,
  1127. * requires us to remain in authenticating state to allow the
  1128. * second authentication attempt to be continued properly.
  1129. */
  1130. wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
  1131. "proceed after disconnection event");
  1132. wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
  1133. os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
  1134. }
  1135. #endif /* CONFIG_SME */
  1136. }
  1137. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1138. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1139. void *sock_ctx)
  1140. {
  1141. struct wpa_supplicant *wpa_s = eloop_ctx;
  1142. if (!wpa_s->pending_mic_error_report)
  1143. return;
  1144. wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
  1145. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1146. wpa_s->pending_mic_error_report = 0;
  1147. }
  1148. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1149. static void
  1150. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1151. union wpa_event_data *data)
  1152. {
  1153. int pairwise;
  1154. struct os_time t;
  1155. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1156. pairwise = (data && data->michael_mic_failure.unicast);
  1157. os_get_time(&t);
  1158. if ((wpa_s->last_michael_mic_error &&
  1159. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1160. wpa_s->pending_mic_error_report) {
  1161. if (wpa_s->pending_mic_error_report) {
  1162. /*
  1163. * Send the pending MIC error report immediately since
  1164. * we are going to start countermeasures and AP better
  1165. * do the same.
  1166. */
  1167. wpa_sm_key_request(wpa_s->wpa, 1,
  1168. wpa_s->pending_mic_error_pairwise);
  1169. }
  1170. /* Send the new MIC error report immediately since we are going
  1171. * to start countermeasures and AP better do the same.
  1172. */
  1173. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1174. /* initialize countermeasures */
  1175. wpa_s->countermeasures = 1;
  1176. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1177. /*
  1178. * Need to wait for completion of request frame. We do not get
  1179. * any callback for the message completion, so just wait a
  1180. * short while and hope for the best. */
  1181. os_sleep(0, 10000);
  1182. wpa_drv_set_countermeasures(wpa_s, 1);
  1183. wpa_supplicant_deauthenticate(wpa_s,
  1184. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1185. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1186. wpa_s, NULL);
  1187. eloop_register_timeout(60, 0,
  1188. wpa_supplicant_stop_countermeasures,
  1189. wpa_s, NULL);
  1190. /* TODO: mark the AP rejected for 60 second. STA is
  1191. * allowed to associate with another AP.. */
  1192. } else {
  1193. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1194. if (wpa_s->mic_errors_seen) {
  1195. /*
  1196. * Reduce the effectiveness of Michael MIC error
  1197. * reports as a means for attacking against TKIP if
  1198. * more than one MIC failure is noticed with the same
  1199. * PTK. We delay the transmission of the reports by a
  1200. * random time between 0 and 60 seconds in order to
  1201. * force the attacker wait 60 seconds before getting
  1202. * the information on whether a frame resulted in a MIC
  1203. * failure.
  1204. */
  1205. u8 rval[4];
  1206. int sec;
  1207. if (os_get_random(rval, sizeof(rval)) < 0)
  1208. sec = os_random() % 60;
  1209. else
  1210. sec = WPA_GET_BE32(rval) % 60;
  1211. wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
  1212. "seconds", sec);
  1213. wpa_s->pending_mic_error_report = 1;
  1214. wpa_s->pending_mic_error_pairwise = pairwise;
  1215. eloop_cancel_timeout(
  1216. wpa_supplicant_delayed_mic_error_report,
  1217. wpa_s, NULL);
  1218. eloop_register_timeout(
  1219. sec, os_random() % 1000000,
  1220. wpa_supplicant_delayed_mic_error_report,
  1221. wpa_s, NULL);
  1222. } else {
  1223. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1224. }
  1225. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1226. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1227. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1228. }
  1229. wpa_s->last_michael_mic_error = t.sec;
  1230. wpa_s->mic_errors_seen++;
  1231. }
  1232. #ifdef CONFIG_TERMINATE_ONLASTIF
  1233. static int any_interfaces(struct wpa_supplicant *head)
  1234. {
  1235. struct wpa_supplicant *wpa_s;
  1236. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1237. if (!wpa_s->interface_removed)
  1238. return 1;
  1239. return 0;
  1240. }
  1241. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1242. static void
  1243. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1244. union wpa_event_data *data)
  1245. {
  1246. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1247. return;
  1248. switch (data->interface_status.ievent) {
  1249. case EVENT_INTERFACE_ADDED:
  1250. if (!wpa_s->interface_removed)
  1251. break;
  1252. wpa_s->interface_removed = 0;
  1253. wpa_printf(MSG_DEBUG, "Configured interface was added.");
  1254. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1255. wpa_printf(MSG_INFO, "Failed to initialize the driver "
  1256. "after interface was added.");
  1257. }
  1258. break;
  1259. case EVENT_INTERFACE_REMOVED:
  1260. wpa_printf(MSG_DEBUG, "Configured interface was removed.");
  1261. wpa_s->interface_removed = 1;
  1262. wpa_supplicant_mark_disassoc(wpa_s);
  1263. l2_packet_deinit(wpa_s->l2);
  1264. wpa_s->l2 = NULL;
  1265. #ifdef CONFIG_TERMINATE_ONLASTIF
  1266. /* check if last interface */
  1267. if (!any_interfaces(wpa_s->global->ifaces))
  1268. eloop_terminate();
  1269. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1270. break;
  1271. }
  1272. }
  1273. #ifdef CONFIG_PEERKEY
  1274. static void
  1275. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1276. union wpa_event_data *data)
  1277. {
  1278. if (data == NULL)
  1279. return;
  1280. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1281. }
  1282. #endif /* CONFIG_PEERKEY */
  1283. #ifdef CONFIG_IEEE80211R
  1284. static void
  1285. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1286. union wpa_event_data *data)
  1287. {
  1288. if (data == NULL)
  1289. return;
  1290. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1291. data->ft_ies.ies_len,
  1292. data->ft_ies.ft_action,
  1293. data->ft_ies.target_ap,
  1294. data->ft_ies.ric_ies,
  1295. data->ft_ies.ric_ies_len) < 0) {
  1296. /* TODO: prevent MLME/driver from trying to associate? */
  1297. }
  1298. }
  1299. #endif /* CONFIG_IEEE80211R */
  1300. #ifdef CONFIG_IBSS_RSN
  1301. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1302. union wpa_event_data *data)
  1303. {
  1304. if (data == NULL)
  1305. return;
  1306. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1307. }
  1308. #endif /* CONFIG_IBSS_RSN */
  1309. #ifdef CONFIG_IEEE80211R
  1310. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1311. size_t len)
  1312. {
  1313. const u8 *sta_addr, *target_ap_addr;
  1314. u16 status;
  1315. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1316. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1317. return; /* only SME case supported for now */
  1318. if (len < 1 + 2 * ETH_ALEN + 2)
  1319. return;
  1320. if (data[0] != 2)
  1321. return; /* Only FT Action Response is supported for now */
  1322. sta_addr = data + 1;
  1323. target_ap_addr = data + 1 + ETH_ALEN;
  1324. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1325. wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
  1326. " TargetAP " MACSTR " status %u",
  1327. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1328. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1329. wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1330. " in FT Action Response", MAC2STR(sta_addr));
  1331. return;
  1332. }
  1333. if (status) {
  1334. wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
  1335. "failure (status code %d)", status);
  1336. /* TODO: report error to FT code(?) */
  1337. return;
  1338. }
  1339. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1340. len - (1 + 2 * ETH_ALEN + 2), 1,
  1341. target_ap_addr, NULL, 0) < 0)
  1342. return;
  1343. #ifdef CONFIG_SME
  1344. {
  1345. struct wpa_bss *bss;
  1346. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1347. if (bss)
  1348. wpa_s->sme.freq = bss->freq;
  1349. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1350. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1351. WLAN_AUTH_FT);
  1352. }
  1353. #endif /* CONFIG_SME */
  1354. }
  1355. #endif /* CONFIG_IEEE80211R */
  1356. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1357. union wpa_event_data *data)
  1358. {
  1359. struct wpa_supplicant *wpa_s = ctx;
  1360. u16 reason_code = 0;
  1361. switch (event) {
  1362. case EVENT_AUTH:
  1363. sme_event_auth(wpa_s, data);
  1364. break;
  1365. case EVENT_ASSOC:
  1366. wpa_supplicant_event_assoc(wpa_s, data);
  1367. break;
  1368. case EVENT_DISASSOC:
  1369. wpa_printf(MSG_DEBUG, "Disassociation notification");
  1370. #ifdef CONFIG_AP
  1371. if (wpa_s->ap_iface && data) {
  1372. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1373. data->disassoc_info.addr);
  1374. break;
  1375. }
  1376. #endif /* CONFIG_AP */
  1377. if (data)
  1378. reason_code = data->deauth_info.reason_code;
  1379. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1380. sme_event_disassoc(wpa_s, data);
  1381. /* fall through */
  1382. case EVENT_DEAUTH:
  1383. if (event == EVENT_DEAUTH) {
  1384. wpa_printf(MSG_DEBUG, "Deauthentication notification");
  1385. if (data)
  1386. reason_code = data->deauth_info.reason_code;
  1387. }
  1388. #ifdef CONFIG_AP
  1389. if (wpa_s->ap_iface && data) {
  1390. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1391. data->deauth_info.addr);
  1392. break;
  1393. }
  1394. #endif /* CONFIG_AP */
  1395. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1396. break;
  1397. case EVENT_MICHAEL_MIC_FAILURE:
  1398. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1399. break;
  1400. #ifndef CONFIG_NO_SCAN_PROCESSING
  1401. case EVENT_SCAN_RESULTS:
  1402. wpa_supplicant_event_scan_results(wpa_s, data);
  1403. break;
  1404. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1405. case EVENT_ASSOCINFO:
  1406. wpa_supplicant_event_associnfo(wpa_s, data);
  1407. break;
  1408. case EVENT_INTERFACE_STATUS:
  1409. wpa_supplicant_event_interface_status(wpa_s, data);
  1410. break;
  1411. case EVENT_PMKID_CANDIDATE:
  1412. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1413. break;
  1414. #ifdef CONFIG_PEERKEY
  1415. case EVENT_STKSTART:
  1416. wpa_supplicant_event_stkstart(wpa_s, data);
  1417. break;
  1418. #endif /* CONFIG_PEERKEY */
  1419. #ifdef CONFIG_IEEE80211R
  1420. case EVENT_FT_RESPONSE:
  1421. wpa_supplicant_event_ft_response(wpa_s, data);
  1422. break;
  1423. #endif /* CONFIG_IEEE80211R */
  1424. #ifdef CONFIG_IBSS_RSN
  1425. case EVENT_IBSS_RSN_START:
  1426. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1427. break;
  1428. #endif /* CONFIG_IBSS_RSN */
  1429. case EVENT_ASSOC_REJECT:
  1430. sme_event_assoc_reject(wpa_s, data);
  1431. break;
  1432. case EVENT_AUTH_TIMED_OUT:
  1433. sme_event_auth_timed_out(wpa_s, data);
  1434. break;
  1435. case EVENT_ASSOC_TIMED_OUT:
  1436. sme_event_assoc_timed_out(wpa_s, data);
  1437. break;
  1438. #ifdef CONFIG_AP
  1439. case EVENT_TX_STATUS:
  1440. if (wpa_s->ap_iface == NULL)
  1441. break;
  1442. switch (data->tx_status.type) {
  1443. case WLAN_FC_TYPE_MGMT:
  1444. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1445. data->tx_status.data_len,
  1446. data->tx_status.stype,
  1447. data->tx_status.ack);
  1448. break;
  1449. case WLAN_FC_TYPE_DATA:
  1450. ap_tx_status(wpa_s, data->tx_status.dst,
  1451. data->tx_status.data,
  1452. data->tx_status.data_len,
  1453. data->tx_status.ack);
  1454. break;
  1455. }
  1456. break;
  1457. case EVENT_RX_FROM_UNKNOWN:
  1458. if (wpa_s->ap_iface == NULL)
  1459. break;
  1460. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1461. data->rx_from_unknown.len);
  1462. break;
  1463. case EVENT_RX_MGMT:
  1464. if (wpa_s->ap_iface == NULL)
  1465. break;
  1466. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1467. break;
  1468. #endif /* CONFIG_AP */
  1469. case EVENT_RX_ACTION:
  1470. wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1471. " Category=%u DataLen=%d freq=%d MHz",
  1472. MAC2STR(data->rx_action.sa),
  1473. data->rx_action.category, (int) data->rx_action.len,
  1474. data->rx_action.freq);
  1475. #ifdef CONFIG_IEEE80211R
  1476. if (data->rx_action.category == WLAN_ACTION_FT) {
  1477. ft_rx_action(wpa_s, data->rx_action.data,
  1478. data->rx_action.len);
  1479. break;
  1480. }
  1481. #endif /* CONFIG_IEEE80211R */
  1482. break;
  1483. #ifdef CONFIG_CLIENT_MLME
  1484. case EVENT_MLME_RX: {
  1485. struct ieee80211_rx_status rx_status;
  1486. os_memset(&rx_status, 0, sizeof(rx_status));
  1487. rx_status.freq = data->mlme_rx.freq;
  1488. rx_status.channel = data->mlme_rx.channel;
  1489. rx_status.ssi = data->mlme_rx.ssi;
  1490. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1491. &rx_status);
  1492. break;
  1493. }
  1494. #endif /* CONFIG_CLIENT_MLME */
  1495. case EVENT_EAPOL_RX:
  1496. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1497. data->eapol_rx.data,
  1498. data->eapol_rx.data_len);
  1499. break;
  1500. case EVENT_SIGNAL_CHANGE:
  1501. bgscan_notify_signal_change(
  1502. wpa_s, data->signal_change.above_threshold);
  1503. break;
  1504. default:
  1505. wpa_printf(MSG_INFO, "Unknown event %d", event);
  1506. break;
  1507. }
  1508. }