events.c 58 KB

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