events.c 74 KB

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