events.c 45 KB

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