events.c 89 KB

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