events.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134
  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. if (data->assoc_info.beacon_ies)
  865. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  866. data->assoc_info.beacon_ies,
  867. data->assoc_info.beacon_ies_len);
  868. if (data->assoc_info.freq)
  869. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  870. data->assoc_info.freq);
  871. p = data->assoc_info.req_ies;
  872. l = data->assoc_info.req_ies_len;
  873. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  874. while (p && l >= 2) {
  875. len = p[1] + 2;
  876. if (len > l) {
  877. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  878. p, l);
  879. break;
  880. }
  881. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  882. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  883. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  884. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  885. break;
  886. found = 1;
  887. wpa_find_assoc_pmkid(wpa_s);
  888. break;
  889. }
  890. l -= len;
  891. p += len;
  892. }
  893. if (!found && data->assoc_info.req_ies)
  894. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  895. #ifdef CONFIG_IEEE80211R
  896. #ifdef CONFIG_SME
  897. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  898. u8 bssid[ETH_ALEN];
  899. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  900. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  901. data->assoc_info.resp_ies,
  902. data->assoc_info.resp_ies_len,
  903. bssid) < 0) {
  904. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  905. "Reassociation Response failed");
  906. wpa_supplicant_deauthenticate(
  907. wpa_s, WLAN_REASON_INVALID_IE);
  908. return -1;
  909. }
  910. }
  911. p = data->assoc_info.resp_ies;
  912. l = data->assoc_info.resp_ies_len;
  913. #ifdef CONFIG_WPS_STRICT
  914. if (wpa_s->current_ssid &&
  915. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  916. struct wpabuf *wps;
  917. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  918. if (wps == NULL) {
  919. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  920. "include WPS IE in (Re)Association Response");
  921. return -1;
  922. }
  923. if (wps_validate_assoc_resp(wps) < 0) {
  924. wpabuf_free(wps);
  925. wpa_supplicant_deauthenticate(
  926. wpa_s, WLAN_REASON_INVALID_IE);
  927. return -1;
  928. }
  929. wpabuf_free(wps);
  930. }
  931. #endif /* CONFIG_WPS_STRICT */
  932. /* Go through the IEs and make a copy of the MDIE, if present. */
  933. while (p && l >= 2) {
  934. len = p[1] + 2;
  935. if (len > l) {
  936. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  937. p, l);
  938. break;
  939. }
  940. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  941. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  942. wpa_s->sme.ft_used = 1;
  943. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  944. MOBILITY_DOMAIN_ID_LEN);
  945. break;
  946. }
  947. l -= len;
  948. p += len;
  949. }
  950. #endif /* CONFIG_SME */
  951. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  952. data->assoc_info.resp_ies_len);
  953. #endif /* CONFIG_IEEE80211R */
  954. /* WPA/RSN IE from Beacon/ProbeResp */
  955. p = data->assoc_info.beacon_ies;
  956. l = data->assoc_info.beacon_ies_len;
  957. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  958. */
  959. wpa_found = rsn_found = 0;
  960. while (p && l >= 2) {
  961. len = p[1] + 2;
  962. if (len > l) {
  963. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  964. p, l);
  965. break;
  966. }
  967. if (!wpa_found &&
  968. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  969. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  970. wpa_found = 1;
  971. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  972. }
  973. if (!rsn_found &&
  974. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  975. rsn_found = 1;
  976. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  977. }
  978. l -= len;
  979. p += len;
  980. }
  981. if (!wpa_found && data->assoc_info.beacon_ies)
  982. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  983. if (!rsn_found && data->assoc_info.beacon_ies)
  984. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  985. if (wpa_found || rsn_found)
  986. wpa_s->ap_ies_from_associnfo = 1;
  987. wpa_s->assoc_freq = data->assoc_info.freq;
  988. return 0;
  989. }
  990. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  991. union wpa_event_data *data)
  992. {
  993. u8 bssid[ETH_ALEN];
  994. int ft_completed;
  995. int bssid_changed;
  996. struct wpa_driver_capa capa;
  997. #ifdef CONFIG_AP
  998. if (wpa_s->ap_iface) {
  999. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1000. data->assoc_info.addr,
  1001. data->assoc_info.req_ies,
  1002. data->assoc_info.req_ies_len);
  1003. return;
  1004. }
  1005. #endif /* CONFIG_AP */
  1006. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1007. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1008. return;
  1009. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1010. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  1011. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  1012. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  1013. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1014. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  1015. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1016. MACSTR, MAC2STR(bssid));
  1017. random_add_randomness(bssid, ETH_ALEN);
  1018. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1019. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1020. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1021. if (bssid_changed)
  1022. wpas_notify_bssid_changed(wpa_s);
  1023. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1024. wpa_clear_keys(wpa_s, bssid);
  1025. }
  1026. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1027. wpa_supplicant_disassociate(
  1028. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1029. return;
  1030. }
  1031. if (wpa_s->current_ssid) {
  1032. struct wpa_bss *bss = NULL;
  1033. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1034. if (ssid->ssid_len > 0)
  1035. bss = wpa_bss_get(wpa_s, bssid,
  1036. ssid->ssid, ssid->ssid_len);
  1037. if (!bss)
  1038. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1039. if (bss)
  1040. wpa_s->current_bss = bss;
  1041. }
  1042. }
  1043. #ifdef CONFIG_SME
  1044. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1045. wpa_s->sme.prev_bssid_set = 1;
  1046. #endif /* CONFIG_SME */
  1047. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1048. if (wpa_s->current_ssid) {
  1049. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1050. * initialized before association, but for other modes,
  1051. * initialize PC/SC here, if the current configuration needs
  1052. * smartcard or SIM/USIM. */
  1053. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1054. }
  1055. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1056. if (wpa_s->l2)
  1057. l2_packet_notify_auth_start(wpa_s->l2);
  1058. /*
  1059. * Set portEnabled first to FALSE in order to get EAP state machine out
  1060. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1061. * state machine may transit to AUTHENTICATING state based on obsolete
  1062. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1063. * AUTHENTICATED without ever giving chance to EAP state machine to
  1064. * reset the state.
  1065. */
  1066. if (!ft_completed) {
  1067. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1068. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1069. }
  1070. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1071. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1072. /* 802.1X::portControl = Auto */
  1073. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1074. wpa_s->eapol_received = 0;
  1075. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1076. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1077. (wpa_s->current_ssid &&
  1078. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1079. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1080. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1081. } else if (!ft_completed) {
  1082. /* Timeout for receiving the first EAPOL packet */
  1083. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1084. }
  1085. wpa_supplicant_cancel_scan(wpa_s);
  1086. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1087. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1088. /*
  1089. * We are done; the driver will take care of RSN 4-way
  1090. * handshake.
  1091. */
  1092. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1093. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1094. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1095. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1096. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1097. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1098. /*
  1099. * The driver will take care of RSN 4-way handshake, so we need
  1100. * to allow EAPOL supplicant to complete its work without
  1101. * waiting for WPA supplicant.
  1102. */
  1103. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1104. } else if (ft_completed) {
  1105. /*
  1106. * FT protocol completed - make sure EAPOL state machine ends
  1107. * up in authenticated.
  1108. */
  1109. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1110. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1111. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1112. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1113. }
  1114. if (wpa_s->pending_eapol_rx) {
  1115. struct os_time now, age;
  1116. os_get_time(&now);
  1117. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1118. if (age.sec == 0 && age.usec < 100000 &&
  1119. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1120. 0) {
  1121. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1122. "frame that was received just before "
  1123. "association notification");
  1124. wpa_supplicant_rx_eapol(
  1125. wpa_s, wpa_s->pending_eapol_rx_src,
  1126. wpabuf_head(wpa_s->pending_eapol_rx),
  1127. wpabuf_len(wpa_s->pending_eapol_rx));
  1128. }
  1129. wpabuf_free(wpa_s->pending_eapol_rx);
  1130. wpa_s->pending_eapol_rx = NULL;
  1131. }
  1132. #ifdef CONFIG_BGSCAN
  1133. if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
  1134. bgscan_deinit(wpa_s);
  1135. if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
  1136. if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
  1137. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to "
  1138. "initialize bgscan");
  1139. /*
  1140. * Live without bgscan; it is only used as a
  1141. * roaming optimization, so the initial
  1142. * connection is not affected.
  1143. */
  1144. } else
  1145. wpa_s->bgscan_ssid = wpa_s->current_ssid;
  1146. } else
  1147. wpa_s->bgscan_ssid = NULL;
  1148. }
  1149. #endif /* CONFIG_BGSCAN */
  1150. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1151. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1152. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1153. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1154. /* Set static WEP keys again */
  1155. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1156. }
  1157. #ifdef CONFIG_IBSS_RSN
  1158. if (wpa_s->current_ssid &&
  1159. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1160. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1161. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE)
  1162. ibss_rsn_connected(wpa_s->ibss_rsn);
  1163. #endif /* CONFIG_IBSS_RSN */
  1164. }
  1165. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1166. u16 reason_code)
  1167. {
  1168. const u8 *bssid;
  1169. int authenticating;
  1170. u8 prev_pending_bssid[ETH_ALEN];
  1171. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1172. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1173. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1174. /*
  1175. * At least Host AP driver and a Prism3 card seemed to be
  1176. * generating streams of disconnected events when configuring
  1177. * IBSS for WPA-None. Ignore them for now.
  1178. */
  1179. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1180. "IBSS/WPA-None mode");
  1181. return;
  1182. }
  1183. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1184. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1185. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1186. "pre-shared key may be incorrect");
  1187. }
  1188. if (!wpa_s->auto_reconnect_disabled ||
  1189. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1190. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
  1191. "reconnect (wps=%d)",
  1192. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
  1193. if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1194. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1195. } else {
  1196. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
  1197. "try to re-connect");
  1198. wpa_s->reassociate = 0;
  1199. wpa_s->disconnected = 1;
  1200. }
  1201. bssid = wpa_s->bssid;
  1202. if (is_zero_ether_addr(bssid))
  1203. bssid = wpa_s->pending_bssid;
  1204. wpas_connection_failed(wpa_s, bssid);
  1205. wpa_sm_notify_disassoc(wpa_s->wpa);
  1206. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1207. " reason=%d",
  1208. MAC2STR(bssid), reason_code);
  1209. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1210. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1211. wpa_s->keys_cleared = 0;
  1212. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1213. }
  1214. wpa_supplicant_mark_disassoc(wpa_s);
  1215. bgscan_deinit(wpa_s);
  1216. wpa_s->bgscan_ssid = NULL;
  1217. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1218. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1219. }
  1220. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1221. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1222. void *sock_ctx)
  1223. {
  1224. struct wpa_supplicant *wpa_s = eloop_ctx;
  1225. if (!wpa_s->pending_mic_error_report)
  1226. return;
  1227. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1228. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1229. wpa_s->pending_mic_error_report = 0;
  1230. }
  1231. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1232. static void
  1233. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1234. union wpa_event_data *data)
  1235. {
  1236. int pairwise;
  1237. struct os_time t;
  1238. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1239. pairwise = (data && data->michael_mic_failure.unicast);
  1240. os_get_time(&t);
  1241. if ((wpa_s->last_michael_mic_error &&
  1242. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1243. wpa_s->pending_mic_error_report) {
  1244. if (wpa_s->pending_mic_error_report) {
  1245. /*
  1246. * Send the pending MIC error report immediately since
  1247. * we are going to start countermeasures and AP better
  1248. * do the same.
  1249. */
  1250. wpa_sm_key_request(wpa_s->wpa, 1,
  1251. wpa_s->pending_mic_error_pairwise);
  1252. }
  1253. /* Send the new MIC error report immediately since we are going
  1254. * to start countermeasures and AP better do the same.
  1255. */
  1256. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1257. /* initialize countermeasures */
  1258. wpa_s->countermeasures = 1;
  1259. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1260. /*
  1261. * Need to wait for completion of request frame. We do not get
  1262. * any callback for the message completion, so just wait a
  1263. * short while and hope for the best. */
  1264. os_sleep(0, 10000);
  1265. wpa_drv_set_countermeasures(wpa_s, 1);
  1266. wpa_supplicant_deauthenticate(wpa_s,
  1267. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1268. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1269. wpa_s, NULL);
  1270. eloop_register_timeout(60, 0,
  1271. wpa_supplicant_stop_countermeasures,
  1272. wpa_s, NULL);
  1273. /* TODO: mark the AP rejected for 60 second. STA is
  1274. * allowed to associate with another AP.. */
  1275. } else {
  1276. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1277. if (wpa_s->mic_errors_seen) {
  1278. /*
  1279. * Reduce the effectiveness of Michael MIC error
  1280. * reports as a means for attacking against TKIP if
  1281. * more than one MIC failure is noticed with the same
  1282. * PTK. We delay the transmission of the reports by a
  1283. * random time between 0 and 60 seconds in order to
  1284. * force the attacker wait 60 seconds before getting
  1285. * the information on whether a frame resulted in a MIC
  1286. * failure.
  1287. */
  1288. u8 rval[4];
  1289. int sec;
  1290. if (os_get_random(rval, sizeof(rval)) < 0)
  1291. sec = os_random() % 60;
  1292. else
  1293. sec = WPA_GET_BE32(rval) % 60;
  1294. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1295. "report %d seconds", sec);
  1296. wpa_s->pending_mic_error_report = 1;
  1297. wpa_s->pending_mic_error_pairwise = pairwise;
  1298. eloop_cancel_timeout(
  1299. wpa_supplicant_delayed_mic_error_report,
  1300. wpa_s, NULL);
  1301. eloop_register_timeout(
  1302. sec, os_random() % 1000000,
  1303. wpa_supplicant_delayed_mic_error_report,
  1304. wpa_s, NULL);
  1305. } else {
  1306. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1307. }
  1308. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1309. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1310. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1311. }
  1312. wpa_s->last_michael_mic_error = t.sec;
  1313. wpa_s->mic_errors_seen++;
  1314. }
  1315. #ifdef CONFIG_TERMINATE_ONLASTIF
  1316. static int any_interfaces(struct wpa_supplicant *head)
  1317. {
  1318. struct wpa_supplicant *wpa_s;
  1319. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1320. if (!wpa_s->interface_removed)
  1321. return 1;
  1322. return 0;
  1323. }
  1324. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1325. static void
  1326. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1327. union wpa_event_data *data)
  1328. {
  1329. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1330. return;
  1331. switch (data->interface_status.ievent) {
  1332. case EVENT_INTERFACE_ADDED:
  1333. if (!wpa_s->interface_removed)
  1334. break;
  1335. wpa_s->interface_removed = 0;
  1336. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1337. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1338. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1339. "driver after interface was added");
  1340. }
  1341. break;
  1342. case EVENT_INTERFACE_REMOVED:
  1343. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1344. wpa_s->interface_removed = 1;
  1345. wpa_supplicant_mark_disassoc(wpa_s);
  1346. l2_packet_deinit(wpa_s->l2);
  1347. wpa_s->l2 = NULL;
  1348. #ifdef CONFIG_TERMINATE_ONLASTIF
  1349. /* check if last interface */
  1350. if (!any_interfaces(wpa_s->global->ifaces))
  1351. eloop_terminate();
  1352. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1353. break;
  1354. }
  1355. }
  1356. #ifdef CONFIG_PEERKEY
  1357. static void
  1358. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1359. union wpa_event_data *data)
  1360. {
  1361. if (data == NULL)
  1362. return;
  1363. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1364. }
  1365. #endif /* CONFIG_PEERKEY */
  1366. #ifdef CONFIG_IEEE80211R
  1367. static void
  1368. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1369. union wpa_event_data *data)
  1370. {
  1371. if (data == NULL)
  1372. return;
  1373. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1374. data->ft_ies.ies_len,
  1375. data->ft_ies.ft_action,
  1376. data->ft_ies.target_ap,
  1377. data->ft_ies.ric_ies,
  1378. data->ft_ies.ric_ies_len) < 0) {
  1379. /* TODO: prevent MLME/driver from trying to associate? */
  1380. }
  1381. }
  1382. #endif /* CONFIG_IEEE80211R */
  1383. #ifdef CONFIG_IBSS_RSN
  1384. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1385. union wpa_event_data *data)
  1386. {
  1387. struct wpa_ssid *ssid;
  1388. if (data == NULL)
  1389. return;
  1390. ssid = wpa_s->current_ssid;
  1391. if (ssid == NULL)
  1392. return;
  1393. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1394. return;
  1395. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1396. }
  1397. #endif /* CONFIG_IBSS_RSN */
  1398. #ifdef CONFIG_IEEE80211R
  1399. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1400. size_t len)
  1401. {
  1402. const u8 *sta_addr, *target_ap_addr;
  1403. u16 status;
  1404. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1405. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1406. return; /* only SME case supported for now */
  1407. if (len < 1 + 2 * ETH_ALEN + 2)
  1408. return;
  1409. if (data[0] != 2)
  1410. return; /* Only FT Action Response is supported for now */
  1411. sta_addr = data + 1;
  1412. target_ap_addr = data + 1 + ETH_ALEN;
  1413. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1414. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1415. MACSTR " TargetAP " MACSTR " status %u",
  1416. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1417. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1418. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1419. " in FT Action Response", MAC2STR(sta_addr));
  1420. return;
  1421. }
  1422. if (status) {
  1423. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1424. "failure (status code %d)", status);
  1425. /* TODO: report error to FT code(?) */
  1426. return;
  1427. }
  1428. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1429. len - (1 + 2 * ETH_ALEN + 2), 1,
  1430. target_ap_addr, NULL, 0) < 0)
  1431. return;
  1432. #ifdef CONFIG_SME
  1433. {
  1434. struct wpa_bss *bss;
  1435. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1436. if (bss)
  1437. wpa_s->sme.freq = bss->freq;
  1438. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1439. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1440. WLAN_AUTH_FT);
  1441. }
  1442. #endif /* CONFIG_SME */
  1443. }
  1444. #endif /* CONFIG_IEEE80211R */
  1445. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1446. struct unprot_deauth *e)
  1447. {
  1448. #ifdef CONFIG_IEEE80211W
  1449. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1450. "dropped: " MACSTR " -> " MACSTR
  1451. " (reason code %u)",
  1452. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1453. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1454. #endif /* CONFIG_IEEE80211W */
  1455. }
  1456. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1457. struct unprot_disassoc *e)
  1458. {
  1459. #ifdef CONFIG_IEEE80211W
  1460. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1461. "dropped: " MACSTR " -> " MACSTR
  1462. " (reason code %u)",
  1463. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1464. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1465. #endif /* CONFIG_IEEE80211W */
  1466. }
  1467. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1468. union wpa_event_data *data)
  1469. {
  1470. struct wpa_supplicant *wpa_s = ctx;
  1471. u16 reason_code = 0;
  1472. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1473. event != EVENT_INTERFACE_ENABLED &&
  1474. event != EVENT_INTERFACE_STATUS) {
  1475. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
  1476. "disabled", event);
  1477. return;
  1478. }
  1479. wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
  1480. event, wpa_s->ifname);
  1481. switch (event) {
  1482. case EVENT_AUTH:
  1483. sme_event_auth(wpa_s, data);
  1484. break;
  1485. case EVENT_ASSOC:
  1486. wpa_supplicant_event_assoc(wpa_s, data);
  1487. break;
  1488. case EVENT_DISASSOC:
  1489. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1490. if (data) {
  1491. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1492. data->disassoc_info.reason_code);
  1493. if (data->disassoc_info.addr)
  1494. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1495. MAC2STR(data->disassoc_info.addr));
  1496. }
  1497. #ifdef CONFIG_AP
  1498. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1499. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1500. data->disassoc_info.addr);
  1501. break;
  1502. }
  1503. #endif /* CONFIG_AP */
  1504. if (data) {
  1505. reason_code = data->disassoc_info.reason_code;
  1506. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1507. data->disassoc_info.ie,
  1508. data->disassoc_info.ie_len);
  1509. #ifdef CONFIG_P2P
  1510. wpas_p2p_disassoc_notif(
  1511. wpa_s, data->disassoc_info.addr, reason_code,
  1512. data->disassoc_info.ie,
  1513. data->disassoc_info.ie_len);
  1514. #endif /* CONFIG_P2P */
  1515. }
  1516. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1517. sme_event_disassoc(wpa_s, data);
  1518. /* fall through */
  1519. case EVENT_DEAUTH:
  1520. if (event == EVENT_DEAUTH) {
  1521. wpa_dbg(wpa_s, MSG_DEBUG,
  1522. "Deauthentication notification");
  1523. if (data) {
  1524. reason_code = data->deauth_info.reason_code;
  1525. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1526. data->deauth_info.reason_code);
  1527. if (data->deauth_info.addr) {
  1528. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1529. MACSTR,
  1530. MAC2STR(data->deauth_info.
  1531. addr));
  1532. }
  1533. wpa_hexdump(MSG_DEBUG,
  1534. "Deauthentication frame IE(s)",
  1535. data->deauth_info.ie,
  1536. data->deauth_info.ie_len);
  1537. #ifdef CONFIG_P2P
  1538. wpas_p2p_deauth_notif(
  1539. wpa_s, data->deauth_info.addr,
  1540. reason_code,
  1541. data->deauth_info.ie,
  1542. data->deauth_info.ie_len);
  1543. #endif /* CONFIG_P2P */
  1544. }
  1545. }
  1546. #ifdef CONFIG_AP
  1547. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1548. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1549. data->deauth_info.addr);
  1550. break;
  1551. }
  1552. #endif /* CONFIG_AP */
  1553. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1554. break;
  1555. case EVENT_MICHAEL_MIC_FAILURE:
  1556. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1557. break;
  1558. #ifndef CONFIG_NO_SCAN_PROCESSING
  1559. case EVENT_SCAN_RESULTS:
  1560. wpa_supplicant_event_scan_results(wpa_s, data);
  1561. break;
  1562. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1563. case EVENT_ASSOCINFO:
  1564. wpa_supplicant_event_associnfo(wpa_s, data);
  1565. break;
  1566. case EVENT_INTERFACE_STATUS:
  1567. wpa_supplicant_event_interface_status(wpa_s, data);
  1568. break;
  1569. case EVENT_PMKID_CANDIDATE:
  1570. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1571. break;
  1572. #ifdef CONFIG_PEERKEY
  1573. case EVENT_STKSTART:
  1574. wpa_supplicant_event_stkstart(wpa_s, data);
  1575. break;
  1576. #endif /* CONFIG_PEERKEY */
  1577. #ifdef CONFIG_IEEE80211R
  1578. case EVENT_FT_RESPONSE:
  1579. wpa_supplicant_event_ft_response(wpa_s, data);
  1580. break;
  1581. #endif /* CONFIG_IEEE80211R */
  1582. #ifdef CONFIG_IBSS_RSN
  1583. case EVENT_IBSS_RSN_START:
  1584. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1585. break;
  1586. #endif /* CONFIG_IBSS_RSN */
  1587. case EVENT_ASSOC_REJECT:
  1588. if (data->assoc_reject.bssid)
  1589. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1590. "bssid=" MACSTR " status_code=%u",
  1591. MAC2STR(data->assoc_reject.bssid),
  1592. data->assoc_reject.status_code);
  1593. else
  1594. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1595. "status_code=%u",
  1596. data->assoc_reject.status_code);
  1597. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1598. sme_event_assoc_reject(wpa_s, data);
  1599. break;
  1600. case EVENT_AUTH_TIMED_OUT:
  1601. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1602. sme_event_auth_timed_out(wpa_s, data);
  1603. break;
  1604. case EVENT_ASSOC_TIMED_OUT:
  1605. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1606. sme_event_assoc_timed_out(wpa_s, data);
  1607. break;
  1608. #ifdef CONFIG_AP
  1609. case EVENT_TX_STATUS:
  1610. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  1611. " type=%d stype=%d",
  1612. MAC2STR(data->tx_status.dst),
  1613. data->tx_status.type, data->tx_status.stype);
  1614. if (wpa_s->ap_iface == NULL) {
  1615. #ifdef CONFIG_P2P
  1616. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1617. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1618. wpas_send_action_tx_status(
  1619. wpa_s, data->tx_status.dst,
  1620. data->tx_status.data,
  1621. data->tx_status.data_len,
  1622. data->tx_status.ack ?
  1623. P2P_SEND_ACTION_SUCCESS :
  1624. P2P_SEND_ACTION_NO_ACK);
  1625. #endif /* CONFIG_P2P */
  1626. break;
  1627. }
  1628. #ifdef CONFIG_P2P
  1629. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  1630. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  1631. /*
  1632. * Catch TX status events for Action frames we sent via group
  1633. * interface in GO mode.
  1634. */
  1635. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1636. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1637. os_memcmp(wpa_s->parent->pending_action_dst,
  1638. data->tx_status.dst, ETH_ALEN) == 0) {
  1639. wpas_send_action_tx_status(
  1640. wpa_s->parent, data->tx_status.dst,
  1641. data->tx_status.data,
  1642. data->tx_status.data_len,
  1643. data->tx_status.ack ?
  1644. P2P_SEND_ACTION_SUCCESS :
  1645. P2P_SEND_ACTION_NO_ACK);
  1646. break;
  1647. }
  1648. #endif /* CONFIG_P2P */
  1649. switch (data->tx_status.type) {
  1650. case WLAN_FC_TYPE_MGMT:
  1651. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1652. data->tx_status.data_len,
  1653. data->tx_status.stype,
  1654. data->tx_status.ack);
  1655. break;
  1656. case WLAN_FC_TYPE_DATA:
  1657. ap_tx_status(wpa_s, data->tx_status.dst,
  1658. data->tx_status.data,
  1659. data->tx_status.data_len,
  1660. data->tx_status.ack);
  1661. break;
  1662. }
  1663. break;
  1664. case EVENT_RX_FROM_UNKNOWN:
  1665. if (wpa_s->ap_iface == NULL)
  1666. break;
  1667. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1668. data->rx_from_unknown.len);
  1669. break;
  1670. case EVENT_RX_MGMT:
  1671. if (wpa_s->ap_iface == NULL) {
  1672. #ifdef CONFIG_P2P
  1673. u16 fc, stype;
  1674. const struct ieee80211_mgmt *mgmt;
  1675. mgmt = (const struct ieee80211_mgmt *)
  1676. data->rx_mgmt.frame;
  1677. fc = le_to_host16(mgmt->frame_control);
  1678. stype = WLAN_FC_GET_STYPE(fc);
  1679. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  1680. data->rx_mgmt.frame_len > 24) {
  1681. const u8 *src = mgmt->sa;
  1682. const u8 *ie = mgmt->u.probe_req.variable;
  1683. size_t ie_len = data->rx_mgmt.frame_len -
  1684. (mgmt->u.probe_req.variable -
  1685. data->rx_mgmt.frame);
  1686. wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
  1687. break;
  1688. }
  1689. #endif /* CONFIG_P2P */
  1690. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  1691. "management frame in non-AP mode");
  1692. break;
  1693. }
  1694. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1695. break;
  1696. #endif /* CONFIG_AP */
  1697. case EVENT_RX_ACTION:
  1698. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1699. " Category=%u DataLen=%d freq=%d MHz",
  1700. MAC2STR(data->rx_action.sa),
  1701. data->rx_action.category, (int) data->rx_action.len,
  1702. data->rx_action.freq);
  1703. #ifdef CONFIG_IEEE80211R
  1704. if (data->rx_action.category == WLAN_ACTION_FT) {
  1705. ft_rx_action(wpa_s, data->rx_action.data,
  1706. data->rx_action.len);
  1707. break;
  1708. }
  1709. #endif /* CONFIG_IEEE80211R */
  1710. #ifdef CONFIG_IEEE80211W
  1711. #ifdef CONFIG_SME
  1712. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  1713. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  1714. data->rx_action.data,
  1715. data->rx_action.len);
  1716. break;
  1717. }
  1718. #endif /* CONFIG_SME */
  1719. #endif /* CONFIG_IEEE80211W */
  1720. #ifdef CONFIG_P2P
  1721. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  1722. data->rx_action.sa,
  1723. data->rx_action.bssid,
  1724. data->rx_action.category,
  1725. data->rx_action.data,
  1726. data->rx_action.len, data->rx_action.freq);
  1727. #endif /* CONFIG_P2P */
  1728. break;
  1729. case EVENT_RX_PROBE_REQ:
  1730. #ifdef CONFIG_AP
  1731. if (wpa_s->ap_iface) {
  1732. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  1733. data->rx_probe_req.sa,
  1734. data->rx_probe_req.ie,
  1735. data->rx_probe_req.ie_len);
  1736. break;
  1737. }
  1738. #endif /* CONFIG_AP */
  1739. #ifdef CONFIG_P2P
  1740. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  1741. data->rx_probe_req.ie,
  1742. data->rx_probe_req.ie_len);
  1743. #endif /* CONFIG_P2P */
  1744. break;
  1745. #ifdef CONFIG_P2P
  1746. case EVENT_REMAIN_ON_CHANNEL:
  1747. wpas_p2p_remain_on_channel_cb(
  1748. wpa_s, data->remain_on_channel.freq,
  1749. data->remain_on_channel.duration);
  1750. break;
  1751. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  1752. wpas_p2p_cancel_remain_on_channel_cb(
  1753. wpa_s, data->remain_on_channel.freq);
  1754. break;
  1755. case EVENT_P2P_DEV_FOUND:
  1756. wpas_dev_found(wpa_s, data->p2p_dev_found.addr,
  1757. data->p2p_dev_found.dev_addr,
  1758. data->p2p_dev_found.pri_dev_type,
  1759. data->p2p_dev_found.dev_name,
  1760. data->p2p_dev_found.config_methods,
  1761. data->p2p_dev_found.dev_capab,
  1762. data->p2p_dev_found.group_capab);
  1763. break;
  1764. case EVENT_P2P_GO_NEG_REQ_RX:
  1765. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  1766. data->p2p_go_neg_req_rx.dev_passwd_id);
  1767. break;
  1768. case EVENT_P2P_GO_NEG_COMPLETED:
  1769. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  1770. break;
  1771. case EVENT_P2P_PROV_DISC_REQUEST:
  1772. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  1773. data->p2p_prov_disc_req.config_methods,
  1774. data->p2p_prov_disc_req.dev_addr,
  1775. data->p2p_prov_disc_req.pri_dev_type,
  1776. data->p2p_prov_disc_req.dev_name,
  1777. data->p2p_prov_disc_req.supp_config_methods,
  1778. data->p2p_prov_disc_req.dev_capab,
  1779. data->p2p_prov_disc_req.group_capab);
  1780. break;
  1781. case EVENT_P2P_PROV_DISC_RESPONSE:
  1782. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  1783. data->p2p_prov_disc_resp.config_methods);
  1784. break;
  1785. case EVENT_P2P_SD_REQUEST:
  1786. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  1787. data->p2p_sd_req.sa,
  1788. data->p2p_sd_req.dialog_token,
  1789. data->p2p_sd_req.update_indic,
  1790. data->p2p_sd_req.tlvs,
  1791. data->p2p_sd_req.tlvs_len);
  1792. break;
  1793. case EVENT_P2P_SD_RESPONSE:
  1794. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  1795. data->p2p_sd_resp.update_indic,
  1796. data->p2p_sd_resp.tlvs,
  1797. data->p2p_sd_resp.tlvs_len);
  1798. break;
  1799. #endif /* CONFIG_P2P */
  1800. #ifdef CONFIG_CLIENT_MLME
  1801. case EVENT_MLME_RX: {
  1802. struct ieee80211_rx_status rx_status;
  1803. os_memset(&rx_status, 0, sizeof(rx_status));
  1804. rx_status.freq = data->mlme_rx.freq;
  1805. rx_status.channel = data->mlme_rx.channel;
  1806. rx_status.ssi = data->mlme_rx.ssi;
  1807. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1808. &rx_status);
  1809. break;
  1810. }
  1811. #endif /* CONFIG_CLIENT_MLME */
  1812. case EVENT_EAPOL_RX:
  1813. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1814. data->eapol_rx.data,
  1815. data->eapol_rx.data_len);
  1816. break;
  1817. case EVENT_SIGNAL_CHANGE:
  1818. bgscan_notify_signal_change(
  1819. wpa_s, data->signal_change.above_threshold,
  1820. data->signal_change.current_signal,
  1821. data->signal_change.current_noise,
  1822. data->signal_change.current_txrate);
  1823. break;
  1824. case EVENT_INTERFACE_ENABLED:
  1825. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  1826. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1827. #ifdef CONFIG_AP
  1828. if (!wpa_s->ap_iface) {
  1829. wpa_supplicant_set_state(wpa_s,
  1830. WPA_DISCONNECTED);
  1831. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1832. } else
  1833. wpa_supplicant_set_state(wpa_s,
  1834. WPA_COMPLETED);
  1835. #else /* CONFIG_AP */
  1836. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1837. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1838. #endif /* CONFIG_AP */
  1839. }
  1840. break;
  1841. case EVENT_INTERFACE_DISABLED:
  1842. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  1843. wpa_supplicant_mark_disassoc(wpa_s);
  1844. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1845. break;
  1846. case EVENT_CHANNEL_LIST_CHANGED:
  1847. if (wpa_s->drv_priv == NULL)
  1848. break; /* Ignore event during drv initialization */
  1849. #ifdef CONFIG_P2P
  1850. wpas_p2p_update_channel_list(wpa_s);
  1851. #endif /* CONFIG_P2P */
  1852. break;
  1853. case EVENT_INTERFACE_UNAVAILABLE:
  1854. #ifdef CONFIG_P2P
  1855. wpas_p2p_interface_unavailable(wpa_s);
  1856. #endif /* CONFIG_P2P */
  1857. break;
  1858. case EVENT_BEST_CHANNEL:
  1859. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  1860. "(%d %d %d)",
  1861. data->best_chan.freq_24, data->best_chan.freq_5,
  1862. data->best_chan.freq_overall);
  1863. wpa_s->best_24_freq = data->best_chan.freq_24;
  1864. wpa_s->best_5_freq = data->best_chan.freq_5;
  1865. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  1866. #ifdef CONFIG_P2P
  1867. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  1868. data->best_chan.freq_5,
  1869. data->best_chan.freq_overall);
  1870. #endif /* CONFIG_P2P */
  1871. break;
  1872. case EVENT_UNPROT_DEAUTH:
  1873. wpa_supplicant_event_unprot_deauth(wpa_s,
  1874. &data->unprot_deauth);
  1875. break;
  1876. case EVENT_UNPROT_DISASSOC:
  1877. wpa_supplicant_event_unprot_disassoc(wpa_s,
  1878. &data->unprot_disassoc);
  1879. break;
  1880. case EVENT_STATION_LOW_ACK:
  1881. #ifdef CONFIG_AP
  1882. if (wpa_s->ap_iface && data)
  1883. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  1884. data->low_ack.addr);
  1885. #endif /* CONFIG_AP */
  1886. break;
  1887. default:
  1888. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  1889. break;
  1890. }
  1891. }