events.c 89 KB

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