events.c 72 KB

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