events.c 63 KB

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