events.c 88 KB

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