events.c 60 KB

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