events.c 62 KB

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