events.c 47 KB

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