events.c 102 KB

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