events.c 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389
  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. static int wpas_temp_disabled(struct wpa_supplicant *wpa_s,
  52. struct wpa_ssid *ssid)
  53. {
  54. struct os_reltime now;
  55. if (ssid == NULL || ssid->disabled_until.sec == 0)
  56. return 0;
  57. os_get_reltime(&now);
  58. if (ssid->disabled_until.sec > now.sec)
  59. return ssid->disabled_until.sec - now.sec;
  60. wpas_clear_temp_disabled(wpa_s, ssid, 0);
  61. return 0;
  62. }
  63. #ifndef CONFIG_NO_SCAN_PROCESSING
  64. /**
  65. * wpas_reenabled_network_time - Time until first network is re-enabled
  66. * @wpa_s: Pointer to wpa_supplicant data
  67. * Returns: If all enabled networks are temporarily disabled, returns the time
  68. * (in sec) until the first network is re-enabled. Otherwise returns 0.
  69. *
  70. * This function is used in case all enabled networks are temporarily disabled,
  71. * in which case it returns the time (in sec) that the first network will be
  72. * re-enabled. The function assumes that at least one network is enabled.
  73. */
  74. static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s)
  75. {
  76. struct wpa_ssid *ssid;
  77. int disabled_for, res = 0;
  78. #ifdef CONFIG_INTERWORKING
  79. if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking &&
  80. wpa_s->conf->cred)
  81. return 0;
  82. #endif /* CONFIG_INTERWORKING */
  83. for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
  84. if (ssid->disabled)
  85. continue;
  86. disabled_for = wpas_temp_disabled(wpa_s, ssid);
  87. if (!disabled_for)
  88. return 0;
  89. if (!res || disabled_for < res)
  90. res = disabled_for;
  91. }
  92. return res;
  93. }
  94. #endif /* CONFIG_NO_SCAN_PROCESSING */
  95. void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx)
  96. {
  97. struct wpa_supplicant *wpa_s = eloop_ctx;
  98. if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING)
  99. return;
  100. wpa_dbg(wpa_s, MSG_DEBUG,
  101. "Try to associate due to network getting re-enabled");
  102. if (wpa_supplicant_fast_associate(wpa_s) != 1) {
  103. wpa_supplicant_cancel_sched_scan(wpa_s);
  104. wpa_supplicant_req_scan(wpa_s, 0, 0);
  105. }
  106. }
  107. static struct wpa_bss * wpa_supplicant_get_new_bss(
  108. struct wpa_supplicant *wpa_s, const u8 *bssid)
  109. {
  110. struct wpa_bss *bss = NULL;
  111. struct wpa_ssid *ssid = wpa_s->current_ssid;
  112. if (ssid->ssid_len > 0)
  113. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  114. if (!bss)
  115. bss = wpa_bss_get_bssid(wpa_s, bssid);
  116. return bss;
  117. }
  118. static void wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s)
  119. {
  120. struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
  121. if (!bss) {
  122. wpa_supplicant_update_scan_results(wpa_s);
  123. /* Get the BSS from the new scan results */
  124. bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid);
  125. }
  126. if (bss)
  127. wpa_s->current_bss = bss;
  128. }
  129. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  130. {
  131. struct wpa_ssid *ssid, *old_ssid;
  132. u8 drv_ssid[SSID_MAX_LEN];
  133. size_t drv_ssid_len;
  134. int res;
  135. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) {
  136. wpa_supplicant_update_current_bss(wpa_s);
  137. if (wpa_s->current_ssid->ssid_len == 0)
  138. return 0; /* current profile still in use */
  139. res = wpa_drv_get_ssid(wpa_s, drv_ssid);
  140. if (res < 0) {
  141. wpa_msg(wpa_s, MSG_INFO,
  142. "Failed to read SSID from driver");
  143. return 0; /* try to use current profile */
  144. }
  145. drv_ssid_len = res;
  146. if (drv_ssid_len == wpa_s->current_ssid->ssid_len &&
  147. os_memcmp(drv_ssid, wpa_s->current_ssid->ssid,
  148. drv_ssid_len) == 0)
  149. return 0; /* current profile still in use */
  150. wpa_msg(wpa_s, MSG_DEBUG,
  151. "Driver-initiated BSS selection changed the SSID to %s",
  152. wpa_ssid_txt(drv_ssid, drv_ssid_len));
  153. /* continue selecting a new network profile */
  154. }
  155. wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
  156. "information");
  157. ssid = wpa_supplicant_get_ssid(wpa_s);
  158. if (ssid == NULL) {
  159. wpa_msg(wpa_s, MSG_INFO,
  160. "No network configuration found for the current AP");
  161. return -1;
  162. }
  163. if (wpas_network_disabled(wpa_s, ssid)) {
  164. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
  165. return -1;
  166. }
  167. if (disallowed_bssid(wpa_s, wpa_s->bssid) ||
  168. disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) {
  169. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed");
  170. return -1;
  171. }
  172. res = wpas_temp_disabled(wpa_s, ssid);
  173. if (res > 0) {
  174. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily "
  175. "disabled for %d second(s)", res);
  176. return -1;
  177. }
  178. wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
  179. "current AP");
  180. if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
  181. u8 wpa_ie[80];
  182. size_t wpa_ie_len = sizeof(wpa_ie);
  183. if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  184. wpa_ie, &wpa_ie_len) < 0)
  185. wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites");
  186. } else {
  187. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  188. }
  189. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  190. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  191. old_ssid = wpa_s->current_ssid;
  192. wpa_s->current_ssid = ssid;
  193. wpa_supplicant_update_current_bss(wpa_s);
  194. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  195. wpa_supplicant_initiate_eapol(wpa_s);
  196. if (old_ssid != wpa_s->current_ssid)
  197. wpas_notify_network_changed(wpa_s);
  198. return 0;
  199. }
  200. void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx)
  201. {
  202. struct wpa_supplicant *wpa_s = eloop_ctx;
  203. if (wpa_s->countermeasures) {
  204. wpa_s->countermeasures = 0;
  205. wpa_drv_set_countermeasures(wpa_s, 0);
  206. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  207. /*
  208. * It is possible that the device is sched scanning, which means
  209. * that a connection attempt will be done only when we receive
  210. * scan results. However, in this case, it would be preferable
  211. * to scan and connect immediately, so cancel the sched_scan and
  212. * issue a regular scan flow.
  213. */
  214. wpa_supplicant_cancel_sched_scan(wpa_s);
  215. wpa_supplicant_req_scan(wpa_s, 0, 0);
  216. }
  217. }
  218. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  219. {
  220. int bssid_changed;
  221. wnm_bss_keep_alive_deinit(wpa_s);
  222. #ifdef CONFIG_IBSS_RSN
  223. ibss_rsn_deinit(wpa_s->ibss_rsn);
  224. wpa_s->ibss_rsn = NULL;
  225. #endif /* CONFIG_IBSS_RSN */
  226. #ifdef CONFIG_AP
  227. wpa_supplicant_ap_deinit(wpa_s);
  228. #endif /* CONFIG_AP */
  229. #ifdef CONFIG_HS20
  230. /* Clear possibly configured frame filters */
  231. wpa_drv_configure_frame_filters(wpa_s, 0);
  232. #endif /* CONFIG_HS20 */
  233. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  234. return;
  235. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  236. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  237. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  238. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  239. sme_clear_on_disassoc(wpa_s);
  240. wpa_s->current_bss = NULL;
  241. wpa_s->assoc_freq = 0;
  242. if (bssid_changed)
  243. wpas_notify_bssid_changed(wpa_s);
  244. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  245. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  246. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  247. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  248. wpa_s->ap_ies_from_associnfo = 0;
  249. wpa_s->current_ssid = NULL;
  250. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  251. wpa_s->key_mgmt = 0;
  252. wpas_rrm_reset(wpa_s);
  253. wpa_s->wnmsleep_used = 0;
  254. }
  255. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  256. {
  257. struct wpa_ie_data ie;
  258. int pmksa_set = -1;
  259. size_t i;
  260. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  261. ie.pmkid == NULL)
  262. return;
  263. for (i = 0; i < ie.num_pmkid; i++) {
  264. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  265. ie.pmkid + i * PMKID_LEN,
  266. NULL, NULL, 0);
  267. if (pmksa_set == 0) {
  268. eapol_sm_notify_pmkid_attempt(wpa_s->eapol);
  269. break;
  270. }
  271. }
  272. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
  273. "PMKSA cache", pmksa_set == 0 ? "" : "not ");
  274. }
  275. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  276. union wpa_event_data *data)
  277. {
  278. if (data == NULL) {
  279. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
  280. "event");
  281. return;
  282. }
  283. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  284. " index=%d preauth=%d",
  285. MAC2STR(data->pmkid_candidate.bssid),
  286. data->pmkid_candidate.index,
  287. data->pmkid_candidate.preauth);
  288. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  289. data->pmkid_candidate.index,
  290. data->pmkid_candidate.preauth);
  291. }
  292. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  293. {
  294. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  295. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  296. return 0;
  297. #ifdef IEEE8021X_EAPOL
  298. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  299. wpa_s->current_ssid &&
  300. !(wpa_s->current_ssid->eapol_flags &
  301. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  302. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  303. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  304. * plaintext or static WEP keys). */
  305. return 0;
  306. }
  307. #endif /* IEEE8021X_EAPOL */
  308. return 1;
  309. }
  310. /**
  311. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  312. * @wpa_s: pointer to wpa_supplicant data
  313. * @ssid: Configuration data for the network
  314. * Returns: 0 on success, -1 on failure
  315. *
  316. * This function is called when starting authentication with a network that is
  317. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  318. */
  319. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  320. struct wpa_ssid *ssid)
  321. {
  322. #ifdef IEEE8021X_EAPOL
  323. #ifdef PCSC_FUNCS
  324. int aka = 0, sim = 0;
  325. if ((ssid != NULL && ssid->eap.pcsc == NULL) ||
  326. wpa_s->scard != NULL || wpa_s->conf->external_sim)
  327. return 0;
  328. if (ssid == NULL || ssid->eap.eap_methods == NULL) {
  329. sim = 1;
  330. aka = 1;
  331. } else {
  332. struct eap_method_type *eap = ssid->eap.eap_methods;
  333. while (eap->vendor != EAP_VENDOR_IETF ||
  334. eap->method != EAP_TYPE_NONE) {
  335. if (eap->vendor == EAP_VENDOR_IETF) {
  336. if (eap->method == EAP_TYPE_SIM)
  337. sim = 1;
  338. else if (eap->method == EAP_TYPE_AKA ||
  339. eap->method == EAP_TYPE_AKA_PRIME)
  340. aka = 1;
  341. }
  342. eap++;
  343. }
  344. }
  345. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  346. sim = 0;
  347. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL &&
  348. eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) ==
  349. NULL)
  350. aka = 0;
  351. if (!sim && !aka) {
  352. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
  353. "use SIM, but neither EAP-SIM nor EAP-AKA are "
  354. "enabled");
  355. return 0;
  356. }
  357. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
  358. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  359. wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader);
  360. if (wpa_s->scard == NULL) {
  361. wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
  362. "(pcsc-lite)");
  363. return -1;
  364. }
  365. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  366. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  367. #endif /* PCSC_FUNCS */
  368. #endif /* IEEE8021X_EAPOL */
  369. return 0;
  370. }
  371. #ifndef CONFIG_NO_SCAN_PROCESSING
  372. static int has_wep_key(struct wpa_ssid *ssid)
  373. {
  374. int i;
  375. for (i = 0; i < NUM_WEP_KEYS; i++) {
  376. if (ssid->wep_key_len[i])
  377. return 1;
  378. }
  379. return 0;
  380. }
  381. static int wpa_supplicant_match_privacy(struct wpa_bss *bss,
  382. struct wpa_ssid *ssid)
  383. {
  384. int privacy = 0;
  385. if (ssid->mixed_cell)
  386. return 1;
  387. #ifdef CONFIG_WPS
  388. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  389. return 1;
  390. #endif /* CONFIG_WPS */
  391. if (has_wep_key(ssid))
  392. privacy = 1;
  393. #ifdef IEEE8021X_EAPOL
  394. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  395. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  396. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  397. privacy = 1;
  398. #endif /* IEEE8021X_EAPOL */
  399. if (wpa_key_mgmt_wpa(ssid->key_mgmt))
  400. privacy = 1;
  401. if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)
  402. privacy = 1;
  403. if (bss->caps & IEEE80211_CAP_PRIVACY)
  404. return privacy;
  405. return !privacy;
  406. }
  407. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  408. struct wpa_ssid *ssid,
  409. struct wpa_bss *bss, 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. (!data->assoc_info.resp_frame ||
  1875. fils_process_assoc_resp(wpa_s->wpa,
  1876. data->assoc_info.resp_frame,
  1877. data->assoc_info.resp_frame_len) < 0)) {
  1878. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED);
  1879. return -1;
  1880. }
  1881. #endif /* CONFIG_SME */
  1882. #endif /* CONFIG_FILS */
  1883. #ifdef CONFIG_IEEE80211R
  1884. #ifdef CONFIG_SME
  1885. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1886. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1887. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1888. data->assoc_info.resp_ies,
  1889. data->assoc_info.resp_ies_len,
  1890. bssid) < 0) {
  1891. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1892. "Reassociation Response failed");
  1893. wpa_supplicant_deauthenticate(
  1894. wpa_s, WLAN_REASON_INVALID_IE);
  1895. return -1;
  1896. }
  1897. }
  1898. p = data->assoc_info.resp_ies;
  1899. l = data->assoc_info.resp_ies_len;
  1900. #ifdef CONFIG_WPS_STRICT
  1901. if (p && wpa_s->current_ssid &&
  1902. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1903. struct wpabuf *wps;
  1904. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1905. if (wps == NULL) {
  1906. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1907. "include WPS IE in (Re)Association Response");
  1908. return -1;
  1909. }
  1910. if (wps_validate_assoc_resp(wps) < 0) {
  1911. wpabuf_free(wps);
  1912. wpa_supplicant_deauthenticate(
  1913. wpa_s, WLAN_REASON_INVALID_IE);
  1914. return -1;
  1915. }
  1916. wpabuf_free(wps);
  1917. }
  1918. #endif /* CONFIG_WPS_STRICT */
  1919. /* Go through the IEs and make a copy of the MDIE, if present. */
  1920. while (p && l >= 2) {
  1921. len = p[1] + 2;
  1922. if (len > l) {
  1923. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1924. p, l);
  1925. break;
  1926. }
  1927. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1928. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1929. wpa_s->sme.ft_used = 1;
  1930. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1931. MOBILITY_DOMAIN_ID_LEN);
  1932. break;
  1933. }
  1934. l -= len;
  1935. p += len;
  1936. }
  1937. #endif /* CONFIG_SME */
  1938. /* Process FT when SME is in the driver */
  1939. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  1940. wpa_ft_is_completed(wpa_s->wpa)) {
  1941. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1942. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1943. data->assoc_info.resp_ies,
  1944. data->assoc_info.resp_ies_len,
  1945. bssid) < 0) {
  1946. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1947. "Reassociation Response failed");
  1948. wpa_supplicant_deauthenticate(
  1949. wpa_s, WLAN_REASON_INVALID_IE);
  1950. return -1;
  1951. }
  1952. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
  1953. }
  1954. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1955. data->assoc_info.resp_ies_len);
  1956. #endif /* CONFIG_IEEE80211R */
  1957. /* WPA/RSN IE from Beacon/ProbeResp */
  1958. p = data->assoc_info.beacon_ies;
  1959. l = data->assoc_info.beacon_ies_len;
  1960. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1961. */
  1962. wpa_found = rsn_found = 0;
  1963. while (p && l >= 2) {
  1964. len = p[1] + 2;
  1965. if (len > l) {
  1966. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1967. p, l);
  1968. break;
  1969. }
  1970. if (!wpa_found &&
  1971. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1972. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1973. wpa_found = 1;
  1974. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1975. }
  1976. if (!rsn_found &&
  1977. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1978. rsn_found = 1;
  1979. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1980. }
  1981. l -= len;
  1982. p += len;
  1983. }
  1984. if (!wpa_found && data->assoc_info.beacon_ies)
  1985. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1986. if (!rsn_found && data->assoc_info.beacon_ies)
  1987. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1988. if (wpa_found || rsn_found)
  1989. wpa_s->ap_ies_from_associnfo = 1;
  1990. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1991. wpa_s->assoc_freq != data->assoc_info.freq) {
  1992. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1993. "%u to %u MHz",
  1994. wpa_s->assoc_freq, data->assoc_info.freq);
  1995. wpa_supplicant_update_scan_results(wpa_s);
  1996. }
  1997. wpa_s->assoc_freq = data->assoc_info.freq;
  1998. return 0;
  1999. }
  2000. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  2001. {
  2002. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  2003. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  2004. return -1;
  2005. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  2006. return 0;
  2007. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  2008. WPA_IE_VENDOR_TYPE);
  2009. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  2010. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  2011. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  2012. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  2013. bss_rsn ? 2 + bss_rsn[1] : 0))
  2014. return -1;
  2015. return 0;
  2016. }
  2017. static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s,
  2018. union wpa_event_data *data)
  2019. {
  2020. #ifdef CONFIG_FST
  2021. struct assoc_info *ai = data ? &data->assoc_info : NULL;
  2022. struct wpa_bss *bss = wpa_s->current_bss;
  2023. const u8 *ieprb, *iebcn;
  2024. wpabuf_free(wpa_s->received_mb_ies);
  2025. wpa_s->received_mb_ies = NULL;
  2026. if (ai &&
  2027. !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) {
  2028. wpa_printf(MSG_DEBUG,
  2029. "FST: MB IEs updated from Association Response frame");
  2030. return;
  2031. }
  2032. if (ai &&
  2033. !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) {
  2034. wpa_printf(MSG_DEBUG,
  2035. "FST: MB IEs updated from association event Beacon IEs");
  2036. return;
  2037. }
  2038. if (!bss)
  2039. return;
  2040. ieprb = (const u8 *) (bss + 1);
  2041. iebcn = ieprb + bss->ie_len;
  2042. if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len))
  2043. wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE");
  2044. else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len))
  2045. wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE");
  2046. #endif /* CONFIG_FST */
  2047. }
  2048. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  2049. union wpa_event_data *data)
  2050. {
  2051. u8 bssid[ETH_ALEN];
  2052. int ft_completed, already_authorized;
  2053. int new_bss = 0;
  2054. #ifdef CONFIG_AP
  2055. if (wpa_s->ap_iface) {
  2056. if (!data)
  2057. return;
  2058. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  2059. data->assoc_info.addr,
  2060. data->assoc_info.req_ies,
  2061. data->assoc_info.req_ies_len,
  2062. data->assoc_info.reassoc);
  2063. return;
  2064. }
  2065. #endif /* CONFIG_AP */
  2066. eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
  2067. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  2068. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  2069. return;
  2070. /*
  2071. * FILS authentication can share the same mechanism to mark the
  2072. * connection fully authenticated, so set ft_completed also based on
  2073. * FILS result.
  2074. */
  2075. if (!ft_completed)
  2076. ft_completed = wpa_fils_is_completed(wpa_s->wpa);
  2077. if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
  2078. wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
  2079. wpa_supplicant_deauthenticate(
  2080. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2081. return;
  2082. }
  2083. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  2084. if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  2085. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  2086. MACSTR, MAC2STR(bssid));
  2087. new_bss = 1;
  2088. random_add_randomness(bssid, ETH_ALEN);
  2089. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  2090. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  2091. wpas_notify_bssid_changed(wpa_s);
  2092. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  2093. wpa_clear_keys(wpa_s, bssid);
  2094. }
  2095. if (wpa_supplicant_select_config(wpa_s) < 0) {
  2096. wpa_supplicant_deauthenticate(
  2097. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2098. return;
  2099. }
  2100. }
  2101. if (wpa_s->conf->ap_scan == 1 &&
  2102. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  2103. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss)
  2104. wpa_msg(wpa_s, MSG_WARNING,
  2105. "WPA/RSN IEs not updated");
  2106. }
  2107. wpas_fst_update_mb_assoc(wpa_s, data);
  2108. #ifdef CONFIG_SME
  2109. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  2110. wpa_s->sme.prev_bssid_set = 1;
  2111. wpa_s->sme.last_unprot_disconnect.sec = 0;
  2112. #endif /* CONFIG_SME */
  2113. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  2114. if (wpa_s->current_ssid) {
  2115. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  2116. * initialized before association, but for other modes,
  2117. * initialize PC/SC here, if the current configuration needs
  2118. * smartcard or SIM/USIM. */
  2119. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  2120. }
  2121. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  2122. if (wpa_s->l2)
  2123. l2_packet_notify_auth_start(wpa_s->l2);
  2124. already_authorized = data && data->assoc_info.authorized;
  2125. /*
  2126. * Set portEnabled first to FALSE in order to get EAP state machine out
  2127. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  2128. * state machine may transit to AUTHENTICATING state based on obsolete
  2129. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  2130. * AUTHENTICATED without ever giving chance to EAP state machine to
  2131. * reset the state.
  2132. */
  2133. if (!ft_completed && !already_authorized) {
  2134. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  2135. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  2136. }
  2137. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed ||
  2138. already_authorized)
  2139. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  2140. /* 802.1X::portControl = Auto */
  2141. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  2142. wpa_s->eapol_received = 0;
  2143. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  2144. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  2145. (wpa_s->current_ssid &&
  2146. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  2147. if (wpa_s->current_ssid &&
  2148. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
  2149. (wpa_s->drv_flags &
  2150. WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  2151. /*
  2152. * Set the key after having received joined-IBSS event
  2153. * from the driver.
  2154. */
  2155. wpa_supplicant_set_wpa_none_key(wpa_s,
  2156. wpa_s->current_ssid);
  2157. }
  2158. wpa_supplicant_cancel_auth_timeout(wpa_s);
  2159. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  2160. } else if (!ft_completed) {
  2161. /* Timeout for receiving the first EAPOL packet */
  2162. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  2163. }
  2164. wpa_supplicant_cancel_scan(wpa_s);
  2165. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  2166. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  2167. /*
  2168. * We are done; the driver will take care of RSN 4-way
  2169. * handshake.
  2170. */
  2171. wpa_supplicant_cancel_auth_timeout(wpa_s);
  2172. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  2173. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  2174. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  2175. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  2176. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  2177. /*
  2178. * The driver will take care of RSN 4-way handshake, so we need
  2179. * to allow EAPOL supplicant to complete its work without
  2180. * waiting for WPA supplicant.
  2181. */
  2182. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  2183. } else if (ft_completed) {
  2184. /*
  2185. * FT protocol completed - make sure EAPOL state machine ends
  2186. * up in authenticated.
  2187. */
  2188. wpa_supplicant_cancel_auth_timeout(wpa_s);
  2189. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  2190. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  2191. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  2192. }
  2193. wpa_s->last_eapol_matches_bssid = 0;
  2194. if (wpa_s->pending_eapol_rx) {
  2195. struct os_reltime now, age;
  2196. os_get_reltime(&now);
  2197. os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  2198. if (age.sec == 0 && age.usec < 200000 &&
  2199. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  2200. 0) {
  2201. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  2202. "frame that was received just before "
  2203. "association notification");
  2204. wpa_supplicant_rx_eapol(
  2205. wpa_s, wpa_s->pending_eapol_rx_src,
  2206. wpabuf_head(wpa_s->pending_eapol_rx),
  2207. wpabuf_len(wpa_s->pending_eapol_rx));
  2208. }
  2209. wpabuf_free(wpa_s->pending_eapol_rx);
  2210. wpa_s->pending_eapol_rx = NULL;
  2211. }
  2212. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  2213. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  2214. wpa_s->current_ssid &&
  2215. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  2216. /* Set static WEP keys again */
  2217. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  2218. }
  2219. #ifdef CONFIG_IBSS_RSN
  2220. if (wpa_s->current_ssid &&
  2221. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  2222. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  2223. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  2224. wpa_s->ibss_rsn == NULL) {
  2225. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid);
  2226. if (!wpa_s->ibss_rsn) {
  2227. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  2228. wpa_supplicant_deauthenticate(
  2229. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2230. return;
  2231. }
  2232. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  2233. }
  2234. #endif /* CONFIG_IBSS_RSN */
  2235. wpas_wps_notify_assoc(wpa_s, bssid);
  2236. if (data) {
  2237. wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies,
  2238. data->assoc_info.resp_ies_len,
  2239. &data->assoc_info.wmm_params);
  2240. if (wpa_s->reassoc_same_bss)
  2241. wmm_ac_restore_tspecs(wpa_s);
  2242. }
  2243. }
  2244. static int disconnect_reason_recoverable(u16 reason_code)
  2245. {
  2246. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  2247. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  2248. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  2249. }
  2250. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  2251. u16 reason_code,
  2252. int locally_generated)
  2253. {
  2254. const u8 *bssid;
  2255. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  2256. /*
  2257. * At least Host AP driver and a Prism3 card seemed to be
  2258. * generating streams of disconnected events when configuring
  2259. * IBSS for WPA-None. Ignore them for now.
  2260. */
  2261. return;
  2262. }
  2263. bssid = wpa_s->bssid;
  2264. if (is_zero_ether_addr(bssid))
  2265. bssid = wpa_s->pending_bssid;
  2266. if (!is_zero_ether_addr(bssid) ||
  2267. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  2268. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  2269. " reason=%d%s",
  2270. MAC2STR(bssid), reason_code,
  2271. locally_generated ? " locally_generated=1" : "");
  2272. }
  2273. }
  2274. static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
  2275. int locally_generated)
  2276. {
  2277. if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
  2278. !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  2279. return 0; /* Not in 4-way handshake with PSK */
  2280. /*
  2281. * It looks like connection was lost while trying to go through PSK
  2282. * 4-way handshake. Filter out known disconnection cases that are caused
  2283. * by something else than PSK mismatch to avoid confusing reports.
  2284. */
  2285. if (locally_generated) {
  2286. if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
  2287. return 0;
  2288. }
  2289. return 1;
  2290. }
  2291. static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
  2292. u16 reason_code,
  2293. int locally_generated)
  2294. {
  2295. const u8 *bssid;
  2296. int authenticating;
  2297. u8 prev_pending_bssid[ETH_ALEN];
  2298. struct wpa_bss *fast_reconnect = NULL;
  2299. struct wpa_ssid *fast_reconnect_ssid = NULL;
  2300. struct wpa_ssid *last_ssid;
  2301. struct wpa_bss *curr = NULL;
  2302. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  2303. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  2304. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  2305. /*
  2306. * At least Host AP driver and a Prism3 card seemed to be
  2307. * generating streams of disconnected events when configuring
  2308. * IBSS for WPA-None. Ignore them for now.
  2309. */
  2310. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  2311. "IBSS/WPA-None mode");
  2312. return;
  2313. }
  2314. if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING &&
  2315. reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY &&
  2316. locally_generated)
  2317. /*
  2318. * Remove the inactive AP (which is probably out of range) from
  2319. * the BSS list after marking disassociation. In particular
  2320. * mac80211-based drivers use the
  2321. * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in
  2322. * locally generated disconnection events for cases where the
  2323. * AP does not reply anymore.
  2324. */
  2325. curr = wpa_s->current_bss;
  2326. if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
  2327. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  2328. "pre-shared key may be incorrect");
  2329. if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
  2330. return; /* P2P group removed */
  2331. wpas_auth_failed(wpa_s, "WRONG_KEY");
  2332. }
  2333. if (!wpa_s->disconnected &&
  2334. (!wpa_s->auto_reconnect_disabled ||
  2335. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS ||
  2336. wpas_wps_searching(wpa_s) ||
  2337. wpas_wps_reenable_networks_pending(wpa_s))) {
  2338. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  2339. "reconnect (wps=%d/%d wpa_state=%d)",
  2340. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  2341. wpas_wps_searching(wpa_s),
  2342. wpa_s->wpa_state);
  2343. if (wpa_s->wpa_state == WPA_COMPLETED &&
  2344. wpa_s->current_ssid &&
  2345. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  2346. !locally_generated &&
  2347. disconnect_reason_recoverable(reason_code)) {
  2348. /*
  2349. * It looks like the AP has dropped association with
  2350. * us, but could allow us to get back in. Try to
  2351. * reconnect to the same BSS without full scan to save
  2352. * time for some common cases.
  2353. */
  2354. fast_reconnect = wpa_s->current_bss;
  2355. fast_reconnect_ssid = wpa_s->current_ssid;
  2356. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  2357. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  2358. else
  2359. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  2360. "immediate scan");
  2361. } else {
  2362. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  2363. "try to re-connect");
  2364. wpa_s->reassociate = 0;
  2365. wpa_s->disconnected = 1;
  2366. if (!wpa_s->pno)
  2367. wpa_supplicant_cancel_sched_scan(wpa_s);
  2368. }
  2369. bssid = wpa_s->bssid;
  2370. if (is_zero_ether_addr(bssid))
  2371. bssid = wpa_s->pending_bssid;
  2372. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  2373. wpas_connection_failed(wpa_s, bssid);
  2374. wpa_sm_notify_disassoc(wpa_s->wpa);
  2375. if (locally_generated)
  2376. wpa_s->disconnect_reason = -reason_code;
  2377. else
  2378. wpa_s->disconnect_reason = reason_code;
  2379. wpas_notify_disconnect_reason(wpa_s);
  2380. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  2381. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  2382. wpa_clear_keys(wpa_s, wpa_s->bssid);
  2383. }
  2384. last_ssid = wpa_s->current_ssid;
  2385. wpa_supplicant_mark_disassoc(wpa_s);
  2386. if (curr)
  2387. wpa_bss_remove(wpa_s, curr, "Connection to AP lost");
  2388. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
  2389. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  2390. wpa_s->current_ssid = last_ssid;
  2391. }
  2392. if (fast_reconnect &&
  2393. !wpas_network_disabled(wpa_s, fast_reconnect_ssid) &&
  2394. !disallowed_bssid(wpa_s, fast_reconnect->bssid) &&
  2395. !disallowed_ssid(wpa_s, fast_reconnect->ssid,
  2396. fast_reconnect->ssid_len) &&
  2397. !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) &&
  2398. !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect->bssid)) {
  2399. #ifndef CONFIG_NO_SCAN_PROCESSING
  2400. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  2401. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  2402. fast_reconnect_ssid) < 0) {
  2403. /* Recover through full scan */
  2404. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  2405. }
  2406. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2407. } else if (fast_reconnect) {
  2408. /*
  2409. * Could not reconnect to the same BSS due to network being
  2410. * disabled. Use a new scan to match the alternative behavior
  2411. * above, i.e., to continue automatic reconnection attempt in a
  2412. * way that enforces disabled network rules.
  2413. */
  2414. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  2415. }
  2416. }
  2417. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  2418. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  2419. {
  2420. struct wpa_supplicant *wpa_s = eloop_ctx;
  2421. if (!wpa_s->pending_mic_error_report)
  2422. return;
  2423. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  2424. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  2425. wpa_s->pending_mic_error_report = 0;
  2426. }
  2427. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  2428. static void
  2429. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  2430. union wpa_event_data *data)
  2431. {
  2432. int pairwise;
  2433. struct os_reltime t;
  2434. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  2435. pairwise = (data && data->michael_mic_failure.unicast);
  2436. os_get_reltime(&t);
  2437. if ((wpa_s->last_michael_mic_error.sec &&
  2438. !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
  2439. wpa_s->pending_mic_error_report) {
  2440. if (wpa_s->pending_mic_error_report) {
  2441. /*
  2442. * Send the pending MIC error report immediately since
  2443. * we are going to start countermeasures and AP better
  2444. * do the same.
  2445. */
  2446. wpa_sm_key_request(wpa_s->wpa, 1,
  2447. wpa_s->pending_mic_error_pairwise);
  2448. }
  2449. /* Send the new MIC error report immediately since we are going
  2450. * to start countermeasures and AP better do the same.
  2451. */
  2452. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  2453. /* initialize countermeasures */
  2454. wpa_s->countermeasures = 1;
  2455. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  2456. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  2457. /*
  2458. * Need to wait for completion of request frame. We do not get
  2459. * any callback for the message completion, so just wait a
  2460. * short while and hope for the best. */
  2461. os_sleep(0, 10000);
  2462. wpa_drv_set_countermeasures(wpa_s, 1);
  2463. wpa_supplicant_deauthenticate(wpa_s,
  2464. WLAN_REASON_MICHAEL_MIC_FAILURE);
  2465. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  2466. wpa_s, NULL);
  2467. eloop_register_timeout(60, 0,
  2468. wpa_supplicant_stop_countermeasures,
  2469. wpa_s, NULL);
  2470. /* TODO: mark the AP rejected for 60 second. STA is
  2471. * allowed to associate with another AP.. */
  2472. } else {
  2473. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  2474. if (wpa_s->mic_errors_seen) {
  2475. /*
  2476. * Reduce the effectiveness of Michael MIC error
  2477. * reports as a means for attacking against TKIP if
  2478. * more than one MIC failure is noticed with the same
  2479. * PTK. We delay the transmission of the reports by a
  2480. * random time between 0 and 60 seconds in order to
  2481. * force the attacker wait 60 seconds before getting
  2482. * the information on whether a frame resulted in a MIC
  2483. * failure.
  2484. */
  2485. u8 rval[4];
  2486. int sec;
  2487. if (os_get_random(rval, sizeof(rval)) < 0)
  2488. sec = os_random() % 60;
  2489. else
  2490. sec = WPA_GET_BE32(rval) % 60;
  2491. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  2492. "report %d seconds", sec);
  2493. wpa_s->pending_mic_error_report = 1;
  2494. wpa_s->pending_mic_error_pairwise = pairwise;
  2495. eloop_cancel_timeout(
  2496. wpa_supplicant_delayed_mic_error_report,
  2497. wpa_s, NULL);
  2498. eloop_register_timeout(
  2499. sec, os_random() % 1000000,
  2500. wpa_supplicant_delayed_mic_error_report,
  2501. wpa_s, NULL);
  2502. } else {
  2503. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  2504. }
  2505. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  2506. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  2507. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  2508. }
  2509. wpa_s->last_michael_mic_error = t;
  2510. wpa_s->mic_errors_seen++;
  2511. }
  2512. #ifdef CONFIG_TERMINATE_ONLASTIF
  2513. static int any_interfaces(struct wpa_supplicant *head)
  2514. {
  2515. struct wpa_supplicant *wpa_s;
  2516. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  2517. if (!wpa_s->interface_removed)
  2518. return 1;
  2519. return 0;
  2520. }
  2521. #endif /* CONFIG_TERMINATE_ONLASTIF */
  2522. static void
  2523. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  2524. union wpa_event_data *data)
  2525. {
  2526. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  2527. return;
  2528. switch (data->interface_status.ievent) {
  2529. case EVENT_INTERFACE_ADDED:
  2530. if (!wpa_s->interface_removed)
  2531. break;
  2532. wpa_s->interface_removed = 0;
  2533. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  2534. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  2535. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  2536. "driver after interface was added");
  2537. }
  2538. #ifdef CONFIG_P2P
  2539. if (!wpa_s->global->p2p &&
  2540. !wpa_s->global->p2p_disabled &&
  2541. !wpa_s->conf->p2p_disabled &&
  2542. (wpa_s->drv_flags &
  2543. WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
  2544. wpas_p2p_add_p2pdev_interface(
  2545. wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) {
  2546. wpa_printf(MSG_INFO,
  2547. "P2P: Failed to enable P2P Device interface");
  2548. /* Try to continue without. P2P will be disabled. */
  2549. }
  2550. #endif /* CONFIG_P2P */
  2551. break;
  2552. case EVENT_INTERFACE_REMOVED:
  2553. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  2554. wpa_s->interface_removed = 1;
  2555. wpa_supplicant_mark_disassoc(wpa_s);
  2556. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2557. l2_packet_deinit(wpa_s->l2);
  2558. wpa_s->l2 = NULL;
  2559. #ifdef CONFIG_P2P
  2560. if (wpa_s->global->p2p &&
  2561. wpa_s->global->p2p_init_wpa_s->parent == wpa_s &&
  2562. (wpa_s->drv_flags &
  2563. WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
  2564. wpa_dbg(wpa_s, MSG_DEBUG,
  2565. "Removing P2P Device interface");
  2566. wpa_supplicant_remove_iface(
  2567. wpa_s->global, wpa_s->global->p2p_init_wpa_s,
  2568. 0);
  2569. wpa_s->global->p2p_init_wpa_s = NULL;
  2570. }
  2571. #endif /* CONFIG_P2P */
  2572. #ifdef CONFIG_MATCH_IFACE
  2573. if (wpa_s->matched) {
  2574. wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
  2575. break;
  2576. }
  2577. #endif /* CONFIG_MATCH_IFACE */
  2578. #ifdef CONFIG_TERMINATE_ONLASTIF
  2579. /* check if last interface */
  2580. if (!any_interfaces(wpa_s->global->ifaces))
  2581. eloop_terminate();
  2582. #endif /* CONFIG_TERMINATE_ONLASTIF */
  2583. break;
  2584. }
  2585. }
  2586. #ifdef CONFIG_PEERKEY
  2587. static void
  2588. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  2589. union wpa_event_data *data)
  2590. {
  2591. if (data == NULL)
  2592. return;
  2593. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  2594. }
  2595. #endif /* CONFIG_PEERKEY */
  2596. #ifdef CONFIG_TDLS
  2597. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  2598. union wpa_event_data *data)
  2599. {
  2600. if (data == NULL)
  2601. return;
  2602. switch (data->tdls.oper) {
  2603. case TDLS_REQUEST_SETUP:
  2604. wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
  2605. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2606. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  2607. else
  2608. wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
  2609. break;
  2610. case TDLS_REQUEST_TEARDOWN:
  2611. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2612. wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
  2613. data->tdls.reason_code);
  2614. else
  2615. wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
  2616. data->tdls.peer);
  2617. break;
  2618. case TDLS_REQUEST_DISCOVER:
  2619. wpa_tdls_send_discovery_request(wpa_s->wpa,
  2620. data->tdls.peer);
  2621. break;
  2622. }
  2623. }
  2624. #endif /* CONFIG_TDLS */
  2625. #ifdef CONFIG_WNM
  2626. static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
  2627. union wpa_event_data *data)
  2628. {
  2629. if (data == NULL)
  2630. return;
  2631. switch (data->wnm.oper) {
  2632. case WNM_OPER_SLEEP:
  2633. wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
  2634. "(action=%d, intval=%d)",
  2635. data->wnm.sleep_action, data->wnm.sleep_intval);
  2636. ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
  2637. data->wnm.sleep_intval, NULL);
  2638. break;
  2639. }
  2640. }
  2641. #endif /* CONFIG_WNM */
  2642. #ifdef CONFIG_IEEE80211R
  2643. static void
  2644. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  2645. union wpa_event_data *data)
  2646. {
  2647. if (data == NULL)
  2648. return;
  2649. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  2650. data->ft_ies.ies_len,
  2651. data->ft_ies.ft_action,
  2652. data->ft_ies.target_ap,
  2653. data->ft_ies.ric_ies,
  2654. data->ft_ies.ric_ies_len) < 0) {
  2655. /* TODO: prevent MLME/driver from trying to associate? */
  2656. }
  2657. }
  2658. #endif /* CONFIG_IEEE80211R */
  2659. #ifdef CONFIG_IBSS_RSN
  2660. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  2661. union wpa_event_data *data)
  2662. {
  2663. struct wpa_ssid *ssid;
  2664. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  2665. return;
  2666. if (data == NULL)
  2667. return;
  2668. ssid = wpa_s->current_ssid;
  2669. if (ssid == NULL)
  2670. return;
  2671. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2672. return;
  2673. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  2674. }
  2675. static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
  2676. union wpa_event_data *data)
  2677. {
  2678. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2679. if (ssid == NULL)
  2680. return;
  2681. /* check if the ssid is correctly configured as IBSS/RSN */
  2682. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2683. return;
  2684. ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
  2685. data->rx_mgmt.frame_len);
  2686. }
  2687. #endif /* CONFIG_IBSS_RSN */
  2688. #ifdef CONFIG_IEEE80211R
  2689. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  2690. size_t len)
  2691. {
  2692. const u8 *sta_addr, *target_ap_addr;
  2693. u16 status;
  2694. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  2695. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  2696. return; /* only SME case supported for now */
  2697. if (len < 1 + 2 * ETH_ALEN + 2)
  2698. return;
  2699. if (data[0] != 2)
  2700. return; /* Only FT Action Response is supported for now */
  2701. sta_addr = data + 1;
  2702. target_ap_addr = data + 1 + ETH_ALEN;
  2703. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  2704. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  2705. MACSTR " TargetAP " MACSTR " status %u",
  2706. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  2707. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  2708. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  2709. " in FT Action Response", MAC2STR(sta_addr));
  2710. return;
  2711. }
  2712. if (status) {
  2713. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  2714. "failure (status code %d)", status);
  2715. /* TODO: report error to FT code(?) */
  2716. return;
  2717. }
  2718. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  2719. len - (1 + 2 * ETH_ALEN + 2), 1,
  2720. target_ap_addr, NULL, 0) < 0)
  2721. return;
  2722. #ifdef CONFIG_SME
  2723. {
  2724. struct wpa_bss *bss;
  2725. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  2726. if (bss)
  2727. wpa_s->sme.freq = bss->freq;
  2728. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  2729. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  2730. WLAN_AUTH_FT);
  2731. }
  2732. #endif /* CONFIG_SME */
  2733. }
  2734. #endif /* CONFIG_IEEE80211R */
  2735. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  2736. struct unprot_deauth *e)
  2737. {
  2738. #ifdef CONFIG_IEEE80211W
  2739. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  2740. "dropped: " MACSTR " -> " MACSTR
  2741. " (reason code %u)",
  2742. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2743. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2744. #endif /* CONFIG_IEEE80211W */
  2745. }
  2746. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  2747. struct unprot_disassoc *e)
  2748. {
  2749. #ifdef CONFIG_IEEE80211W
  2750. wpa_printf(MSG_DEBUG, "Unprotected Disassociation 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 wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
  2758. u16 reason_code, int locally_generated,
  2759. const u8 *ie, size_t ie_len, int deauth)
  2760. {
  2761. #ifdef CONFIG_AP
  2762. if (wpa_s->ap_iface && addr) {
  2763. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
  2764. return;
  2765. }
  2766. if (wpa_s->ap_iface) {
  2767. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
  2768. return;
  2769. }
  2770. #endif /* CONFIG_AP */
  2771. if (!locally_generated)
  2772. wpa_s->own_disconnect_req = 0;
  2773. wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
  2774. if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
  2775. ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  2776. (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
  2777. eapol_sm_failed(wpa_s->eapol))) &&
  2778. !wpa_s->eap_expected_failure))
  2779. wpas_auth_failed(wpa_s, "AUTH_FAILED");
  2780. #ifdef CONFIG_P2P
  2781. if (deauth && reason_code > 0) {
  2782. if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
  2783. locally_generated) > 0) {
  2784. /*
  2785. * The interface was removed, so cannot continue
  2786. * processing any additional operations after this.
  2787. */
  2788. return;
  2789. }
  2790. }
  2791. #endif /* CONFIG_P2P */
  2792. wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
  2793. locally_generated);
  2794. }
  2795. static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
  2796. struct disassoc_info *info)
  2797. {
  2798. u16 reason_code = 0;
  2799. int locally_generated = 0;
  2800. const u8 *addr = NULL;
  2801. const u8 *ie = NULL;
  2802. size_t ie_len = 0;
  2803. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  2804. if (info) {
  2805. addr = info->addr;
  2806. ie = info->ie;
  2807. ie_len = info->ie_len;
  2808. reason_code = info->reason_code;
  2809. locally_generated = info->locally_generated;
  2810. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
  2811. locally_generated ? " (locally generated)" : "");
  2812. if (addr)
  2813. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2814. MAC2STR(addr));
  2815. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  2816. ie, ie_len);
  2817. }
  2818. #ifdef CONFIG_AP
  2819. if (wpa_s->ap_iface && info && info->addr) {
  2820. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
  2821. return;
  2822. }
  2823. if (wpa_s->ap_iface) {
  2824. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
  2825. return;
  2826. }
  2827. #endif /* CONFIG_AP */
  2828. #ifdef CONFIG_P2P
  2829. if (info) {
  2830. wpas_p2p_disassoc_notif(
  2831. wpa_s, info->addr, reason_code, info->ie, info->ie_len,
  2832. locally_generated);
  2833. }
  2834. #endif /* CONFIG_P2P */
  2835. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2836. sme_event_disassoc(wpa_s, info);
  2837. wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
  2838. ie, ie_len, 0);
  2839. }
  2840. static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
  2841. struct deauth_info *info)
  2842. {
  2843. u16 reason_code = 0;
  2844. int locally_generated = 0;
  2845. const u8 *addr = NULL;
  2846. const u8 *ie = NULL;
  2847. size_t ie_len = 0;
  2848. wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
  2849. if (info) {
  2850. addr = info->addr;
  2851. ie = info->ie;
  2852. ie_len = info->ie_len;
  2853. reason_code = info->reason_code;
  2854. locally_generated = info->locally_generated;
  2855. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  2856. reason_code,
  2857. locally_generated ? " (locally generated)" : "");
  2858. if (addr) {
  2859. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2860. MAC2STR(addr));
  2861. }
  2862. wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
  2863. ie, ie_len);
  2864. }
  2865. wpa_reset_ft_completed(wpa_s->wpa);
  2866. wpas_event_disconnect(wpa_s, addr, reason_code,
  2867. locally_generated, ie, ie_len, 1);
  2868. }
  2869. static const char * reg_init_str(enum reg_change_initiator init)
  2870. {
  2871. switch (init) {
  2872. case REGDOM_SET_BY_CORE:
  2873. return "CORE";
  2874. case REGDOM_SET_BY_USER:
  2875. return "USER";
  2876. case REGDOM_SET_BY_DRIVER:
  2877. return "DRIVER";
  2878. case REGDOM_SET_BY_COUNTRY_IE:
  2879. return "COUNTRY_IE";
  2880. case REGDOM_BEACON_HINT:
  2881. return "BEACON_HINT";
  2882. }
  2883. return "?";
  2884. }
  2885. static const char * reg_type_str(enum reg_type type)
  2886. {
  2887. switch (type) {
  2888. case REGDOM_TYPE_UNKNOWN:
  2889. return "UNKNOWN";
  2890. case REGDOM_TYPE_COUNTRY:
  2891. return "COUNTRY";
  2892. case REGDOM_TYPE_WORLD:
  2893. return "WORLD";
  2894. case REGDOM_TYPE_CUSTOM_WORLD:
  2895. return "CUSTOM_WORLD";
  2896. case REGDOM_TYPE_INTERSECTION:
  2897. return "INTERSECTION";
  2898. }
  2899. return "?";
  2900. }
  2901. static void wpa_supplicant_update_channel_list(
  2902. struct wpa_supplicant *wpa_s, struct channel_list_changed *info)
  2903. {
  2904. struct wpa_supplicant *ifs;
  2905. /*
  2906. * To allow backwards compatibility with higher level layers that
  2907. * assumed the REGDOM_CHANGE event is sent over the initially added
  2908. * interface. Find the highest parent of this interface and use it to
  2909. * send the event.
  2910. */
  2911. for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent)
  2912. ;
  2913. wpa_msg(ifs, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s",
  2914. reg_init_str(info->initiator), reg_type_str(info->type),
  2915. info->alpha2[0] ? " alpha2=" : "",
  2916. info->alpha2[0] ? info->alpha2 : "");
  2917. if (wpa_s->drv_priv == NULL)
  2918. return; /* Ignore event during drv initialization */
  2919. dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
  2920. radio_list) {
  2921. wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
  2922. ifs->ifname);
  2923. free_hw_features(ifs);
  2924. ifs->hw.modes = wpa_drv_get_hw_feature_data(
  2925. ifs, &ifs->hw.num_modes, &ifs->hw.flags);
  2926. /* Restart PNO/sched_scan with updated channel list */
  2927. if (ifs->pno) {
  2928. wpas_stop_pno(ifs);
  2929. wpas_start_pno(ifs);
  2930. } else if (ifs->sched_scanning && !ifs->pno_sched_pending) {
  2931. wpa_dbg(ifs, MSG_DEBUG,
  2932. "Channel list changed - restart sched_scan");
  2933. wpas_scan_restart_sched_scan(ifs);
  2934. }
  2935. }
  2936. wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER);
  2937. }
  2938. static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s,
  2939. const u8 *frame, size_t len, int freq,
  2940. int rssi)
  2941. {
  2942. const struct ieee80211_mgmt *mgmt;
  2943. const u8 *payload;
  2944. size_t plen;
  2945. u8 category;
  2946. if (len < IEEE80211_HDRLEN + 2)
  2947. return;
  2948. mgmt = (const struct ieee80211_mgmt *) frame;
  2949. payload = frame + IEEE80211_HDRLEN;
  2950. category = *payload++;
  2951. plen = len - IEEE80211_HDRLEN - 1;
  2952. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2953. " Category=%u DataLen=%d freq=%d MHz",
  2954. MAC2STR(mgmt->sa), category, (int) plen, freq);
  2955. if (category == WLAN_ACTION_WMM) {
  2956. wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen);
  2957. return;
  2958. }
  2959. #ifdef CONFIG_IEEE80211R
  2960. if (category == WLAN_ACTION_FT) {
  2961. ft_rx_action(wpa_s, payload, plen);
  2962. return;
  2963. }
  2964. #endif /* CONFIG_IEEE80211R */
  2965. #ifdef CONFIG_IEEE80211W
  2966. #ifdef CONFIG_SME
  2967. if (category == WLAN_ACTION_SA_QUERY) {
  2968. sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen);
  2969. return;
  2970. }
  2971. #endif /* CONFIG_SME */
  2972. #endif /* CONFIG_IEEE80211W */
  2973. #ifdef CONFIG_WNM
  2974. if (mgmt->u.action.category == WLAN_ACTION_WNM) {
  2975. ieee802_11_rx_wnm_action(wpa_s, mgmt, len);
  2976. return;
  2977. }
  2978. #endif /* CONFIG_WNM */
  2979. #ifdef CONFIG_GAS
  2980. if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
  2981. mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
  2982. gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid,
  2983. mgmt->u.action.category,
  2984. payload, plen, freq) == 0)
  2985. return;
  2986. #endif /* CONFIG_GAS */
  2987. #ifdef CONFIG_TDLS
  2988. if (category == WLAN_ACTION_PUBLIC && plen >= 4 &&
  2989. payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2990. wpa_dbg(wpa_s, MSG_DEBUG,
  2991. "TDLS: Received Discovery Response from " MACSTR,
  2992. MAC2STR(mgmt->sa));
  2993. return;
  2994. }
  2995. #endif /* CONFIG_TDLS */
  2996. #ifdef CONFIG_INTERWORKING
  2997. if (category == WLAN_ACTION_QOS && plen >= 1 &&
  2998. payload[0] == QOS_QOS_MAP_CONFIG) {
  2999. const u8 *pos = payload + 1;
  3000. size_t qlen = plen - 1;
  3001. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
  3002. MACSTR, MAC2STR(mgmt->sa));
  3003. if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 &&
  3004. qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
  3005. pos[1] <= qlen - 2 && pos[1] >= 16)
  3006. wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
  3007. return;
  3008. }
  3009. #endif /* CONFIG_INTERWORKING */
  3010. if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
  3011. payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) {
  3012. wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa,
  3013. payload + 1,
  3014. plen - 1);
  3015. return;
  3016. }
  3017. if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
  3018. payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) {
  3019. wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1);
  3020. return;
  3021. }
  3022. if (category == WLAN_ACTION_RADIO_MEASUREMENT &&
  3023. payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) {
  3024. wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa,
  3025. payload + 1, plen - 1,
  3026. rssi);
  3027. return;
  3028. }
  3029. #ifdef CONFIG_FST
  3030. if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) {
  3031. fst_rx_action(wpa_s->fst, mgmt, len);
  3032. return;
  3033. }
  3034. #endif /* CONFIG_FST */
  3035. wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
  3036. category, payload, plen, freq);
  3037. if (wpa_s->ifmsh)
  3038. mesh_mpm_action_rx(wpa_s, mgmt, len);
  3039. }
  3040. static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s,
  3041. union wpa_event_data *event)
  3042. {
  3043. struct wpa_freq_range_list *list;
  3044. char *str = NULL;
  3045. list = &event->freq_range;
  3046. if (list->num)
  3047. str = freq_range_list_str(list);
  3048. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s",
  3049. str ? str : "");
  3050. #ifdef CONFIG_P2P
  3051. if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) {
  3052. wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range",
  3053. __func__);
  3054. } else {
  3055. wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event");
  3056. /*
  3057. * The update channel flow will also take care of moving a GO
  3058. * from the unsafe frequency if needed.
  3059. */
  3060. wpas_p2p_update_channel_list(wpa_s,
  3061. WPAS_P2P_CHANNEL_UPDATE_AVOID);
  3062. }
  3063. #endif /* CONFIG_P2P */
  3064. os_free(str);
  3065. }
  3066. static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s,
  3067. union wpa_event_data *data)
  3068. {
  3069. wpa_dbg(wpa_s, MSG_DEBUG,
  3070. "Connection authorized by device, previous state %d",
  3071. wpa_s->wpa_state);
  3072. if (wpa_s->wpa_state == WPA_ASSOCIATED) {
  3073. wpa_supplicant_cancel_auth_timeout(wpa_s);
  3074. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  3075. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  3076. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  3077. }
  3078. wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr);
  3079. wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck,
  3080. data->assoc_info.ptk_kck_len,
  3081. data->assoc_info.ptk_kek,
  3082. data->assoc_info.ptk_kek_len);
  3083. }
  3084. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  3085. union wpa_event_data *data)
  3086. {
  3087. struct wpa_supplicant *wpa_s = ctx;
  3088. int resched;
  3089. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  3090. event != EVENT_INTERFACE_ENABLED &&
  3091. event != EVENT_INTERFACE_STATUS &&
  3092. event != EVENT_SCAN_RESULTS &&
  3093. event != EVENT_SCHED_SCAN_STOPPED) {
  3094. wpa_dbg(wpa_s, MSG_DEBUG,
  3095. "Ignore event %s (%d) while interface is disabled",
  3096. event_to_string(event), event);
  3097. return;
  3098. }
  3099. #ifndef CONFIG_NO_STDOUT_DEBUG
  3100. {
  3101. int level = MSG_DEBUG;
  3102. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
  3103. const struct ieee80211_hdr *hdr;
  3104. u16 fc;
  3105. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  3106. fc = le_to_host16(hdr->frame_control);
  3107. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  3108. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  3109. level = MSG_EXCESSIVE;
  3110. }
  3111. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  3112. event_to_string(event), event);
  3113. }
  3114. #endif /* CONFIG_NO_STDOUT_DEBUG */
  3115. switch (event) {
  3116. case EVENT_AUTH:
  3117. #ifdef CONFIG_FST
  3118. if (!wpas_fst_update_mbie(wpa_s, data->auth.ies,
  3119. data->auth.ies_len))
  3120. wpa_printf(MSG_DEBUG,
  3121. "FST: MB IEs updated from auth IE");
  3122. #endif /* CONFIG_FST */
  3123. sme_event_auth(wpa_s, data);
  3124. break;
  3125. case EVENT_ASSOC:
  3126. #ifdef CONFIG_TESTING_OPTIONS
  3127. if (wpa_s->ignore_auth_resp) {
  3128. wpa_printf(MSG_INFO,
  3129. "EVENT_ASSOC - ignore_auth_resp active!");
  3130. break;
  3131. }
  3132. #endif /* CONFIG_TESTING_OPTIONS */
  3133. wpa_supplicant_event_assoc(wpa_s, data);
  3134. if (data && data->assoc_info.authorized)
  3135. wpa_supplicant_event_assoc_auth(wpa_s, data);
  3136. if (data) {
  3137. wpa_msg(wpa_s, MSG_INFO,
  3138. WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u",
  3139. data->assoc_info.subnet_status);
  3140. }
  3141. break;
  3142. case EVENT_DISASSOC:
  3143. wpas_event_disassoc(wpa_s,
  3144. data ? &data->disassoc_info : NULL);
  3145. break;
  3146. case EVENT_DEAUTH:
  3147. #ifdef CONFIG_TESTING_OPTIONS
  3148. if (wpa_s->ignore_auth_resp) {
  3149. wpa_printf(MSG_INFO,
  3150. "EVENT_DEAUTH - ignore_auth_resp active!");
  3151. break;
  3152. }
  3153. #endif /* CONFIG_TESTING_OPTIONS */
  3154. wpas_event_deauth(wpa_s,
  3155. data ? &data->deauth_info : NULL);
  3156. break;
  3157. case EVENT_MICHAEL_MIC_FAILURE:
  3158. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  3159. break;
  3160. #ifndef CONFIG_NO_SCAN_PROCESSING
  3161. case EVENT_SCAN_STARTED:
  3162. if (wpa_s->own_scan_requested ||
  3163. (data && !data->scan_info.external_scan)) {
  3164. struct os_reltime diff;
  3165. os_get_reltime(&wpa_s->scan_start_time);
  3166. os_reltime_sub(&wpa_s->scan_start_time,
  3167. &wpa_s->scan_trigger_time, &diff);
  3168. wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds",
  3169. diff.sec, diff.usec);
  3170. wpa_s->own_scan_requested = 0;
  3171. wpa_s->own_scan_running = 1;
  3172. if (wpa_s->last_scan_req == MANUAL_SCAN_REQ &&
  3173. wpa_s->manual_scan_use_id) {
  3174. wpa_msg_ctrl(wpa_s, MSG_INFO,
  3175. WPA_EVENT_SCAN_STARTED "id=%u",
  3176. wpa_s->manual_scan_id);
  3177. } else {
  3178. wpa_msg_ctrl(wpa_s, MSG_INFO,
  3179. WPA_EVENT_SCAN_STARTED);
  3180. }
  3181. } else {
  3182. wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
  3183. wpa_s->radio->external_scan_running = 1;
  3184. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
  3185. }
  3186. break;
  3187. case EVENT_SCAN_RESULTS:
  3188. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  3189. wpa_s->scan_res_handler = NULL;
  3190. wpa_s->own_scan_running = 0;
  3191. wpa_s->radio->external_scan_running = 0;
  3192. wpa_s->last_scan_req = NORMAL_SCAN_REQ;
  3193. break;
  3194. }
  3195. if (!(data && data->scan_info.external_scan) &&
  3196. os_reltime_initialized(&wpa_s->scan_start_time)) {
  3197. struct os_reltime now, diff;
  3198. os_get_reltime(&now);
  3199. os_reltime_sub(&now, &wpa_s->scan_start_time, &diff);
  3200. wpa_s->scan_start_time.sec = 0;
  3201. wpa_s->scan_start_time.usec = 0;
  3202. wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds",
  3203. diff.sec, diff.usec);
  3204. }
  3205. if (wpa_supplicant_event_scan_results(wpa_s, data))
  3206. break; /* interface may have been removed */
  3207. if (!(data && data->scan_info.external_scan))
  3208. wpa_s->own_scan_running = 0;
  3209. if (data && data->scan_info.nl_scan_event)
  3210. wpa_s->radio->external_scan_running = 0;
  3211. radio_work_check_next(wpa_s);
  3212. break;
  3213. #endif /* CONFIG_NO_SCAN_PROCESSING */
  3214. case EVENT_ASSOCINFO:
  3215. wpa_supplicant_event_associnfo(wpa_s, data);
  3216. break;
  3217. case EVENT_INTERFACE_STATUS:
  3218. wpa_supplicant_event_interface_status(wpa_s, data);
  3219. break;
  3220. case EVENT_PMKID_CANDIDATE:
  3221. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  3222. break;
  3223. #ifdef CONFIG_PEERKEY
  3224. case EVENT_STKSTART:
  3225. wpa_supplicant_event_stkstart(wpa_s, data);
  3226. break;
  3227. #endif /* CONFIG_PEERKEY */
  3228. #ifdef CONFIG_TDLS
  3229. case EVENT_TDLS:
  3230. wpa_supplicant_event_tdls(wpa_s, data);
  3231. break;
  3232. #endif /* CONFIG_TDLS */
  3233. #ifdef CONFIG_WNM
  3234. case EVENT_WNM:
  3235. wpa_supplicant_event_wnm(wpa_s, data);
  3236. break;
  3237. #endif /* CONFIG_WNM */
  3238. #ifdef CONFIG_IEEE80211R
  3239. case EVENT_FT_RESPONSE:
  3240. wpa_supplicant_event_ft_response(wpa_s, data);
  3241. break;
  3242. #endif /* CONFIG_IEEE80211R */
  3243. #ifdef CONFIG_IBSS_RSN
  3244. case EVENT_IBSS_RSN_START:
  3245. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  3246. break;
  3247. #endif /* CONFIG_IBSS_RSN */
  3248. case EVENT_ASSOC_REJECT:
  3249. if (data->assoc_reject.bssid)
  3250. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  3251. "bssid=" MACSTR " status_code=%u%s",
  3252. MAC2STR(data->assoc_reject.bssid),
  3253. data->assoc_reject.status_code,
  3254. data->assoc_reject.timed_out ? " timeout" : "");
  3255. else
  3256. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  3257. "status_code=%u%s",
  3258. data->assoc_reject.status_code,
  3259. data->assoc_reject.timed_out ? " timeout" : "");
  3260. wpa_s->assoc_status_code = data->assoc_reject.status_code;
  3261. wpas_notify_assoc_status_code(wpa_s);
  3262. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  3263. sme_event_assoc_reject(wpa_s, data);
  3264. else {
  3265. const u8 *bssid = data->assoc_reject.bssid;
  3266. if (bssid == NULL || is_zero_ether_addr(bssid))
  3267. bssid = wpa_s->pending_bssid;
  3268. wpas_connection_failed(wpa_s, bssid);
  3269. wpa_supplicant_mark_disassoc(wpa_s);
  3270. }
  3271. break;
  3272. case EVENT_AUTH_TIMED_OUT:
  3273. /* It is possible to get this event from earlier connection */
  3274. if (wpa_s->current_ssid &&
  3275. wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
  3276. wpa_dbg(wpa_s, MSG_DEBUG,
  3277. "Ignore AUTH_TIMED_OUT in mesh configuration");
  3278. break;
  3279. }
  3280. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  3281. sme_event_auth_timed_out(wpa_s, data);
  3282. break;
  3283. case EVENT_ASSOC_TIMED_OUT:
  3284. /* It is possible to get this event from earlier connection */
  3285. if (wpa_s->current_ssid &&
  3286. wpa_s->current_ssid->mode == WPAS_MODE_MESH) {
  3287. wpa_dbg(wpa_s, MSG_DEBUG,
  3288. "Ignore ASSOC_TIMED_OUT in mesh configuration");
  3289. break;
  3290. }
  3291. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  3292. sme_event_assoc_timed_out(wpa_s, data);
  3293. break;
  3294. case EVENT_TX_STATUS:
  3295. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  3296. " type=%d stype=%d",
  3297. MAC2STR(data->tx_status.dst),
  3298. data->tx_status.type, data->tx_status.stype);
  3299. #ifdef CONFIG_AP
  3300. if (wpa_s->ap_iface == NULL) {
  3301. #ifdef CONFIG_OFFCHANNEL
  3302. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  3303. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  3304. offchannel_send_action_tx_status(
  3305. wpa_s, data->tx_status.dst,
  3306. data->tx_status.data,
  3307. data->tx_status.data_len,
  3308. data->tx_status.ack ?
  3309. OFFCHANNEL_SEND_ACTION_SUCCESS :
  3310. OFFCHANNEL_SEND_ACTION_NO_ACK);
  3311. #endif /* CONFIG_OFFCHANNEL */
  3312. break;
  3313. }
  3314. #endif /* CONFIG_AP */
  3315. #ifdef CONFIG_OFFCHANNEL
  3316. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  3317. MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst));
  3318. /*
  3319. * Catch TX status events for Action frames we sent via group
  3320. * interface in GO mode, or via standalone AP interface.
  3321. * Note, wpa_s->p2pdev will be the same as wpa_s->parent,
  3322. * except when the primary interface is used as a GO interface
  3323. * (for drivers which do not have group interface concurrency)
  3324. */
  3325. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  3326. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  3327. os_memcmp(wpa_s->p2pdev->pending_action_dst,
  3328. data->tx_status.dst, ETH_ALEN) == 0) {
  3329. offchannel_send_action_tx_status(
  3330. wpa_s->p2pdev, data->tx_status.dst,
  3331. data->tx_status.data,
  3332. data->tx_status.data_len,
  3333. data->tx_status.ack ?
  3334. OFFCHANNEL_SEND_ACTION_SUCCESS :
  3335. OFFCHANNEL_SEND_ACTION_NO_ACK);
  3336. break;
  3337. }
  3338. #endif /* CONFIG_OFFCHANNEL */
  3339. #ifdef CONFIG_AP
  3340. switch (data->tx_status.type) {
  3341. case WLAN_FC_TYPE_MGMT:
  3342. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  3343. data->tx_status.data_len,
  3344. data->tx_status.stype,
  3345. data->tx_status.ack);
  3346. break;
  3347. case WLAN_FC_TYPE_DATA:
  3348. ap_tx_status(wpa_s, data->tx_status.dst,
  3349. data->tx_status.data,
  3350. data->tx_status.data_len,
  3351. data->tx_status.ack);
  3352. break;
  3353. }
  3354. #endif /* CONFIG_AP */
  3355. break;
  3356. #ifdef CONFIG_AP
  3357. case EVENT_EAPOL_TX_STATUS:
  3358. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  3359. data->eapol_tx_status.data,
  3360. data->eapol_tx_status.data_len,
  3361. data->eapol_tx_status.ack);
  3362. break;
  3363. case EVENT_DRIVER_CLIENT_POLL_OK:
  3364. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  3365. break;
  3366. case EVENT_RX_FROM_UNKNOWN:
  3367. if (wpa_s->ap_iface == NULL)
  3368. break;
  3369. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  3370. data->rx_from_unknown.wds);
  3371. break;
  3372. case EVENT_CH_SWITCH:
  3373. if (!data || !wpa_s->current_ssid)
  3374. break;
  3375. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
  3376. "freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
  3377. data->ch_switch.freq,
  3378. data->ch_switch.ht_enabled,
  3379. data->ch_switch.ch_offset,
  3380. channel_width_to_string(data->ch_switch.ch_width),
  3381. data->ch_switch.cf1,
  3382. data->ch_switch.cf2);
  3383. wpa_s->assoc_freq = data->ch_switch.freq;
  3384. wpa_s->current_ssid->frequency = data->ch_switch.freq;
  3385. if (wpa_s->current_ssid->mode == WPAS_MODE_AP ||
  3386. wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO ||
  3387. wpa_s->current_ssid->mode ==
  3388. WPAS_MODE_P2P_GROUP_FORMATION) {
  3389. wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
  3390. data->ch_switch.ht_enabled,
  3391. data->ch_switch.ch_offset,
  3392. data->ch_switch.ch_width,
  3393. data->ch_switch.cf1,
  3394. data->ch_switch.cf2);
  3395. }
  3396. wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS);
  3397. break;
  3398. #ifdef NEED_AP_MLME
  3399. case EVENT_DFS_RADAR_DETECTED:
  3400. if (data)
  3401. wpas_event_dfs_radar_detected(wpa_s, &data->dfs_event);
  3402. break;
  3403. case EVENT_DFS_CAC_STARTED:
  3404. if (data)
  3405. wpas_event_dfs_cac_started(wpa_s, &data->dfs_event);
  3406. break;
  3407. case EVENT_DFS_CAC_FINISHED:
  3408. if (data)
  3409. wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event);
  3410. break;
  3411. case EVENT_DFS_CAC_ABORTED:
  3412. if (data)
  3413. wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event);
  3414. break;
  3415. case EVENT_DFS_NOP_FINISHED:
  3416. if (data)
  3417. wpas_event_dfs_cac_nop_finished(wpa_s,
  3418. &data->dfs_event);
  3419. break;
  3420. #endif /* NEED_AP_MLME */
  3421. #endif /* CONFIG_AP */
  3422. case EVENT_RX_MGMT: {
  3423. u16 fc, stype;
  3424. const struct ieee80211_mgmt *mgmt;
  3425. #ifdef CONFIG_TESTING_OPTIONS
  3426. if (wpa_s->ext_mgmt_frame_handling) {
  3427. struct rx_mgmt *rx = &data->rx_mgmt;
  3428. size_t hex_len = 2 * rx->frame_len + 1;
  3429. char *hex = os_malloc(hex_len);
  3430. if (hex) {
  3431. wpa_snprintf_hex(hex, hex_len,
  3432. rx->frame, rx->frame_len);
  3433. wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s",
  3434. rx->freq, rx->datarate, rx->ssi_signal,
  3435. hex);
  3436. os_free(hex);
  3437. }
  3438. break;
  3439. }
  3440. #endif /* CONFIG_TESTING_OPTIONS */
  3441. mgmt = (const struct ieee80211_mgmt *)
  3442. data->rx_mgmt.frame;
  3443. fc = le_to_host16(mgmt->frame_control);
  3444. stype = WLAN_FC_GET_STYPE(fc);
  3445. #ifdef CONFIG_AP
  3446. if (wpa_s->ap_iface == NULL) {
  3447. #endif /* CONFIG_AP */
  3448. #ifdef CONFIG_P2P
  3449. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  3450. data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
  3451. const u8 *src = mgmt->sa;
  3452. const u8 *ie;
  3453. size_t ie_len;
  3454. ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
  3455. ie_len = data->rx_mgmt.frame_len -
  3456. IEEE80211_HDRLEN;
  3457. wpas_p2p_probe_req_rx(
  3458. wpa_s, src, mgmt->da,
  3459. mgmt->bssid, ie, ie_len,
  3460. data->rx_mgmt.freq,
  3461. data->rx_mgmt.ssi_signal);
  3462. break;
  3463. }
  3464. #endif /* CONFIG_P2P */
  3465. #ifdef CONFIG_IBSS_RSN
  3466. if (wpa_s->current_ssid &&
  3467. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  3468. stype == WLAN_FC_STYPE_AUTH &&
  3469. data->rx_mgmt.frame_len >= 30) {
  3470. wpa_supplicant_event_ibss_auth(wpa_s, data);
  3471. break;
  3472. }
  3473. #endif /* CONFIG_IBSS_RSN */
  3474. if (stype == WLAN_FC_STYPE_ACTION) {
  3475. wpas_event_rx_mgmt_action(
  3476. wpa_s, data->rx_mgmt.frame,
  3477. data->rx_mgmt.frame_len,
  3478. data->rx_mgmt.freq,
  3479. data->rx_mgmt.ssi_signal);
  3480. break;
  3481. }
  3482. if (wpa_s->ifmsh) {
  3483. mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt);
  3484. break;
  3485. }
  3486. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  3487. "management frame in non-AP mode");
  3488. break;
  3489. #ifdef CONFIG_AP
  3490. }
  3491. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  3492. data->rx_mgmt.frame_len > IEEE80211_HDRLEN) {
  3493. const u8 *ie;
  3494. size_t ie_len;
  3495. ie = data->rx_mgmt.frame + IEEE80211_HDRLEN;
  3496. ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN;
  3497. wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
  3498. mgmt->bssid, ie, ie_len,
  3499. data->rx_mgmt.ssi_signal);
  3500. }
  3501. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  3502. #endif /* CONFIG_AP */
  3503. break;
  3504. }
  3505. case EVENT_RX_PROBE_REQ:
  3506. if (data->rx_probe_req.sa == NULL ||
  3507. data->rx_probe_req.ie == NULL)
  3508. break;
  3509. #ifdef CONFIG_AP
  3510. if (wpa_s->ap_iface) {
  3511. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  3512. data->rx_probe_req.sa,
  3513. data->rx_probe_req.da,
  3514. data->rx_probe_req.bssid,
  3515. data->rx_probe_req.ie,
  3516. data->rx_probe_req.ie_len,
  3517. data->rx_probe_req.ssi_signal);
  3518. break;
  3519. }
  3520. #endif /* CONFIG_AP */
  3521. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  3522. data->rx_probe_req.da,
  3523. data->rx_probe_req.bssid,
  3524. data->rx_probe_req.ie,
  3525. data->rx_probe_req.ie_len,
  3526. 0,
  3527. data->rx_probe_req.ssi_signal);
  3528. break;
  3529. case EVENT_REMAIN_ON_CHANNEL:
  3530. #ifdef CONFIG_OFFCHANNEL
  3531. offchannel_remain_on_channel_cb(
  3532. wpa_s, data->remain_on_channel.freq,
  3533. data->remain_on_channel.duration);
  3534. #endif /* CONFIG_OFFCHANNEL */
  3535. wpas_p2p_remain_on_channel_cb(
  3536. wpa_s, data->remain_on_channel.freq,
  3537. data->remain_on_channel.duration);
  3538. break;
  3539. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  3540. #ifdef CONFIG_OFFCHANNEL
  3541. offchannel_cancel_remain_on_channel_cb(
  3542. wpa_s, data->remain_on_channel.freq);
  3543. #endif /* CONFIG_OFFCHANNEL */
  3544. wpas_p2p_cancel_remain_on_channel_cb(
  3545. wpa_s, data->remain_on_channel.freq);
  3546. break;
  3547. case EVENT_EAPOL_RX:
  3548. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  3549. data->eapol_rx.data,
  3550. data->eapol_rx.data_len);
  3551. break;
  3552. case EVENT_SIGNAL_CHANGE:
  3553. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
  3554. "above=%d signal=%d noise=%d txrate=%d",
  3555. data->signal_change.above_threshold,
  3556. data->signal_change.current_signal,
  3557. data->signal_change.current_noise,
  3558. data->signal_change.current_txrate);
  3559. wpa_bss_update_level(wpa_s->current_bss,
  3560. data->signal_change.current_signal);
  3561. bgscan_notify_signal_change(
  3562. wpa_s, data->signal_change.above_threshold,
  3563. data->signal_change.current_signal,
  3564. data->signal_change.current_noise,
  3565. data->signal_change.current_txrate);
  3566. break;
  3567. case EVENT_INTERFACE_ENABLED:
  3568. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  3569. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  3570. wpa_supplicant_update_mac_addr(wpa_s);
  3571. if (wpa_s->p2p_mgmt) {
  3572. wpa_supplicant_set_state(wpa_s,
  3573. WPA_DISCONNECTED);
  3574. break;
  3575. }
  3576. #ifdef CONFIG_AP
  3577. if (!wpa_s->ap_iface) {
  3578. wpa_supplicant_set_state(wpa_s,
  3579. WPA_DISCONNECTED);
  3580. wpa_s->scan_req = NORMAL_SCAN_REQ;
  3581. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3582. } else
  3583. wpa_supplicant_set_state(wpa_s,
  3584. WPA_COMPLETED);
  3585. #else /* CONFIG_AP */
  3586. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  3587. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3588. #endif /* CONFIG_AP */
  3589. }
  3590. break;
  3591. case EVENT_INTERFACE_DISABLED:
  3592. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  3593. #ifdef CONFIG_P2P
  3594. if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
  3595. (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
  3596. wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
  3597. /*
  3598. * Mark interface disabled if this happens to end up not
  3599. * being removed as a separate P2P group interface.
  3600. */
  3601. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  3602. /*
  3603. * The interface was externally disabled. Remove
  3604. * it assuming an external entity will start a
  3605. * new session if needed.
  3606. */
  3607. if (wpa_s->current_ssid &&
  3608. wpa_s->current_ssid->p2p_group)
  3609. wpas_p2p_interface_unavailable(wpa_s);
  3610. else
  3611. wpas_p2p_disconnect(wpa_s);
  3612. /*
  3613. * wpa_s instance may have been freed, so must not use
  3614. * it here anymore.
  3615. */
  3616. break;
  3617. }
  3618. if (wpa_s->p2p_scan_work && wpa_s->global->p2p &&
  3619. p2p_in_progress(wpa_s->global->p2p) > 1) {
  3620. /* This radio work will be cancelled, so clear P2P
  3621. * state as well.
  3622. */
  3623. p2p_stop_find(wpa_s->global->p2p);
  3624. }
  3625. #endif /* CONFIG_P2P */
  3626. if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  3627. /*
  3628. * Indicate disconnection to keep ctrl_iface events
  3629. * consistent.
  3630. */
  3631. wpa_supplicant_event_disassoc(
  3632. wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1);
  3633. }
  3634. wpa_supplicant_mark_disassoc(wpa_s);
  3635. wpa_bss_flush(wpa_s);
  3636. radio_remove_works(wpa_s, NULL, 0);
  3637. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  3638. break;
  3639. case EVENT_CHANNEL_LIST_CHANGED:
  3640. wpa_supplicant_update_channel_list(
  3641. wpa_s, &data->channel_list_changed);
  3642. break;
  3643. case EVENT_INTERFACE_UNAVAILABLE:
  3644. wpas_p2p_interface_unavailable(wpa_s);
  3645. break;
  3646. case EVENT_BEST_CHANNEL:
  3647. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  3648. "(%d %d %d)",
  3649. data->best_chan.freq_24, data->best_chan.freq_5,
  3650. data->best_chan.freq_overall);
  3651. wpa_s->best_24_freq = data->best_chan.freq_24;
  3652. wpa_s->best_5_freq = data->best_chan.freq_5;
  3653. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  3654. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  3655. data->best_chan.freq_5,
  3656. data->best_chan.freq_overall);
  3657. break;
  3658. case EVENT_UNPROT_DEAUTH:
  3659. wpa_supplicant_event_unprot_deauth(wpa_s,
  3660. &data->unprot_deauth);
  3661. break;
  3662. case EVENT_UNPROT_DISASSOC:
  3663. wpa_supplicant_event_unprot_disassoc(wpa_s,
  3664. &data->unprot_disassoc);
  3665. break;
  3666. case EVENT_STATION_LOW_ACK:
  3667. #ifdef CONFIG_AP
  3668. if (wpa_s->ap_iface && data)
  3669. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  3670. data->low_ack.addr);
  3671. #endif /* CONFIG_AP */
  3672. #ifdef CONFIG_TDLS
  3673. if (data)
  3674. wpa_tdls_disable_unreachable_link(wpa_s->wpa,
  3675. data->low_ack.addr);
  3676. #endif /* CONFIG_TDLS */
  3677. break;
  3678. case EVENT_IBSS_PEER_LOST:
  3679. #ifdef CONFIG_IBSS_RSN
  3680. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  3681. #endif /* CONFIG_IBSS_RSN */
  3682. break;
  3683. case EVENT_DRIVER_GTK_REKEY:
  3684. if (os_memcmp(data->driver_gtk_rekey.bssid,
  3685. wpa_s->bssid, ETH_ALEN))
  3686. break;
  3687. if (!wpa_s->wpa)
  3688. break;
  3689. wpa_sm_update_replay_ctr(wpa_s->wpa,
  3690. data->driver_gtk_rekey.replay_ctr);
  3691. break;
  3692. case EVENT_SCHED_SCAN_STOPPED:
  3693. wpa_s->sched_scanning = 0;
  3694. resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s);
  3695. wpa_supplicant_notify_scanning(wpa_s, 0);
  3696. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3697. break;
  3698. /*
  3699. * If the driver stopped scanning without being requested to,
  3700. * request a new scan to continue scanning for networks.
  3701. */
  3702. if (!wpa_s->sched_scan_stop_req &&
  3703. wpa_s->wpa_state == WPA_SCANNING) {
  3704. wpa_dbg(wpa_s, MSG_DEBUG,
  3705. "Restart scanning after unexpected sched_scan stop event");
  3706. wpa_supplicant_req_scan(wpa_s, 1, 0);
  3707. break;
  3708. }
  3709. wpa_s->sched_scan_stop_req = 0;
  3710. /*
  3711. * Start a new sched scan to continue searching for more SSIDs
  3712. * either if timed out or PNO schedule scan is pending.
  3713. */
  3714. if (wpa_s->sched_scan_timed_out) {
  3715. wpa_supplicant_req_sched_scan(wpa_s);
  3716. } else if (wpa_s->pno_sched_pending) {
  3717. wpa_s->pno_sched_pending = 0;
  3718. wpas_start_pno(wpa_s);
  3719. } else if (resched) {
  3720. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3721. }
  3722. break;
  3723. case EVENT_WPS_BUTTON_PUSHED:
  3724. #ifdef CONFIG_WPS
  3725. wpas_wps_start_pbc(wpa_s, NULL, 0);
  3726. #endif /* CONFIG_WPS */
  3727. break;
  3728. case EVENT_AVOID_FREQUENCIES:
  3729. wpa_supplicant_notify_avoid_freq(wpa_s, data);
  3730. break;
  3731. case EVENT_CONNECT_FAILED_REASON:
  3732. #ifdef CONFIG_AP
  3733. if (!wpa_s->ap_iface || !data)
  3734. break;
  3735. hostapd_event_connect_failed_reason(
  3736. wpa_s->ap_iface->bss[0],
  3737. data->connect_failed_reason.addr,
  3738. data->connect_failed_reason.code);
  3739. #endif /* CONFIG_AP */
  3740. break;
  3741. case EVENT_NEW_PEER_CANDIDATE:
  3742. #ifdef CONFIG_MESH
  3743. if (!wpa_s->ifmsh || !data)
  3744. break;
  3745. wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer,
  3746. data->mesh_peer.ies,
  3747. data->mesh_peer.ie_len);
  3748. #endif /* CONFIG_MESH */
  3749. break;
  3750. case EVENT_SURVEY:
  3751. #ifdef CONFIG_AP
  3752. if (!wpa_s->ap_iface)
  3753. break;
  3754. hostapd_event_get_survey(wpa_s->ap_iface,
  3755. &data->survey_results);
  3756. #endif /* CONFIG_AP */
  3757. break;
  3758. case EVENT_ACS_CHANNEL_SELECTED:
  3759. #ifdef CONFIG_AP
  3760. #ifdef CONFIG_ACS
  3761. if (!wpa_s->ap_iface)
  3762. break;
  3763. hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
  3764. &data->acs_selected_channels);
  3765. #endif /* CONFIG_ACS */
  3766. #endif /* CONFIG_AP */
  3767. break;
  3768. case EVENT_P2P_LO_STOP:
  3769. #ifdef CONFIG_P2P
  3770. wpa_s->p2p_lo_started = 0;
  3771. wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP
  3772. P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d",
  3773. data->p2p_lo_stop.reason_code);
  3774. #endif /* CONFIG_P2P */
  3775. break;
  3776. case EVENT_BEACON_LOSS:
  3777. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  3778. break;
  3779. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS);
  3780. bgscan_notify_beacon_loss(wpa_s);
  3781. break;
  3782. default:
  3783. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  3784. break;
  3785. }
  3786. }
  3787. void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
  3788. union wpa_event_data *data)
  3789. {
  3790. struct wpa_supplicant *wpa_s;
  3791. if (event != EVENT_INTERFACE_STATUS)
  3792. return;
  3793. wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname);
  3794. if (wpa_s && wpa_s->driver->get_ifindex) {
  3795. unsigned int ifindex;
  3796. ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv);
  3797. if (ifindex != data->interface_status.ifindex) {
  3798. wpa_dbg(wpa_s, MSG_DEBUG,
  3799. "interface status ifindex %d mismatch (%d)",
  3800. ifindex, data->interface_status.ifindex);
  3801. return;
  3802. }
  3803. }
  3804. #ifdef CONFIG_MATCH_IFACE
  3805. else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) {
  3806. struct wpa_interface *wpa_i;
  3807. wpa_i = wpa_supplicant_match_iface(
  3808. ctx, data->interface_status.ifname);
  3809. if (!wpa_i)
  3810. return;
  3811. wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL);
  3812. os_free(wpa_i);
  3813. if (wpa_s)
  3814. wpa_s->matched = 1;
  3815. }
  3816. #endif /* CONFIG_MATCH_IFACE */
  3817. if (wpa_s)
  3818. wpa_supplicant_event(wpa_s, event, data);
  3819. }