events.c 118 KB

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