events.c 86 KB

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