events.c 104 KB

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