events.c 121 KB

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