events.c 62 KB

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