events.c 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280
  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. if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) {
  722. struct wpabuf *p2p_ie;
  723. u8 dev_addr[ETH_ALEN];
  724. ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  725. if (ie == NULL) {
  726. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element");
  727. continue;
  728. }
  729. p2p_ie = wpa_bss_get_vendor_ie_multi(
  730. bss, P2P_IE_VENDOR_TYPE);
  731. if (p2p_ie == NULL) {
  732. wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element");
  733. continue;
  734. }
  735. if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0
  736. || os_memcmp(dev_addr, ssid->go_p2p_dev_addr,
  737. ETH_ALEN) != 0) {
  738. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element");
  739. wpabuf_free(p2p_ie);
  740. continue;
  741. }
  742. wpabuf_free(p2p_ie);
  743. }
  744. /*
  745. * TODO: skip the AP if its P2P IE has Group Formation
  746. * bit set in the P2P Group Capability Bitmap and we
  747. * are not in Group Formation with that device.
  748. */
  749. #endif /* CONFIG_P2P */
  750. /* Matching configuration found */
  751. return ssid;
  752. }
  753. /* No matching configuration found */
  754. return NULL;
  755. }
  756. static struct wpa_bss *
  757. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  758. struct wpa_ssid *group,
  759. struct wpa_ssid **selected_ssid)
  760. {
  761. unsigned int i;
  762. wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
  763. group->priority);
  764. for (i = 0; i < wpa_s->last_scan_res_used; i++) {
  765. struct wpa_bss *bss = wpa_s->last_scan_res[i];
  766. *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
  767. if (!*selected_ssid)
  768. continue;
  769. wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
  770. " ssid='%s'",
  771. MAC2STR(bss->bssid),
  772. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  773. return bss;
  774. }
  775. return NULL;
  776. }
  777. struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  778. struct wpa_ssid **selected_ssid)
  779. {
  780. struct wpa_bss *selected = NULL;
  781. int prio;
  782. if (wpa_s->last_scan_res == NULL ||
  783. wpa_s->last_scan_res_used == 0)
  784. return NULL; /* no scan results from last update */
  785. while (selected == NULL) {
  786. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  787. selected = wpa_supplicant_select_bss(
  788. wpa_s, wpa_s->conf->pssid[prio],
  789. selected_ssid);
  790. if (selected)
  791. break;
  792. }
  793. if (selected == NULL && wpa_s->blacklist &&
  794. !wpa_s->countermeasures) {
  795. wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
  796. "blacklist and try again");
  797. wpa_blacklist_clear(wpa_s);
  798. wpa_s->blacklist_cleared++;
  799. } else if (selected == NULL)
  800. break;
  801. }
  802. return selected;
  803. }
  804. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  805. int timeout_sec, int timeout_usec)
  806. {
  807. if (!wpa_supplicant_enabled_networks(wpa_s)) {
  808. /*
  809. * No networks are enabled; short-circuit request so
  810. * we don't wait timeout seconds before transitioning
  811. * to INACTIVE state.
  812. */
  813. wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request "
  814. "since there are no enabled networks");
  815. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  816. #ifdef CONFIG_P2P
  817. wpa_s->sta_scan_pending = 0;
  818. #endif /* CONFIG_P2P */
  819. return;
  820. }
  821. wpa_s->scan_for_connection = 1;
  822. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  823. }
  824. int wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  825. struct wpa_bss *selected,
  826. struct wpa_ssid *ssid)
  827. {
  828. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  829. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  830. "PBC session overlap");
  831. #ifdef CONFIG_P2P
  832. if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
  833. return -1;
  834. #endif /* CONFIG_P2P */
  835. #ifdef CONFIG_WPS
  836. wpas_wps_cancel(wpa_s);
  837. #endif /* CONFIG_WPS */
  838. return -1;
  839. }
  840. wpa_msg(wpa_s, MSG_DEBUG,
  841. "Considering connect request: reassociate: %d selected: "
  842. MACSTR " bssid: " MACSTR " pending: " MACSTR
  843. " wpa_state: %s ssid=%p current_ssid=%p",
  844. wpa_s->reassociate, MAC2STR(selected->bssid),
  845. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  846. wpa_supplicant_state_txt(wpa_s->wpa_state),
  847. ssid, wpa_s->current_ssid);
  848. /*
  849. * Do not trigger new association unless the BSSID has changed or if
  850. * reassociation is requested. If we are in process of associating with
  851. * the selected BSSID, do not trigger new attempt.
  852. */
  853. if (wpa_s->reassociate ||
  854. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  855. ((wpa_s->wpa_state != WPA_ASSOCIATING &&
  856. wpa_s->wpa_state != WPA_AUTHENTICATING) ||
  857. (!is_zero_ether_addr(wpa_s->pending_bssid) &&
  858. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  859. 0) ||
  860. (is_zero_ether_addr(wpa_s->pending_bssid) &&
  861. ssid != wpa_s->current_ssid)))) {
  862. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  863. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  864. return 0;
  865. }
  866. wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR,
  867. MAC2STR(selected->bssid));
  868. wpa_supplicant_associate(wpa_s, selected, ssid);
  869. } else {
  870. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to "
  871. "connect with the selected AP");
  872. }
  873. return 0;
  874. }
  875. static struct wpa_ssid *
  876. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  877. {
  878. int prio;
  879. struct wpa_ssid *ssid;
  880. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  881. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  882. {
  883. if (wpas_network_disabled(wpa_s, ssid))
  884. continue;
  885. if (ssid->mode == IEEE80211_MODE_IBSS ||
  886. ssid->mode == IEEE80211_MODE_AP)
  887. return ssid;
  888. }
  889. }
  890. return NULL;
  891. }
  892. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  893. * on BSS added and BSS changed events */
  894. static void wpa_supplicant_rsn_preauth_scan_results(
  895. struct wpa_supplicant *wpa_s)
  896. {
  897. struct wpa_bss *bss;
  898. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  899. return;
  900. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  901. const u8 *ssid, *rsn;
  902. ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  903. if (ssid == NULL)
  904. continue;
  905. rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  906. if (rsn == NULL)
  907. continue;
  908. rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn);
  909. }
  910. }
  911. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  912. struct wpa_bss *selected,
  913. struct wpa_ssid *ssid)
  914. {
  915. struct wpa_bss *current_bss = NULL;
  916. int min_diff;
  917. if (wpa_s->reassociate)
  918. return 1; /* explicit request to reassociate */
  919. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  920. return 1; /* we are not associated; continue */
  921. if (wpa_s->current_ssid == NULL)
  922. return 1; /* unknown current SSID */
  923. if (wpa_s->current_ssid != ssid)
  924. return 1; /* different network block */
  925. if (wpas_driver_bss_selection(wpa_s))
  926. return 0; /* Driver-based roaming */
  927. if (wpa_s->current_ssid->ssid)
  928. current_bss = wpa_bss_get(wpa_s, wpa_s->bssid,
  929. wpa_s->current_ssid->ssid,
  930. wpa_s->current_ssid->ssid_len);
  931. if (!current_bss)
  932. current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid);
  933. if (!current_bss)
  934. return 1; /* current BSS not seen in scan results */
  935. if (current_bss == selected)
  936. return 0;
  937. if (selected->last_update_idx > current_bss->last_update_idx)
  938. return 1; /* current BSS not seen in the last scan */
  939. #ifndef CONFIG_NO_ROAMING
  940. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  941. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  942. MAC2STR(current_bss->bssid), current_bss->level);
  943. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  944. MAC2STR(selected->bssid), selected->level);
  945. if (wpa_s->current_ssid->bssid_set &&
  946. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  947. 0) {
  948. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  949. "has preferred BSSID");
  950. return 1;
  951. }
  952. if (current_bss->level < 0 && current_bss->level > selected->level) {
  953. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better "
  954. "signal level");
  955. return 0;
  956. }
  957. min_diff = 2;
  958. if (current_bss->level < 0) {
  959. if (current_bss->level < -85)
  960. min_diff = 1;
  961. else if (current_bss->level < -80)
  962. min_diff = 2;
  963. else if (current_bss->level < -75)
  964. min_diff = 3;
  965. else if (current_bss->level < -70)
  966. min_diff = 4;
  967. else
  968. min_diff = 5;
  969. }
  970. if (abs(current_bss->level - selected->level) < min_diff) {
  971. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  972. "in signal level");
  973. return 0;
  974. }
  975. return 1;
  976. #else /* CONFIG_NO_ROAMING */
  977. return 0;
  978. #endif /* CONFIG_NO_ROAMING */
  979. }
  980. /* Return != 0 if no scan results could be fetched or if scan results should not
  981. * be shared with other virtual interfaces. */
  982. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  983. union wpa_event_data *data,
  984. int own_request)
  985. {
  986. struct wpa_scan_results *scan_res;
  987. int ap = 0;
  988. #ifndef CONFIG_NO_RANDOM_POOL
  989. size_t i, num;
  990. #endif /* CONFIG_NO_RANDOM_POOL */
  991. #ifdef CONFIG_AP
  992. if (wpa_s->ap_iface)
  993. ap = 1;
  994. #endif /* CONFIG_AP */
  995. wpa_supplicant_notify_scanning(wpa_s, 0);
  996. #ifdef CONFIG_P2P
  997. if (own_request && wpa_s->global->p2p_cb_on_scan_complete &&
  998. !wpa_s->global->p2p_disabled &&
  999. wpa_s->global->p2p != NULL && !wpa_s->sta_scan_pending &&
  1000. !wpa_s->scan_res_handler) {
  1001. wpa_s->global->p2p_cb_on_scan_complete = 0;
  1002. if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
  1003. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
  1004. "stopped scan processing");
  1005. wpa_s->sta_scan_pending = 1;
  1006. wpa_supplicant_req_scan(wpa_s, 5, 0);
  1007. return -1;
  1008. }
  1009. }
  1010. wpa_s->sta_scan_pending = 0;
  1011. #endif /* CONFIG_P2P */
  1012. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  1013. data ? &data->scan_info :
  1014. NULL, 1);
  1015. if (scan_res == NULL) {
  1016. if (wpa_s->conf->ap_scan == 2 || ap ||
  1017. wpa_s->scan_res_handler == scan_only_handler)
  1018. return -1;
  1019. if (!own_request)
  1020. return -1;
  1021. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  1022. "scanning again");
  1023. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  1024. return -1;
  1025. }
  1026. #ifndef CONFIG_NO_RANDOM_POOL
  1027. num = scan_res->num;
  1028. if (num > 10)
  1029. num = 10;
  1030. for (i = 0; i < num; i++) {
  1031. u8 buf[5];
  1032. struct wpa_scan_res *res = scan_res->res[i];
  1033. buf[0] = res->bssid[5];
  1034. buf[1] = res->qual & 0xff;
  1035. buf[2] = res->noise & 0xff;
  1036. buf[3] = res->level & 0xff;
  1037. buf[4] = res->tsf & 0xff;
  1038. random_add_randomness(buf, sizeof(buf));
  1039. }
  1040. #endif /* CONFIG_NO_RANDOM_POOL */
  1041. if (own_request && wpa_s->scan_res_handler) {
  1042. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  1043. struct wpa_scan_results *scan_res);
  1044. scan_res_handler = wpa_s->scan_res_handler;
  1045. wpa_s->scan_res_handler = NULL;
  1046. scan_res_handler(wpa_s, scan_res);
  1047. wpa_scan_results_free(scan_res);
  1048. return -2;
  1049. }
  1050. if (ap) {
  1051. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  1052. #ifdef CONFIG_AP
  1053. if (wpa_s->ap_iface->scan_cb)
  1054. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  1055. #endif /* CONFIG_AP */
  1056. wpa_scan_results_free(scan_res);
  1057. return 0;
  1058. }
  1059. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  1060. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  1061. wpas_notify_scan_results(wpa_s);
  1062. wpas_notify_scan_done(wpa_s, 1);
  1063. if (sme_proc_obss_scan(wpa_s) > 0) {
  1064. wpa_scan_results_free(scan_res);
  1065. return 0;
  1066. }
  1067. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  1068. wpa_scan_results_free(scan_res);
  1069. return 0;
  1070. }
  1071. if (autoscan_notify_scan(wpa_s, scan_res)) {
  1072. wpa_scan_results_free(scan_res);
  1073. return 0;
  1074. }
  1075. if (wpa_s->disconnected) {
  1076. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1077. wpa_scan_results_free(scan_res);
  1078. return 0;
  1079. }
  1080. if (!wpas_driver_bss_selection(wpa_s) &&
  1081. bgscan_notify_scan(wpa_s, scan_res) == 1) {
  1082. wpa_scan_results_free(scan_res);
  1083. return 0;
  1084. }
  1085. wpas_wps_update_ap_info(wpa_s, scan_res);
  1086. wpa_scan_results_free(scan_res);
  1087. return wpas_select_network_from_last_scan(wpa_s, 1);
  1088. }
  1089. static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
  1090. int new_scan)
  1091. {
  1092. struct wpa_bss *selected;
  1093. struct wpa_ssid *ssid = NULL;
  1094. selected = wpa_supplicant_pick_network(wpa_s, &ssid);
  1095. if (selected) {
  1096. int skip;
  1097. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
  1098. if (skip) {
  1099. if (new_scan)
  1100. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1101. return 0;
  1102. }
  1103. if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
  1104. wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
  1105. return -1;
  1106. }
  1107. if (new_scan)
  1108. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1109. /*
  1110. * Do not notify other virtual radios of scan results since we do not
  1111. * want them to start other associations at the same time.
  1112. */
  1113. return 1;
  1114. } else {
  1115. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  1116. ssid = wpa_supplicant_pick_new_network(wpa_s);
  1117. if (ssid) {
  1118. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  1119. wpa_supplicant_associate(wpa_s, NULL, ssid);
  1120. if (new_scan)
  1121. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1122. } else {
  1123. int timeout_sec = wpa_s->scan_interval;
  1124. int timeout_usec = 0;
  1125. #ifdef CONFIG_P2P
  1126. if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
  1127. return 0;
  1128. if (wpa_s->p2p_in_provisioning) {
  1129. /*
  1130. * Use shorter wait during P2P Provisioning
  1131. * state to speed up group formation.
  1132. */
  1133. timeout_sec = 0;
  1134. timeout_usec = 250000;
  1135. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1136. timeout_usec);
  1137. return 0;
  1138. }
  1139. #endif /* CONFIG_P2P */
  1140. #ifdef CONFIG_INTERWORKING
  1141. if (wpa_s->conf->auto_interworking &&
  1142. wpa_s->conf->interworking &&
  1143. wpa_s->conf->cred) {
  1144. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
  1145. "start ANQP fetch since no matching "
  1146. "networks found");
  1147. wpa_s->network_select = 1;
  1148. wpa_s->auto_network_select = 1;
  1149. interworking_start_fetch_anqp(wpa_s);
  1150. return 1;
  1151. }
  1152. #endif /* CONFIG_INTERWORKING */
  1153. if (wpa_supplicant_req_sched_scan(wpa_s))
  1154. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1155. timeout_usec);
  1156. }
  1157. }
  1158. return 0;
  1159. }
  1160. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  1161. union wpa_event_data *data)
  1162. {
  1163. const char *rn, *rn2;
  1164. struct wpa_supplicant *ifs;
  1165. if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
  1166. /*
  1167. * If no scan results could be fetched, then no need to
  1168. * notify those interfaces that did not actually request
  1169. * this scan. Similarly, if scan results started a new operation on this
  1170. * interface, do not notify other interfaces to avoid concurrent
  1171. * operations during a connection attempt.
  1172. */
  1173. return;
  1174. }
  1175. /*
  1176. * Check other interfaces to see if they have the same radio-name. If
  1177. * so, they get updated with this same scan info.
  1178. */
  1179. if (!wpa_s->driver->get_radio_name)
  1180. return;
  1181. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  1182. if (rn == NULL || rn[0] == '\0')
  1183. return;
  1184. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  1185. "sharing same radio (%s) in event_scan_results", rn);
  1186. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  1187. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  1188. continue;
  1189. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  1190. if (rn2 && os_strcmp(rn, rn2) == 0) {
  1191. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  1192. "sibling", ifs->ifname);
  1193. _wpa_supplicant_event_scan_results(ifs, data, 0);
  1194. }
  1195. }
  1196. }
  1197. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1198. int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
  1199. {
  1200. #ifdef CONFIG_NO_SCAN_PROCESSING
  1201. return -1;
  1202. #else /* CONFIG_NO_SCAN_PROCESSING */
  1203. struct os_time now;
  1204. if (wpa_s->last_scan_res_used <= 0)
  1205. return -1;
  1206. os_get_time(&now);
  1207. if (now.sec - wpa_s->last_scan.sec > 5) {
  1208. wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
  1209. return -1;
  1210. }
  1211. return wpas_select_network_from_last_scan(wpa_s, 0);
  1212. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1213. }
  1214. #ifdef CONFIG_WNM
  1215. static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
  1216. {
  1217. struct wpa_supplicant *wpa_s = eloop_ctx;
  1218. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1219. return;
  1220. if (!wpa_s->no_keep_alive) {
  1221. wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
  1222. MAC2STR(wpa_s->bssid));
  1223. /* TODO: could skip this if normal data traffic has been sent */
  1224. /* TODO: Consider using some more appropriate data frame for
  1225. * this */
  1226. if (wpa_s->l2)
  1227. l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
  1228. (u8 *) "", 0);
  1229. }
  1230. #ifdef CONFIG_SME
  1231. if (wpa_s->sme.bss_max_idle_period) {
  1232. unsigned int msec;
  1233. msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
  1234. if (msec > 100)
  1235. msec -= 100;
  1236. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1237. wnm_bss_keep_alive, wpa_s, NULL);
  1238. }
  1239. #endif /* CONFIG_SME */
  1240. }
  1241. static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1242. const u8 *ies, size_t ies_len)
  1243. {
  1244. struct ieee802_11_elems elems;
  1245. if (ies == NULL)
  1246. return;
  1247. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1248. return;
  1249. #ifdef CONFIG_SME
  1250. if (elems.bss_max_idle_period) {
  1251. unsigned int msec;
  1252. wpa_s->sme.bss_max_idle_period =
  1253. WPA_GET_LE16(elems.bss_max_idle_period);
  1254. wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
  1255. "TU)%s", wpa_s->sme.bss_max_idle_period,
  1256. (elems.bss_max_idle_period[2] & 0x01) ?
  1257. " (protected keep-live required)" : "");
  1258. if (wpa_s->sme.bss_max_idle_period == 0)
  1259. wpa_s->sme.bss_max_idle_period = 1;
  1260. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
  1261. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1262. /* msec times 1000 */
  1263. msec = wpa_s->sme.bss_max_idle_period * 1024;
  1264. if (msec > 100)
  1265. msec -= 100;
  1266. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1267. wnm_bss_keep_alive, wpa_s,
  1268. NULL);
  1269. }
  1270. }
  1271. #endif /* CONFIG_SME */
  1272. }
  1273. #endif /* CONFIG_WNM */
  1274. void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
  1275. {
  1276. #ifdef CONFIG_WNM
  1277. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1278. #endif /* CONFIG_WNM */
  1279. }
  1280. #ifdef CONFIG_INTERWORKING
  1281. static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
  1282. size_t len)
  1283. {
  1284. int res;
  1285. wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
  1286. res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
  1287. if (res) {
  1288. wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
  1289. }
  1290. return res;
  1291. }
  1292. static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1293. const u8 *ies, size_t ies_len)
  1294. {
  1295. struct ieee802_11_elems elems;
  1296. if (ies == NULL)
  1297. return;
  1298. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1299. return;
  1300. if (elems.qos_map_set) {
  1301. wpas_qos_map_set(wpa_s, elems.qos_map_set,
  1302. elems.qos_map_set_len);
  1303. }
  1304. }
  1305. #endif /* CONFIG_INTERWORKING */
  1306. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  1307. union wpa_event_data *data)
  1308. {
  1309. int l, len, found = 0, wpa_found, rsn_found;
  1310. const u8 *p;
  1311. #ifdef CONFIG_IEEE80211R
  1312. u8 bssid[ETH_ALEN];
  1313. #endif /* CONFIG_IEEE80211R */
  1314. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  1315. if (data->assoc_info.req_ies)
  1316. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  1317. data->assoc_info.req_ies_len);
  1318. if (data->assoc_info.resp_ies) {
  1319. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  1320. data->assoc_info.resp_ies_len);
  1321. #ifdef CONFIG_TDLS
  1322. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  1323. data->assoc_info.resp_ies_len);
  1324. #endif /* CONFIG_TDLS */
  1325. #ifdef CONFIG_WNM
  1326. wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1327. data->assoc_info.resp_ies_len);
  1328. #endif /* CONFIG_WNM */
  1329. #ifdef CONFIG_INTERWORKING
  1330. interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1331. data->assoc_info.resp_ies_len);
  1332. #endif /* CONFIG_INTERWORKING */
  1333. }
  1334. if (data->assoc_info.beacon_ies)
  1335. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  1336. data->assoc_info.beacon_ies,
  1337. data->assoc_info.beacon_ies_len);
  1338. if (data->assoc_info.freq)
  1339. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  1340. data->assoc_info.freq);
  1341. p = data->assoc_info.req_ies;
  1342. l = data->assoc_info.req_ies_len;
  1343. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  1344. while (p && l >= 2) {
  1345. len = p[1] + 2;
  1346. if (len > l) {
  1347. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1348. p, l);
  1349. break;
  1350. }
  1351. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1352. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  1353. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  1354. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  1355. break;
  1356. found = 1;
  1357. wpa_find_assoc_pmkid(wpa_s);
  1358. break;
  1359. }
  1360. l -= len;
  1361. p += len;
  1362. }
  1363. if (!found && data->assoc_info.req_ies)
  1364. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1365. #ifdef CONFIG_IEEE80211R
  1366. #ifdef CONFIG_SME
  1367. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1368. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1369. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1370. data->assoc_info.resp_ies,
  1371. data->assoc_info.resp_ies_len,
  1372. bssid) < 0) {
  1373. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1374. "Reassociation Response failed");
  1375. wpa_supplicant_deauthenticate(
  1376. wpa_s, WLAN_REASON_INVALID_IE);
  1377. return -1;
  1378. }
  1379. }
  1380. p = data->assoc_info.resp_ies;
  1381. l = data->assoc_info.resp_ies_len;
  1382. #ifdef CONFIG_WPS_STRICT
  1383. if (p && wpa_s->current_ssid &&
  1384. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1385. struct wpabuf *wps;
  1386. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1387. if (wps == NULL) {
  1388. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1389. "include WPS IE in (Re)Association Response");
  1390. return -1;
  1391. }
  1392. if (wps_validate_assoc_resp(wps) < 0) {
  1393. wpabuf_free(wps);
  1394. wpa_supplicant_deauthenticate(
  1395. wpa_s, WLAN_REASON_INVALID_IE);
  1396. return -1;
  1397. }
  1398. wpabuf_free(wps);
  1399. }
  1400. #endif /* CONFIG_WPS_STRICT */
  1401. /* Go through the IEs and make a copy of the MDIE, if present. */
  1402. while (p && l >= 2) {
  1403. len = p[1] + 2;
  1404. if (len > l) {
  1405. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1406. p, l);
  1407. break;
  1408. }
  1409. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1410. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1411. wpa_s->sme.ft_used = 1;
  1412. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1413. MOBILITY_DOMAIN_ID_LEN);
  1414. break;
  1415. }
  1416. l -= len;
  1417. p += len;
  1418. }
  1419. #endif /* CONFIG_SME */
  1420. /* Process FT when SME is in the driver */
  1421. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  1422. wpa_ft_is_completed(wpa_s->wpa)) {
  1423. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1424. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1425. data->assoc_info.resp_ies,
  1426. data->assoc_info.resp_ies_len,
  1427. bssid) < 0) {
  1428. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1429. "Reassociation Response failed");
  1430. wpa_supplicant_deauthenticate(
  1431. wpa_s, WLAN_REASON_INVALID_IE);
  1432. return -1;
  1433. }
  1434. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
  1435. }
  1436. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1437. data->assoc_info.resp_ies_len);
  1438. #endif /* CONFIG_IEEE80211R */
  1439. /* WPA/RSN IE from Beacon/ProbeResp */
  1440. p = data->assoc_info.beacon_ies;
  1441. l = data->assoc_info.beacon_ies_len;
  1442. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1443. */
  1444. wpa_found = rsn_found = 0;
  1445. while (p && l >= 2) {
  1446. len = p[1] + 2;
  1447. if (len > l) {
  1448. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1449. p, l);
  1450. break;
  1451. }
  1452. if (!wpa_found &&
  1453. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1454. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1455. wpa_found = 1;
  1456. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1457. }
  1458. if (!rsn_found &&
  1459. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1460. rsn_found = 1;
  1461. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1462. }
  1463. l -= len;
  1464. p += len;
  1465. }
  1466. if (!wpa_found && data->assoc_info.beacon_ies)
  1467. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1468. if (!rsn_found && data->assoc_info.beacon_ies)
  1469. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1470. if (wpa_found || rsn_found)
  1471. wpa_s->ap_ies_from_associnfo = 1;
  1472. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1473. wpa_s->assoc_freq != data->assoc_info.freq) {
  1474. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1475. "%u to %u MHz",
  1476. wpa_s->assoc_freq, data->assoc_info.freq);
  1477. wpa_supplicant_update_scan_results(wpa_s);
  1478. }
  1479. wpa_s->assoc_freq = data->assoc_info.freq;
  1480. return 0;
  1481. }
  1482. static struct wpa_bss * wpa_supplicant_get_new_bss(
  1483. struct wpa_supplicant *wpa_s, const u8 *bssid)
  1484. {
  1485. struct wpa_bss *bss = NULL;
  1486. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1487. if (ssid->ssid_len > 0)
  1488. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  1489. if (!bss)
  1490. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1491. return bss;
  1492. }
  1493. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  1494. {
  1495. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  1496. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  1497. return -1;
  1498. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  1499. return 0;
  1500. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1501. WPA_IE_VENDOR_TYPE);
  1502. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  1503. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  1504. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  1505. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  1506. bss_rsn ? 2 + bss_rsn[1] : 0))
  1507. return -1;
  1508. return 0;
  1509. }
  1510. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1511. union wpa_event_data *data)
  1512. {
  1513. u8 bssid[ETH_ALEN];
  1514. int ft_completed;
  1515. #ifdef CONFIG_AP
  1516. if (wpa_s->ap_iface) {
  1517. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1518. data->assoc_info.addr,
  1519. data->assoc_info.req_ies,
  1520. data->assoc_info.req_ies_len,
  1521. data->assoc_info.reassoc);
  1522. return;
  1523. }
  1524. #endif /* CONFIG_AP */
  1525. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1526. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1527. return;
  1528. if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
  1529. wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
  1530. wpa_supplicant_deauthenticate(
  1531. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1532. return;
  1533. }
  1534. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1535. if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  1536. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1537. MACSTR, MAC2STR(bssid));
  1538. random_add_randomness(bssid, ETH_ALEN);
  1539. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1540. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1541. wpas_notify_bssid_changed(wpa_s);
  1542. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1543. wpa_clear_keys(wpa_s, bssid);
  1544. }
  1545. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1546. wpa_supplicant_deauthenticate(
  1547. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1548. return;
  1549. }
  1550. if (wpa_s->current_ssid) {
  1551. struct wpa_bss *bss = NULL;
  1552. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1553. if (!bss) {
  1554. wpa_supplicant_update_scan_results(wpa_s);
  1555. /* Get the BSS from the new scan results */
  1556. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1557. }
  1558. if (bss)
  1559. wpa_s->current_bss = bss;
  1560. }
  1561. if (wpa_s->conf->ap_scan == 1 &&
  1562. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  1563. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
  1564. wpa_msg(wpa_s, MSG_WARNING,
  1565. "WPA/RSN IEs not updated");
  1566. }
  1567. }
  1568. #ifdef CONFIG_SME
  1569. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1570. wpa_s->sme.prev_bssid_set = 1;
  1571. #endif /* CONFIG_SME */
  1572. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1573. if (wpa_s->current_ssid) {
  1574. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1575. * initialized before association, but for other modes,
  1576. * initialize PC/SC here, if the current configuration needs
  1577. * smartcard or SIM/USIM. */
  1578. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1579. }
  1580. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1581. if (wpa_s->l2)
  1582. l2_packet_notify_auth_start(wpa_s->l2);
  1583. /*
  1584. * Set portEnabled first to FALSE in order to get EAP state machine out
  1585. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1586. * state machine may transit to AUTHENTICATING state based on obsolete
  1587. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1588. * AUTHENTICATED without ever giving chance to EAP state machine to
  1589. * reset the state.
  1590. */
  1591. if (!ft_completed) {
  1592. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1593. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1594. }
  1595. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1596. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1597. /* 802.1X::portControl = Auto */
  1598. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1599. wpa_s->eapol_received = 0;
  1600. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1601. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1602. (wpa_s->current_ssid &&
  1603. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1604. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
  1605. (wpa_s->drv_flags &
  1606. WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  1607. /*
  1608. * Set the key after having received joined-IBSS event
  1609. * from the driver.
  1610. */
  1611. wpa_supplicant_set_wpa_none_key(wpa_s,
  1612. wpa_s->current_ssid);
  1613. }
  1614. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1615. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1616. } else if (!ft_completed) {
  1617. /* Timeout for receiving the first EAPOL packet */
  1618. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1619. }
  1620. wpa_supplicant_cancel_scan(wpa_s);
  1621. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1622. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1623. /*
  1624. * We are done; the driver will take care of RSN 4-way
  1625. * handshake.
  1626. */
  1627. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1628. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1629. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1630. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1631. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1632. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1633. /*
  1634. * The driver will take care of RSN 4-way handshake, so we need
  1635. * to allow EAPOL supplicant to complete its work without
  1636. * waiting for WPA supplicant.
  1637. */
  1638. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1639. } else if (ft_completed) {
  1640. /*
  1641. * FT protocol completed - make sure EAPOL state machine ends
  1642. * up in authenticated.
  1643. */
  1644. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1645. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1646. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1647. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1648. }
  1649. wpa_s->last_eapol_matches_bssid = 0;
  1650. if (wpa_s->pending_eapol_rx) {
  1651. struct os_time now, age;
  1652. os_get_time(&now);
  1653. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1654. if (age.sec == 0 && age.usec < 100000 &&
  1655. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1656. 0) {
  1657. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1658. "frame that was received just before "
  1659. "association notification");
  1660. wpa_supplicant_rx_eapol(
  1661. wpa_s, wpa_s->pending_eapol_rx_src,
  1662. wpabuf_head(wpa_s->pending_eapol_rx),
  1663. wpabuf_len(wpa_s->pending_eapol_rx));
  1664. }
  1665. wpabuf_free(wpa_s->pending_eapol_rx);
  1666. wpa_s->pending_eapol_rx = NULL;
  1667. }
  1668. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1669. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1670. wpa_s->current_ssid &&
  1671. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  1672. /* Set static WEP keys again */
  1673. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1674. }
  1675. #ifdef CONFIG_IBSS_RSN
  1676. if (wpa_s->current_ssid &&
  1677. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1678. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1679. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1680. wpa_s->ibss_rsn == NULL) {
  1681. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1682. if (!wpa_s->ibss_rsn) {
  1683. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1684. wpa_supplicant_deauthenticate(
  1685. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1686. return;
  1687. }
  1688. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1689. }
  1690. #endif /* CONFIG_IBSS_RSN */
  1691. wpas_wps_notify_assoc(wpa_s, bssid);
  1692. }
  1693. static int disconnect_reason_recoverable(u16 reason_code)
  1694. {
  1695. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  1696. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  1697. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  1698. }
  1699. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1700. u16 reason_code,
  1701. int locally_generated)
  1702. {
  1703. const u8 *bssid;
  1704. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1705. /*
  1706. * At least Host AP driver and a Prism3 card seemed to be
  1707. * generating streams of disconnected events when configuring
  1708. * IBSS for WPA-None. Ignore them for now.
  1709. */
  1710. return;
  1711. }
  1712. bssid = wpa_s->bssid;
  1713. if (is_zero_ether_addr(bssid))
  1714. bssid = wpa_s->pending_bssid;
  1715. if (!is_zero_ether_addr(bssid) ||
  1716. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  1717. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1718. " reason=%d%s",
  1719. MAC2STR(bssid), reason_code,
  1720. locally_generated ? " locally_generated=1" : "");
  1721. }
  1722. }
  1723. static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
  1724. int locally_generated)
  1725. {
  1726. if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
  1727. !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  1728. return 0; /* Not in 4-way handshake with PSK */
  1729. /*
  1730. * It looks like connection was lost while trying to go through PSK
  1731. * 4-way handshake. Filter out known disconnection cases that are caused
  1732. * by something else than PSK mismatch to avoid confusing reports.
  1733. */
  1734. if (locally_generated) {
  1735. if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
  1736. return 0;
  1737. }
  1738. return 1;
  1739. }
  1740. static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
  1741. u16 reason_code,
  1742. int locally_generated)
  1743. {
  1744. const u8 *bssid;
  1745. int authenticating;
  1746. u8 prev_pending_bssid[ETH_ALEN];
  1747. struct wpa_bss *fast_reconnect = NULL;
  1748. #ifndef CONFIG_NO_SCAN_PROCESSING
  1749. struct wpa_ssid *fast_reconnect_ssid = NULL;
  1750. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1751. struct wpa_ssid *last_ssid;
  1752. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1753. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1754. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1755. /*
  1756. * At least Host AP driver and a Prism3 card seemed to be
  1757. * generating streams of disconnected events when configuring
  1758. * IBSS for WPA-None. Ignore them for now.
  1759. */
  1760. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1761. "IBSS/WPA-None mode");
  1762. return;
  1763. }
  1764. if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
  1765. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1766. "pre-shared key may be incorrect");
  1767. if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
  1768. return; /* P2P group removed */
  1769. wpas_auth_failed(wpa_s);
  1770. }
  1771. if (!wpa_s->disconnected &&
  1772. (!wpa_s->auto_reconnect_disabled ||
  1773. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
  1774. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  1775. "reconnect (wps=%d wpa_state=%d)",
  1776. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  1777. wpa_s->wpa_state);
  1778. if (wpa_s->wpa_state == WPA_COMPLETED &&
  1779. wpa_s->current_ssid &&
  1780. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  1781. !locally_generated &&
  1782. disconnect_reason_recoverable(reason_code)) {
  1783. /*
  1784. * It looks like the AP has dropped association with
  1785. * us, but could allow us to get back in. Try to
  1786. * reconnect to the same BSS without full scan to save
  1787. * time for some common cases.
  1788. */
  1789. fast_reconnect = wpa_s->current_bss;
  1790. #ifndef CONFIG_NO_SCAN_PROCESSING
  1791. fast_reconnect_ssid = wpa_s->current_ssid;
  1792. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1793. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1794. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1795. else
  1796. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  1797. "immediate scan");
  1798. } else {
  1799. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  1800. "try to re-connect");
  1801. wpa_s->reassociate = 0;
  1802. wpa_s->disconnected = 1;
  1803. wpa_supplicant_cancel_sched_scan(wpa_s);
  1804. }
  1805. bssid = wpa_s->bssid;
  1806. if (is_zero_ether_addr(bssid))
  1807. bssid = wpa_s->pending_bssid;
  1808. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  1809. wpas_connection_failed(wpa_s, bssid);
  1810. wpa_sm_notify_disassoc(wpa_s->wpa);
  1811. if (locally_generated)
  1812. wpa_s->disconnect_reason = -reason_code;
  1813. else
  1814. wpa_s->disconnect_reason = reason_code;
  1815. wpas_notify_disconnect_reason(wpa_s);
  1816. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1817. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1818. wpa_s->keys_cleared = 0;
  1819. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1820. }
  1821. last_ssid = wpa_s->current_ssid;
  1822. wpa_supplicant_mark_disassoc(wpa_s);
  1823. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
  1824. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1825. wpa_s->current_ssid = last_ssid;
  1826. }
  1827. if (fast_reconnect) {
  1828. #ifndef CONFIG_NO_SCAN_PROCESSING
  1829. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  1830. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  1831. fast_reconnect_ssid) < 0) {
  1832. /* Recover through full scan */
  1833. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1834. }
  1835. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1836. }
  1837. }
  1838. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1839. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  1840. {
  1841. struct wpa_supplicant *wpa_s = eloop_ctx;
  1842. if (!wpa_s->pending_mic_error_report)
  1843. return;
  1844. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1845. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1846. wpa_s->pending_mic_error_report = 0;
  1847. }
  1848. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1849. static void
  1850. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1851. union wpa_event_data *data)
  1852. {
  1853. int pairwise;
  1854. struct os_time t;
  1855. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1856. pairwise = (data && data->michael_mic_failure.unicast);
  1857. os_get_time(&t);
  1858. if ((wpa_s->last_michael_mic_error &&
  1859. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1860. wpa_s->pending_mic_error_report) {
  1861. if (wpa_s->pending_mic_error_report) {
  1862. /*
  1863. * Send the pending MIC error report immediately since
  1864. * we are going to start countermeasures and AP better
  1865. * do the same.
  1866. */
  1867. wpa_sm_key_request(wpa_s->wpa, 1,
  1868. wpa_s->pending_mic_error_pairwise);
  1869. }
  1870. /* Send the new MIC error report immediately since we are going
  1871. * to start countermeasures and AP better do the same.
  1872. */
  1873. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1874. /* initialize countermeasures */
  1875. wpa_s->countermeasures = 1;
  1876. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  1877. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1878. /*
  1879. * Need to wait for completion of request frame. We do not get
  1880. * any callback for the message completion, so just wait a
  1881. * short while and hope for the best. */
  1882. os_sleep(0, 10000);
  1883. wpa_drv_set_countermeasures(wpa_s, 1);
  1884. wpa_supplicant_deauthenticate(wpa_s,
  1885. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1886. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1887. wpa_s, NULL);
  1888. eloop_register_timeout(60, 0,
  1889. wpa_supplicant_stop_countermeasures,
  1890. wpa_s, NULL);
  1891. /* TODO: mark the AP rejected for 60 second. STA is
  1892. * allowed to associate with another AP.. */
  1893. } else {
  1894. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1895. if (wpa_s->mic_errors_seen) {
  1896. /*
  1897. * Reduce the effectiveness of Michael MIC error
  1898. * reports as a means for attacking against TKIP if
  1899. * more than one MIC failure is noticed with the same
  1900. * PTK. We delay the transmission of the reports by a
  1901. * random time between 0 and 60 seconds in order to
  1902. * force the attacker wait 60 seconds before getting
  1903. * the information on whether a frame resulted in a MIC
  1904. * failure.
  1905. */
  1906. u8 rval[4];
  1907. int sec;
  1908. if (os_get_random(rval, sizeof(rval)) < 0)
  1909. sec = os_random() % 60;
  1910. else
  1911. sec = WPA_GET_BE32(rval) % 60;
  1912. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1913. "report %d seconds", sec);
  1914. wpa_s->pending_mic_error_report = 1;
  1915. wpa_s->pending_mic_error_pairwise = pairwise;
  1916. eloop_cancel_timeout(
  1917. wpa_supplicant_delayed_mic_error_report,
  1918. wpa_s, NULL);
  1919. eloop_register_timeout(
  1920. sec, os_random() % 1000000,
  1921. wpa_supplicant_delayed_mic_error_report,
  1922. wpa_s, NULL);
  1923. } else {
  1924. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1925. }
  1926. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1927. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1928. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1929. }
  1930. wpa_s->last_michael_mic_error = t.sec;
  1931. wpa_s->mic_errors_seen++;
  1932. }
  1933. #ifdef CONFIG_TERMINATE_ONLASTIF
  1934. static int any_interfaces(struct wpa_supplicant *head)
  1935. {
  1936. struct wpa_supplicant *wpa_s;
  1937. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1938. if (!wpa_s->interface_removed)
  1939. return 1;
  1940. return 0;
  1941. }
  1942. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1943. static void
  1944. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1945. union wpa_event_data *data)
  1946. {
  1947. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1948. return;
  1949. switch (data->interface_status.ievent) {
  1950. case EVENT_INTERFACE_ADDED:
  1951. if (!wpa_s->interface_removed)
  1952. break;
  1953. wpa_s->interface_removed = 0;
  1954. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1955. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1956. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1957. "driver after interface was added");
  1958. }
  1959. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1960. break;
  1961. case EVENT_INTERFACE_REMOVED:
  1962. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1963. wpa_s->interface_removed = 1;
  1964. wpa_supplicant_mark_disassoc(wpa_s);
  1965. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1966. l2_packet_deinit(wpa_s->l2);
  1967. wpa_s->l2 = NULL;
  1968. #ifdef CONFIG_IBSS_RSN
  1969. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1970. wpa_s->ibss_rsn = NULL;
  1971. #endif /* CONFIG_IBSS_RSN */
  1972. #ifdef CONFIG_TERMINATE_ONLASTIF
  1973. /* check if last interface */
  1974. if (!any_interfaces(wpa_s->global->ifaces))
  1975. eloop_terminate();
  1976. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1977. break;
  1978. }
  1979. }
  1980. #ifdef CONFIG_PEERKEY
  1981. static void
  1982. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1983. union wpa_event_data *data)
  1984. {
  1985. if (data == NULL)
  1986. return;
  1987. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1988. }
  1989. #endif /* CONFIG_PEERKEY */
  1990. #ifdef CONFIG_TDLS
  1991. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1992. union wpa_event_data *data)
  1993. {
  1994. if (data == NULL)
  1995. return;
  1996. switch (data->tdls.oper) {
  1997. case TDLS_REQUEST_SETUP:
  1998. wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
  1999. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2000. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  2001. else
  2002. wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
  2003. break;
  2004. case TDLS_REQUEST_TEARDOWN:
  2005. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2006. wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
  2007. data->tdls.reason_code);
  2008. else
  2009. wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
  2010. data->tdls.peer);
  2011. break;
  2012. }
  2013. }
  2014. #endif /* CONFIG_TDLS */
  2015. #ifdef CONFIG_WNM
  2016. static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
  2017. union wpa_event_data *data)
  2018. {
  2019. if (data == NULL)
  2020. return;
  2021. switch (data->wnm.oper) {
  2022. case WNM_OPER_SLEEP:
  2023. wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
  2024. "(action=%d, intval=%d)",
  2025. data->wnm.sleep_action, data->wnm.sleep_intval);
  2026. ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
  2027. data->wnm.sleep_intval, NULL);
  2028. break;
  2029. }
  2030. }
  2031. #endif /* CONFIG_WNM */
  2032. #ifdef CONFIG_IEEE80211R
  2033. static void
  2034. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  2035. union wpa_event_data *data)
  2036. {
  2037. if (data == NULL)
  2038. return;
  2039. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  2040. data->ft_ies.ies_len,
  2041. data->ft_ies.ft_action,
  2042. data->ft_ies.target_ap,
  2043. data->ft_ies.ric_ies,
  2044. data->ft_ies.ric_ies_len) < 0) {
  2045. /* TODO: prevent MLME/driver from trying to associate? */
  2046. }
  2047. }
  2048. #endif /* CONFIG_IEEE80211R */
  2049. #ifdef CONFIG_IBSS_RSN
  2050. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  2051. union wpa_event_data *data)
  2052. {
  2053. struct wpa_ssid *ssid;
  2054. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  2055. return;
  2056. if (data == NULL)
  2057. return;
  2058. ssid = wpa_s->current_ssid;
  2059. if (ssid == NULL)
  2060. return;
  2061. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2062. return;
  2063. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  2064. }
  2065. static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
  2066. union wpa_event_data *data)
  2067. {
  2068. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2069. if (ssid == NULL)
  2070. return;
  2071. /* check if the ssid is correctly configured as IBSS/RSN */
  2072. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2073. return;
  2074. ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
  2075. data->rx_mgmt.frame_len);
  2076. }
  2077. #endif /* CONFIG_IBSS_RSN */
  2078. #ifdef CONFIG_IEEE80211R
  2079. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  2080. size_t len)
  2081. {
  2082. const u8 *sta_addr, *target_ap_addr;
  2083. u16 status;
  2084. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  2085. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  2086. return; /* only SME case supported for now */
  2087. if (len < 1 + 2 * ETH_ALEN + 2)
  2088. return;
  2089. if (data[0] != 2)
  2090. return; /* Only FT Action Response is supported for now */
  2091. sta_addr = data + 1;
  2092. target_ap_addr = data + 1 + ETH_ALEN;
  2093. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  2094. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  2095. MACSTR " TargetAP " MACSTR " status %u",
  2096. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  2097. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  2098. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  2099. " in FT Action Response", MAC2STR(sta_addr));
  2100. return;
  2101. }
  2102. if (status) {
  2103. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  2104. "failure (status code %d)", status);
  2105. /* TODO: report error to FT code(?) */
  2106. return;
  2107. }
  2108. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  2109. len - (1 + 2 * ETH_ALEN + 2), 1,
  2110. target_ap_addr, NULL, 0) < 0)
  2111. return;
  2112. #ifdef CONFIG_SME
  2113. {
  2114. struct wpa_bss *bss;
  2115. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  2116. if (bss)
  2117. wpa_s->sme.freq = bss->freq;
  2118. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  2119. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  2120. WLAN_AUTH_FT);
  2121. }
  2122. #endif /* CONFIG_SME */
  2123. }
  2124. #endif /* CONFIG_IEEE80211R */
  2125. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  2126. struct unprot_deauth *e)
  2127. {
  2128. #ifdef CONFIG_IEEE80211W
  2129. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  2130. "dropped: " MACSTR " -> " MACSTR
  2131. " (reason code %u)",
  2132. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2133. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2134. #endif /* CONFIG_IEEE80211W */
  2135. }
  2136. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  2137. struct unprot_disassoc *e)
  2138. {
  2139. #ifdef CONFIG_IEEE80211W
  2140. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  2141. "dropped: " MACSTR " -> " MACSTR
  2142. " (reason code %u)",
  2143. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2144. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2145. #endif /* CONFIG_IEEE80211W */
  2146. }
  2147. static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
  2148. u16 reason_code, int locally_generated,
  2149. const u8 *ie, size_t ie_len, int deauth)
  2150. {
  2151. #ifdef CONFIG_AP
  2152. if (wpa_s->ap_iface && addr) {
  2153. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
  2154. return;
  2155. }
  2156. if (wpa_s->ap_iface) {
  2157. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
  2158. return;
  2159. }
  2160. #endif /* CONFIG_AP */
  2161. wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
  2162. if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
  2163. ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  2164. (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
  2165. eapol_sm_failed(wpa_s->eapol)))
  2166. wpas_auth_failed(wpa_s);
  2167. #ifdef CONFIG_P2P
  2168. if (deauth && reason_code > 0) {
  2169. if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
  2170. locally_generated) > 0) {
  2171. /*
  2172. * The interface was removed, so cannot continue
  2173. * processing any additional operations after this.
  2174. */
  2175. return;
  2176. }
  2177. }
  2178. #endif /* CONFIG_P2P */
  2179. wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
  2180. locally_generated);
  2181. }
  2182. static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
  2183. struct disassoc_info *info)
  2184. {
  2185. u16 reason_code = 0;
  2186. int locally_generated = 0;
  2187. const u8 *addr = NULL;
  2188. const u8 *ie = NULL;
  2189. size_t ie_len = 0;
  2190. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  2191. if (info) {
  2192. addr = info->addr;
  2193. ie = info->ie;
  2194. ie_len = info->ie_len;
  2195. reason_code = info->reason_code;
  2196. locally_generated = info->locally_generated;
  2197. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
  2198. locally_generated ? " (locally generated)" : "");
  2199. if (addr)
  2200. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2201. MAC2STR(addr));
  2202. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  2203. ie, ie_len);
  2204. }
  2205. #ifdef CONFIG_AP
  2206. if (wpa_s->ap_iface && info && info->addr) {
  2207. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
  2208. return;
  2209. }
  2210. if (wpa_s->ap_iface) {
  2211. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
  2212. return;
  2213. }
  2214. #endif /* CONFIG_AP */
  2215. #ifdef CONFIG_P2P
  2216. if (info) {
  2217. wpas_p2p_disassoc_notif(
  2218. wpa_s, info->addr, reason_code, info->ie, info->ie_len,
  2219. locally_generated);
  2220. }
  2221. #endif /* CONFIG_P2P */
  2222. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2223. sme_event_disassoc(wpa_s, info);
  2224. wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
  2225. ie, ie_len, 0);
  2226. }
  2227. static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
  2228. struct deauth_info *info)
  2229. {
  2230. u16 reason_code = 0;
  2231. int locally_generated = 0;
  2232. const u8 *addr = NULL;
  2233. const u8 *ie = NULL;
  2234. size_t ie_len = 0;
  2235. wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
  2236. if (info) {
  2237. addr = info->addr;
  2238. ie = info->ie;
  2239. ie_len = info->ie_len;
  2240. reason_code = info->reason_code;
  2241. locally_generated = info->locally_generated;
  2242. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  2243. reason_code,
  2244. locally_generated ? " (locally generated)" : "");
  2245. if (addr) {
  2246. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2247. MAC2STR(addr));
  2248. }
  2249. wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
  2250. ie, ie_len);
  2251. }
  2252. wpa_reset_ft_completed(wpa_s->wpa);
  2253. wpas_event_disconnect(wpa_s, addr, reason_code,
  2254. locally_generated, ie, ie_len, 1);
  2255. }
  2256. static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
  2257. {
  2258. const char *rn, *rn2;
  2259. struct wpa_supplicant *ifs;
  2260. if (wpa_s->drv_priv == NULL)
  2261. return; /* Ignore event during drv initialization */
  2262. free_hw_features(wpa_s);
  2263. wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
  2264. wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
  2265. #ifdef CONFIG_P2P
  2266. wpas_p2p_update_channel_list(wpa_s);
  2267. #endif /* CONFIG_P2P */
  2268. /*
  2269. * Check other interfaces to see if they have the same radio-name. If
  2270. * so, they get updated with this same hw mode info.
  2271. */
  2272. if (!wpa_s->driver->get_radio_name)
  2273. return;
  2274. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  2275. if (rn == NULL || rn[0] == '\0')
  2276. return;
  2277. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  2278. "sharing same radio (%s) in event_channel_list_change", rn);
  2279. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  2280. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  2281. continue;
  2282. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  2283. if (rn2 && os_strcmp(rn, rn2) == 0) {
  2284. wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
  2285. ifs->ifname);
  2286. free_hw_features(ifs);
  2287. ifs->hw.modes = wpa_drv_get_hw_feature_data(
  2288. ifs, &ifs->hw.num_modes, &ifs->hw.flags);
  2289. }
  2290. }
  2291. }
  2292. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  2293. union wpa_event_data *data)
  2294. {
  2295. struct wpa_supplicant *wpa_s = ctx;
  2296. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  2297. event != EVENT_INTERFACE_ENABLED &&
  2298. event != EVENT_INTERFACE_STATUS &&
  2299. event != EVENT_SCHED_SCAN_STOPPED) {
  2300. wpa_dbg(wpa_s, MSG_DEBUG,
  2301. "Ignore event %s (%d) while interface is disabled",
  2302. event_to_string(event), event);
  2303. return;
  2304. }
  2305. #ifndef CONFIG_NO_STDOUT_DEBUG
  2306. {
  2307. int level = MSG_DEBUG;
  2308. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
  2309. const struct ieee80211_hdr *hdr;
  2310. u16 fc;
  2311. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  2312. fc = le_to_host16(hdr->frame_control);
  2313. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  2314. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  2315. level = MSG_EXCESSIVE;
  2316. }
  2317. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  2318. event_to_string(event), event);
  2319. }
  2320. #endif /* CONFIG_NO_STDOUT_DEBUG */
  2321. switch (event) {
  2322. case EVENT_AUTH:
  2323. sme_event_auth(wpa_s, data);
  2324. break;
  2325. case EVENT_ASSOC:
  2326. wpa_supplicant_event_assoc(wpa_s, data);
  2327. break;
  2328. case EVENT_DISASSOC:
  2329. wpas_event_disassoc(wpa_s,
  2330. data ? &data->disassoc_info : NULL);
  2331. break;
  2332. case EVENT_DEAUTH:
  2333. wpas_event_deauth(wpa_s,
  2334. data ? &data->deauth_info : NULL);
  2335. break;
  2336. case EVENT_MICHAEL_MIC_FAILURE:
  2337. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  2338. break;
  2339. #ifndef CONFIG_NO_SCAN_PROCESSING
  2340. case EVENT_SCAN_RESULTS:
  2341. wpa_supplicant_event_scan_results(wpa_s, data);
  2342. if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
  2343. wpa_s->wpa_state != WPA_ASSOCIATING)
  2344. wpas_p2p_continue_after_scan(wpa_s);
  2345. break;
  2346. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2347. case EVENT_ASSOCINFO:
  2348. wpa_supplicant_event_associnfo(wpa_s, data);
  2349. break;
  2350. case EVENT_INTERFACE_STATUS:
  2351. wpa_supplicant_event_interface_status(wpa_s, data);
  2352. break;
  2353. case EVENT_PMKID_CANDIDATE:
  2354. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  2355. break;
  2356. #ifdef CONFIG_PEERKEY
  2357. case EVENT_STKSTART:
  2358. wpa_supplicant_event_stkstart(wpa_s, data);
  2359. break;
  2360. #endif /* CONFIG_PEERKEY */
  2361. #ifdef CONFIG_TDLS
  2362. case EVENT_TDLS:
  2363. wpa_supplicant_event_tdls(wpa_s, data);
  2364. break;
  2365. #endif /* CONFIG_TDLS */
  2366. #ifdef CONFIG_WNM
  2367. case EVENT_WNM:
  2368. wpa_supplicant_event_wnm(wpa_s, data);
  2369. break;
  2370. #endif /* CONFIG_WNM */
  2371. #ifdef CONFIG_IEEE80211R
  2372. case EVENT_FT_RESPONSE:
  2373. wpa_supplicant_event_ft_response(wpa_s, data);
  2374. break;
  2375. #endif /* CONFIG_IEEE80211R */
  2376. #ifdef CONFIG_IBSS_RSN
  2377. case EVENT_IBSS_RSN_START:
  2378. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  2379. break;
  2380. #endif /* CONFIG_IBSS_RSN */
  2381. case EVENT_ASSOC_REJECT:
  2382. if (data->assoc_reject.bssid)
  2383. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2384. "bssid=" MACSTR " status_code=%u",
  2385. MAC2STR(data->assoc_reject.bssid),
  2386. data->assoc_reject.status_code);
  2387. else
  2388. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2389. "status_code=%u",
  2390. data->assoc_reject.status_code);
  2391. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2392. sme_event_assoc_reject(wpa_s, data);
  2393. else {
  2394. const u8 *bssid = data->assoc_reject.bssid;
  2395. if (bssid == NULL || is_zero_ether_addr(bssid))
  2396. bssid = wpa_s->pending_bssid;
  2397. wpas_connection_failed(wpa_s, bssid);
  2398. wpa_supplicant_mark_disassoc(wpa_s);
  2399. }
  2400. break;
  2401. case EVENT_AUTH_TIMED_OUT:
  2402. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2403. sme_event_auth_timed_out(wpa_s, data);
  2404. break;
  2405. case EVENT_ASSOC_TIMED_OUT:
  2406. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2407. sme_event_assoc_timed_out(wpa_s, data);
  2408. break;
  2409. case EVENT_TX_STATUS:
  2410. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  2411. " type=%d stype=%d",
  2412. MAC2STR(data->tx_status.dst),
  2413. data->tx_status.type, data->tx_status.stype);
  2414. #ifdef CONFIG_AP
  2415. if (wpa_s->ap_iface == NULL) {
  2416. #ifdef CONFIG_OFFCHANNEL
  2417. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2418. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  2419. offchannel_send_action_tx_status(
  2420. wpa_s, data->tx_status.dst,
  2421. data->tx_status.data,
  2422. data->tx_status.data_len,
  2423. data->tx_status.ack ?
  2424. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2425. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2426. #endif /* CONFIG_OFFCHANNEL */
  2427. break;
  2428. }
  2429. #endif /* CONFIG_AP */
  2430. #ifdef CONFIG_OFFCHANNEL
  2431. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  2432. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  2433. /*
  2434. * Catch TX status events for Action frames we sent via group
  2435. * interface in GO mode.
  2436. */
  2437. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2438. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  2439. os_memcmp(wpa_s->parent->pending_action_dst,
  2440. data->tx_status.dst, ETH_ALEN) == 0) {
  2441. offchannel_send_action_tx_status(
  2442. wpa_s->parent, data->tx_status.dst,
  2443. data->tx_status.data,
  2444. data->tx_status.data_len,
  2445. data->tx_status.ack ?
  2446. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2447. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2448. break;
  2449. }
  2450. #endif /* CONFIG_OFFCHANNEL */
  2451. #ifdef CONFIG_AP
  2452. switch (data->tx_status.type) {
  2453. case WLAN_FC_TYPE_MGMT:
  2454. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  2455. data->tx_status.data_len,
  2456. data->tx_status.stype,
  2457. data->tx_status.ack);
  2458. break;
  2459. case WLAN_FC_TYPE_DATA:
  2460. ap_tx_status(wpa_s, data->tx_status.dst,
  2461. data->tx_status.data,
  2462. data->tx_status.data_len,
  2463. data->tx_status.ack);
  2464. break;
  2465. }
  2466. #endif /* CONFIG_AP */
  2467. break;
  2468. #ifdef CONFIG_AP
  2469. case EVENT_EAPOL_TX_STATUS:
  2470. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  2471. data->eapol_tx_status.data,
  2472. data->eapol_tx_status.data_len,
  2473. data->eapol_tx_status.ack);
  2474. break;
  2475. case EVENT_DRIVER_CLIENT_POLL_OK:
  2476. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  2477. break;
  2478. case EVENT_RX_FROM_UNKNOWN:
  2479. if (wpa_s->ap_iface == NULL)
  2480. break;
  2481. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  2482. data->rx_from_unknown.wds);
  2483. break;
  2484. case EVENT_CH_SWITCH:
  2485. if (!data)
  2486. break;
  2487. if (!wpa_s->ap_iface) {
  2488. wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
  2489. "event in non-AP mode");
  2490. break;
  2491. }
  2492. wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
  2493. data->ch_switch.ht_enabled,
  2494. data->ch_switch.ch_offset);
  2495. break;
  2496. #endif /* CONFIG_AP */
  2497. #if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
  2498. case EVENT_RX_MGMT: {
  2499. u16 fc, stype;
  2500. const struct ieee80211_mgmt *mgmt;
  2501. mgmt = (const struct ieee80211_mgmt *)
  2502. data->rx_mgmt.frame;
  2503. fc = le_to_host16(mgmt->frame_control);
  2504. stype = WLAN_FC_GET_STYPE(fc);
  2505. #ifdef CONFIG_AP
  2506. if (wpa_s->ap_iface == NULL) {
  2507. #endif /* CONFIG_AP */
  2508. #ifdef CONFIG_P2P
  2509. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2510. data->rx_mgmt.frame_len > 24) {
  2511. const u8 *src = mgmt->sa;
  2512. const u8 *ie = mgmt->u.probe_req.variable;
  2513. size_t ie_len = data->rx_mgmt.frame_len -
  2514. (mgmt->u.probe_req.variable -
  2515. data->rx_mgmt.frame);
  2516. wpas_p2p_probe_req_rx(
  2517. wpa_s, src, mgmt->da,
  2518. mgmt->bssid, ie, ie_len,
  2519. data->rx_mgmt.ssi_signal);
  2520. break;
  2521. }
  2522. #endif /* CONFIG_P2P */
  2523. #ifdef CONFIG_IBSS_RSN
  2524. if (stype == WLAN_FC_STYPE_AUTH &&
  2525. data->rx_mgmt.frame_len >= 30) {
  2526. wpa_supplicant_event_ibss_auth(wpa_s, data);
  2527. break;
  2528. }
  2529. #endif /* CONFIG_IBSS_RSN */
  2530. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  2531. "management frame in non-AP mode");
  2532. break;
  2533. #ifdef CONFIG_AP
  2534. }
  2535. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2536. data->rx_mgmt.frame_len > 24) {
  2537. const u8 *ie = mgmt->u.probe_req.variable;
  2538. size_t ie_len = data->rx_mgmt.frame_len -
  2539. (mgmt->u.probe_req.variable -
  2540. data->rx_mgmt.frame);
  2541. wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
  2542. mgmt->bssid, ie, ie_len,
  2543. data->rx_mgmt.ssi_signal);
  2544. }
  2545. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  2546. #endif /* CONFIG_AP */
  2547. break;
  2548. }
  2549. #endif /* CONFIG_AP || CONFIG_IBSS_RSN */
  2550. case EVENT_RX_ACTION:
  2551. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2552. " Category=%u DataLen=%d freq=%d MHz",
  2553. MAC2STR(data->rx_action.sa),
  2554. data->rx_action.category, (int) data->rx_action.len,
  2555. data->rx_action.freq);
  2556. #ifdef CONFIG_IEEE80211R
  2557. if (data->rx_action.category == WLAN_ACTION_FT) {
  2558. ft_rx_action(wpa_s, data->rx_action.data,
  2559. data->rx_action.len);
  2560. break;
  2561. }
  2562. #endif /* CONFIG_IEEE80211R */
  2563. #ifdef CONFIG_IEEE80211W
  2564. #ifdef CONFIG_SME
  2565. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  2566. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  2567. data->rx_action.data,
  2568. data->rx_action.len);
  2569. break;
  2570. }
  2571. #endif /* CONFIG_SME */
  2572. #endif /* CONFIG_IEEE80211W */
  2573. #ifdef CONFIG_WNM
  2574. if (data->rx_action.category == WLAN_ACTION_WNM) {
  2575. ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
  2576. break;
  2577. }
  2578. #endif /* CONFIG_WNM */
  2579. #ifdef CONFIG_GAS
  2580. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2581. gas_query_rx(wpa_s->gas, data->rx_action.da,
  2582. data->rx_action.sa, data->rx_action.bssid,
  2583. data->rx_action.data, data->rx_action.len,
  2584. data->rx_action.freq) == 0)
  2585. break;
  2586. #endif /* CONFIG_GAS */
  2587. #ifdef CONFIG_TDLS
  2588. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2589. data->rx_action.len >= 4 &&
  2590. data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2591. wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
  2592. "Response from " MACSTR,
  2593. MAC2STR(data->rx_action.sa));
  2594. break;
  2595. }
  2596. #endif /* CONFIG_TDLS */
  2597. #ifdef CONFIG_INTERWORKING
  2598. if (data->rx_action.category == WLAN_ACTION_QOS &&
  2599. data->rx_action.len >= 1 &&
  2600. data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
  2601. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
  2602. MACSTR, MAC2STR(data->rx_action.sa));
  2603. if (os_memcmp(data->rx_action.sa, wpa_s->bssid, ETH_ALEN)
  2604. == 0)
  2605. wpas_qos_map_set(wpa_s, data->rx_action.data + 1,
  2606. data->rx_action.len - 1);
  2607. break;
  2608. }
  2609. #endif /* CONFIG_INTERWORKING */
  2610. #ifdef CONFIG_P2P
  2611. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  2612. data->rx_action.sa,
  2613. data->rx_action.bssid,
  2614. data->rx_action.category,
  2615. data->rx_action.data,
  2616. data->rx_action.len, data->rx_action.freq);
  2617. #endif /* CONFIG_P2P */
  2618. break;
  2619. case EVENT_RX_PROBE_REQ:
  2620. if (data->rx_probe_req.sa == NULL ||
  2621. data->rx_probe_req.ie == NULL)
  2622. break;
  2623. #ifdef CONFIG_AP
  2624. if (wpa_s->ap_iface) {
  2625. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  2626. data->rx_probe_req.sa,
  2627. data->rx_probe_req.da,
  2628. data->rx_probe_req.bssid,
  2629. data->rx_probe_req.ie,
  2630. data->rx_probe_req.ie_len,
  2631. data->rx_probe_req.ssi_signal);
  2632. break;
  2633. }
  2634. #endif /* CONFIG_AP */
  2635. #ifdef CONFIG_P2P
  2636. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  2637. data->rx_probe_req.da,
  2638. data->rx_probe_req.bssid,
  2639. data->rx_probe_req.ie,
  2640. data->rx_probe_req.ie_len,
  2641. data->rx_probe_req.ssi_signal);
  2642. #endif /* CONFIG_P2P */
  2643. break;
  2644. case EVENT_REMAIN_ON_CHANNEL:
  2645. #ifdef CONFIG_OFFCHANNEL
  2646. offchannel_remain_on_channel_cb(
  2647. wpa_s, data->remain_on_channel.freq,
  2648. data->remain_on_channel.duration);
  2649. #endif /* CONFIG_OFFCHANNEL */
  2650. #ifdef CONFIG_P2P
  2651. wpas_p2p_remain_on_channel_cb(
  2652. wpa_s, data->remain_on_channel.freq,
  2653. data->remain_on_channel.duration);
  2654. #endif /* CONFIG_P2P */
  2655. break;
  2656. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  2657. #ifdef CONFIG_OFFCHANNEL
  2658. offchannel_cancel_remain_on_channel_cb(
  2659. wpa_s, data->remain_on_channel.freq);
  2660. #endif /* CONFIG_OFFCHANNEL */
  2661. #ifdef CONFIG_P2P
  2662. wpas_p2p_cancel_remain_on_channel_cb(
  2663. wpa_s, data->remain_on_channel.freq);
  2664. #endif /* CONFIG_P2P */
  2665. break;
  2666. #ifdef CONFIG_P2P
  2667. case EVENT_P2P_DEV_FOUND: {
  2668. struct p2p_peer_info peer_info;
  2669. os_memset(&peer_info, 0, sizeof(peer_info));
  2670. if (data->p2p_dev_found.dev_addr)
  2671. os_memcpy(peer_info.p2p_device_addr,
  2672. data->p2p_dev_found.dev_addr, ETH_ALEN);
  2673. if (data->p2p_dev_found.pri_dev_type)
  2674. os_memcpy(peer_info.pri_dev_type,
  2675. data->p2p_dev_found.pri_dev_type,
  2676. sizeof(peer_info.pri_dev_type));
  2677. if (data->p2p_dev_found.dev_name)
  2678. os_strlcpy(peer_info.device_name,
  2679. data->p2p_dev_found.dev_name,
  2680. sizeof(peer_info.device_name));
  2681. peer_info.config_methods = data->p2p_dev_found.config_methods;
  2682. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  2683. peer_info.group_capab = data->p2p_dev_found.group_capab;
  2684. /*
  2685. * FIX: new_device=1 is not necessarily correct. We should
  2686. * maintain a P2P peer database in wpa_supplicant and update
  2687. * this information based on whether the peer is truly new.
  2688. */
  2689. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  2690. break;
  2691. }
  2692. case EVENT_P2P_GO_NEG_REQ_RX:
  2693. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  2694. data->p2p_go_neg_req_rx.dev_passwd_id);
  2695. break;
  2696. case EVENT_P2P_GO_NEG_COMPLETED:
  2697. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  2698. break;
  2699. case EVENT_P2P_PROV_DISC_REQUEST:
  2700. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  2701. data->p2p_prov_disc_req.config_methods,
  2702. data->p2p_prov_disc_req.dev_addr,
  2703. data->p2p_prov_disc_req.pri_dev_type,
  2704. data->p2p_prov_disc_req.dev_name,
  2705. data->p2p_prov_disc_req.supp_config_methods,
  2706. data->p2p_prov_disc_req.dev_capab,
  2707. data->p2p_prov_disc_req.group_capab,
  2708. NULL, 0);
  2709. break;
  2710. case EVENT_P2P_PROV_DISC_RESPONSE:
  2711. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  2712. data->p2p_prov_disc_resp.config_methods);
  2713. break;
  2714. case EVENT_P2P_SD_REQUEST:
  2715. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  2716. data->p2p_sd_req.sa,
  2717. data->p2p_sd_req.dialog_token,
  2718. data->p2p_sd_req.update_indic,
  2719. data->p2p_sd_req.tlvs,
  2720. data->p2p_sd_req.tlvs_len);
  2721. break;
  2722. case EVENT_P2P_SD_RESPONSE:
  2723. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  2724. data->p2p_sd_resp.update_indic,
  2725. data->p2p_sd_resp.tlvs,
  2726. data->p2p_sd_resp.tlvs_len);
  2727. break;
  2728. #endif /* CONFIG_P2P */
  2729. case EVENT_EAPOL_RX:
  2730. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  2731. data->eapol_rx.data,
  2732. data->eapol_rx.data_len);
  2733. break;
  2734. case EVENT_SIGNAL_CHANGE:
  2735. bgscan_notify_signal_change(
  2736. wpa_s, data->signal_change.above_threshold,
  2737. data->signal_change.current_signal,
  2738. data->signal_change.current_noise,
  2739. data->signal_change.current_txrate);
  2740. break;
  2741. case EVENT_INTERFACE_ENABLED:
  2742. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  2743. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  2744. wpa_supplicant_update_mac_addr(wpa_s);
  2745. #ifdef CONFIG_AP
  2746. if (!wpa_s->ap_iface) {
  2747. wpa_supplicant_set_state(wpa_s,
  2748. WPA_DISCONNECTED);
  2749. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2750. } else
  2751. wpa_supplicant_set_state(wpa_s,
  2752. WPA_COMPLETED);
  2753. #else /* CONFIG_AP */
  2754. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  2755. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2756. #endif /* CONFIG_AP */
  2757. }
  2758. break;
  2759. case EVENT_INTERFACE_DISABLED:
  2760. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  2761. wpa_supplicant_mark_disassoc(wpa_s);
  2762. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2763. break;
  2764. case EVENT_CHANNEL_LIST_CHANGED:
  2765. wpa_supplicant_update_channel_list(wpa_s);
  2766. break;
  2767. case EVENT_INTERFACE_UNAVAILABLE:
  2768. #ifdef CONFIG_P2P
  2769. wpas_p2p_interface_unavailable(wpa_s);
  2770. #endif /* CONFIG_P2P */
  2771. break;
  2772. case EVENT_BEST_CHANNEL:
  2773. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  2774. "(%d %d %d)",
  2775. data->best_chan.freq_24, data->best_chan.freq_5,
  2776. data->best_chan.freq_overall);
  2777. wpa_s->best_24_freq = data->best_chan.freq_24;
  2778. wpa_s->best_5_freq = data->best_chan.freq_5;
  2779. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  2780. #ifdef CONFIG_P2P
  2781. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  2782. data->best_chan.freq_5,
  2783. data->best_chan.freq_overall);
  2784. #endif /* CONFIG_P2P */
  2785. break;
  2786. case EVENT_UNPROT_DEAUTH:
  2787. wpa_supplicant_event_unprot_deauth(wpa_s,
  2788. &data->unprot_deauth);
  2789. break;
  2790. case EVENT_UNPROT_DISASSOC:
  2791. wpa_supplicant_event_unprot_disassoc(wpa_s,
  2792. &data->unprot_disassoc);
  2793. break;
  2794. case EVENT_STATION_LOW_ACK:
  2795. #ifdef CONFIG_AP
  2796. if (wpa_s->ap_iface && data)
  2797. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  2798. data->low_ack.addr);
  2799. #endif /* CONFIG_AP */
  2800. #ifdef CONFIG_TDLS
  2801. if (data)
  2802. wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
  2803. #endif /* CONFIG_TDLS */
  2804. break;
  2805. case EVENT_IBSS_PEER_LOST:
  2806. #ifdef CONFIG_IBSS_RSN
  2807. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  2808. #endif /* CONFIG_IBSS_RSN */
  2809. break;
  2810. case EVENT_DRIVER_GTK_REKEY:
  2811. if (os_memcmp(data->driver_gtk_rekey.bssid,
  2812. wpa_s->bssid, ETH_ALEN))
  2813. break;
  2814. if (!wpa_s->wpa)
  2815. break;
  2816. wpa_sm_update_replay_ctr(wpa_s->wpa,
  2817. data->driver_gtk_rekey.replay_ctr);
  2818. break;
  2819. case EVENT_SCHED_SCAN_STOPPED:
  2820. wpa_s->sched_scanning = 0;
  2821. wpa_supplicant_notify_scanning(wpa_s, 0);
  2822. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2823. break;
  2824. /*
  2825. * If we timed out, start a new sched scan to continue
  2826. * searching for more SSIDs.
  2827. */
  2828. if (wpa_s->sched_scan_timed_out)
  2829. wpa_supplicant_req_sched_scan(wpa_s);
  2830. break;
  2831. case EVENT_WPS_BUTTON_PUSHED:
  2832. #ifdef CONFIG_WPS
  2833. wpas_wps_start_pbc(wpa_s, NULL, 0);
  2834. #endif /* CONFIG_WPS */
  2835. break;
  2836. case EVENT_CONNECT_FAILED_REASON:
  2837. #ifdef CONFIG_AP
  2838. if (!wpa_s->ap_iface || !data)
  2839. break;
  2840. hostapd_event_connect_failed_reason(
  2841. wpa_s->ap_iface->bss[0],
  2842. data->connect_failed_reason.addr,
  2843. data->connect_failed_reason.code);
  2844. #endif /* CONFIG_AP */
  2845. break;
  2846. default:
  2847. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  2848. break;
  2849. }
  2850. }