events.c 88 KB

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