events.c 79 KB

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