events.c 114 KB

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