events.c 79 KB

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