events.c 89 KB

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