events.c 118 KB

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