events.c 48 KB

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