events.c 89 KB

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