events.c 90 KB

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