events.c 49 KB

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