events.c 103 KB

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