events.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294
  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. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  1062. wpas_notify_scan_results(wpa_s);
  1063. wpas_notify_scan_done(wpa_s, 1);
  1064. if (sme_proc_obss_scan(wpa_s) > 0) {
  1065. wpa_scan_results_free(scan_res);
  1066. return 0;
  1067. }
  1068. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  1069. wpa_scan_results_free(scan_res);
  1070. return 0;
  1071. }
  1072. if (autoscan_notify_scan(wpa_s, scan_res)) {
  1073. wpa_scan_results_free(scan_res);
  1074. return 0;
  1075. }
  1076. if (wpa_s->disconnected) {
  1077. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1078. wpa_scan_results_free(scan_res);
  1079. return 0;
  1080. }
  1081. if (!wpas_driver_bss_selection(wpa_s) &&
  1082. bgscan_notify_scan(wpa_s, scan_res) == 1) {
  1083. wpa_scan_results_free(scan_res);
  1084. return 0;
  1085. }
  1086. wpas_wps_update_ap_info(wpa_s, scan_res);
  1087. wpa_scan_results_free(scan_res);
  1088. return wpas_select_network_from_last_scan(wpa_s, 1, own_request);
  1089. }
  1090. static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s,
  1091. int new_scan, int own_request)
  1092. {
  1093. struct wpa_bss *selected;
  1094. struct wpa_ssid *ssid = NULL;
  1095. selected = wpa_supplicant_pick_network(wpa_s, &ssid);
  1096. if (selected) {
  1097. int skip;
  1098. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid);
  1099. if (skip) {
  1100. if (new_scan)
  1101. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1102. return 0;
  1103. }
  1104. if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) {
  1105. wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed");
  1106. return -1;
  1107. }
  1108. if (new_scan)
  1109. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1110. /*
  1111. * Do not notify other virtual radios of scan results since we do not
  1112. * want them to start other associations at the same time.
  1113. */
  1114. return 1;
  1115. } else {
  1116. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  1117. ssid = wpa_supplicant_pick_new_network(wpa_s);
  1118. if (ssid) {
  1119. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  1120. wpa_supplicant_associate(wpa_s, NULL, ssid);
  1121. if (new_scan)
  1122. wpa_supplicant_rsn_preauth_scan_results(wpa_s);
  1123. } else if (own_request) {
  1124. /*
  1125. * No SSID found. If SCAN results are as a result of
  1126. * own scan request and not due to a scan request on
  1127. * another shared interface, try another scan.
  1128. */
  1129. int timeout_sec = wpa_s->scan_interval;
  1130. int timeout_usec = 0;
  1131. #ifdef CONFIG_P2P
  1132. if (wpas_p2p_scan_no_go_seen(wpa_s) == 1)
  1133. return 0;
  1134. if (wpa_s->p2p_in_provisioning ||
  1135. wpa_s->show_group_started) {
  1136. /*
  1137. * Use shorter wait during P2P Provisioning
  1138. * state and during P2P join-a-group operation
  1139. * to speed up group formation.
  1140. */
  1141. timeout_sec = 0;
  1142. timeout_usec = 250000;
  1143. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1144. timeout_usec);
  1145. return 0;
  1146. }
  1147. #endif /* CONFIG_P2P */
  1148. #ifdef CONFIG_INTERWORKING
  1149. if (wpa_s->conf->auto_interworking &&
  1150. wpa_s->conf->interworking &&
  1151. wpa_s->conf->cred) {
  1152. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: "
  1153. "start ANQP fetch since no matching "
  1154. "networks found");
  1155. wpa_s->network_select = 1;
  1156. wpa_s->auto_network_select = 1;
  1157. interworking_start_fetch_anqp(wpa_s);
  1158. return 1;
  1159. }
  1160. #endif /* CONFIG_INTERWORKING */
  1161. if (wpa_supplicant_req_sched_scan(wpa_s))
  1162. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  1163. timeout_usec);
  1164. }
  1165. }
  1166. return 0;
  1167. }
  1168. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  1169. union wpa_event_data *data)
  1170. {
  1171. struct wpa_supplicant *ifs;
  1172. if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) {
  1173. /*
  1174. * If no scan results could be fetched, then no need to
  1175. * notify those interfaces that did not actually request
  1176. * this scan. Similarly, if scan results started a new operation on this
  1177. * interface, do not notify other interfaces to avoid concurrent
  1178. * operations during a connection attempt.
  1179. */
  1180. return;
  1181. }
  1182. /*
  1183. * Check other interfaces to see if they share the same radio. If
  1184. * so, they get updated with this same scan info.
  1185. */
  1186. dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
  1187. radio_list) {
  1188. if (ifs != wpa_s) {
  1189. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  1190. "sibling", ifs->ifname);
  1191. _wpa_supplicant_event_scan_results(ifs, data, 0);
  1192. }
  1193. }
  1194. }
  1195. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1196. int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s)
  1197. {
  1198. #ifdef CONFIG_NO_SCAN_PROCESSING
  1199. return -1;
  1200. #else /* CONFIG_NO_SCAN_PROCESSING */
  1201. struct os_reltime now;
  1202. if (wpa_s->last_scan_res_used <= 0)
  1203. return -1;
  1204. os_get_reltime(&now);
  1205. if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) {
  1206. wpa_printf(MSG_DEBUG, "Fast associate: Old scan results");
  1207. return -1;
  1208. }
  1209. return wpas_select_network_from_last_scan(wpa_s, 0, 1);
  1210. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1211. }
  1212. #ifdef CONFIG_WNM
  1213. static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx)
  1214. {
  1215. struct wpa_supplicant *wpa_s = eloop_ctx;
  1216. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1217. return;
  1218. if (!wpa_s->no_keep_alive) {
  1219. wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR,
  1220. MAC2STR(wpa_s->bssid));
  1221. /* TODO: could skip this if normal data traffic has been sent */
  1222. /* TODO: Consider using some more appropriate data frame for
  1223. * this */
  1224. if (wpa_s->l2)
  1225. l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800,
  1226. (u8 *) "", 0);
  1227. }
  1228. #ifdef CONFIG_SME
  1229. if (wpa_s->sme.bss_max_idle_period) {
  1230. unsigned int msec;
  1231. msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */
  1232. if (msec > 100)
  1233. msec -= 100;
  1234. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1235. wnm_bss_keep_alive, wpa_s, NULL);
  1236. }
  1237. #endif /* CONFIG_SME */
  1238. }
  1239. static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1240. const u8 *ies, size_t ies_len)
  1241. {
  1242. struct ieee802_11_elems elems;
  1243. if (ies == NULL)
  1244. return;
  1245. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1246. return;
  1247. #ifdef CONFIG_SME
  1248. if (elems.bss_max_idle_period) {
  1249. unsigned int msec;
  1250. wpa_s->sme.bss_max_idle_period =
  1251. WPA_GET_LE16(elems.bss_max_idle_period);
  1252. wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 "
  1253. "TU)%s", wpa_s->sme.bss_max_idle_period,
  1254. (elems.bss_max_idle_period[2] & 0x01) ?
  1255. " (protected keep-live required)" : "");
  1256. if (wpa_s->sme.bss_max_idle_period == 0)
  1257. wpa_s->sme.bss_max_idle_period = 1;
  1258. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) {
  1259. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1260. /* msec times 1000 */
  1261. msec = wpa_s->sme.bss_max_idle_period * 1024;
  1262. if (msec > 100)
  1263. msec -= 100;
  1264. eloop_register_timeout(msec / 1000, msec % 1000 * 1000,
  1265. wnm_bss_keep_alive, wpa_s,
  1266. NULL);
  1267. }
  1268. }
  1269. #endif /* CONFIG_SME */
  1270. }
  1271. #endif /* CONFIG_WNM */
  1272. void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s)
  1273. {
  1274. #ifdef CONFIG_WNM
  1275. eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL);
  1276. #endif /* CONFIG_WNM */
  1277. }
  1278. #ifdef CONFIG_INTERWORKING
  1279. static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map,
  1280. size_t len)
  1281. {
  1282. int res;
  1283. wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len);
  1284. res = wpa_drv_set_qos_map(wpa_s, qos_map, len);
  1285. if (res) {
  1286. wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver");
  1287. }
  1288. return res;
  1289. }
  1290. static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s,
  1291. const u8 *ies, size_t ies_len)
  1292. {
  1293. struct ieee802_11_elems elems;
  1294. if (ies == NULL)
  1295. return;
  1296. if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed)
  1297. return;
  1298. if (elems.qos_map_set) {
  1299. wpas_qos_map_set(wpa_s, elems.qos_map_set,
  1300. elems.qos_map_set_len);
  1301. }
  1302. }
  1303. #endif /* CONFIG_INTERWORKING */
  1304. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  1305. union wpa_event_data *data)
  1306. {
  1307. int l, len, found = 0, wpa_found, rsn_found;
  1308. const u8 *p;
  1309. #ifdef CONFIG_IEEE80211R
  1310. u8 bssid[ETH_ALEN];
  1311. #endif /* CONFIG_IEEE80211R */
  1312. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  1313. if (data->assoc_info.req_ies)
  1314. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  1315. data->assoc_info.req_ies_len);
  1316. if (data->assoc_info.resp_ies) {
  1317. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  1318. data->assoc_info.resp_ies_len);
  1319. #ifdef CONFIG_TDLS
  1320. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  1321. data->assoc_info.resp_ies_len);
  1322. #endif /* CONFIG_TDLS */
  1323. #ifdef CONFIG_WNM
  1324. wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1325. data->assoc_info.resp_ies_len);
  1326. #endif /* CONFIG_WNM */
  1327. #ifdef CONFIG_INTERWORKING
  1328. interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies,
  1329. data->assoc_info.resp_ies_len);
  1330. #endif /* CONFIG_INTERWORKING */
  1331. }
  1332. if (data->assoc_info.beacon_ies)
  1333. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  1334. data->assoc_info.beacon_ies,
  1335. data->assoc_info.beacon_ies_len);
  1336. if (data->assoc_info.freq)
  1337. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  1338. data->assoc_info.freq);
  1339. p = data->assoc_info.req_ies;
  1340. l = data->assoc_info.req_ies_len;
  1341. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  1342. while (p && l >= 2) {
  1343. len = p[1] + 2;
  1344. if (len > l) {
  1345. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1346. p, l);
  1347. break;
  1348. }
  1349. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1350. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  1351. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  1352. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  1353. break;
  1354. found = 1;
  1355. wpa_find_assoc_pmkid(wpa_s);
  1356. break;
  1357. }
  1358. l -= len;
  1359. p += len;
  1360. }
  1361. if (!found && data->assoc_info.req_ies)
  1362. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  1363. #ifdef CONFIG_IEEE80211R
  1364. #ifdef CONFIG_SME
  1365. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  1366. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1367. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1368. data->assoc_info.resp_ies,
  1369. data->assoc_info.resp_ies_len,
  1370. bssid) < 0) {
  1371. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1372. "Reassociation Response failed");
  1373. wpa_supplicant_deauthenticate(
  1374. wpa_s, WLAN_REASON_INVALID_IE);
  1375. return -1;
  1376. }
  1377. }
  1378. p = data->assoc_info.resp_ies;
  1379. l = data->assoc_info.resp_ies_len;
  1380. #ifdef CONFIG_WPS_STRICT
  1381. if (p && wpa_s->current_ssid &&
  1382. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  1383. struct wpabuf *wps;
  1384. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  1385. if (wps == NULL) {
  1386. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  1387. "include WPS IE in (Re)Association Response");
  1388. return -1;
  1389. }
  1390. if (wps_validate_assoc_resp(wps) < 0) {
  1391. wpabuf_free(wps);
  1392. wpa_supplicant_deauthenticate(
  1393. wpa_s, WLAN_REASON_INVALID_IE);
  1394. return -1;
  1395. }
  1396. wpabuf_free(wps);
  1397. }
  1398. #endif /* CONFIG_WPS_STRICT */
  1399. /* Go through the IEs and make a copy of the MDIE, if present. */
  1400. while (p && l >= 2) {
  1401. len = p[1] + 2;
  1402. if (len > l) {
  1403. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  1404. p, l);
  1405. break;
  1406. }
  1407. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  1408. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  1409. wpa_s->sme.ft_used = 1;
  1410. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  1411. MOBILITY_DOMAIN_ID_LEN);
  1412. break;
  1413. }
  1414. l -= len;
  1415. p += len;
  1416. }
  1417. #endif /* CONFIG_SME */
  1418. /* Process FT when SME is in the driver */
  1419. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  1420. wpa_ft_is_completed(wpa_s->wpa)) {
  1421. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  1422. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  1423. data->assoc_info.resp_ies,
  1424. data->assoc_info.resp_ies_len,
  1425. bssid) < 0) {
  1426. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  1427. "Reassociation Response failed");
  1428. wpa_supplicant_deauthenticate(
  1429. wpa_s, WLAN_REASON_INVALID_IE);
  1430. return -1;
  1431. }
  1432. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done");
  1433. }
  1434. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  1435. data->assoc_info.resp_ies_len);
  1436. #endif /* CONFIG_IEEE80211R */
  1437. /* WPA/RSN IE from Beacon/ProbeResp */
  1438. p = data->assoc_info.beacon_ies;
  1439. l = data->assoc_info.beacon_ies_len;
  1440. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  1441. */
  1442. wpa_found = rsn_found = 0;
  1443. while (p && l >= 2) {
  1444. len = p[1] + 2;
  1445. if (len > l) {
  1446. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  1447. p, l);
  1448. break;
  1449. }
  1450. if (!wpa_found &&
  1451. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  1452. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  1453. wpa_found = 1;
  1454. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  1455. }
  1456. if (!rsn_found &&
  1457. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  1458. rsn_found = 1;
  1459. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  1460. }
  1461. l -= len;
  1462. p += len;
  1463. }
  1464. if (!wpa_found && data->assoc_info.beacon_ies)
  1465. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1466. if (!rsn_found && data->assoc_info.beacon_ies)
  1467. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1468. if (wpa_found || rsn_found)
  1469. wpa_s->ap_ies_from_associnfo = 1;
  1470. if (wpa_s->assoc_freq && data->assoc_info.freq &&
  1471. wpa_s->assoc_freq != data->assoc_info.freq) {
  1472. wpa_printf(MSG_DEBUG, "Operating frequency changed from "
  1473. "%u to %u MHz",
  1474. wpa_s->assoc_freq, data->assoc_info.freq);
  1475. wpa_supplicant_update_scan_results(wpa_s);
  1476. }
  1477. wpa_s->assoc_freq = data->assoc_info.freq;
  1478. return 0;
  1479. }
  1480. static struct wpa_bss * wpa_supplicant_get_new_bss(
  1481. struct wpa_supplicant *wpa_s, const u8 *bssid)
  1482. {
  1483. struct wpa_bss *bss = NULL;
  1484. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1485. if (ssid->ssid_len > 0)
  1486. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  1487. if (!bss)
  1488. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1489. return bss;
  1490. }
  1491. static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s)
  1492. {
  1493. const u8 *bss_wpa = NULL, *bss_rsn = NULL;
  1494. if (!wpa_s->current_bss || !wpa_s->current_ssid)
  1495. return -1;
  1496. if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt))
  1497. return 0;
  1498. bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1499. WPA_IE_VENDOR_TYPE);
  1500. bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN);
  1501. if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa,
  1502. bss_wpa ? 2 + bss_wpa[1] : 0) ||
  1503. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn,
  1504. bss_rsn ? 2 + bss_rsn[1] : 0))
  1505. return -1;
  1506. return 0;
  1507. }
  1508. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1509. union wpa_event_data *data)
  1510. {
  1511. u8 bssid[ETH_ALEN];
  1512. int ft_completed;
  1513. #ifdef CONFIG_AP
  1514. if (wpa_s->ap_iface) {
  1515. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1516. data->assoc_info.addr,
  1517. data->assoc_info.req_ies,
  1518. data->assoc_info.req_ies_len,
  1519. data->assoc_info.reassoc);
  1520. return;
  1521. }
  1522. #endif /* CONFIG_AP */
  1523. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1524. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1525. return;
  1526. if (wpa_drv_get_bssid(wpa_s, bssid) < 0) {
  1527. wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID");
  1528. wpa_supplicant_deauthenticate(
  1529. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1530. return;
  1531. }
  1532. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1533. if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) {
  1534. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1535. MACSTR, MAC2STR(bssid));
  1536. random_add_randomness(bssid, ETH_ALEN);
  1537. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1538. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1539. wpas_notify_bssid_changed(wpa_s);
  1540. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1541. wpa_clear_keys(wpa_s, bssid);
  1542. }
  1543. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1544. wpa_supplicant_deauthenticate(
  1545. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1546. return;
  1547. }
  1548. if (wpa_s->current_ssid) {
  1549. struct wpa_bss *bss = NULL;
  1550. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1551. if (!bss) {
  1552. wpa_supplicant_update_scan_results(wpa_s);
  1553. /* Get the BSS from the new scan results */
  1554. bss = wpa_supplicant_get_new_bss(wpa_s, bssid);
  1555. }
  1556. if (bss)
  1557. wpa_s->current_bss = bss;
  1558. }
  1559. if (wpa_s->conf->ap_scan == 1 &&
  1560. wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) {
  1561. if (wpa_supplicant_assoc_update_ie(wpa_s) < 0)
  1562. wpa_msg(wpa_s, MSG_WARNING,
  1563. "WPA/RSN IEs not updated");
  1564. }
  1565. }
  1566. #ifdef CONFIG_SME
  1567. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1568. wpa_s->sme.prev_bssid_set = 1;
  1569. #endif /* CONFIG_SME */
  1570. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1571. if (wpa_s->current_ssid) {
  1572. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1573. * initialized before association, but for other modes,
  1574. * initialize PC/SC here, if the current configuration needs
  1575. * smartcard or SIM/USIM. */
  1576. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1577. }
  1578. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1579. if (wpa_s->l2)
  1580. l2_packet_notify_auth_start(wpa_s->l2);
  1581. /*
  1582. * Set portEnabled first to FALSE in order to get EAP state machine out
  1583. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1584. * state machine may transit to AUTHENTICATING state based on obsolete
  1585. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1586. * AUTHENTICATED without ever giving chance to EAP state machine to
  1587. * reset the state.
  1588. */
  1589. if (!ft_completed) {
  1590. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1591. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1592. }
  1593. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1594. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1595. /* 802.1X::portControl = Auto */
  1596. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1597. wpa_s->eapol_received = 0;
  1598. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1599. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1600. (wpa_s->current_ssid &&
  1601. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1602. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE &&
  1603. (wpa_s->drv_flags &
  1604. WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  1605. /*
  1606. * Set the key after having received joined-IBSS event
  1607. * from the driver.
  1608. */
  1609. wpa_supplicant_set_wpa_none_key(wpa_s,
  1610. wpa_s->current_ssid);
  1611. }
  1612. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1613. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1614. } else if (!ft_completed) {
  1615. /* Timeout for receiving the first EAPOL packet */
  1616. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1617. }
  1618. wpa_supplicant_cancel_scan(wpa_s);
  1619. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1620. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1621. /*
  1622. * We are done; the driver will take care of RSN 4-way
  1623. * handshake.
  1624. */
  1625. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1626. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1627. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1628. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1629. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1630. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1631. /*
  1632. * The driver will take care of RSN 4-way handshake, so we need
  1633. * to allow EAPOL supplicant to complete its work without
  1634. * waiting for WPA supplicant.
  1635. */
  1636. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1637. } else if (ft_completed) {
  1638. /*
  1639. * FT protocol completed - make sure EAPOL state machine ends
  1640. * up in authenticated.
  1641. */
  1642. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1643. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1644. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1645. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1646. }
  1647. wpa_s->last_eapol_matches_bssid = 0;
  1648. if (wpa_s->pending_eapol_rx) {
  1649. struct os_reltime now, age;
  1650. os_get_reltime(&now);
  1651. os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1652. if (age.sec == 0 && age.usec < 100000 &&
  1653. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1654. 0) {
  1655. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1656. "frame that was received just before "
  1657. "association notification");
  1658. wpa_supplicant_rx_eapol(
  1659. wpa_s, wpa_s->pending_eapol_rx_src,
  1660. wpabuf_head(wpa_s->pending_eapol_rx),
  1661. wpabuf_len(wpa_s->pending_eapol_rx));
  1662. }
  1663. wpabuf_free(wpa_s->pending_eapol_rx);
  1664. wpa_s->pending_eapol_rx = NULL;
  1665. }
  1666. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1667. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1668. wpa_s->current_ssid &&
  1669. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) {
  1670. /* Set static WEP keys again */
  1671. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1672. }
  1673. #ifdef CONFIG_IBSS_RSN
  1674. if (wpa_s->current_ssid &&
  1675. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1676. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1677. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1678. wpa_s->ibss_rsn == NULL) {
  1679. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1680. if (!wpa_s->ibss_rsn) {
  1681. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1682. wpa_supplicant_deauthenticate(
  1683. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1684. return;
  1685. }
  1686. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1687. }
  1688. #endif /* CONFIG_IBSS_RSN */
  1689. wpas_wps_notify_assoc(wpa_s, bssid);
  1690. }
  1691. static int disconnect_reason_recoverable(u16 reason_code)
  1692. {
  1693. return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY ||
  1694. reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA ||
  1695. reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA;
  1696. }
  1697. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1698. u16 reason_code,
  1699. int locally_generated)
  1700. {
  1701. const u8 *bssid;
  1702. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1703. /*
  1704. * At least Host AP driver and a Prism3 card seemed to be
  1705. * generating streams of disconnected events when configuring
  1706. * IBSS for WPA-None. Ignore them for now.
  1707. */
  1708. return;
  1709. }
  1710. bssid = wpa_s->bssid;
  1711. if (is_zero_ether_addr(bssid))
  1712. bssid = wpa_s->pending_bssid;
  1713. if (!is_zero_ether_addr(bssid) ||
  1714. wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  1715. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1716. " reason=%d%s",
  1717. MAC2STR(bssid), reason_code,
  1718. locally_generated ? " locally_generated=1" : "");
  1719. }
  1720. }
  1721. static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code,
  1722. int locally_generated)
  1723. {
  1724. if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE ||
  1725. !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  1726. return 0; /* Not in 4-way handshake with PSK */
  1727. /*
  1728. * It looks like connection was lost while trying to go through PSK
  1729. * 4-way handshake. Filter out known disconnection cases that are caused
  1730. * by something else than PSK mismatch to avoid confusing reports.
  1731. */
  1732. if (locally_generated) {
  1733. if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS)
  1734. return 0;
  1735. }
  1736. return 1;
  1737. }
  1738. static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s,
  1739. u16 reason_code,
  1740. int locally_generated)
  1741. {
  1742. const u8 *bssid;
  1743. int authenticating;
  1744. u8 prev_pending_bssid[ETH_ALEN];
  1745. struct wpa_bss *fast_reconnect = NULL;
  1746. #ifndef CONFIG_NO_SCAN_PROCESSING
  1747. struct wpa_ssid *fast_reconnect_ssid = NULL;
  1748. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1749. struct wpa_ssid *last_ssid;
  1750. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1751. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1752. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1753. /*
  1754. * At least Host AP driver and a Prism3 card seemed to be
  1755. * generating streams of disconnected events when configuring
  1756. * IBSS for WPA-None. Ignore them for now.
  1757. */
  1758. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1759. "IBSS/WPA-None mode");
  1760. return;
  1761. }
  1762. if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) {
  1763. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1764. "pre-shared key may be incorrect");
  1765. if (wpas_p2p_4way_hs_failed(wpa_s) > 0)
  1766. return; /* P2P group removed */
  1767. wpas_auth_failed(wpa_s);
  1768. }
  1769. if (!wpa_s->disconnected &&
  1770. (!wpa_s->auto_reconnect_disabled ||
  1771. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) {
  1772. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to "
  1773. "reconnect (wps=%d wpa_state=%d)",
  1774. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS,
  1775. wpa_s->wpa_state);
  1776. if (wpa_s->wpa_state == WPA_COMPLETED &&
  1777. wpa_s->current_ssid &&
  1778. wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
  1779. !locally_generated &&
  1780. disconnect_reason_recoverable(reason_code)) {
  1781. /*
  1782. * It looks like the AP has dropped association with
  1783. * us, but could allow us to get back in. Try to
  1784. * reconnect to the same BSS without full scan to save
  1785. * time for some common cases.
  1786. */
  1787. fast_reconnect = wpa_s->current_bss;
  1788. #ifndef CONFIG_NO_SCAN_PROCESSING
  1789. fast_reconnect_ssid = wpa_s->current_ssid;
  1790. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1791. } else if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1792. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1793. else
  1794. wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new "
  1795. "immediate scan");
  1796. } else {
  1797. wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not "
  1798. "try to re-connect");
  1799. wpa_s->reassociate = 0;
  1800. wpa_s->disconnected = 1;
  1801. wpa_supplicant_cancel_sched_scan(wpa_s);
  1802. }
  1803. bssid = wpa_s->bssid;
  1804. if (is_zero_ether_addr(bssid))
  1805. bssid = wpa_s->pending_bssid;
  1806. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  1807. wpas_connection_failed(wpa_s, bssid);
  1808. wpa_sm_notify_disassoc(wpa_s->wpa);
  1809. if (locally_generated)
  1810. wpa_s->disconnect_reason = -reason_code;
  1811. else
  1812. wpa_s->disconnect_reason = reason_code;
  1813. wpas_notify_disconnect_reason(wpa_s);
  1814. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1815. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1816. wpa_s->keys_cleared = 0;
  1817. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1818. }
  1819. last_ssid = wpa_s->current_ssid;
  1820. wpa_supplicant_mark_disassoc(wpa_s);
  1821. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) {
  1822. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1823. wpa_s->current_ssid = last_ssid;
  1824. }
  1825. if (fast_reconnect) {
  1826. #ifndef CONFIG_NO_SCAN_PROCESSING
  1827. wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS");
  1828. if (wpa_supplicant_connect(wpa_s, fast_reconnect,
  1829. fast_reconnect_ssid) < 0) {
  1830. /* Recover through full scan */
  1831. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1832. }
  1833. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1834. }
  1835. }
  1836. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1837. void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx)
  1838. {
  1839. struct wpa_supplicant *wpa_s = eloop_ctx;
  1840. if (!wpa_s->pending_mic_error_report)
  1841. return;
  1842. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1843. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1844. wpa_s->pending_mic_error_report = 0;
  1845. }
  1846. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1847. static void
  1848. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1849. union wpa_event_data *data)
  1850. {
  1851. int pairwise;
  1852. struct os_reltime t;
  1853. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1854. pairwise = (data && data->michael_mic_failure.unicast);
  1855. os_get_reltime(&t);
  1856. if ((wpa_s->last_michael_mic_error.sec &&
  1857. !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) ||
  1858. wpa_s->pending_mic_error_report) {
  1859. if (wpa_s->pending_mic_error_report) {
  1860. /*
  1861. * Send the pending MIC error report immediately since
  1862. * we are going to start countermeasures and AP better
  1863. * do the same.
  1864. */
  1865. wpa_sm_key_request(wpa_s->wpa, 1,
  1866. wpa_s->pending_mic_error_pairwise);
  1867. }
  1868. /* Send the new MIC error report immediately since we are going
  1869. * to start countermeasures and AP better do the same.
  1870. */
  1871. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1872. /* initialize countermeasures */
  1873. wpa_s->countermeasures = 1;
  1874. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  1875. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1876. /*
  1877. * Need to wait for completion of request frame. We do not get
  1878. * any callback for the message completion, so just wait a
  1879. * short while and hope for the best. */
  1880. os_sleep(0, 10000);
  1881. wpa_drv_set_countermeasures(wpa_s, 1);
  1882. wpa_supplicant_deauthenticate(wpa_s,
  1883. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1884. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1885. wpa_s, NULL);
  1886. eloop_register_timeout(60, 0,
  1887. wpa_supplicant_stop_countermeasures,
  1888. wpa_s, NULL);
  1889. /* TODO: mark the AP rejected for 60 second. STA is
  1890. * allowed to associate with another AP.. */
  1891. } else {
  1892. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1893. if (wpa_s->mic_errors_seen) {
  1894. /*
  1895. * Reduce the effectiveness of Michael MIC error
  1896. * reports as a means for attacking against TKIP if
  1897. * more than one MIC failure is noticed with the same
  1898. * PTK. We delay the transmission of the reports by a
  1899. * random time between 0 and 60 seconds in order to
  1900. * force the attacker wait 60 seconds before getting
  1901. * the information on whether a frame resulted in a MIC
  1902. * failure.
  1903. */
  1904. u8 rval[4];
  1905. int sec;
  1906. if (os_get_random(rval, sizeof(rval)) < 0)
  1907. sec = os_random() % 60;
  1908. else
  1909. sec = WPA_GET_BE32(rval) % 60;
  1910. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1911. "report %d seconds", sec);
  1912. wpa_s->pending_mic_error_report = 1;
  1913. wpa_s->pending_mic_error_pairwise = pairwise;
  1914. eloop_cancel_timeout(
  1915. wpa_supplicant_delayed_mic_error_report,
  1916. wpa_s, NULL);
  1917. eloop_register_timeout(
  1918. sec, os_random() % 1000000,
  1919. wpa_supplicant_delayed_mic_error_report,
  1920. wpa_s, NULL);
  1921. } else {
  1922. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1923. }
  1924. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1925. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1926. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1927. }
  1928. wpa_s->last_michael_mic_error = t;
  1929. wpa_s->mic_errors_seen++;
  1930. }
  1931. #ifdef CONFIG_TERMINATE_ONLASTIF
  1932. static int any_interfaces(struct wpa_supplicant *head)
  1933. {
  1934. struct wpa_supplicant *wpa_s;
  1935. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1936. if (!wpa_s->interface_removed)
  1937. return 1;
  1938. return 0;
  1939. }
  1940. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1941. static void
  1942. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1943. union wpa_event_data *data)
  1944. {
  1945. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1946. return;
  1947. switch (data->interface_status.ievent) {
  1948. case EVENT_INTERFACE_ADDED:
  1949. if (!wpa_s->interface_removed)
  1950. break;
  1951. wpa_s->interface_removed = 0;
  1952. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1953. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1954. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1955. "driver after interface was added");
  1956. }
  1957. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1958. break;
  1959. case EVENT_INTERFACE_REMOVED:
  1960. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1961. wpa_s->interface_removed = 1;
  1962. wpa_supplicant_mark_disassoc(wpa_s);
  1963. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1964. l2_packet_deinit(wpa_s->l2);
  1965. wpa_s->l2 = NULL;
  1966. #ifdef CONFIG_IBSS_RSN
  1967. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1968. wpa_s->ibss_rsn = NULL;
  1969. #endif /* CONFIG_IBSS_RSN */
  1970. #ifdef CONFIG_TERMINATE_ONLASTIF
  1971. /* check if last interface */
  1972. if (!any_interfaces(wpa_s->global->ifaces))
  1973. eloop_terminate();
  1974. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1975. break;
  1976. }
  1977. }
  1978. #ifdef CONFIG_PEERKEY
  1979. static void
  1980. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1981. union wpa_event_data *data)
  1982. {
  1983. if (data == NULL)
  1984. return;
  1985. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1986. }
  1987. #endif /* CONFIG_PEERKEY */
  1988. #ifdef CONFIG_TDLS
  1989. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1990. union wpa_event_data *data)
  1991. {
  1992. if (data == NULL)
  1993. return;
  1994. switch (data->tdls.oper) {
  1995. case TDLS_REQUEST_SETUP:
  1996. wpa_tdls_remove(wpa_s->wpa, data->tdls.peer);
  1997. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  1998. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1999. else
  2000. wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer);
  2001. break;
  2002. case TDLS_REQUEST_TEARDOWN:
  2003. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  2004. wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer,
  2005. data->tdls.reason_code);
  2006. else
  2007. wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN,
  2008. data->tdls.peer);
  2009. break;
  2010. }
  2011. }
  2012. #endif /* CONFIG_TDLS */
  2013. #ifdef CONFIG_WNM
  2014. static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s,
  2015. union wpa_event_data *data)
  2016. {
  2017. if (data == NULL)
  2018. return;
  2019. switch (data->wnm.oper) {
  2020. case WNM_OPER_SLEEP:
  2021. wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request "
  2022. "(action=%d, intval=%d)",
  2023. data->wnm.sleep_action, data->wnm.sleep_intval);
  2024. ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action,
  2025. data->wnm.sleep_intval, NULL);
  2026. break;
  2027. }
  2028. }
  2029. #endif /* CONFIG_WNM */
  2030. #ifdef CONFIG_IEEE80211R
  2031. static void
  2032. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  2033. union wpa_event_data *data)
  2034. {
  2035. if (data == NULL)
  2036. return;
  2037. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  2038. data->ft_ies.ies_len,
  2039. data->ft_ies.ft_action,
  2040. data->ft_ies.target_ap,
  2041. data->ft_ies.ric_ies,
  2042. data->ft_ies.ric_ies_len) < 0) {
  2043. /* TODO: prevent MLME/driver from trying to associate? */
  2044. }
  2045. }
  2046. #endif /* CONFIG_IEEE80211R */
  2047. #ifdef CONFIG_IBSS_RSN
  2048. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  2049. union wpa_event_data *data)
  2050. {
  2051. struct wpa_ssid *ssid;
  2052. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  2053. return;
  2054. if (data == NULL)
  2055. return;
  2056. ssid = wpa_s->current_ssid;
  2057. if (ssid == NULL)
  2058. return;
  2059. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2060. return;
  2061. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  2062. }
  2063. static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s,
  2064. union wpa_event_data *data)
  2065. {
  2066. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2067. if (ssid == NULL)
  2068. return;
  2069. /* check if the ssid is correctly configured as IBSS/RSN */
  2070. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  2071. return;
  2072. ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame,
  2073. data->rx_mgmt.frame_len);
  2074. }
  2075. #endif /* CONFIG_IBSS_RSN */
  2076. #ifdef CONFIG_IEEE80211R
  2077. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  2078. size_t len)
  2079. {
  2080. const u8 *sta_addr, *target_ap_addr;
  2081. u16 status;
  2082. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  2083. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  2084. return; /* only SME case supported for now */
  2085. if (len < 1 + 2 * ETH_ALEN + 2)
  2086. return;
  2087. if (data[0] != 2)
  2088. return; /* Only FT Action Response is supported for now */
  2089. sta_addr = data + 1;
  2090. target_ap_addr = data + 1 + ETH_ALEN;
  2091. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  2092. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  2093. MACSTR " TargetAP " MACSTR " status %u",
  2094. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  2095. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  2096. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  2097. " in FT Action Response", MAC2STR(sta_addr));
  2098. return;
  2099. }
  2100. if (status) {
  2101. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  2102. "failure (status code %d)", status);
  2103. /* TODO: report error to FT code(?) */
  2104. return;
  2105. }
  2106. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  2107. len - (1 + 2 * ETH_ALEN + 2), 1,
  2108. target_ap_addr, NULL, 0) < 0)
  2109. return;
  2110. #ifdef CONFIG_SME
  2111. {
  2112. struct wpa_bss *bss;
  2113. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  2114. if (bss)
  2115. wpa_s->sme.freq = bss->freq;
  2116. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  2117. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  2118. WLAN_AUTH_FT);
  2119. }
  2120. #endif /* CONFIG_SME */
  2121. }
  2122. #endif /* CONFIG_IEEE80211R */
  2123. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  2124. struct unprot_deauth *e)
  2125. {
  2126. #ifdef CONFIG_IEEE80211W
  2127. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  2128. "dropped: " MACSTR " -> " MACSTR
  2129. " (reason code %u)",
  2130. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2131. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2132. #endif /* CONFIG_IEEE80211W */
  2133. }
  2134. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  2135. struct unprot_disassoc *e)
  2136. {
  2137. #ifdef CONFIG_IEEE80211W
  2138. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  2139. "dropped: " MACSTR " -> " MACSTR
  2140. " (reason code %u)",
  2141. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  2142. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  2143. #endif /* CONFIG_IEEE80211W */
  2144. }
  2145. static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr,
  2146. u16 reason_code, int locally_generated,
  2147. const u8 *ie, size_t ie_len, int deauth)
  2148. {
  2149. #ifdef CONFIG_AP
  2150. if (wpa_s->ap_iface && addr) {
  2151. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr);
  2152. return;
  2153. }
  2154. if (wpa_s->ap_iface) {
  2155. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode");
  2156. return;
  2157. }
  2158. #endif /* CONFIG_AP */
  2159. wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated);
  2160. if (reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED ||
  2161. ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  2162. (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) &&
  2163. eapol_sm_failed(wpa_s->eapol)))
  2164. wpas_auth_failed(wpa_s);
  2165. #ifdef CONFIG_P2P
  2166. if (deauth && reason_code > 0) {
  2167. if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len,
  2168. locally_generated) > 0) {
  2169. /*
  2170. * The interface was removed, so cannot continue
  2171. * processing any additional operations after this.
  2172. */
  2173. return;
  2174. }
  2175. }
  2176. #endif /* CONFIG_P2P */
  2177. wpa_supplicant_event_disassoc_finish(wpa_s, reason_code,
  2178. locally_generated);
  2179. }
  2180. static void wpas_event_disassoc(struct wpa_supplicant *wpa_s,
  2181. struct disassoc_info *info)
  2182. {
  2183. u16 reason_code = 0;
  2184. int locally_generated = 0;
  2185. const u8 *addr = NULL;
  2186. const u8 *ie = NULL;
  2187. size_t ie_len = 0;
  2188. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  2189. if (info) {
  2190. addr = info->addr;
  2191. ie = info->ie;
  2192. ie_len = info->ie_len;
  2193. reason_code = info->reason_code;
  2194. locally_generated = info->locally_generated;
  2195. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code,
  2196. locally_generated ? " (locally generated)" : "");
  2197. if (addr)
  2198. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2199. MAC2STR(addr));
  2200. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  2201. ie, ie_len);
  2202. }
  2203. #ifdef CONFIG_AP
  2204. if (wpa_s->ap_iface && info && info->addr) {
  2205. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr);
  2206. return;
  2207. }
  2208. if (wpa_s->ap_iface) {
  2209. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode");
  2210. return;
  2211. }
  2212. #endif /* CONFIG_AP */
  2213. #ifdef CONFIG_P2P
  2214. if (info) {
  2215. wpas_p2p_disassoc_notif(
  2216. wpa_s, info->addr, reason_code, info->ie, info->ie_len,
  2217. locally_generated);
  2218. }
  2219. #endif /* CONFIG_P2P */
  2220. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2221. sme_event_disassoc(wpa_s, info);
  2222. wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated,
  2223. ie, ie_len, 0);
  2224. }
  2225. static void wpas_event_deauth(struct wpa_supplicant *wpa_s,
  2226. struct deauth_info *info)
  2227. {
  2228. u16 reason_code = 0;
  2229. int locally_generated = 0;
  2230. const u8 *addr = NULL;
  2231. const u8 *ie = NULL;
  2232. size_t ie_len = 0;
  2233. wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification");
  2234. if (info) {
  2235. addr = info->addr;
  2236. ie = info->ie;
  2237. ie_len = info->ie_len;
  2238. reason_code = info->reason_code;
  2239. locally_generated = info->locally_generated;
  2240. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s",
  2241. reason_code,
  2242. locally_generated ? " (locally generated)" : "");
  2243. if (addr) {
  2244. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  2245. MAC2STR(addr));
  2246. }
  2247. wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)",
  2248. ie, ie_len);
  2249. }
  2250. wpa_reset_ft_completed(wpa_s->wpa);
  2251. wpas_event_disconnect(wpa_s, addr, reason_code,
  2252. locally_generated, ie, ie_len, 1);
  2253. }
  2254. static void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s)
  2255. {
  2256. struct wpa_supplicant *ifs;
  2257. if (wpa_s->drv_priv == NULL)
  2258. return; /* Ignore event during drv initialization */
  2259. free_hw_features(wpa_s);
  2260. wpa_s->hw.modes = wpa_drv_get_hw_feature_data(
  2261. wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags);
  2262. #ifdef CONFIG_P2P
  2263. wpas_p2p_update_channel_list(wpa_s);
  2264. #endif /* CONFIG_P2P */
  2265. /*
  2266. * Check other interfaces to see if they share the same radio. If
  2267. * so, they get updated with this same hw mode info.
  2268. */
  2269. dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
  2270. radio_list) {
  2271. if (ifs != wpa_s) {
  2272. wpa_printf(MSG_DEBUG, "%s: Updating hw mode",
  2273. ifs->ifname);
  2274. free_hw_features(ifs);
  2275. ifs->hw.modes = wpa_drv_get_hw_feature_data(
  2276. ifs, &ifs->hw.num_modes, &ifs->hw.flags);
  2277. }
  2278. }
  2279. }
  2280. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  2281. union wpa_event_data *data)
  2282. {
  2283. struct wpa_supplicant *wpa_s = ctx;
  2284. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  2285. event != EVENT_INTERFACE_ENABLED &&
  2286. event != EVENT_INTERFACE_STATUS &&
  2287. event != EVENT_SCHED_SCAN_STOPPED) {
  2288. wpa_dbg(wpa_s, MSG_DEBUG,
  2289. "Ignore event %s (%d) while interface is disabled",
  2290. event_to_string(event), event);
  2291. return;
  2292. }
  2293. #ifndef CONFIG_NO_STDOUT_DEBUG
  2294. {
  2295. int level = MSG_DEBUG;
  2296. if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) {
  2297. const struct ieee80211_hdr *hdr;
  2298. u16 fc;
  2299. hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
  2300. fc = le_to_host16(hdr->frame_control);
  2301. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  2302. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
  2303. level = MSG_EXCESSIVE;
  2304. }
  2305. wpa_dbg(wpa_s, level, "Event %s (%d) received",
  2306. event_to_string(event), event);
  2307. }
  2308. #endif /* CONFIG_NO_STDOUT_DEBUG */
  2309. switch (event) {
  2310. case EVENT_AUTH:
  2311. sme_event_auth(wpa_s, data);
  2312. break;
  2313. case EVENT_ASSOC:
  2314. wpa_supplicant_event_assoc(wpa_s, data);
  2315. break;
  2316. case EVENT_DISASSOC:
  2317. wpas_event_disassoc(wpa_s,
  2318. data ? &data->disassoc_info : NULL);
  2319. break;
  2320. case EVENT_DEAUTH:
  2321. wpas_event_deauth(wpa_s,
  2322. data ? &data->deauth_info : NULL);
  2323. break;
  2324. case EVENT_MICHAEL_MIC_FAILURE:
  2325. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  2326. break;
  2327. #ifndef CONFIG_NO_SCAN_PROCESSING
  2328. case EVENT_SCAN_STARTED:
  2329. if (wpa_s->own_scan_requested) {
  2330. wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan");
  2331. wpa_s->own_scan_requested = 0;
  2332. wpa_s->own_scan_running = 1;
  2333. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
  2334. } else {
  2335. wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan");
  2336. wpa_s->external_scan_running = 1;
  2337. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED);
  2338. }
  2339. break;
  2340. case EVENT_SCAN_RESULTS:
  2341. wpa_supplicant_event_scan_results(wpa_s, data);
  2342. wpa_s->own_scan_running = 0;
  2343. wpa_s->external_scan_running = 0;
  2344. if (wpa_s->wpa_state != WPA_AUTHENTICATING &&
  2345. wpa_s->wpa_state != WPA_ASSOCIATING)
  2346. wpas_p2p_continue_after_scan(wpa_s);
  2347. break;
  2348. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2349. case EVENT_ASSOCINFO:
  2350. wpa_supplicant_event_associnfo(wpa_s, data);
  2351. break;
  2352. case EVENT_INTERFACE_STATUS:
  2353. wpa_supplicant_event_interface_status(wpa_s, data);
  2354. break;
  2355. case EVENT_PMKID_CANDIDATE:
  2356. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  2357. break;
  2358. #ifdef CONFIG_PEERKEY
  2359. case EVENT_STKSTART:
  2360. wpa_supplicant_event_stkstart(wpa_s, data);
  2361. break;
  2362. #endif /* CONFIG_PEERKEY */
  2363. #ifdef CONFIG_TDLS
  2364. case EVENT_TDLS:
  2365. wpa_supplicant_event_tdls(wpa_s, data);
  2366. break;
  2367. #endif /* CONFIG_TDLS */
  2368. #ifdef CONFIG_WNM
  2369. case EVENT_WNM:
  2370. wpa_supplicant_event_wnm(wpa_s, data);
  2371. break;
  2372. #endif /* CONFIG_WNM */
  2373. #ifdef CONFIG_IEEE80211R
  2374. case EVENT_FT_RESPONSE:
  2375. wpa_supplicant_event_ft_response(wpa_s, data);
  2376. break;
  2377. #endif /* CONFIG_IEEE80211R */
  2378. #ifdef CONFIG_IBSS_RSN
  2379. case EVENT_IBSS_RSN_START:
  2380. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  2381. break;
  2382. #endif /* CONFIG_IBSS_RSN */
  2383. case EVENT_ASSOC_REJECT:
  2384. if (data->assoc_reject.bssid)
  2385. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2386. "bssid=" MACSTR " status_code=%u",
  2387. MAC2STR(data->assoc_reject.bssid),
  2388. data->assoc_reject.status_code);
  2389. else
  2390. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  2391. "status_code=%u",
  2392. data->assoc_reject.status_code);
  2393. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2394. sme_event_assoc_reject(wpa_s, data);
  2395. else {
  2396. const u8 *bssid = data->assoc_reject.bssid;
  2397. if (bssid == NULL || is_zero_ether_addr(bssid))
  2398. bssid = wpa_s->pending_bssid;
  2399. wpas_connection_failed(wpa_s, bssid);
  2400. wpa_supplicant_mark_disassoc(wpa_s);
  2401. }
  2402. break;
  2403. case EVENT_AUTH_TIMED_OUT:
  2404. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2405. sme_event_auth_timed_out(wpa_s, data);
  2406. break;
  2407. case EVENT_ASSOC_TIMED_OUT:
  2408. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  2409. sme_event_assoc_timed_out(wpa_s, data);
  2410. break;
  2411. case EVENT_TX_STATUS:
  2412. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  2413. " type=%d stype=%d",
  2414. MAC2STR(data->tx_status.dst),
  2415. data->tx_status.type, data->tx_status.stype);
  2416. #ifdef CONFIG_AP
  2417. if (wpa_s->ap_iface == NULL) {
  2418. #ifdef CONFIG_OFFCHANNEL
  2419. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2420. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  2421. offchannel_send_action_tx_status(
  2422. wpa_s, data->tx_status.dst,
  2423. data->tx_status.data,
  2424. data->tx_status.data_len,
  2425. data->tx_status.ack ?
  2426. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2427. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2428. #endif /* CONFIG_OFFCHANNEL */
  2429. break;
  2430. }
  2431. #endif /* CONFIG_AP */
  2432. #ifdef CONFIG_OFFCHANNEL
  2433. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  2434. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  2435. /*
  2436. * Catch TX status events for Action frames we sent via group
  2437. * interface in GO mode.
  2438. */
  2439. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  2440. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  2441. os_memcmp(wpa_s->parent->pending_action_dst,
  2442. data->tx_status.dst, ETH_ALEN) == 0) {
  2443. offchannel_send_action_tx_status(
  2444. wpa_s->parent, data->tx_status.dst,
  2445. data->tx_status.data,
  2446. data->tx_status.data_len,
  2447. data->tx_status.ack ?
  2448. OFFCHANNEL_SEND_ACTION_SUCCESS :
  2449. OFFCHANNEL_SEND_ACTION_NO_ACK);
  2450. break;
  2451. }
  2452. #endif /* CONFIG_OFFCHANNEL */
  2453. #ifdef CONFIG_AP
  2454. switch (data->tx_status.type) {
  2455. case WLAN_FC_TYPE_MGMT:
  2456. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  2457. data->tx_status.data_len,
  2458. data->tx_status.stype,
  2459. data->tx_status.ack);
  2460. break;
  2461. case WLAN_FC_TYPE_DATA:
  2462. ap_tx_status(wpa_s, data->tx_status.dst,
  2463. data->tx_status.data,
  2464. data->tx_status.data_len,
  2465. data->tx_status.ack);
  2466. break;
  2467. }
  2468. #endif /* CONFIG_AP */
  2469. break;
  2470. #ifdef CONFIG_AP
  2471. case EVENT_EAPOL_TX_STATUS:
  2472. ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst,
  2473. data->eapol_tx_status.data,
  2474. data->eapol_tx_status.data_len,
  2475. data->eapol_tx_status.ack);
  2476. break;
  2477. case EVENT_DRIVER_CLIENT_POLL_OK:
  2478. ap_client_poll_ok(wpa_s, data->client_poll.addr);
  2479. break;
  2480. case EVENT_RX_FROM_UNKNOWN:
  2481. if (wpa_s->ap_iface == NULL)
  2482. break;
  2483. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr,
  2484. data->rx_from_unknown.wds);
  2485. break;
  2486. case EVENT_CH_SWITCH:
  2487. if (!data)
  2488. break;
  2489. if (!wpa_s->ap_iface) {
  2490. wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch "
  2491. "event in non-AP mode");
  2492. break;
  2493. }
  2494. wpas_ap_ch_switch(wpa_s, data->ch_switch.freq,
  2495. data->ch_switch.ht_enabled,
  2496. data->ch_switch.ch_offset,
  2497. data->ch_switch.ch_width,
  2498. data->ch_switch.cf1,
  2499. data->ch_switch.cf2);
  2500. break;
  2501. #endif /* CONFIG_AP */
  2502. #if defined(CONFIG_AP) || defined(CONFIG_IBSS_RSN)
  2503. case EVENT_RX_MGMT: {
  2504. u16 fc, stype;
  2505. const struct ieee80211_mgmt *mgmt;
  2506. mgmt = (const struct ieee80211_mgmt *)
  2507. data->rx_mgmt.frame;
  2508. fc = le_to_host16(mgmt->frame_control);
  2509. stype = WLAN_FC_GET_STYPE(fc);
  2510. #ifdef CONFIG_AP
  2511. if (wpa_s->ap_iface == NULL) {
  2512. #endif /* CONFIG_AP */
  2513. #ifdef CONFIG_P2P
  2514. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2515. data->rx_mgmt.frame_len > 24) {
  2516. const u8 *src = mgmt->sa;
  2517. const u8 *ie = mgmt->u.probe_req.variable;
  2518. size_t ie_len = data->rx_mgmt.frame_len -
  2519. (mgmt->u.probe_req.variable -
  2520. data->rx_mgmt.frame);
  2521. wpas_p2p_probe_req_rx(
  2522. wpa_s, src, mgmt->da,
  2523. mgmt->bssid, ie, ie_len,
  2524. data->rx_mgmt.ssi_signal);
  2525. break;
  2526. }
  2527. #endif /* CONFIG_P2P */
  2528. #ifdef CONFIG_IBSS_RSN
  2529. if (stype == WLAN_FC_STYPE_AUTH &&
  2530. data->rx_mgmt.frame_len >= 30) {
  2531. wpa_supplicant_event_ibss_auth(wpa_s, data);
  2532. break;
  2533. }
  2534. #endif /* CONFIG_IBSS_RSN */
  2535. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  2536. "management frame in non-AP mode");
  2537. break;
  2538. #ifdef CONFIG_AP
  2539. }
  2540. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  2541. data->rx_mgmt.frame_len > 24) {
  2542. const u8 *ie = mgmt->u.probe_req.variable;
  2543. size_t ie_len = data->rx_mgmt.frame_len -
  2544. (mgmt->u.probe_req.variable -
  2545. data->rx_mgmt.frame);
  2546. wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da,
  2547. mgmt->bssid, ie, ie_len,
  2548. data->rx_mgmt.ssi_signal);
  2549. }
  2550. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  2551. #endif /* CONFIG_AP */
  2552. break;
  2553. }
  2554. #endif /* CONFIG_AP || CONFIG_IBSS_RSN */
  2555. case EVENT_RX_ACTION:
  2556. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  2557. " Category=%u DataLen=%d freq=%d MHz",
  2558. MAC2STR(data->rx_action.sa),
  2559. data->rx_action.category, (int) data->rx_action.len,
  2560. data->rx_action.freq);
  2561. #ifdef CONFIG_IEEE80211R
  2562. if (data->rx_action.category == WLAN_ACTION_FT) {
  2563. ft_rx_action(wpa_s, data->rx_action.data,
  2564. data->rx_action.len);
  2565. break;
  2566. }
  2567. #endif /* CONFIG_IEEE80211R */
  2568. #ifdef CONFIG_IEEE80211W
  2569. #ifdef CONFIG_SME
  2570. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  2571. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  2572. data->rx_action.data,
  2573. data->rx_action.len);
  2574. break;
  2575. }
  2576. #endif /* CONFIG_SME */
  2577. #endif /* CONFIG_IEEE80211W */
  2578. #ifdef CONFIG_WNM
  2579. if (data->rx_action.category == WLAN_ACTION_WNM) {
  2580. ieee802_11_rx_wnm_action(wpa_s, &data->rx_action);
  2581. break;
  2582. }
  2583. #endif /* CONFIG_WNM */
  2584. #ifdef CONFIG_GAS
  2585. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2586. gas_query_rx(wpa_s->gas, data->rx_action.da,
  2587. data->rx_action.sa, data->rx_action.bssid,
  2588. data->rx_action.data, data->rx_action.len,
  2589. data->rx_action.freq) == 0)
  2590. break;
  2591. #endif /* CONFIG_GAS */
  2592. #ifdef CONFIG_TDLS
  2593. if (data->rx_action.category == WLAN_ACTION_PUBLIC &&
  2594. data->rx_action.len >= 4 &&
  2595. data->rx_action.data[0] == WLAN_TDLS_DISCOVERY_RESPONSE) {
  2596. wpa_dbg(wpa_s, MSG_DEBUG, "TDLS: Received Discovery "
  2597. "Response from " MACSTR,
  2598. MAC2STR(data->rx_action.sa));
  2599. break;
  2600. }
  2601. #endif /* CONFIG_TDLS */
  2602. #ifdef CONFIG_INTERWORKING
  2603. if (data->rx_action.category == WLAN_ACTION_QOS &&
  2604. data->rx_action.len >= 1 &&
  2605. data->rx_action.data[0] == QOS_QOS_MAP_CONFIG) {
  2606. const u8 *pos = data->rx_action.data + 1;
  2607. size_t len = data->rx_action.len - 1;
  2608. wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from "
  2609. MACSTR, MAC2STR(data->rx_action.sa));
  2610. if (os_memcmp(data->rx_action.sa, wpa_s->bssid,
  2611. ETH_ALEN) == 0 &&
  2612. len > 2 && pos[0] == WLAN_EID_QOS_MAP_SET &&
  2613. pos[1] <= len - 2 && pos[1] >= 16)
  2614. wpas_qos_map_set(wpa_s, pos + 2, pos[1]);
  2615. break;
  2616. }
  2617. #endif /* CONFIG_INTERWORKING */
  2618. #ifdef CONFIG_P2P
  2619. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  2620. data->rx_action.sa,
  2621. data->rx_action.bssid,
  2622. data->rx_action.category,
  2623. data->rx_action.data,
  2624. data->rx_action.len, data->rx_action.freq);
  2625. #endif /* CONFIG_P2P */
  2626. break;
  2627. case EVENT_RX_PROBE_REQ:
  2628. if (data->rx_probe_req.sa == NULL ||
  2629. data->rx_probe_req.ie == NULL)
  2630. break;
  2631. #ifdef CONFIG_AP
  2632. if (wpa_s->ap_iface) {
  2633. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  2634. data->rx_probe_req.sa,
  2635. data->rx_probe_req.da,
  2636. data->rx_probe_req.bssid,
  2637. data->rx_probe_req.ie,
  2638. data->rx_probe_req.ie_len,
  2639. data->rx_probe_req.ssi_signal);
  2640. break;
  2641. }
  2642. #endif /* CONFIG_AP */
  2643. #ifdef CONFIG_P2P
  2644. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  2645. data->rx_probe_req.da,
  2646. data->rx_probe_req.bssid,
  2647. data->rx_probe_req.ie,
  2648. data->rx_probe_req.ie_len,
  2649. data->rx_probe_req.ssi_signal);
  2650. #endif /* CONFIG_P2P */
  2651. break;
  2652. case EVENT_REMAIN_ON_CHANNEL:
  2653. #ifdef CONFIG_OFFCHANNEL
  2654. offchannel_remain_on_channel_cb(
  2655. wpa_s, data->remain_on_channel.freq,
  2656. data->remain_on_channel.duration);
  2657. #endif /* CONFIG_OFFCHANNEL */
  2658. #ifdef CONFIG_P2P
  2659. wpas_p2p_remain_on_channel_cb(
  2660. wpa_s, data->remain_on_channel.freq,
  2661. data->remain_on_channel.duration);
  2662. #endif /* CONFIG_P2P */
  2663. break;
  2664. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  2665. #ifdef CONFIG_OFFCHANNEL
  2666. offchannel_cancel_remain_on_channel_cb(
  2667. wpa_s, data->remain_on_channel.freq);
  2668. #endif /* CONFIG_OFFCHANNEL */
  2669. #ifdef CONFIG_P2P
  2670. wpas_p2p_cancel_remain_on_channel_cb(
  2671. wpa_s, data->remain_on_channel.freq);
  2672. #endif /* CONFIG_P2P */
  2673. break;
  2674. #ifdef CONFIG_P2P
  2675. case EVENT_P2P_DEV_FOUND: {
  2676. struct p2p_peer_info peer_info;
  2677. os_memset(&peer_info, 0, sizeof(peer_info));
  2678. if (data->p2p_dev_found.dev_addr)
  2679. os_memcpy(peer_info.p2p_device_addr,
  2680. data->p2p_dev_found.dev_addr, ETH_ALEN);
  2681. if (data->p2p_dev_found.pri_dev_type)
  2682. os_memcpy(peer_info.pri_dev_type,
  2683. data->p2p_dev_found.pri_dev_type,
  2684. sizeof(peer_info.pri_dev_type));
  2685. if (data->p2p_dev_found.dev_name)
  2686. os_strlcpy(peer_info.device_name,
  2687. data->p2p_dev_found.dev_name,
  2688. sizeof(peer_info.device_name));
  2689. peer_info.config_methods = data->p2p_dev_found.config_methods;
  2690. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  2691. peer_info.group_capab = data->p2p_dev_found.group_capab;
  2692. /*
  2693. * FIX: new_device=1 is not necessarily correct. We should
  2694. * maintain a P2P peer database in wpa_supplicant and update
  2695. * this information based on whether the peer is truly new.
  2696. */
  2697. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  2698. break;
  2699. }
  2700. case EVENT_P2P_GO_NEG_REQ_RX:
  2701. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  2702. data->p2p_go_neg_req_rx.dev_passwd_id);
  2703. break;
  2704. case EVENT_P2P_GO_NEG_COMPLETED:
  2705. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  2706. break;
  2707. case EVENT_P2P_PROV_DISC_REQUEST:
  2708. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  2709. data->p2p_prov_disc_req.config_methods,
  2710. data->p2p_prov_disc_req.dev_addr,
  2711. data->p2p_prov_disc_req.pri_dev_type,
  2712. data->p2p_prov_disc_req.dev_name,
  2713. data->p2p_prov_disc_req.supp_config_methods,
  2714. data->p2p_prov_disc_req.dev_capab,
  2715. data->p2p_prov_disc_req.group_capab,
  2716. NULL, 0);
  2717. break;
  2718. case EVENT_P2P_PROV_DISC_RESPONSE:
  2719. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  2720. data->p2p_prov_disc_resp.config_methods);
  2721. break;
  2722. case EVENT_P2P_SD_REQUEST:
  2723. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  2724. data->p2p_sd_req.sa,
  2725. data->p2p_sd_req.dialog_token,
  2726. data->p2p_sd_req.update_indic,
  2727. data->p2p_sd_req.tlvs,
  2728. data->p2p_sd_req.tlvs_len);
  2729. break;
  2730. case EVENT_P2P_SD_RESPONSE:
  2731. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  2732. data->p2p_sd_resp.update_indic,
  2733. data->p2p_sd_resp.tlvs,
  2734. data->p2p_sd_resp.tlvs_len);
  2735. break;
  2736. #endif /* CONFIG_P2P */
  2737. case EVENT_EAPOL_RX:
  2738. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  2739. data->eapol_rx.data,
  2740. data->eapol_rx.data_len);
  2741. break;
  2742. case EVENT_SIGNAL_CHANGE:
  2743. bgscan_notify_signal_change(
  2744. wpa_s, data->signal_change.above_threshold,
  2745. data->signal_change.current_signal,
  2746. data->signal_change.current_noise,
  2747. data->signal_change.current_txrate);
  2748. break;
  2749. case EVENT_INTERFACE_ENABLED:
  2750. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  2751. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  2752. wpa_supplicant_update_mac_addr(wpa_s);
  2753. #ifdef CONFIG_AP
  2754. if (!wpa_s->ap_iface) {
  2755. wpa_supplicant_set_state(wpa_s,
  2756. WPA_DISCONNECTED);
  2757. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2758. } else
  2759. wpa_supplicant_set_state(wpa_s,
  2760. WPA_COMPLETED);
  2761. #else /* CONFIG_AP */
  2762. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  2763. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2764. #endif /* CONFIG_AP */
  2765. }
  2766. break;
  2767. case EVENT_INTERFACE_DISABLED:
  2768. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  2769. #ifdef CONFIG_P2P
  2770. if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
  2771. (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group &&
  2772. wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) {
  2773. /*
  2774. * The interface was externally disabled. Remove
  2775. * it assuming an external entity will start a
  2776. * new session if needed.
  2777. */
  2778. wpas_p2p_disconnect(wpa_s);
  2779. break;
  2780. }
  2781. #endif /* CONFIG_P2P */
  2782. wpa_supplicant_mark_disassoc(wpa_s);
  2783. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  2784. break;
  2785. case EVENT_CHANNEL_LIST_CHANGED:
  2786. wpa_supplicant_update_channel_list(wpa_s);
  2787. break;
  2788. case EVENT_INTERFACE_UNAVAILABLE:
  2789. #ifdef CONFIG_P2P
  2790. wpas_p2p_interface_unavailable(wpa_s);
  2791. #endif /* CONFIG_P2P */
  2792. break;
  2793. case EVENT_BEST_CHANNEL:
  2794. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  2795. "(%d %d %d)",
  2796. data->best_chan.freq_24, data->best_chan.freq_5,
  2797. data->best_chan.freq_overall);
  2798. wpa_s->best_24_freq = data->best_chan.freq_24;
  2799. wpa_s->best_5_freq = data->best_chan.freq_5;
  2800. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  2801. #ifdef CONFIG_P2P
  2802. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  2803. data->best_chan.freq_5,
  2804. data->best_chan.freq_overall);
  2805. #endif /* CONFIG_P2P */
  2806. break;
  2807. case EVENT_UNPROT_DEAUTH:
  2808. wpa_supplicant_event_unprot_deauth(wpa_s,
  2809. &data->unprot_deauth);
  2810. break;
  2811. case EVENT_UNPROT_DISASSOC:
  2812. wpa_supplicant_event_unprot_disassoc(wpa_s,
  2813. &data->unprot_disassoc);
  2814. break;
  2815. case EVENT_STATION_LOW_ACK:
  2816. #ifdef CONFIG_AP
  2817. if (wpa_s->ap_iface && data)
  2818. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  2819. data->low_ack.addr);
  2820. #endif /* CONFIG_AP */
  2821. #ifdef CONFIG_TDLS
  2822. if (data)
  2823. wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr);
  2824. #endif /* CONFIG_TDLS */
  2825. break;
  2826. case EVENT_IBSS_PEER_LOST:
  2827. #ifdef CONFIG_IBSS_RSN
  2828. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  2829. #endif /* CONFIG_IBSS_RSN */
  2830. break;
  2831. case EVENT_DRIVER_GTK_REKEY:
  2832. if (os_memcmp(data->driver_gtk_rekey.bssid,
  2833. wpa_s->bssid, ETH_ALEN))
  2834. break;
  2835. if (!wpa_s->wpa)
  2836. break;
  2837. wpa_sm_update_replay_ctr(wpa_s->wpa,
  2838. data->driver_gtk_rekey.replay_ctr);
  2839. break;
  2840. case EVENT_SCHED_SCAN_STOPPED:
  2841. wpa_s->sched_scanning = 0;
  2842. wpa_supplicant_notify_scanning(wpa_s, 0);
  2843. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  2844. break;
  2845. /*
  2846. * If we timed out, start a new sched scan to continue
  2847. * searching for more SSIDs.
  2848. */
  2849. if (wpa_s->sched_scan_timed_out)
  2850. wpa_supplicant_req_sched_scan(wpa_s);
  2851. break;
  2852. case EVENT_WPS_BUTTON_PUSHED:
  2853. #ifdef CONFIG_WPS
  2854. wpas_wps_start_pbc(wpa_s, NULL, 0);
  2855. #endif /* CONFIG_WPS */
  2856. break;
  2857. case EVENT_CONNECT_FAILED_REASON:
  2858. #ifdef CONFIG_AP
  2859. if (!wpa_s->ap_iface || !data)
  2860. break;
  2861. hostapd_event_connect_failed_reason(
  2862. wpa_s->ap_iface->bss[0],
  2863. data->connect_failed_reason.addr,
  2864. data->connect_failed_reason.code);
  2865. #endif /* CONFIG_AP */
  2866. break;
  2867. default:
  2868. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  2869. break;
  2870. }
  2871. }