events.c 61 KB

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