events.c 88 KB

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