events.c 90 KB

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