events.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  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. #ifdef CONFIG_P2P
  520. if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
  521. return;
  522. #endif /* CONFIG_P2P */
  523. wpas_wps_cancel(wpa_s);
  524. return;
  525. }
  526. /*
  527. * Do not trigger new association unless the BSSID has changed or if
  528. * reassociation is requested. If we are in process of associating with
  529. * the selected BSSID, do not trigger new attempt.
  530. */
  531. if (wpa_s->reassociate ||
  532. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  533. (wpa_s->wpa_state != WPA_ASSOCIATING ||
  534. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  535. 0))) {
  536. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  537. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  538. return;
  539. }
  540. wpa_supplicant_associate(wpa_s, selected, ssid);
  541. } else {
  542. wpa_printf(MSG_DEBUG, "Already associated with the selected "
  543. "AP");
  544. }
  545. }
  546. static struct wpa_ssid *
  547. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  548. {
  549. int prio;
  550. struct wpa_ssid *ssid;
  551. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  552. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  553. {
  554. if (ssid->disabled)
  555. continue;
  556. if (ssid->mode == IEEE80211_MODE_IBSS ||
  557. ssid->mode == IEEE80211_MODE_AP)
  558. return ssid;
  559. }
  560. }
  561. return NULL;
  562. }
  563. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  564. * on BSS added and BSS changed events */
  565. static void wpa_supplicant_rsn_preauth_scan_results(
  566. struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
  567. {
  568. int i;
  569. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  570. return;
  571. for (i = scan_res->num - 1; i >= 0; i--) {
  572. const u8 *ssid, *rsn;
  573. struct wpa_scan_res *r;
  574. r = scan_res->res[i];
  575. ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
  576. if (ssid == NULL)
  577. continue;
  578. rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
  579. if (rsn == NULL)
  580. continue;
  581. rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
  582. }
  583. }
  584. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  585. struct wpa_bss *selected,
  586. struct wpa_ssid *ssid,
  587. struct wpa_scan_results *scan_res)
  588. {
  589. size_t i;
  590. struct wpa_scan_res *current_bss = NULL;
  591. int min_diff;
  592. if (wpa_s->reassociate)
  593. return 1; /* explicit request to reassociate */
  594. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  595. return 1; /* we are not associated; continue */
  596. if (wpa_s->current_ssid == NULL)
  597. return 1; /* unknown current SSID */
  598. if (wpa_s->current_ssid != ssid)
  599. return 1; /* different network block */
  600. for (i = 0; i < scan_res->num; i++) {
  601. struct wpa_scan_res *res = scan_res->res[i];
  602. const u8 *ie;
  603. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  604. continue;
  605. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  606. if (ie == NULL)
  607. continue;
  608. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  609. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  610. continue;
  611. current_bss = res;
  612. break;
  613. }
  614. if (!current_bss)
  615. return 1; /* current BSS not seen in scan results */
  616. wpa_printf(MSG_DEBUG, "Considering within-ESS reassociation");
  617. wpa_printf(MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  618. MAC2STR(current_bss->bssid), current_bss->level);
  619. wpa_printf(MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  620. MAC2STR(selected->bssid), selected->level);
  621. if (wpa_s->current_ssid->bssid_set &&
  622. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  623. 0) {
  624. wpa_printf(MSG_DEBUG, "Allow reassociation - selected BSS has "
  625. "preferred BSSID");
  626. return 1;
  627. }
  628. min_diff = 2;
  629. if (current_bss->level < 0) {
  630. if (current_bss->level < -85)
  631. min_diff = 1;
  632. else if (current_bss->level < -80)
  633. min_diff = 2;
  634. else if (current_bss->level < -75)
  635. min_diff = 3;
  636. else if (current_bss->level < -70)
  637. min_diff = 4;
  638. else
  639. min_diff = 5;
  640. }
  641. if (abs(current_bss->level - selected->level) < min_diff) {
  642. wpa_printf(MSG_DEBUG, "Skip roam - too small difference in "
  643. "signal level");
  644. return 0;
  645. }
  646. return 1;
  647. }
  648. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  649. union wpa_event_data *data)
  650. {
  651. struct wpa_bss *selected;
  652. struct wpa_ssid *ssid = NULL;
  653. struct wpa_scan_results *scan_res;
  654. int ap = 0;
  655. #ifdef CONFIG_AP
  656. if (wpa_s->ap_iface)
  657. ap = 1;
  658. #endif /* CONFIG_AP */
  659. wpa_supplicant_notify_scanning(wpa_s, 0);
  660. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  661. data ? &data->scan_info :
  662. NULL, 1);
  663. if (scan_res == NULL) {
  664. if (wpa_s->conf->ap_scan == 2 || ap)
  665. return;
  666. wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
  667. "scanning again");
  668. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  669. return;
  670. }
  671. if (wpa_s->scan_res_handler) {
  672. wpa_s->scan_res_handler(wpa_s, scan_res);
  673. wpa_s->scan_res_handler = NULL;
  674. wpa_scan_results_free(scan_res);
  675. return;
  676. }
  677. if (ap) {
  678. wpa_printf(MSG_DEBUG, "Ignore scan results in AP mode");
  679. wpa_scan_results_free(scan_res);
  680. return;
  681. }
  682. wpa_printf(MSG_DEBUG, "New scan results available");
  683. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  684. wpas_notify_scan_results(wpa_s);
  685. wpas_notify_scan_done(wpa_s, 1);
  686. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  687. wpa_scan_results_free(scan_res);
  688. return;
  689. }
  690. if (wpa_s->disconnected) {
  691. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  692. wpa_scan_results_free(scan_res);
  693. return;
  694. }
  695. if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
  696. wpa_scan_results_free(scan_res);
  697. return;
  698. }
  699. wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
  700. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  701. if (selected) {
  702. int skip;
  703. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  704. scan_res);
  705. wpa_scan_results_free(scan_res);
  706. if (skip)
  707. return;
  708. wpa_supplicant_connect(wpa_s, selected, ssid);
  709. } else {
  710. wpa_scan_results_free(scan_res);
  711. wpa_printf(MSG_DEBUG, "No suitable network found");
  712. ssid = wpa_supplicant_pick_new_network(wpa_s);
  713. if (ssid) {
  714. wpa_printf(MSG_DEBUG, "Setup a new network");
  715. wpa_supplicant_associate(wpa_s, NULL, ssid);
  716. } else {
  717. int timeout_sec = 5;
  718. int timeout_usec = 0;
  719. #ifdef CONFIG_P2P
  720. if (wpa_s->p2p_in_provisioning) {
  721. /*
  722. * Use shorter wait during P2P Provisioning
  723. * state to speed up group formation.
  724. */
  725. timeout_sec = 0;
  726. timeout_usec = 250000;
  727. }
  728. #endif /* CONFIG_P2P */
  729. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  730. timeout_usec);
  731. }
  732. }
  733. }
  734. #endif /* CONFIG_NO_SCAN_PROCESSING */
  735. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  736. union wpa_event_data *data)
  737. {
  738. int l, len, found = 0, wpa_found, rsn_found;
  739. const u8 *p;
  740. wpa_printf(MSG_DEBUG, "Association info event");
  741. if (data->assoc_info.req_ies)
  742. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  743. data->assoc_info.req_ies_len);
  744. if (data->assoc_info.resp_ies)
  745. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  746. data->assoc_info.resp_ies_len);
  747. if (data->assoc_info.beacon_ies)
  748. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  749. data->assoc_info.beacon_ies,
  750. data->assoc_info.beacon_ies_len);
  751. if (data->assoc_info.freq)
  752. wpa_printf(MSG_DEBUG, "freq=%u MHz", data->assoc_info.freq);
  753. p = data->assoc_info.req_ies;
  754. l = data->assoc_info.req_ies_len;
  755. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  756. while (p && l >= 2) {
  757. len = p[1] + 2;
  758. if (len > l) {
  759. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  760. p, l);
  761. break;
  762. }
  763. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  764. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  765. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  766. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  767. break;
  768. found = 1;
  769. wpa_find_assoc_pmkid(wpa_s);
  770. break;
  771. }
  772. l -= len;
  773. p += len;
  774. }
  775. if (!found && data->assoc_info.req_ies)
  776. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  777. #ifdef CONFIG_IEEE80211R
  778. #ifdef CONFIG_SME
  779. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  780. u8 bssid[ETH_ALEN];
  781. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  782. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  783. data->assoc_info.resp_ies,
  784. data->assoc_info.resp_ies_len,
  785. bssid) < 0) {
  786. wpa_printf(MSG_DEBUG, "FT: Validation of "
  787. "Reassociation Response failed");
  788. wpa_supplicant_deauthenticate(
  789. wpa_s, WLAN_REASON_INVALID_IE);
  790. return -1;
  791. }
  792. }
  793. p = data->assoc_info.resp_ies;
  794. l = data->assoc_info.resp_ies_len;
  795. #ifdef CONFIG_WPS_STRICT
  796. if (wpa_s->current_ssid &&
  797. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  798. struct wpabuf *wps;
  799. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  800. if (wps == NULL) {
  801. wpa_printf(MSG_INFO, "WPS-STRICT: AP did not include "
  802. "WPS IE in (Re)Association Response");
  803. return -1;
  804. }
  805. if (wps_validate_assoc_resp(wps) < 0) {
  806. wpabuf_free(wps);
  807. wpa_supplicant_deauthenticate(
  808. wpa_s, WLAN_REASON_INVALID_IE);
  809. return -1;
  810. }
  811. wpabuf_free(wps);
  812. }
  813. #endif /* CONFIG_WPS_STRICT */
  814. /* Go through the IEs and make a copy of the MDIE, if present. */
  815. while (p && l >= 2) {
  816. len = p[1] + 2;
  817. if (len > l) {
  818. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  819. p, l);
  820. break;
  821. }
  822. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  823. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  824. wpa_s->sme.ft_used = 1;
  825. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  826. MOBILITY_DOMAIN_ID_LEN);
  827. break;
  828. }
  829. l -= len;
  830. p += len;
  831. }
  832. #endif /* CONFIG_SME */
  833. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  834. data->assoc_info.resp_ies_len);
  835. #endif /* CONFIG_IEEE80211R */
  836. /* WPA/RSN IE from Beacon/ProbeResp */
  837. p = data->assoc_info.beacon_ies;
  838. l = data->assoc_info.beacon_ies_len;
  839. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  840. */
  841. wpa_found = rsn_found = 0;
  842. while (p && l >= 2) {
  843. len = p[1] + 2;
  844. if (len > l) {
  845. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  846. p, l);
  847. break;
  848. }
  849. if (!wpa_found &&
  850. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  851. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  852. wpa_found = 1;
  853. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  854. }
  855. if (!rsn_found &&
  856. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  857. rsn_found = 1;
  858. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  859. }
  860. l -= len;
  861. p += len;
  862. }
  863. if (!wpa_found && data->assoc_info.beacon_ies)
  864. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  865. if (!rsn_found && data->assoc_info.beacon_ies)
  866. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  867. if (wpa_found || rsn_found)
  868. wpa_s->ap_ies_from_associnfo = 1;
  869. wpa_s->assoc_freq = data->assoc_info.freq;
  870. return 0;
  871. }
  872. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  873. union wpa_event_data *data)
  874. {
  875. u8 bssid[ETH_ALEN];
  876. int ft_completed;
  877. int bssid_changed;
  878. struct wpa_driver_capa capa;
  879. #ifdef CONFIG_AP
  880. if (wpa_s->ap_iface) {
  881. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  882. data->assoc_info.addr,
  883. data->assoc_info.req_ies,
  884. data->assoc_info.req_ies_len);
  885. return;
  886. }
  887. #endif /* CONFIG_AP */
  888. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  889. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  890. return;
  891. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  892. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  893. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  894. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  895. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  896. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  897. wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  898. MACSTR, MAC2STR(bssid));
  899. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  900. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  901. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  902. if (bssid_changed)
  903. wpas_notify_bssid_changed(wpa_s);
  904. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  905. wpa_clear_keys(wpa_s, bssid);
  906. }
  907. if (wpa_supplicant_select_config(wpa_s) < 0) {
  908. wpa_supplicant_disassociate(
  909. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  910. return;
  911. }
  912. if (wpa_s->current_ssid) {
  913. struct wpa_bss *bss = NULL;
  914. struct wpa_ssid *ssid = wpa_s->current_ssid;
  915. if (ssid->ssid_len > 0)
  916. bss = wpa_bss_get(wpa_s, bssid,
  917. ssid->ssid, ssid->ssid_len);
  918. if (!bss)
  919. bss = wpa_bss_get_bssid(wpa_s, bssid);
  920. if (bss)
  921. wpa_s->current_bss = bss;
  922. }
  923. }
  924. #ifdef CONFIG_SME
  925. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  926. wpa_s->sme.prev_bssid_set = 1;
  927. #endif /* CONFIG_SME */
  928. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  929. if (wpa_s->current_ssid) {
  930. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  931. * initialized before association, but for other modes,
  932. * initialize PC/SC here, if the current configuration needs
  933. * smartcard or SIM/USIM. */
  934. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  935. }
  936. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  937. if (wpa_s->l2)
  938. l2_packet_notify_auth_start(wpa_s->l2);
  939. /*
  940. * Set portEnabled first to FALSE in order to get EAP state machine out
  941. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  942. * state machine may transit to AUTHENTICATING state based on obsolete
  943. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  944. * AUTHENTICATED without ever giving chance to EAP state machine to
  945. * reset the state.
  946. */
  947. if (!ft_completed) {
  948. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  949. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  950. }
  951. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  952. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  953. /* 802.1X::portControl = Auto */
  954. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  955. wpa_s->eapol_received = 0;
  956. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  957. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  958. (wpa_s->current_ssid &&
  959. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  960. wpa_supplicant_cancel_auth_timeout(wpa_s);
  961. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  962. } else if (!ft_completed) {
  963. /* Timeout for receiving the first EAPOL packet */
  964. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  965. }
  966. wpa_supplicant_cancel_scan(wpa_s);
  967. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  968. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  969. /*
  970. * We are done; the driver will take care of RSN 4-way
  971. * handshake.
  972. */
  973. wpa_supplicant_cancel_auth_timeout(wpa_s);
  974. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  975. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  976. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  977. }
  978. if (wpa_s->pending_eapol_rx) {
  979. struct os_time now, age;
  980. os_get_time(&now);
  981. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  982. if (age.sec == 0 && age.usec < 100000 &&
  983. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  984. 0) {
  985. wpa_printf(MSG_DEBUG, "Process pending EAPOL frame "
  986. "that was received just before association "
  987. "notification");
  988. wpa_supplicant_rx_eapol(
  989. wpa_s, wpa_s->pending_eapol_rx_src,
  990. wpabuf_head(wpa_s->pending_eapol_rx),
  991. wpabuf_len(wpa_s->pending_eapol_rx));
  992. }
  993. wpabuf_free(wpa_s->pending_eapol_rx);
  994. wpa_s->pending_eapol_rx = NULL;
  995. }
  996. #ifdef CONFIG_BGSCAN
  997. if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
  998. bgscan_deinit(wpa_s);
  999. if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
  1000. if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
  1001. wpa_printf(MSG_DEBUG, "Failed to initialize "
  1002. "bgscan");
  1003. /*
  1004. * Live without bgscan; it is only used as a
  1005. * roaming optimization, so the initial
  1006. * connection is not affected.
  1007. */
  1008. } else
  1009. wpa_s->bgscan_ssid = wpa_s->current_ssid;
  1010. } else
  1011. wpa_s->bgscan_ssid = NULL;
  1012. }
  1013. #endif /* CONFIG_BGSCAN */
  1014. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1015. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1016. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1017. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1018. /* Set static WEP keys again */
  1019. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1020. }
  1021. }
  1022. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1023. u16 reason_code)
  1024. {
  1025. const u8 *bssid;
  1026. #ifdef CONFIG_SME
  1027. int authenticating;
  1028. u8 prev_pending_bssid[ETH_ALEN];
  1029. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1030. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1031. #endif /* CONFIG_SME */
  1032. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1033. /*
  1034. * At least Host AP driver and a Prism3 card seemed to be
  1035. * generating streams of disconnected events when configuring
  1036. * IBSS for WPA-None. Ignore them for now.
  1037. */
  1038. wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
  1039. "IBSS/WPA-None mode");
  1040. return;
  1041. }
  1042. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1043. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1044. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1045. "pre-shared key may be incorrect");
  1046. }
  1047. if (!wpa_s->auto_reconnect_disabled ||
  1048. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1049. wpa_printf(MSG_DEBUG, "WPA: Auto connect enabled: try to "
  1050. "reconnect (wps=%d)",
  1051. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
  1052. if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1053. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1054. } else {
  1055. wpa_printf(MSG_DEBUG, "WPA: Auto connect disabled: do not try "
  1056. "to re-connect");
  1057. wpa_s->reassociate = 0;
  1058. wpa_s->disconnected = 1;
  1059. }
  1060. bssid = wpa_s->bssid;
  1061. if (is_zero_ether_addr(bssid))
  1062. bssid = wpa_s->pending_bssid;
  1063. wpa_blacklist_add(wpa_s, bssid);
  1064. wpa_sm_notify_disassoc(wpa_s->wpa);
  1065. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1066. " reason=%d",
  1067. MAC2STR(bssid), reason_code);
  1068. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1069. wpa_printf(MSG_DEBUG, "Disconnect event - remove keys");
  1070. wpa_s->keys_cleared = 0;
  1071. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1072. }
  1073. wpa_supplicant_mark_disassoc(wpa_s);
  1074. bgscan_deinit(wpa_s);
  1075. wpa_s->bgscan_ssid = NULL;
  1076. #ifdef CONFIG_SME
  1077. if (authenticating &&
  1078. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
  1079. /*
  1080. * mac80211-workaround to force deauth on failed auth cmd,
  1081. * requires us to remain in authenticating state to allow the
  1082. * second authentication attempt to be continued properly.
  1083. */
  1084. wpa_printf(MSG_DEBUG, "SME: Allow pending authentication to "
  1085. "proceed after disconnection event");
  1086. wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
  1087. os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
  1088. }
  1089. #endif /* CONFIG_SME */
  1090. }
  1091. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1092. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1093. void *sock_ctx)
  1094. {
  1095. struct wpa_supplicant *wpa_s = eloop_ctx;
  1096. if (!wpa_s->pending_mic_error_report)
  1097. return;
  1098. wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
  1099. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1100. wpa_s->pending_mic_error_report = 0;
  1101. }
  1102. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1103. static void
  1104. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1105. union wpa_event_data *data)
  1106. {
  1107. int pairwise;
  1108. struct os_time t;
  1109. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1110. pairwise = (data && data->michael_mic_failure.unicast);
  1111. os_get_time(&t);
  1112. if ((wpa_s->last_michael_mic_error &&
  1113. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1114. wpa_s->pending_mic_error_report) {
  1115. if (wpa_s->pending_mic_error_report) {
  1116. /*
  1117. * Send the pending MIC error report immediately since
  1118. * we are going to start countermeasures and AP better
  1119. * do the same.
  1120. */
  1121. wpa_sm_key_request(wpa_s->wpa, 1,
  1122. wpa_s->pending_mic_error_pairwise);
  1123. }
  1124. /* Send the new MIC error report immediately since we are going
  1125. * to start countermeasures and AP better do the same.
  1126. */
  1127. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1128. /* initialize countermeasures */
  1129. wpa_s->countermeasures = 1;
  1130. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1131. /*
  1132. * Need to wait for completion of request frame. We do not get
  1133. * any callback for the message completion, so just wait a
  1134. * short while and hope for the best. */
  1135. os_sleep(0, 10000);
  1136. wpa_drv_set_countermeasures(wpa_s, 1);
  1137. wpa_supplicant_deauthenticate(wpa_s,
  1138. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1139. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1140. wpa_s, NULL);
  1141. eloop_register_timeout(60, 0,
  1142. wpa_supplicant_stop_countermeasures,
  1143. wpa_s, NULL);
  1144. /* TODO: mark the AP rejected for 60 second. STA is
  1145. * allowed to associate with another AP.. */
  1146. } else {
  1147. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1148. if (wpa_s->mic_errors_seen) {
  1149. /*
  1150. * Reduce the effectiveness of Michael MIC error
  1151. * reports as a means for attacking against TKIP if
  1152. * more than one MIC failure is noticed with the same
  1153. * PTK. We delay the transmission of the reports by a
  1154. * random time between 0 and 60 seconds in order to
  1155. * force the attacker wait 60 seconds before getting
  1156. * the information on whether a frame resulted in a MIC
  1157. * failure.
  1158. */
  1159. u8 rval[4];
  1160. int sec;
  1161. if (os_get_random(rval, sizeof(rval)) < 0)
  1162. sec = os_random() % 60;
  1163. else
  1164. sec = WPA_GET_BE32(rval) % 60;
  1165. wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
  1166. "seconds", sec);
  1167. wpa_s->pending_mic_error_report = 1;
  1168. wpa_s->pending_mic_error_pairwise = pairwise;
  1169. eloop_cancel_timeout(
  1170. wpa_supplicant_delayed_mic_error_report,
  1171. wpa_s, NULL);
  1172. eloop_register_timeout(
  1173. sec, os_random() % 1000000,
  1174. wpa_supplicant_delayed_mic_error_report,
  1175. wpa_s, NULL);
  1176. } else {
  1177. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1178. }
  1179. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1180. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1181. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1182. }
  1183. wpa_s->last_michael_mic_error = t.sec;
  1184. wpa_s->mic_errors_seen++;
  1185. }
  1186. #ifdef CONFIG_TERMINATE_ONLASTIF
  1187. static int any_interfaces(struct wpa_supplicant *head)
  1188. {
  1189. struct wpa_supplicant *wpa_s;
  1190. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1191. if (!wpa_s->interface_removed)
  1192. return 1;
  1193. return 0;
  1194. }
  1195. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1196. static void
  1197. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1198. union wpa_event_data *data)
  1199. {
  1200. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1201. return;
  1202. switch (data->interface_status.ievent) {
  1203. case EVENT_INTERFACE_ADDED:
  1204. if (!wpa_s->interface_removed)
  1205. break;
  1206. wpa_s->interface_removed = 0;
  1207. wpa_printf(MSG_DEBUG, "Configured interface was added.");
  1208. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1209. wpa_printf(MSG_INFO, "Failed to initialize the driver "
  1210. "after interface was added.");
  1211. }
  1212. break;
  1213. case EVENT_INTERFACE_REMOVED:
  1214. wpa_printf(MSG_DEBUG, "Configured interface was removed.");
  1215. wpa_s->interface_removed = 1;
  1216. wpa_supplicant_mark_disassoc(wpa_s);
  1217. l2_packet_deinit(wpa_s->l2);
  1218. wpa_s->l2 = NULL;
  1219. #ifdef CONFIG_TERMINATE_ONLASTIF
  1220. /* check if last interface */
  1221. if (!any_interfaces(wpa_s->global->ifaces))
  1222. eloop_terminate();
  1223. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1224. break;
  1225. }
  1226. }
  1227. #ifdef CONFIG_PEERKEY
  1228. static void
  1229. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1230. union wpa_event_data *data)
  1231. {
  1232. if (data == NULL)
  1233. return;
  1234. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1235. }
  1236. #endif /* CONFIG_PEERKEY */
  1237. #ifdef CONFIG_IEEE80211R
  1238. static void
  1239. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1240. union wpa_event_data *data)
  1241. {
  1242. if (data == NULL)
  1243. return;
  1244. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1245. data->ft_ies.ies_len,
  1246. data->ft_ies.ft_action,
  1247. data->ft_ies.target_ap,
  1248. data->ft_ies.ric_ies,
  1249. data->ft_ies.ric_ies_len) < 0) {
  1250. /* TODO: prevent MLME/driver from trying to associate? */
  1251. }
  1252. }
  1253. #endif /* CONFIG_IEEE80211R */
  1254. #ifdef CONFIG_IBSS_RSN
  1255. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1256. union wpa_event_data *data)
  1257. {
  1258. if (data == NULL)
  1259. return;
  1260. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1261. }
  1262. #endif /* CONFIG_IBSS_RSN */
  1263. #ifdef CONFIG_IEEE80211R
  1264. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1265. size_t len)
  1266. {
  1267. const u8 *sta_addr, *target_ap_addr;
  1268. u16 status;
  1269. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1270. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1271. return; /* only SME case supported for now */
  1272. if (len < 1 + 2 * ETH_ALEN + 2)
  1273. return;
  1274. if (data[0] != 2)
  1275. return; /* Only FT Action Response is supported for now */
  1276. sta_addr = data + 1;
  1277. target_ap_addr = data + 1 + ETH_ALEN;
  1278. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1279. wpa_printf(MSG_DEBUG, "FT: Received FT Action Response: STA " MACSTR
  1280. " TargetAP " MACSTR " status %u",
  1281. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1282. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1283. wpa_printf(MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1284. " in FT Action Response", MAC2STR(sta_addr));
  1285. return;
  1286. }
  1287. if (status) {
  1288. wpa_printf(MSG_DEBUG, "FT: FT Action Response indicates "
  1289. "failure (status code %d)", status);
  1290. /* TODO: report error to FT code(?) */
  1291. return;
  1292. }
  1293. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1294. len - (1 + 2 * ETH_ALEN + 2), 1,
  1295. target_ap_addr, NULL, 0) < 0)
  1296. return;
  1297. #ifdef CONFIG_SME
  1298. {
  1299. struct wpa_bss *bss;
  1300. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1301. if (bss)
  1302. wpa_s->sme.freq = bss->freq;
  1303. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1304. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1305. WLAN_AUTH_FT);
  1306. }
  1307. #endif /* CONFIG_SME */
  1308. }
  1309. #endif /* CONFIG_IEEE80211R */
  1310. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1311. union wpa_event_data *data)
  1312. {
  1313. struct wpa_supplicant *wpa_s = ctx;
  1314. u16 reason_code = 0;
  1315. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1316. event != EVENT_INTERFACE_ENABLED &&
  1317. event != EVENT_INTERFACE_STATUS) {
  1318. wpa_printf(MSG_DEBUG, "Ignore event %d while interface is "
  1319. "disabled", event);
  1320. return;
  1321. }
  1322. wpa_printf(MSG_DEBUG, "Event %d received on interface %s",
  1323. event, wpa_s->ifname);
  1324. switch (event) {
  1325. case EVENT_AUTH:
  1326. sme_event_auth(wpa_s, data);
  1327. break;
  1328. case EVENT_ASSOC:
  1329. wpa_supplicant_event_assoc(wpa_s, data);
  1330. break;
  1331. case EVENT_DISASSOC:
  1332. wpa_printf(MSG_DEBUG, "Disassociation notification");
  1333. if (data) {
  1334. wpa_printf(MSG_DEBUG, " * reason %u",
  1335. data->disassoc_info.reason_code);
  1336. if (data->disassoc_info.addr)
  1337. wpa_printf(MSG_DEBUG, " * address " MACSTR,
  1338. MAC2STR(data->disassoc_info.addr));
  1339. }
  1340. #ifdef CONFIG_AP
  1341. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1342. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1343. data->disassoc_info.addr);
  1344. break;
  1345. }
  1346. #endif /* CONFIG_AP */
  1347. if (data) {
  1348. reason_code = data->disassoc_info.reason_code;
  1349. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1350. data->disassoc_info.ie,
  1351. data->disassoc_info.ie_len);
  1352. #ifdef CONFIG_P2P
  1353. wpas_p2p_disassoc_notif(
  1354. wpa_s, data->disassoc_info.addr, reason_code,
  1355. data->disassoc_info.ie,
  1356. data->disassoc_info.ie_len);
  1357. #endif /* CONFIG_P2P */
  1358. }
  1359. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1360. sme_event_disassoc(wpa_s, data);
  1361. /* fall through */
  1362. case EVENT_DEAUTH:
  1363. if (event == EVENT_DEAUTH) {
  1364. wpa_printf(MSG_DEBUG, "Deauthentication notification");
  1365. if (data) {
  1366. reason_code = data->deauth_info.reason_code;
  1367. wpa_printf(MSG_DEBUG, " * reason %u",
  1368. data->deauth_info.reason_code);
  1369. if (data->deauth_info.addr) {
  1370. wpa_printf(MSG_DEBUG, " * address "
  1371. MACSTR,
  1372. MAC2STR(data->deauth_info.
  1373. addr));
  1374. }
  1375. wpa_hexdump(MSG_DEBUG,
  1376. "Deauthentication frame IE(s)",
  1377. data->deauth_info.ie,
  1378. data->deauth_info.ie_len);
  1379. #ifdef CONFIG_P2P
  1380. wpas_p2p_deauth_notif(
  1381. wpa_s, data->deauth_info.addr,
  1382. reason_code,
  1383. data->deauth_info.ie,
  1384. data->deauth_info.ie_len);
  1385. #endif /* CONFIG_P2P */
  1386. }
  1387. }
  1388. #ifdef CONFIG_AP
  1389. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1390. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1391. data->deauth_info.addr);
  1392. break;
  1393. }
  1394. #endif /* CONFIG_AP */
  1395. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1396. break;
  1397. case EVENT_MICHAEL_MIC_FAILURE:
  1398. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1399. break;
  1400. #ifndef CONFIG_NO_SCAN_PROCESSING
  1401. case EVENT_SCAN_RESULTS:
  1402. wpa_supplicant_event_scan_results(wpa_s, data);
  1403. break;
  1404. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1405. case EVENT_ASSOCINFO:
  1406. wpa_supplicant_event_associnfo(wpa_s, data);
  1407. break;
  1408. case EVENT_INTERFACE_STATUS:
  1409. wpa_supplicant_event_interface_status(wpa_s, data);
  1410. break;
  1411. case EVENT_PMKID_CANDIDATE:
  1412. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1413. break;
  1414. #ifdef CONFIG_PEERKEY
  1415. case EVENT_STKSTART:
  1416. wpa_supplicant_event_stkstart(wpa_s, data);
  1417. break;
  1418. #endif /* CONFIG_PEERKEY */
  1419. #ifdef CONFIG_IEEE80211R
  1420. case EVENT_FT_RESPONSE:
  1421. wpa_supplicant_event_ft_response(wpa_s, data);
  1422. break;
  1423. #endif /* CONFIG_IEEE80211R */
  1424. #ifdef CONFIG_IBSS_RSN
  1425. case EVENT_IBSS_RSN_START:
  1426. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1427. break;
  1428. #endif /* CONFIG_IBSS_RSN */
  1429. case EVENT_ASSOC_REJECT:
  1430. sme_event_assoc_reject(wpa_s, data);
  1431. break;
  1432. case EVENT_AUTH_TIMED_OUT:
  1433. sme_event_auth_timed_out(wpa_s, data);
  1434. break;
  1435. case EVENT_ASSOC_TIMED_OUT:
  1436. sme_event_assoc_timed_out(wpa_s, data);
  1437. break;
  1438. #ifdef CONFIG_AP
  1439. case EVENT_TX_STATUS:
  1440. wpa_printf(MSG_DEBUG, "EVENT_TX_STATUS on %s dst=" MACSTR
  1441. " type=%d stype=%d pending_dst=" MACSTR,
  1442. wpa_s->ifname, MAC2STR(data->tx_status.dst),
  1443. data->tx_status.type, data->tx_status.stype,
  1444. MAC2STR(wpa_s->parent->pending_action_dst));
  1445. if (wpa_s->ap_iface == NULL) {
  1446. #ifdef CONFIG_P2P
  1447. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1448. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1449. wpas_send_action_tx_status(
  1450. wpa_s, data->tx_status.dst,
  1451. data->tx_status.data,
  1452. data->tx_status.data_len,
  1453. data->tx_status.ack);
  1454. #endif /* CONFIG_P2P */
  1455. break;
  1456. }
  1457. #ifdef CONFIG_P2P
  1458. /*
  1459. * Catch TX status events for Action frames we sent via group
  1460. * interface in GO mode.
  1461. */
  1462. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1463. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1464. os_memcmp(wpa_s->parent->pending_action_dst,
  1465. data->tx_status.dst, ETH_ALEN) == 0) {
  1466. wpas_send_action_tx_status(
  1467. wpa_s->parent, data->tx_status.dst,
  1468. data->tx_status.data,
  1469. data->tx_status.data_len,
  1470. data->tx_status.ack);
  1471. break;
  1472. }
  1473. #endif /* CONFIG_P2P */
  1474. switch (data->tx_status.type) {
  1475. case WLAN_FC_TYPE_MGMT:
  1476. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1477. data->tx_status.data_len,
  1478. data->tx_status.stype,
  1479. data->tx_status.ack);
  1480. break;
  1481. case WLAN_FC_TYPE_DATA:
  1482. ap_tx_status(wpa_s, data->tx_status.dst,
  1483. data->tx_status.data,
  1484. data->tx_status.data_len,
  1485. data->tx_status.ack);
  1486. break;
  1487. }
  1488. break;
  1489. case EVENT_RX_FROM_UNKNOWN:
  1490. if (wpa_s->ap_iface == NULL)
  1491. break;
  1492. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1493. data->rx_from_unknown.len);
  1494. break;
  1495. case EVENT_RX_MGMT:
  1496. if (wpa_s->ap_iface == NULL) {
  1497. #ifdef CONFIG_P2P
  1498. u16 fc, stype;
  1499. const struct ieee80211_mgmt *mgmt;
  1500. mgmt = (const struct ieee80211_mgmt *)
  1501. data->rx_mgmt.frame;
  1502. fc = le_to_host16(mgmt->frame_control);
  1503. stype = WLAN_FC_GET_STYPE(fc);
  1504. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  1505. data->rx_mgmt.frame_len > 24) {
  1506. const u8 *src = mgmt->sa;
  1507. const u8 *ie = mgmt->u.probe_req.variable;
  1508. size_t ie_len = data->rx_mgmt.frame_len -
  1509. (mgmt->u.probe_req.variable -
  1510. data->rx_mgmt.frame);
  1511. wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
  1512. break;
  1513. }
  1514. #endif /* CONFIG_P2P */
  1515. wpa_printf(MSG_DEBUG, "AP: ignore received management "
  1516. "frame in non-AP mode");
  1517. break;
  1518. }
  1519. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1520. break;
  1521. #endif /* CONFIG_AP */
  1522. case EVENT_RX_ACTION:
  1523. wpa_printf(MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1524. " Category=%u DataLen=%d freq=%d MHz",
  1525. MAC2STR(data->rx_action.sa),
  1526. data->rx_action.category, (int) data->rx_action.len,
  1527. data->rx_action.freq);
  1528. #ifdef CONFIG_IEEE80211R
  1529. if (data->rx_action.category == WLAN_ACTION_FT) {
  1530. ft_rx_action(wpa_s, data->rx_action.data,
  1531. data->rx_action.len);
  1532. break;
  1533. }
  1534. #endif /* CONFIG_IEEE80211R */
  1535. #ifdef CONFIG_P2P
  1536. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  1537. data->rx_action.sa,
  1538. data->rx_action.bssid,
  1539. data->rx_action.category,
  1540. data->rx_action.data,
  1541. data->rx_action.len, data->rx_action.freq);
  1542. #endif /* CONFIG_P2P */
  1543. break;
  1544. #ifdef CONFIG_P2P
  1545. case EVENT_REMAIN_ON_CHANNEL:
  1546. wpas_p2p_remain_on_channel_cb(
  1547. wpa_s, data->remain_on_channel.freq,
  1548. data->remain_on_channel.duration);
  1549. break;
  1550. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  1551. wpas_p2p_cancel_remain_on_channel_cb(
  1552. wpa_s, data->remain_on_channel.freq);
  1553. break;
  1554. case EVENT_RX_PROBE_REQ:
  1555. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  1556. data->rx_probe_req.ie,
  1557. data->rx_probe_req.ie_len);
  1558. break;
  1559. #endif /* CONFIG_P2P */
  1560. #ifdef CONFIG_CLIENT_MLME
  1561. case EVENT_MLME_RX: {
  1562. struct ieee80211_rx_status rx_status;
  1563. os_memset(&rx_status, 0, sizeof(rx_status));
  1564. rx_status.freq = data->mlme_rx.freq;
  1565. rx_status.channel = data->mlme_rx.channel;
  1566. rx_status.ssi = data->mlme_rx.ssi;
  1567. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1568. &rx_status);
  1569. break;
  1570. }
  1571. #endif /* CONFIG_CLIENT_MLME */
  1572. case EVENT_EAPOL_RX:
  1573. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1574. data->eapol_rx.data,
  1575. data->eapol_rx.data_len);
  1576. break;
  1577. case EVENT_SIGNAL_CHANGE:
  1578. bgscan_notify_signal_change(
  1579. wpa_s, data->signal_change.above_threshold,
  1580. data->signal_change.current_signal);
  1581. break;
  1582. case EVENT_INTERFACE_ENABLED:
  1583. wpa_printf(MSG_DEBUG, "Interface was enabled");
  1584. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1585. wpa_supplicant_set_state(wpa_s,
  1586. WPA_DISCONNECTED);
  1587. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1588. }
  1589. break;
  1590. case EVENT_INTERFACE_DISABLED:
  1591. wpa_printf(MSG_DEBUG, "Interface was disabled");
  1592. wpa_supplicant_mark_disassoc(wpa_s);
  1593. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1594. break;
  1595. default:
  1596. wpa_printf(MSG_INFO, "Unknown event %d", event);
  1597. break;
  1598. }
  1599. }