Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2011, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #include "includes.h"
  15. #include "common.h"
  16. #include "eapol_supp/eapol_supp_sm.h"
  17. #include "rsn_supp/wpa.h"
  18. #include "eloop.h"
  19. #include "config.h"
  20. #include "l2_packet/l2_packet.h"
  21. #include "wpa_supplicant_i.h"
  22. #include "driver_i.h"
  23. #include "pcsc_funcs.h"
  24. #include "rsn_supp/preauth.h"
  25. #include "rsn_supp/pmksa_cache.h"
  26. #include "common/wpa_ctrl.h"
  27. #include "eap_peer/eap.h"
  28. #include "ap/hostapd.h"
  29. #include "p2p/p2p.h"
  30. #include "notify.h"
  31. #include "common/ieee802_11_defs.h"
  32. #include "common/ieee802_11_common.h"
  33. #include "crypto/random.h"
  34. #include "blacklist.h"
  35. #include "wpas_glue.h"
  36. #include "wps_supplicant.h"
  37. #include "ibss_rsn.h"
  38. #include "sme.h"
  39. #include "p2p_supplicant.h"
  40. #include "bgscan.h"
  41. #include "ap.h"
  42. #include "bss.h"
  43. #include "mlme.h"
  44. #include "scan.h"
  45. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  46. {
  47. struct wpa_ssid *ssid, *old_ssid;
  48. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  49. return 0;
  50. wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association "
  51. "information");
  52. ssid = wpa_supplicant_get_ssid(wpa_s);
  53. if (ssid == NULL) {
  54. wpa_msg(wpa_s, MSG_INFO,
  55. "No network configuration found for the current AP");
  56. return -1;
  57. }
  58. if (ssid->disabled) {
  59. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled");
  60. return -1;
  61. }
  62. wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the "
  63. "current AP");
  64. if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  65. WPA_KEY_MGMT_WPA_NONE |
  66. WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
  67. WPA_KEY_MGMT_PSK_SHA256 |
  68. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  69. u8 wpa_ie[80];
  70. size_t wpa_ie_len = sizeof(wpa_ie);
  71. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  72. wpa_ie, &wpa_ie_len);
  73. } else {
  74. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  75. }
  76. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  77. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  78. old_ssid = wpa_s->current_ssid;
  79. wpa_s->current_ssid = ssid;
  80. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  81. wpa_supplicant_initiate_eapol(wpa_s);
  82. if (old_ssid != wpa_s->current_ssid)
  83. wpas_notify_network_changed(wpa_s);
  84. return 0;
  85. }
  86. static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
  87. void *sock_ctx)
  88. {
  89. struct wpa_supplicant *wpa_s = eloop_ctx;
  90. if (wpa_s->countermeasures) {
  91. wpa_s->countermeasures = 0;
  92. wpa_drv_set_countermeasures(wpa_s, 0);
  93. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  94. wpa_supplicant_req_scan(wpa_s, 0, 0);
  95. }
  96. }
  97. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  98. {
  99. int bssid_changed;
  100. #ifdef CONFIG_IBSS_RSN
  101. ibss_rsn_deinit(wpa_s->ibss_rsn);
  102. wpa_s->ibss_rsn = NULL;
  103. #endif /* CONFIG_IBSS_RSN */
  104. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  105. return;
  106. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  107. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  108. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  109. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  110. wpa_s->current_bss = NULL;
  111. wpa_s->assoc_freq = 0;
  112. if (bssid_changed)
  113. wpas_notify_bssid_changed(wpa_s);
  114. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  115. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  116. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  117. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  118. wpa_s->ap_ies_from_associnfo = 0;
  119. }
  120. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  121. {
  122. struct wpa_ie_data ie;
  123. int pmksa_set = -1;
  124. size_t i;
  125. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  126. ie.pmkid == NULL)
  127. return;
  128. for (i = 0; i < ie.num_pmkid; i++) {
  129. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  130. ie.pmkid + i * PMKID_LEN,
  131. NULL, NULL, 0);
  132. if (pmksa_set == 0) {
  133. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  134. break;
  135. }
  136. }
  137. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from "
  138. "PMKSA cache", pmksa_set == 0 ? "" : "not ");
  139. }
  140. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  141. union wpa_event_data *data)
  142. {
  143. if (data == NULL) {
  144. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate "
  145. "event");
  146. return;
  147. }
  148. wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  149. " index=%d preauth=%d",
  150. MAC2STR(data->pmkid_candidate.bssid),
  151. data->pmkid_candidate.index,
  152. data->pmkid_candidate.preauth);
  153. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  154. data->pmkid_candidate.index,
  155. data->pmkid_candidate.preauth);
  156. }
  157. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  158. {
  159. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  160. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  161. return 0;
  162. #ifdef IEEE8021X_EAPOL
  163. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  164. wpa_s->current_ssid &&
  165. !(wpa_s->current_ssid->eapol_flags &
  166. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  167. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  168. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  169. * plaintext or static WEP keys). */
  170. return 0;
  171. }
  172. #endif /* IEEE8021X_EAPOL */
  173. return 1;
  174. }
  175. /**
  176. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  177. * @wpa_s: pointer to wpa_supplicant data
  178. * @ssid: Configuration data for the network
  179. * Returns: 0 on success, -1 on failure
  180. *
  181. * This function is called when starting authentication with a network that is
  182. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  183. */
  184. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  185. struct wpa_ssid *ssid)
  186. {
  187. #ifdef IEEE8021X_EAPOL
  188. int aka = 0, sim = 0, type;
  189. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  190. return 0;
  191. if (ssid->eap.eap_methods == NULL) {
  192. sim = 1;
  193. aka = 1;
  194. } else {
  195. struct eap_method_type *eap = ssid->eap.eap_methods;
  196. while (eap->vendor != EAP_VENDOR_IETF ||
  197. eap->method != EAP_TYPE_NONE) {
  198. if (eap->vendor == EAP_VENDOR_IETF) {
  199. if (eap->method == EAP_TYPE_SIM)
  200. sim = 1;
  201. else if (eap->method == EAP_TYPE_AKA)
  202. aka = 1;
  203. }
  204. eap++;
  205. }
  206. }
  207. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  208. sim = 0;
  209. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  210. aka = 0;
  211. if (!sim && !aka) {
  212. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to "
  213. "use SIM, but neither EAP-SIM nor EAP-AKA are "
  214. "enabled");
  215. return 0;
  216. }
  217. wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM "
  218. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  219. if (sim && aka)
  220. type = SCARD_TRY_BOTH;
  221. else if (aka)
  222. type = SCARD_USIM_ONLY;
  223. else
  224. type = SCARD_GSM_SIM_ONLY;
  225. wpa_s->scard = scard_init(type);
  226. if (wpa_s->scard == NULL) {
  227. wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM "
  228. "(pcsc-lite)");
  229. return -1;
  230. }
  231. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  232. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  233. #endif /* IEEE8021X_EAPOL */
  234. return 0;
  235. }
  236. #ifndef CONFIG_NO_SCAN_PROCESSING
  237. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  238. struct wpa_ssid *ssid)
  239. {
  240. int i, privacy = 0;
  241. if (ssid->mixed_cell)
  242. return 1;
  243. #ifdef CONFIG_WPS
  244. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  245. return 1;
  246. #endif /* CONFIG_WPS */
  247. for (i = 0; i < NUM_WEP_KEYS; i++) {
  248. if (ssid->wep_key_len[i]) {
  249. privacy = 1;
  250. break;
  251. }
  252. }
  253. #ifdef IEEE8021X_EAPOL
  254. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  255. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  256. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  257. privacy = 1;
  258. #endif /* IEEE8021X_EAPOL */
  259. if (bss->caps & IEEE80211_CAP_PRIVACY)
  260. return privacy;
  261. return !privacy;
  262. }
  263. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  264. struct wpa_ssid *ssid,
  265. struct wpa_scan_res *bss)
  266. {
  267. struct wpa_ie_data ie;
  268. int proto_match = 0;
  269. const u8 *rsn_ie, *wpa_ie;
  270. int ret;
  271. int wep_ok;
  272. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  273. if (ret >= 0)
  274. return ret;
  275. /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */
  276. wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) &&
  277. (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  278. ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) ||
  279. (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA));
  280. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  281. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  282. proto_match++;
  283. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  284. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse "
  285. "failed");
  286. break;
  287. }
  288. if (wep_ok &&
  289. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  290. {
  291. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  292. "in RSN IE");
  293. return 1;
  294. }
  295. if (!(ie.proto & ssid->proto)) {
  296. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto "
  297. "mismatch");
  298. break;
  299. }
  300. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  301. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK "
  302. "cipher mismatch");
  303. break;
  304. }
  305. if (!(ie.group_cipher & ssid->group_cipher)) {
  306. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK "
  307. "cipher mismatch");
  308. break;
  309. }
  310. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  311. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt "
  312. "mismatch");
  313. break;
  314. }
  315. #ifdef CONFIG_IEEE80211W
  316. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  317. ssid->ieee80211w == MGMT_FRAME_PROTECTION_REQUIRED) {
  318. wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt "
  319. "frame protection");
  320. break;
  321. }
  322. #endif /* CONFIG_IEEE80211W */
  323. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE");
  324. return 1;
  325. }
  326. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  327. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  328. proto_match++;
  329. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  330. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse "
  331. "failed");
  332. break;
  333. }
  334. if (wep_ok &&
  335. (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104)))
  336. {
  337. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN "
  338. "in WPA IE");
  339. return 1;
  340. }
  341. if (!(ie.proto & ssid->proto)) {
  342. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto "
  343. "mismatch");
  344. break;
  345. }
  346. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  347. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK "
  348. "cipher mismatch");
  349. break;
  350. }
  351. if (!(ie.group_cipher & ssid->group_cipher)) {
  352. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK "
  353. "cipher mismatch");
  354. break;
  355. }
  356. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  357. wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt "
  358. "mismatch");
  359. break;
  360. }
  361. wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE");
  362. return 1;
  363. }
  364. if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) &&
  365. wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) {
  366. wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match");
  367. return 0;
  368. }
  369. if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) {
  370. wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2");
  371. return 1;
  372. }
  373. wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with "
  374. "WPA/WPA2");
  375. return 0;
  376. }
  377. static int freq_allowed(int *freqs, int freq)
  378. {
  379. int i;
  380. if (freqs == NULL)
  381. return 1;
  382. for (i = 0; freqs[i]; i++)
  383. if (freqs[i] == freq)
  384. return 1;
  385. return 0;
  386. }
  387. static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s,
  388. int i, struct wpa_scan_res *bss,
  389. struct wpa_ssid *group)
  390. {
  391. const u8 *ssid_;
  392. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  393. int wpa;
  394. struct wpa_blacklist *e;
  395. const u8 *ie;
  396. struct wpa_ssid *ssid;
  397. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  398. ssid_ = ie ? ie + 2 : (u8 *) "";
  399. ssid_len = ie ? ie[1] : 0;
  400. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  401. wpa_ie_len = ie ? ie[1] : 0;
  402. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  403. rsn_ie_len = ie ? ie[1] : 0;
  404. wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  405. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s",
  406. i, MAC2STR(bss->bssid), wpa_ssid_txt(ssid_, ssid_len),
  407. wpa_ie_len, rsn_ie_len, bss->caps, bss->level,
  408. wpa_scan_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "");
  409. e = wpa_blacklist_get(wpa_s, bss->bssid);
  410. if (e) {
  411. int limit = 1;
  412. if (wpa_supplicant_enabled_networks(wpa_s->conf) == 1) {
  413. /*
  414. * When only a single network is enabled, we can
  415. * trigger blacklisting on the first failure. This
  416. * should not be done with multiple enabled networks to
  417. * avoid getting forced to move into a worse ESS on
  418. * single error if there are no other BSSes of the
  419. * current ESS.
  420. */
  421. limit = 0;
  422. }
  423. if (e->count > limit) {
  424. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  425. "(count=%d limit=%d)", e->count, limit);
  426. return NULL;
  427. }
  428. }
  429. if (ssid_len == 0) {
  430. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known");
  431. return NULL;
  432. }
  433. wpa = wpa_ie_len > 0 || rsn_ie_len > 0;
  434. for (ssid = group; ssid; ssid = ssid->pnext) {
  435. int check_ssid = wpa ? 1 : (ssid->ssid_len != 0);
  436. if (ssid->disabled) {
  437. wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled");
  438. continue;
  439. }
  440. #ifdef CONFIG_WPS
  441. if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) {
  442. wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted "
  443. "(WPS)");
  444. continue;
  445. }
  446. if (wpa && ssid->ssid_len == 0 &&
  447. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  448. check_ssid = 0;
  449. if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
  450. /* Only allow wildcard SSID match if an AP
  451. * advertises active WPS operation that matches
  452. * with our mode. */
  453. check_ssid = 1;
  454. if (ssid->ssid_len == 0 &&
  455. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  456. check_ssid = 0;
  457. }
  458. #endif /* CONFIG_WPS */
  459. if (check_ssid &&
  460. (ssid_len != ssid->ssid_len ||
  461. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  462. wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch");
  463. continue;
  464. }
  465. if (ssid->bssid_set &&
  466. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) {
  467. wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch");
  468. continue;
  469. }
  470. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  471. continue;
  472. if (!wpa &&
  473. !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  474. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  475. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) {
  476. wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network "
  477. "not allowed");
  478. continue;
  479. }
  480. if (!wpa && !wpa_supplicant_match_privacy(bss, ssid)) {
  481. wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy "
  482. "mismatch");
  483. continue;
  484. }
  485. if (!wpa && (bss->caps & IEEE80211_CAP_IBSS)) {
  486. wpa_dbg(wpa_s, MSG_DEBUG, " skip - IBSS (adhoc) "
  487. "network");
  488. continue;
  489. }
  490. if (!freq_allowed(ssid->freq_list, bss->freq)) {
  491. wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not "
  492. "allowed");
  493. continue;
  494. }
  495. #ifdef CONFIG_P2P
  496. /*
  497. * TODO: skip the AP if its P2P IE has Group Formation
  498. * bit set in the P2P Group Capability Bitmap and we
  499. * are not in Group Formation with that device.
  500. */
  501. #endif /* CONFIG_P2P */
  502. /* Matching configuration found */
  503. return ssid;
  504. }
  505. /* No matching configuration found */
  506. return NULL;
  507. }
  508. static struct wpa_bss *
  509. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s,
  510. struct wpa_scan_results *scan_res,
  511. struct wpa_ssid *group,
  512. struct wpa_ssid **selected_ssid)
  513. {
  514. size_t i;
  515. wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d",
  516. group->priority);
  517. for (i = 0; i < scan_res->num; i++) {
  518. struct wpa_scan_res *bss = scan_res->res[i];
  519. const u8 *ie, *ssid;
  520. u8 ssid_len;
  521. *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group);
  522. if (!*selected_ssid)
  523. continue;
  524. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  525. ssid = ie ? ie + 2 : (u8 *) "";
  526. ssid_len = ie ? ie[1] : 0;
  527. wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR
  528. " ssid='%s'",
  529. MAC2STR(bss->bssid), wpa_ssid_txt(ssid, ssid_len));
  530. return wpa_bss_get(wpa_s, bss->bssid, ssid, ssid_len);
  531. }
  532. return NULL;
  533. }
  534. static struct wpa_bss *
  535. wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s,
  536. struct wpa_scan_results *scan_res,
  537. struct wpa_ssid **selected_ssid)
  538. {
  539. struct wpa_bss *selected = NULL;
  540. int prio;
  541. while (selected == NULL) {
  542. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  543. selected = wpa_supplicant_select_bss(
  544. wpa_s, scan_res, wpa_s->conf->pssid[prio],
  545. selected_ssid);
  546. if (selected)
  547. break;
  548. }
  549. if (selected == NULL && wpa_s->blacklist) {
  550. wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear "
  551. "blacklist and try again");
  552. wpa_blacklist_clear(wpa_s);
  553. wpa_s->blacklist_cleared++;
  554. } else if (selected == NULL)
  555. break;
  556. }
  557. return selected;
  558. }
  559. static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s,
  560. int timeout_sec, int timeout_usec)
  561. {
  562. if (!wpa_supplicant_enabled_networks(wpa_s->conf)) {
  563. /*
  564. * No networks are enabled; short-circuit request so
  565. * we don't wait timeout seconds before transitioning
  566. * to INACTIVE state.
  567. */
  568. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  569. return;
  570. }
  571. wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec);
  572. }
  573. void wpa_supplicant_connect(struct wpa_supplicant *wpa_s,
  574. struct wpa_bss *selected,
  575. struct wpa_ssid *ssid)
  576. {
  577. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  578. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  579. "PBC session overlap");
  580. #ifdef CONFIG_P2P
  581. if (wpas_p2p_notif_pbc_overlap(wpa_s) == 1)
  582. return;
  583. #endif /* CONFIG_P2P */
  584. #ifdef CONFIG_WPS
  585. wpas_wps_cancel(wpa_s);
  586. #endif /* CONFIG_WPS */
  587. return;
  588. }
  589. /*
  590. * Do not trigger new association unless the BSSID has changed or if
  591. * reassociation is requested. If we are in process of associating with
  592. * the selected BSSID, do not trigger new attempt.
  593. */
  594. if (wpa_s->reassociate ||
  595. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  596. ((wpa_s->wpa_state != WPA_ASSOCIATING &&
  597. wpa_s->wpa_state != WPA_AUTHENTICATING) ||
  598. os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) !=
  599. 0))) {
  600. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  601. wpa_supplicant_req_new_scan(wpa_s, 10, 0);
  602. return;
  603. }
  604. wpa_msg(wpa_s, MSG_DEBUG, "Request association: "
  605. "reassociate: %d selected: "MACSTR " bssid: " MACSTR
  606. " pending: " MACSTR " wpa_state: %s",
  607. wpa_s->reassociate, MAC2STR(selected->bssid),
  608. MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid),
  609. wpa_supplicant_state_txt(wpa_s->wpa_state));
  610. wpa_supplicant_associate(wpa_s, selected, ssid);
  611. } else {
  612. wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with the "
  613. "selected AP");
  614. }
  615. }
  616. static struct wpa_ssid *
  617. wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s)
  618. {
  619. int prio;
  620. struct wpa_ssid *ssid;
  621. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  622. for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext)
  623. {
  624. if (ssid->disabled)
  625. continue;
  626. if (ssid->mode == IEEE80211_MODE_IBSS ||
  627. ssid->mode == IEEE80211_MODE_AP)
  628. return ssid;
  629. }
  630. }
  631. return NULL;
  632. }
  633. /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based
  634. * on BSS added and BSS changed events */
  635. static void wpa_supplicant_rsn_preauth_scan_results(
  636. struct wpa_supplicant *wpa_s, struct wpa_scan_results *scan_res)
  637. {
  638. int i;
  639. if (rsn_preauth_scan_results(wpa_s->wpa) < 0)
  640. return;
  641. for (i = scan_res->num - 1; i >= 0; i--) {
  642. const u8 *ssid, *rsn;
  643. struct wpa_scan_res *r;
  644. r = scan_res->res[i];
  645. ssid = wpa_scan_get_ie(r, WLAN_EID_SSID);
  646. if (ssid == NULL)
  647. continue;
  648. rsn = wpa_scan_get_ie(r, WLAN_EID_RSN);
  649. if (rsn == NULL)
  650. continue;
  651. rsn_preauth_scan_result(wpa_s->wpa, r->bssid, ssid, rsn);
  652. }
  653. }
  654. static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s,
  655. struct wpa_bss *selected,
  656. struct wpa_ssid *ssid,
  657. struct wpa_scan_results *scan_res)
  658. {
  659. size_t i;
  660. struct wpa_scan_res *current_bss = NULL;
  661. int min_diff;
  662. if (wpa_s->reassociate)
  663. return 1; /* explicit request to reassociate */
  664. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  665. return 1; /* we are not associated; continue */
  666. if (wpa_s->current_ssid == NULL)
  667. return 1; /* unknown current SSID */
  668. if (wpa_s->current_ssid != ssid)
  669. return 1; /* different network block */
  670. for (i = 0; i < scan_res->num; i++) {
  671. struct wpa_scan_res *res = scan_res->res[i];
  672. const u8 *ie;
  673. if (os_memcmp(res->bssid, wpa_s->bssid, ETH_ALEN) != 0)
  674. continue;
  675. ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
  676. if (ie == NULL)
  677. continue;
  678. if (ie[1] != wpa_s->current_ssid->ssid_len ||
  679. os_memcmp(ie + 2, wpa_s->current_ssid->ssid, ie[1]) != 0)
  680. continue;
  681. current_bss = res;
  682. break;
  683. }
  684. if (!current_bss)
  685. return 1; /* current BSS not seen in scan results */
  686. wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation");
  687. wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d",
  688. MAC2STR(current_bss->bssid), current_bss->level);
  689. wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d",
  690. MAC2STR(selected->bssid), selected->level);
  691. if (wpa_s->current_ssid->bssid_set &&
  692. os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) ==
  693. 0) {
  694. wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS "
  695. "has preferred BSSID");
  696. return 1;
  697. }
  698. min_diff = 2;
  699. if (current_bss->level < 0) {
  700. if (current_bss->level < -85)
  701. min_diff = 1;
  702. else if (current_bss->level < -80)
  703. min_diff = 2;
  704. else if (current_bss->level < -75)
  705. min_diff = 3;
  706. else if (current_bss->level < -70)
  707. min_diff = 4;
  708. else
  709. min_diff = 5;
  710. }
  711. if (abs(current_bss->level - selected->level) < min_diff) {
  712. wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference "
  713. "in signal level");
  714. return 0;
  715. }
  716. return 1;
  717. }
  718. /* Return < 0 if no scan results could be fetched. */
  719. static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  720. union wpa_event_data *data)
  721. {
  722. struct wpa_bss *selected;
  723. struct wpa_ssid *ssid = NULL;
  724. struct wpa_scan_results *scan_res;
  725. int ap = 0;
  726. #ifdef CONFIG_AP
  727. if (wpa_s->ap_iface)
  728. ap = 1;
  729. #endif /* CONFIG_AP */
  730. wpa_supplicant_notify_scanning(wpa_s, 0);
  731. scan_res = wpa_supplicant_get_scan_results(wpa_s,
  732. data ? &data->scan_info :
  733. NULL, 1);
  734. if (scan_res == NULL) {
  735. if (wpa_s->conf->ap_scan == 2 || ap)
  736. return -1;
  737. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
  738. "scanning again");
  739. wpa_supplicant_req_new_scan(wpa_s, 1, 0);
  740. return -1;
  741. }
  742. #ifndef CONFIG_NO_RANDOM_POOL
  743. size_t i, num;
  744. num = scan_res->num;
  745. if (num > 10)
  746. num = 10;
  747. for (i = 0; i < num; i++) {
  748. u8 buf[5];
  749. struct wpa_scan_res *res = scan_res->res[i];
  750. buf[0] = res->bssid[5];
  751. buf[1] = res->qual & 0xff;
  752. buf[2] = res->noise & 0xff;
  753. buf[3] = res->level & 0xff;
  754. buf[4] = res->tsf & 0xff;
  755. random_add_randomness(buf, sizeof(buf));
  756. }
  757. #endif /* CONFIG_NO_RANDOM_POOL */
  758. if (wpa_s->scan_res_handler) {
  759. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  760. struct wpa_scan_results *scan_res);
  761. scan_res_handler = wpa_s->scan_res_handler;
  762. wpa_s->scan_res_handler = NULL;
  763. scan_res_handler(wpa_s, scan_res);
  764. wpa_scan_results_free(scan_res);
  765. return 0;
  766. }
  767. if (ap) {
  768. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode");
  769. #ifdef CONFIG_AP
  770. if (wpa_s->ap_iface->scan_cb)
  771. wpa_s->ap_iface->scan_cb(wpa_s->ap_iface);
  772. #endif /* CONFIG_AP */
  773. wpa_scan_results_free(scan_res);
  774. return 0;
  775. }
  776. wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available");
  777. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  778. wpas_notify_scan_results(wpa_s);
  779. wpas_notify_scan_done(wpa_s, 1);
  780. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) {
  781. wpa_scan_results_free(scan_res);
  782. return 0;
  783. }
  784. if (wpa_s->disconnected) {
  785. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  786. wpa_scan_results_free(scan_res);
  787. return 0;
  788. }
  789. if (bgscan_notify_scan(wpa_s, scan_res) == 1) {
  790. wpa_scan_results_free(scan_res);
  791. return 0;
  792. }
  793. wpa_supplicant_rsn_preauth_scan_results(wpa_s, scan_res);
  794. selected = wpa_supplicant_pick_network(wpa_s, scan_res, &ssid);
  795. if (selected) {
  796. int skip;
  797. skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid,
  798. scan_res);
  799. wpa_scan_results_free(scan_res);
  800. if (skip)
  801. return 0;
  802. wpa_supplicant_connect(wpa_s, selected, ssid);
  803. } else {
  804. wpa_scan_results_free(scan_res);
  805. wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found");
  806. ssid = wpa_supplicant_pick_new_network(wpa_s);
  807. if (ssid) {
  808. wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network");
  809. wpa_supplicant_associate(wpa_s, NULL, ssid);
  810. } else {
  811. int timeout_sec = wpa_s->scan_interval;
  812. int timeout_usec = 0;
  813. #ifdef CONFIG_P2P
  814. if (wpa_s->p2p_in_provisioning) {
  815. /*
  816. * Use shorter wait during P2P Provisioning
  817. * state to speed up group formation.
  818. */
  819. timeout_sec = 0;
  820. timeout_usec = 250000;
  821. }
  822. #endif /* CONFIG_P2P */
  823. wpa_supplicant_req_new_scan(wpa_s, timeout_sec,
  824. timeout_usec);
  825. }
  826. }
  827. return 0;
  828. }
  829. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
  830. union wpa_event_data *data)
  831. {
  832. const char *rn, *rn2;
  833. struct wpa_supplicant *ifs;
  834. if (_wpa_supplicant_event_scan_results(wpa_s, data) < 0) {
  835. /*
  836. * If no scan results could be fetched, then no need to
  837. * notify those interfaces that did not actually request
  838. * this scan.
  839. */
  840. return;
  841. }
  842. /*
  843. * Check other interfaces to see if they have the same radio-name. If
  844. * so, they get updated with this same scan info.
  845. */
  846. if (!wpa_s->driver->get_radio_name)
  847. return;
  848. rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
  849. if (rn == NULL || rn[0] == '\0')
  850. return;
  851. wpa_dbg(wpa_s, MSG_DEBUG, "Checking for other virtual interfaces "
  852. "sharing same radio (%s) in event_scan_results", rn);
  853. for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
  854. if (ifs == wpa_s || !ifs->driver->get_radio_name)
  855. continue;
  856. rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
  857. if (rn2 && os_strcmp(rn, rn2) == 0) {
  858. wpa_printf(MSG_DEBUG, "%s: Updating scan results from "
  859. "sibling", ifs->ifname);
  860. _wpa_supplicant_event_scan_results(ifs, data);
  861. }
  862. }
  863. }
  864. #endif /* CONFIG_NO_SCAN_PROCESSING */
  865. static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  866. union wpa_event_data *data)
  867. {
  868. int l, len, found = 0, wpa_found, rsn_found;
  869. const u8 *p;
  870. wpa_dbg(wpa_s, MSG_DEBUG, "Association info event");
  871. if (data->assoc_info.req_ies)
  872. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  873. data->assoc_info.req_ies_len);
  874. if (data->assoc_info.resp_ies) {
  875. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  876. data->assoc_info.resp_ies_len);
  877. #ifdef CONFIG_TDLS
  878. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  879. data->assoc_info.resp_ies_len);
  880. #endif /* CONFIG_TDLS */
  881. }
  882. if (data->assoc_info.beacon_ies)
  883. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  884. data->assoc_info.beacon_ies,
  885. data->assoc_info.beacon_ies_len);
  886. if (data->assoc_info.freq)
  887. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  888. data->assoc_info.freq);
  889. p = data->assoc_info.req_ies;
  890. l = data->assoc_info.req_ies_len;
  891. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  892. while (p && l >= 2) {
  893. len = p[1] + 2;
  894. if (len > l) {
  895. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  896. p, l);
  897. break;
  898. }
  899. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  900. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  901. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  902. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  903. break;
  904. found = 1;
  905. wpa_find_assoc_pmkid(wpa_s);
  906. break;
  907. }
  908. l -= len;
  909. p += len;
  910. }
  911. if (!found && data->assoc_info.req_ies)
  912. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  913. #ifdef CONFIG_IEEE80211R
  914. #ifdef CONFIG_SME
  915. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  916. u8 bssid[ETH_ALEN];
  917. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  918. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  919. data->assoc_info.resp_ies,
  920. data->assoc_info.resp_ies_len,
  921. bssid) < 0) {
  922. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  923. "Reassociation Response failed");
  924. wpa_supplicant_deauthenticate(
  925. wpa_s, WLAN_REASON_INVALID_IE);
  926. return -1;
  927. }
  928. }
  929. p = data->assoc_info.resp_ies;
  930. l = data->assoc_info.resp_ies_len;
  931. #ifdef CONFIG_WPS_STRICT
  932. if (p && wpa_s->current_ssid &&
  933. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  934. struct wpabuf *wps;
  935. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  936. if (wps == NULL) {
  937. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  938. "include WPS IE in (Re)Association Response");
  939. return -1;
  940. }
  941. if (wps_validate_assoc_resp(wps) < 0) {
  942. wpabuf_free(wps);
  943. wpa_supplicant_deauthenticate(
  944. wpa_s, WLAN_REASON_INVALID_IE);
  945. return -1;
  946. }
  947. wpabuf_free(wps);
  948. }
  949. #endif /* CONFIG_WPS_STRICT */
  950. /* Go through the IEs and make a copy of the MDIE, if present. */
  951. while (p && l >= 2) {
  952. len = p[1] + 2;
  953. if (len > l) {
  954. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  955. p, l);
  956. break;
  957. }
  958. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  959. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  960. wpa_s->sme.ft_used = 1;
  961. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  962. MOBILITY_DOMAIN_ID_LEN);
  963. break;
  964. }
  965. l -= len;
  966. p += len;
  967. }
  968. #endif /* CONFIG_SME */
  969. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  970. data->assoc_info.resp_ies_len);
  971. #endif /* CONFIG_IEEE80211R */
  972. /* WPA/RSN IE from Beacon/ProbeResp */
  973. p = data->assoc_info.beacon_ies;
  974. l = data->assoc_info.beacon_ies_len;
  975. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  976. */
  977. wpa_found = rsn_found = 0;
  978. while (p && l >= 2) {
  979. len = p[1] + 2;
  980. if (len > l) {
  981. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  982. p, l);
  983. break;
  984. }
  985. if (!wpa_found &&
  986. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  987. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  988. wpa_found = 1;
  989. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  990. }
  991. if (!rsn_found &&
  992. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  993. rsn_found = 1;
  994. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  995. }
  996. l -= len;
  997. p += len;
  998. }
  999. if (!wpa_found && data->assoc_info.beacon_ies)
  1000. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  1001. if (!rsn_found && data->assoc_info.beacon_ies)
  1002. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  1003. if (wpa_found || rsn_found)
  1004. wpa_s->ap_ies_from_associnfo = 1;
  1005. wpa_s->assoc_freq = data->assoc_info.freq;
  1006. return 0;
  1007. }
  1008. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  1009. union wpa_event_data *data)
  1010. {
  1011. u8 bssid[ETH_ALEN];
  1012. int ft_completed;
  1013. int bssid_changed;
  1014. struct wpa_driver_capa capa;
  1015. #ifdef CONFIG_AP
  1016. if (wpa_s->ap_iface) {
  1017. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1018. data->assoc_info.addr,
  1019. data->assoc_info.req_ies,
  1020. data->assoc_info.req_ies_len,
  1021. data->assoc_info.reassoc);
  1022. return;
  1023. }
  1024. #endif /* CONFIG_AP */
  1025. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1026. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1027. return;
  1028. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1029. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  1030. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  1031. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  1032. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1033. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  1034. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1035. MACSTR, MAC2STR(bssid));
  1036. random_add_randomness(bssid, ETH_ALEN);
  1037. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1038. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1039. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1040. if (bssid_changed)
  1041. wpas_notify_bssid_changed(wpa_s);
  1042. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1043. wpa_clear_keys(wpa_s, bssid);
  1044. }
  1045. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1046. wpa_supplicant_disassociate(
  1047. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1048. return;
  1049. }
  1050. if (wpa_s->current_ssid) {
  1051. struct wpa_bss *bss = NULL;
  1052. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1053. if (ssid->ssid_len > 0)
  1054. bss = wpa_bss_get(wpa_s, bssid,
  1055. ssid->ssid, ssid->ssid_len);
  1056. if (!bss)
  1057. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1058. if (bss)
  1059. wpa_s->current_bss = bss;
  1060. }
  1061. }
  1062. #ifdef CONFIG_SME
  1063. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1064. wpa_s->sme.prev_bssid_set = 1;
  1065. #endif /* CONFIG_SME */
  1066. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1067. if (wpa_s->current_ssid) {
  1068. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1069. * initialized before association, but for other modes,
  1070. * initialize PC/SC here, if the current configuration needs
  1071. * smartcard or SIM/USIM. */
  1072. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1073. }
  1074. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1075. if (wpa_s->l2)
  1076. l2_packet_notify_auth_start(wpa_s->l2);
  1077. /*
  1078. * Set portEnabled first to FALSE in order to get EAP state machine out
  1079. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1080. * state machine may transit to AUTHENTICATING state based on obsolete
  1081. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1082. * AUTHENTICATED without ever giving chance to EAP state machine to
  1083. * reset the state.
  1084. */
  1085. if (!ft_completed) {
  1086. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1087. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1088. }
  1089. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1090. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1091. /* 802.1X::portControl = Auto */
  1092. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1093. wpa_s->eapol_received = 0;
  1094. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1095. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1096. (wpa_s->current_ssid &&
  1097. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1098. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1099. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1100. } else if (!ft_completed) {
  1101. /* Timeout for receiving the first EAPOL packet */
  1102. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1103. }
  1104. wpa_supplicant_cancel_scan(wpa_s);
  1105. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1106. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1107. /*
  1108. * We are done; the driver will take care of RSN 4-way
  1109. * handshake.
  1110. */
  1111. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1112. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1113. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1114. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1115. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1116. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1117. /*
  1118. * The driver will take care of RSN 4-way handshake, so we need
  1119. * to allow EAPOL supplicant to complete its work without
  1120. * waiting for WPA supplicant.
  1121. */
  1122. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1123. } else if (ft_completed) {
  1124. /*
  1125. * FT protocol completed - make sure EAPOL state machine ends
  1126. * up in authenticated.
  1127. */
  1128. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1129. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1130. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1131. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1132. }
  1133. if (wpa_s->pending_eapol_rx) {
  1134. struct os_time now, age;
  1135. os_get_time(&now);
  1136. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1137. if (age.sec == 0 && age.usec < 100000 &&
  1138. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1139. 0) {
  1140. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1141. "frame that was received just before "
  1142. "association notification");
  1143. wpa_supplicant_rx_eapol(
  1144. wpa_s, wpa_s->pending_eapol_rx_src,
  1145. wpabuf_head(wpa_s->pending_eapol_rx),
  1146. wpabuf_len(wpa_s->pending_eapol_rx));
  1147. }
  1148. wpabuf_free(wpa_s->pending_eapol_rx);
  1149. wpa_s->pending_eapol_rx = NULL;
  1150. }
  1151. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1152. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1153. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1154. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1155. /* Set static WEP keys again */
  1156. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1157. }
  1158. #ifdef CONFIG_IBSS_RSN
  1159. if (wpa_s->current_ssid &&
  1160. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1161. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1162. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE &&
  1163. wpa_s->ibss_rsn == NULL) {
  1164. wpa_s->ibss_rsn = ibss_rsn_init(wpa_s);
  1165. if (!wpa_s->ibss_rsn) {
  1166. wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN");
  1167. wpa_supplicant_deauthenticate(
  1168. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1169. return;
  1170. }
  1171. ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk);
  1172. }
  1173. #endif /* CONFIG_IBSS_RSN */
  1174. }
  1175. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1176. u16 reason_code)
  1177. {
  1178. const u8 *bssid;
  1179. int authenticating;
  1180. u8 prev_pending_bssid[ETH_ALEN];
  1181. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1182. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1183. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1184. /*
  1185. * At least Host AP driver and a Prism3 card seemed to be
  1186. * generating streams of disconnected events when configuring
  1187. * IBSS for WPA-None. Ignore them for now.
  1188. */
  1189. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1190. "IBSS/WPA-None mode");
  1191. return;
  1192. }
  1193. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1194. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1195. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1196. "pre-shared key may be incorrect");
  1197. }
  1198. if (!wpa_s->auto_reconnect_disabled ||
  1199. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1200. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
  1201. "reconnect (wps=%d)",
  1202. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
  1203. if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1204. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1205. } else {
  1206. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
  1207. "try to re-connect");
  1208. wpa_s->reassociate = 0;
  1209. wpa_s->disconnected = 1;
  1210. }
  1211. bssid = wpa_s->bssid;
  1212. if (is_zero_ether_addr(bssid))
  1213. bssid = wpa_s->pending_bssid;
  1214. wpas_connection_failed(wpa_s, bssid);
  1215. wpa_sm_notify_disassoc(wpa_s->wpa);
  1216. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1217. " reason=%d",
  1218. MAC2STR(bssid), reason_code);
  1219. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1220. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1221. wpa_s->keys_cleared = 0;
  1222. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1223. }
  1224. wpa_supplicant_mark_disassoc(wpa_s);
  1225. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1226. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1227. }
  1228. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1229. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1230. void *sock_ctx)
  1231. {
  1232. struct wpa_supplicant *wpa_s = eloop_ctx;
  1233. if (!wpa_s->pending_mic_error_report)
  1234. return;
  1235. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1236. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1237. wpa_s->pending_mic_error_report = 0;
  1238. }
  1239. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1240. static void
  1241. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1242. union wpa_event_data *data)
  1243. {
  1244. int pairwise;
  1245. struct os_time t;
  1246. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1247. pairwise = (data && data->michael_mic_failure.unicast);
  1248. os_get_time(&t);
  1249. if ((wpa_s->last_michael_mic_error &&
  1250. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1251. wpa_s->pending_mic_error_report) {
  1252. if (wpa_s->pending_mic_error_report) {
  1253. /*
  1254. * Send the pending MIC error report immediately since
  1255. * we are going to start countermeasures and AP better
  1256. * do the same.
  1257. */
  1258. wpa_sm_key_request(wpa_s->wpa, 1,
  1259. wpa_s->pending_mic_error_pairwise);
  1260. }
  1261. /* Send the new MIC error report immediately since we are going
  1262. * to start countermeasures and AP better do the same.
  1263. */
  1264. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1265. /* initialize countermeasures */
  1266. wpa_s->countermeasures = 1;
  1267. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1268. /*
  1269. * Need to wait for completion of request frame. We do not get
  1270. * any callback for the message completion, so just wait a
  1271. * short while and hope for the best. */
  1272. os_sleep(0, 10000);
  1273. wpa_drv_set_countermeasures(wpa_s, 1);
  1274. wpa_supplicant_deauthenticate(wpa_s,
  1275. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1276. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1277. wpa_s, NULL);
  1278. eloop_register_timeout(60, 0,
  1279. wpa_supplicant_stop_countermeasures,
  1280. wpa_s, NULL);
  1281. /* TODO: mark the AP rejected for 60 second. STA is
  1282. * allowed to associate with another AP.. */
  1283. } else {
  1284. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1285. if (wpa_s->mic_errors_seen) {
  1286. /*
  1287. * Reduce the effectiveness of Michael MIC error
  1288. * reports as a means for attacking against TKIP if
  1289. * more than one MIC failure is noticed with the same
  1290. * PTK. We delay the transmission of the reports by a
  1291. * random time between 0 and 60 seconds in order to
  1292. * force the attacker wait 60 seconds before getting
  1293. * the information on whether a frame resulted in a MIC
  1294. * failure.
  1295. */
  1296. u8 rval[4];
  1297. int sec;
  1298. if (os_get_random(rval, sizeof(rval)) < 0)
  1299. sec = os_random() % 60;
  1300. else
  1301. sec = WPA_GET_BE32(rval) % 60;
  1302. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1303. "report %d seconds", sec);
  1304. wpa_s->pending_mic_error_report = 1;
  1305. wpa_s->pending_mic_error_pairwise = pairwise;
  1306. eloop_cancel_timeout(
  1307. wpa_supplicant_delayed_mic_error_report,
  1308. wpa_s, NULL);
  1309. eloop_register_timeout(
  1310. sec, os_random() % 1000000,
  1311. wpa_supplicant_delayed_mic_error_report,
  1312. wpa_s, NULL);
  1313. } else {
  1314. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1315. }
  1316. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1317. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1318. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1319. }
  1320. wpa_s->last_michael_mic_error = t.sec;
  1321. wpa_s->mic_errors_seen++;
  1322. }
  1323. #ifdef CONFIG_TERMINATE_ONLASTIF
  1324. static int any_interfaces(struct wpa_supplicant *head)
  1325. {
  1326. struct wpa_supplicant *wpa_s;
  1327. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1328. if (!wpa_s->interface_removed)
  1329. return 1;
  1330. return 0;
  1331. }
  1332. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1333. static void
  1334. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1335. union wpa_event_data *data)
  1336. {
  1337. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1338. return;
  1339. switch (data->interface_status.ievent) {
  1340. case EVENT_INTERFACE_ADDED:
  1341. if (!wpa_s->interface_removed)
  1342. break;
  1343. wpa_s->interface_removed = 0;
  1344. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1345. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1346. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1347. "driver after interface was added");
  1348. }
  1349. break;
  1350. case EVENT_INTERFACE_REMOVED:
  1351. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1352. wpa_s->interface_removed = 1;
  1353. wpa_supplicant_mark_disassoc(wpa_s);
  1354. l2_packet_deinit(wpa_s->l2);
  1355. wpa_s->l2 = NULL;
  1356. #ifdef CONFIG_IBSS_RSN
  1357. ibss_rsn_deinit(wpa_s->ibss_rsn);
  1358. wpa_s->ibss_rsn = NULL;
  1359. #endif /* CONFIG_IBSS_RSN */
  1360. #ifdef CONFIG_TERMINATE_ONLASTIF
  1361. /* check if last interface */
  1362. if (!any_interfaces(wpa_s->global->ifaces))
  1363. eloop_terminate();
  1364. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1365. break;
  1366. }
  1367. }
  1368. #ifdef CONFIG_PEERKEY
  1369. static void
  1370. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1371. union wpa_event_data *data)
  1372. {
  1373. if (data == NULL)
  1374. return;
  1375. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1376. }
  1377. #endif /* CONFIG_PEERKEY */
  1378. #ifdef CONFIG_TDLS
  1379. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1380. union wpa_event_data *data)
  1381. {
  1382. if (data == NULL)
  1383. return;
  1384. switch (data->tdls.oper) {
  1385. case TDLS_REQUEST_SETUP:
  1386. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1387. break;
  1388. case TDLS_REQUEST_TEARDOWN:
  1389. /* request from driver to add FTIE */
  1390. wpa_tdls_recv_teardown_notify(wpa_s->wpa, data->tdls.peer,
  1391. data->tdls.reason_code);
  1392. break;
  1393. }
  1394. }
  1395. #endif /* CONFIG_TDLS */
  1396. #ifdef CONFIG_IEEE80211R
  1397. static void
  1398. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1399. union wpa_event_data *data)
  1400. {
  1401. if (data == NULL)
  1402. return;
  1403. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1404. data->ft_ies.ies_len,
  1405. data->ft_ies.ft_action,
  1406. data->ft_ies.target_ap,
  1407. data->ft_ies.ric_ies,
  1408. data->ft_ies.ric_ies_len) < 0) {
  1409. /* TODO: prevent MLME/driver from trying to associate? */
  1410. }
  1411. }
  1412. #endif /* CONFIG_IEEE80211R */
  1413. #ifdef CONFIG_IBSS_RSN
  1414. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1415. union wpa_event_data *data)
  1416. {
  1417. struct wpa_ssid *ssid;
  1418. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1419. return;
  1420. if (data == NULL)
  1421. return;
  1422. ssid = wpa_s->current_ssid;
  1423. if (ssid == NULL)
  1424. return;
  1425. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1426. return;
  1427. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1428. }
  1429. #endif /* CONFIG_IBSS_RSN */
  1430. #ifdef CONFIG_IEEE80211R
  1431. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1432. size_t len)
  1433. {
  1434. const u8 *sta_addr, *target_ap_addr;
  1435. u16 status;
  1436. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1437. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1438. return; /* only SME case supported for now */
  1439. if (len < 1 + 2 * ETH_ALEN + 2)
  1440. return;
  1441. if (data[0] != 2)
  1442. return; /* Only FT Action Response is supported for now */
  1443. sta_addr = data + 1;
  1444. target_ap_addr = data + 1 + ETH_ALEN;
  1445. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1446. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1447. MACSTR " TargetAP " MACSTR " status %u",
  1448. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1449. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1450. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1451. " in FT Action Response", MAC2STR(sta_addr));
  1452. return;
  1453. }
  1454. if (status) {
  1455. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1456. "failure (status code %d)", status);
  1457. /* TODO: report error to FT code(?) */
  1458. return;
  1459. }
  1460. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1461. len - (1 + 2 * ETH_ALEN + 2), 1,
  1462. target_ap_addr, NULL, 0) < 0)
  1463. return;
  1464. #ifdef CONFIG_SME
  1465. {
  1466. struct wpa_bss *bss;
  1467. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1468. if (bss)
  1469. wpa_s->sme.freq = bss->freq;
  1470. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1471. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1472. WLAN_AUTH_FT);
  1473. }
  1474. #endif /* CONFIG_SME */
  1475. }
  1476. #endif /* CONFIG_IEEE80211R */
  1477. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1478. struct unprot_deauth *e)
  1479. {
  1480. #ifdef CONFIG_IEEE80211W
  1481. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1482. "dropped: " MACSTR " -> " MACSTR
  1483. " (reason code %u)",
  1484. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1485. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1486. #endif /* CONFIG_IEEE80211W */
  1487. }
  1488. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1489. struct unprot_disassoc *e)
  1490. {
  1491. #ifdef CONFIG_IEEE80211W
  1492. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1493. "dropped: " MACSTR " -> " MACSTR
  1494. " (reason code %u)",
  1495. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1496. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1497. #endif /* CONFIG_IEEE80211W */
  1498. }
  1499. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1500. union wpa_event_data *data)
  1501. {
  1502. struct wpa_supplicant *wpa_s = ctx;
  1503. u16 reason_code = 0;
  1504. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1505. event != EVENT_INTERFACE_ENABLED &&
  1506. event != EVENT_INTERFACE_STATUS) {
  1507. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
  1508. "disabled", event);
  1509. return;
  1510. }
  1511. wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
  1512. event, wpa_s->ifname);
  1513. switch (event) {
  1514. case EVENT_AUTH:
  1515. sme_event_auth(wpa_s, data);
  1516. break;
  1517. case EVENT_ASSOC:
  1518. wpa_supplicant_event_assoc(wpa_s, data);
  1519. break;
  1520. case EVENT_DISASSOC:
  1521. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1522. if (data) {
  1523. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1524. data->disassoc_info.reason_code);
  1525. if (data->disassoc_info.addr)
  1526. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1527. MAC2STR(data->disassoc_info.addr));
  1528. }
  1529. #ifdef CONFIG_AP
  1530. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1531. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1532. data->disassoc_info.addr);
  1533. break;
  1534. }
  1535. #endif /* CONFIG_AP */
  1536. if (data) {
  1537. reason_code = data->disassoc_info.reason_code;
  1538. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1539. data->disassoc_info.ie,
  1540. data->disassoc_info.ie_len);
  1541. #ifdef CONFIG_P2P
  1542. wpas_p2p_disassoc_notif(
  1543. wpa_s, data->disassoc_info.addr, reason_code,
  1544. data->disassoc_info.ie,
  1545. data->disassoc_info.ie_len);
  1546. #endif /* CONFIG_P2P */
  1547. }
  1548. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1549. sme_event_disassoc(wpa_s, data);
  1550. /* fall through */
  1551. case EVENT_DEAUTH:
  1552. if (event == EVENT_DEAUTH) {
  1553. wpa_dbg(wpa_s, MSG_DEBUG,
  1554. "Deauthentication notification");
  1555. if (data) {
  1556. reason_code = data->deauth_info.reason_code;
  1557. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1558. data->deauth_info.reason_code);
  1559. if (data->deauth_info.addr) {
  1560. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1561. MACSTR,
  1562. MAC2STR(data->deauth_info.
  1563. addr));
  1564. }
  1565. wpa_hexdump(MSG_DEBUG,
  1566. "Deauthentication frame IE(s)",
  1567. data->deauth_info.ie,
  1568. data->deauth_info.ie_len);
  1569. #ifdef CONFIG_P2P
  1570. wpas_p2p_deauth_notif(
  1571. wpa_s, data->deauth_info.addr,
  1572. reason_code,
  1573. data->deauth_info.ie,
  1574. data->deauth_info.ie_len);
  1575. #endif /* CONFIG_P2P */
  1576. }
  1577. }
  1578. #ifdef CONFIG_AP
  1579. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1580. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1581. data->deauth_info.addr);
  1582. break;
  1583. }
  1584. #endif /* CONFIG_AP */
  1585. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1586. break;
  1587. case EVENT_MICHAEL_MIC_FAILURE:
  1588. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1589. break;
  1590. #ifndef CONFIG_NO_SCAN_PROCESSING
  1591. case EVENT_SCAN_RESULTS:
  1592. wpa_supplicant_event_scan_results(wpa_s, data);
  1593. break;
  1594. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1595. case EVENT_ASSOCINFO:
  1596. wpa_supplicant_event_associnfo(wpa_s, data);
  1597. break;
  1598. case EVENT_INTERFACE_STATUS:
  1599. wpa_supplicant_event_interface_status(wpa_s, data);
  1600. break;
  1601. case EVENT_PMKID_CANDIDATE:
  1602. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1603. break;
  1604. #ifdef CONFIG_PEERKEY
  1605. case EVENT_STKSTART:
  1606. wpa_supplicant_event_stkstart(wpa_s, data);
  1607. break;
  1608. #endif /* CONFIG_PEERKEY */
  1609. #ifdef CONFIG_TDLS
  1610. case EVENT_TDLS:
  1611. wpa_supplicant_event_tdls(wpa_s, data);
  1612. break;
  1613. #endif /* CONFIG_TDLS */
  1614. #ifdef CONFIG_IEEE80211R
  1615. case EVENT_FT_RESPONSE:
  1616. wpa_supplicant_event_ft_response(wpa_s, data);
  1617. break;
  1618. #endif /* CONFIG_IEEE80211R */
  1619. #ifdef CONFIG_IBSS_RSN
  1620. case EVENT_IBSS_RSN_START:
  1621. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1622. break;
  1623. #endif /* CONFIG_IBSS_RSN */
  1624. case EVENT_ASSOC_REJECT:
  1625. if (data->assoc_reject.bssid)
  1626. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1627. "bssid=" MACSTR " status_code=%u",
  1628. MAC2STR(data->assoc_reject.bssid),
  1629. data->assoc_reject.status_code);
  1630. else
  1631. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1632. "status_code=%u",
  1633. data->assoc_reject.status_code);
  1634. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1635. sme_event_assoc_reject(wpa_s, data);
  1636. break;
  1637. case EVENT_AUTH_TIMED_OUT:
  1638. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1639. sme_event_auth_timed_out(wpa_s, data);
  1640. break;
  1641. case EVENT_ASSOC_TIMED_OUT:
  1642. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1643. sme_event_assoc_timed_out(wpa_s, data);
  1644. break;
  1645. #ifdef CONFIG_AP
  1646. case EVENT_TX_STATUS:
  1647. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  1648. " type=%d stype=%d",
  1649. MAC2STR(data->tx_status.dst),
  1650. data->tx_status.type, data->tx_status.stype);
  1651. if (wpa_s->ap_iface == NULL) {
  1652. #ifdef CONFIG_P2P
  1653. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1654. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1655. wpas_send_action_tx_status(
  1656. wpa_s, data->tx_status.dst,
  1657. data->tx_status.data,
  1658. data->tx_status.data_len,
  1659. data->tx_status.ack ?
  1660. P2P_SEND_ACTION_SUCCESS :
  1661. P2P_SEND_ACTION_NO_ACK);
  1662. #endif /* CONFIG_P2P */
  1663. break;
  1664. }
  1665. #ifdef CONFIG_P2P
  1666. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  1667. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  1668. /*
  1669. * Catch TX status events for Action frames we sent via group
  1670. * interface in GO mode.
  1671. */
  1672. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1673. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1674. os_memcmp(wpa_s->parent->pending_action_dst,
  1675. data->tx_status.dst, ETH_ALEN) == 0) {
  1676. wpas_send_action_tx_status(
  1677. wpa_s->parent, data->tx_status.dst,
  1678. data->tx_status.data,
  1679. data->tx_status.data_len,
  1680. data->tx_status.ack ?
  1681. P2P_SEND_ACTION_SUCCESS :
  1682. P2P_SEND_ACTION_NO_ACK);
  1683. break;
  1684. }
  1685. #endif /* CONFIG_P2P */
  1686. switch (data->tx_status.type) {
  1687. case WLAN_FC_TYPE_MGMT:
  1688. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1689. data->tx_status.data_len,
  1690. data->tx_status.stype,
  1691. data->tx_status.ack);
  1692. break;
  1693. case WLAN_FC_TYPE_DATA:
  1694. ap_tx_status(wpa_s, data->tx_status.dst,
  1695. data->tx_status.data,
  1696. data->tx_status.data_len,
  1697. data->tx_status.ack);
  1698. break;
  1699. }
  1700. break;
  1701. case EVENT_RX_FROM_UNKNOWN:
  1702. if (wpa_s->ap_iface == NULL)
  1703. break;
  1704. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1705. data->rx_from_unknown.len);
  1706. break;
  1707. case EVENT_RX_MGMT:
  1708. if (wpa_s->ap_iface == NULL) {
  1709. #ifdef CONFIG_P2P
  1710. u16 fc, stype;
  1711. const struct ieee80211_mgmt *mgmt;
  1712. mgmt = (const struct ieee80211_mgmt *)
  1713. data->rx_mgmt.frame;
  1714. fc = le_to_host16(mgmt->frame_control);
  1715. stype = WLAN_FC_GET_STYPE(fc);
  1716. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  1717. data->rx_mgmt.frame_len > 24) {
  1718. const u8 *src = mgmt->sa;
  1719. const u8 *ie = mgmt->u.probe_req.variable;
  1720. size_t ie_len = data->rx_mgmt.frame_len -
  1721. (mgmt->u.probe_req.variable -
  1722. data->rx_mgmt.frame);
  1723. wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
  1724. break;
  1725. }
  1726. #endif /* CONFIG_P2P */
  1727. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  1728. "management frame in non-AP mode");
  1729. break;
  1730. }
  1731. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1732. break;
  1733. #endif /* CONFIG_AP */
  1734. case EVENT_RX_ACTION:
  1735. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1736. " Category=%u DataLen=%d freq=%d MHz",
  1737. MAC2STR(data->rx_action.sa),
  1738. data->rx_action.category, (int) data->rx_action.len,
  1739. data->rx_action.freq);
  1740. #ifdef CONFIG_IEEE80211R
  1741. if (data->rx_action.category == WLAN_ACTION_FT) {
  1742. ft_rx_action(wpa_s, data->rx_action.data,
  1743. data->rx_action.len);
  1744. break;
  1745. }
  1746. #endif /* CONFIG_IEEE80211R */
  1747. #ifdef CONFIG_IEEE80211W
  1748. #ifdef CONFIG_SME
  1749. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  1750. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  1751. data->rx_action.data,
  1752. data->rx_action.len);
  1753. break;
  1754. }
  1755. #endif /* CONFIG_SME */
  1756. #endif /* CONFIG_IEEE80211W */
  1757. #ifdef CONFIG_P2P
  1758. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  1759. data->rx_action.sa,
  1760. data->rx_action.bssid,
  1761. data->rx_action.category,
  1762. data->rx_action.data,
  1763. data->rx_action.len, data->rx_action.freq);
  1764. #endif /* CONFIG_P2P */
  1765. break;
  1766. case EVENT_RX_PROBE_REQ:
  1767. if (data->rx_probe_req.sa == NULL ||
  1768. data->rx_probe_req.ie == NULL)
  1769. break;
  1770. #ifdef CONFIG_AP
  1771. if (wpa_s->ap_iface) {
  1772. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  1773. data->rx_probe_req.sa,
  1774. data->rx_probe_req.ie,
  1775. data->rx_probe_req.ie_len);
  1776. break;
  1777. }
  1778. #endif /* CONFIG_AP */
  1779. #ifdef CONFIG_P2P
  1780. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  1781. data->rx_probe_req.ie,
  1782. data->rx_probe_req.ie_len);
  1783. #endif /* CONFIG_P2P */
  1784. break;
  1785. #ifdef CONFIG_P2P
  1786. case EVENT_REMAIN_ON_CHANNEL:
  1787. wpas_p2p_remain_on_channel_cb(
  1788. wpa_s, data->remain_on_channel.freq,
  1789. data->remain_on_channel.duration);
  1790. break;
  1791. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  1792. wpas_p2p_cancel_remain_on_channel_cb(
  1793. wpa_s, data->remain_on_channel.freq);
  1794. break;
  1795. case EVENT_P2P_DEV_FOUND: {
  1796. struct p2p_peer_info peer_info;
  1797. os_memset(&peer_info, 0, sizeof(peer_info));
  1798. if (data->p2p_dev_found.dev_addr)
  1799. os_memcpy(peer_info.p2p_device_addr,
  1800. data->p2p_dev_found.dev_addr, ETH_ALEN);
  1801. if (data->p2p_dev_found.pri_dev_type)
  1802. os_memcpy(peer_info.pri_dev_type,
  1803. data->p2p_dev_found.pri_dev_type,
  1804. sizeof(peer_info.pri_dev_type));
  1805. if (data->p2p_dev_found.dev_name)
  1806. os_strlcpy(peer_info.device_name,
  1807. data->p2p_dev_found.dev_name,
  1808. sizeof(peer_info.device_name));
  1809. peer_info.config_methods = data->p2p_dev_found.config_methods;
  1810. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  1811. peer_info.group_capab = data->p2p_dev_found.group_capab;
  1812. /*
  1813. * FIX: new_device=1 is not necessarily correct. We should
  1814. * maintain a P2P peer database in wpa_supplicant and update
  1815. * this information based on whether the peer is truly new.
  1816. */
  1817. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  1818. break;
  1819. }
  1820. case EVENT_P2P_GO_NEG_REQ_RX:
  1821. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  1822. data->p2p_go_neg_req_rx.dev_passwd_id);
  1823. break;
  1824. case EVENT_P2P_GO_NEG_COMPLETED:
  1825. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  1826. break;
  1827. case EVENT_P2P_PROV_DISC_REQUEST:
  1828. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  1829. data->p2p_prov_disc_req.config_methods,
  1830. data->p2p_prov_disc_req.dev_addr,
  1831. data->p2p_prov_disc_req.pri_dev_type,
  1832. data->p2p_prov_disc_req.dev_name,
  1833. data->p2p_prov_disc_req.supp_config_methods,
  1834. data->p2p_prov_disc_req.dev_capab,
  1835. data->p2p_prov_disc_req.group_capab);
  1836. break;
  1837. case EVENT_P2P_PROV_DISC_RESPONSE:
  1838. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  1839. data->p2p_prov_disc_resp.config_methods);
  1840. break;
  1841. case EVENT_P2P_SD_REQUEST:
  1842. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  1843. data->p2p_sd_req.sa,
  1844. data->p2p_sd_req.dialog_token,
  1845. data->p2p_sd_req.update_indic,
  1846. data->p2p_sd_req.tlvs,
  1847. data->p2p_sd_req.tlvs_len);
  1848. break;
  1849. case EVENT_P2P_SD_RESPONSE:
  1850. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  1851. data->p2p_sd_resp.update_indic,
  1852. data->p2p_sd_resp.tlvs,
  1853. data->p2p_sd_resp.tlvs_len);
  1854. break;
  1855. #endif /* CONFIG_P2P */
  1856. #ifdef CONFIG_CLIENT_MLME
  1857. case EVENT_MLME_RX: {
  1858. struct ieee80211_rx_status rx_status;
  1859. os_memset(&rx_status, 0, sizeof(rx_status));
  1860. rx_status.freq = data->mlme_rx.freq;
  1861. rx_status.channel = data->mlme_rx.channel;
  1862. rx_status.ssi = data->mlme_rx.ssi;
  1863. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1864. &rx_status);
  1865. break;
  1866. }
  1867. #endif /* CONFIG_CLIENT_MLME */
  1868. case EVENT_EAPOL_RX:
  1869. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1870. data->eapol_rx.data,
  1871. data->eapol_rx.data_len);
  1872. break;
  1873. case EVENT_SIGNAL_CHANGE:
  1874. bgscan_notify_signal_change(
  1875. wpa_s, data->signal_change.above_threshold,
  1876. data->signal_change.current_signal,
  1877. data->signal_change.current_noise,
  1878. data->signal_change.current_txrate);
  1879. break;
  1880. case EVENT_INTERFACE_ENABLED:
  1881. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  1882. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1883. #ifdef CONFIG_AP
  1884. if (!wpa_s->ap_iface) {
  1885. wpa_supplicant_set_state(wpa_s,
  1886. WPA_DISCONNECTED);
  1887. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1888. } else
  1889. wpa_supplicant_set_state(wpa_s,
  1890. WPA_COMPLETED);
  1891. #else /* CONFIG_AP */
  1892. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1893. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1894. #endif /* CONFIG_AP */
  1895. }
  1896. break;
  1897. case EVENT_INTERFACE_DISABLED:
  1898. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  1899. wpa_supplicant_mark_disassoc(wpa_s);
  1900. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1901. break;
  1902. case EVENT_CHANNEL_LIST_CHANGED:
  1903. if (wpa_s->drv_priv == NULL)
  1904. break; /* Ignore event during drv initialization */
  1905. #ifdef CONFIG_P2P
  1906. wpas_p2p_update_channel_list(wpa_s);
  1907. #endif /* CONFIG_P2P */
  1908. break;
  1909. case EVENT_INTERFACE_UNAVAILABLE:
  1910. #ifdef CONFIG_P2P
  1911. wpas_p2p_interface_unavailable(wpa_s);
  1912. #endif /* CONFIG_P2P */
  1913. break;
  1914. case EVENT_BEST_CHANNEL:
  1915. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  1916. "(%d %d %d)",
  1917. data->best_chan.freq_24, data->best_chan.freq_5,
  1918. data->best_chan.freq_overall);
  1919. wpa_s->best_24_freq = data->best_chan.freq_24;
  1920. wpa_s->best_5_freq = data->best_chan.freq_5;
  1921. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  1922. #ifdef CONFIG_P2P
  1923. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  1924. data->best_chan.freq_5,
  1925. data->best_chan.freq_overall);
  1926. #endif /* CONFIG_P2P */
  1927. break;
  1928. case EVENT_UNPROT_DEAUTH:
  1929. wpa_supplicant_event_unprot_deauth(wpa_s,
  1930. &data->unprot_deauth);
  1931. break;
  1932. case EVENT_UNPROT_DISASSOC:
  1933. wpa_supplicant_event_unprot_disassoc(wpa_s,
  1934. &data->unprot_disassoc);
  1935. break;
  1936. case EVENT_STATION_LOW_ACK:
  1937. #ifdef CONFIG_AP
  1938. if (wpa_s->ap_iface && data)
  1939. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  1940. data->low_ack.addr);
  1941. #endif /* CONFIG_AP */
  1942. break;
  1943. case EVENT_IBSS_PEER_LOST:
  1944. #ifdef CONFIG_IBSS_RSN
  1945. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  1946. #endif /* CONFIG_IBSS_RSN */
  1947. break;
  1948. default:
  1949. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  1950. break;
  1951. }
  1952. }