events.c 126 KB

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