events.c 61 KB

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