events.c 124 KB

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