events.c 101 KB

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