events.c 59 KB

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