events.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193
  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. #ifdef CONFIG_TDLS
  865. wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies,
  866. data->assoc_info.resp_ies_len);
  867. #endif /* CONFIG_TDLS */
  868. }
  869. if (data->assoc_info.beacon_ies)
  870. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  871. data->assoc_info.beacon_ies,
  872. data->assoc_info.beacon_ies_len);
  873. if (data->assoc_info.freq)
  874. wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz",
  875. data->assoc_info.freq);
  876. p = data->assoc_info.req_ies;
  877. l = data->assoc_info.req_ies_len;
  878. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  879. while (p && l >= 2) {
  880. len = p[1] + 2;
  881. if (len > l) {
  882. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  883. p, l);
  884. break;
  885. }
  886. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  887. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  888. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  889. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  890. break;
  891. found = 1;
  892. wpa_find_assoc_pmkid(wpa_s);
  893. break;
  894. }
  895. l -= len;
  896. p += len;
  897. }
  898. if (!found && data->assoc_info.req_ies)
  899. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  900. #ifdef CONFIG_IEEE80211R
  901. #ifdef CONFIG_SME
  902. if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) {
  903. u8 bssid[ETH_ALEN];
  904. if (wpa_drv_get_bssid(wpa_s, bssid) < 0 ||
  905. wpa_ft_validate_reassoc_resp(wpa_s->wpa,
  906. data->assoc_info.resp_ies,
  907. data->assoc_info.resp_ies_len,
  908. bssid) < 0) {
  909. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of "
  910. "Reassociation Response failed");
  911. wpa_supplicant_deauthenticate(
  912. wpa_s, WLAN_REASON_INVALID_IE);
  913. return -1;
  914. }
  915. }
  916. p = data->assoc_info.resp_ies;
  917. l = data->assoc_info.resp_ies_len;
  918. #ifdef CONFIG_WPS_STRICT
  919. if (wpa_s->current_ssid &&
  920. wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) {
  921. struct wpabuf *wps;
  922. wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE);
  923. if (wps == NULL) {
  924. wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not "
  925. "include WPS IE in (Re)Association Response");
  926. return -1;
  927. }
  928. if (wps_validate_assoc_resp(wps) < 0) {
  929. wpabuf_free(wps);
  930. wpa_supplicant_deauthenticate(
  931. wpa_s, WLAN_REASON_INVALID_IE);
  932. return -1;
  933. }
  934. wpabuf_free(wps);
  935. }
  936. #endif /* CONFIG_WPS_STRICT */
  937. /* Go through the IEs and make a copy of the MDIE, if present. */
  938. while (p && l >= 2) {
  939. len = p[1] + 2;
  940. if (len > l) {
  941. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  942. p, l);
  943. break;
  944. }
  945. if (p[0] == WLAN_EID_MOBILITY_DOMAIN &&
  946. p[1] >= MOBILITY_DOMAIN_ID_LEN) {
  947. wpa_s->sme.ft_used = 1;
  948. os_memcpy(wpa_s->sme.mobility_domain, p + 2,
  949. MOBILITY_DOMAIN_ID_LEN);
  950. break;
  951. }
  952. l -= len;
  953. p += len;
  954. }
  955. #endif /* CONFIG_SME */
  956. wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies,
  957. data->assoc_info.resp_ies_len);
  958. #endif /* CONFIG_IEEE80211R */
  959. /* WPA/RSN IE from Beacon/ProbeResp */
  960. p = data->assoc_info.beacon_ies;
  961. l = data->assoc_info.beacon_ies_len;
  962. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  963. */
  964. wpa_found = rsn_found = 0;
  965. while (p && l >= 2) {
  966. len = p[1] + 2;
  967. if (len > l) {
  968. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  969. p, l);
  970. break;
  971. }
  972. if (!wpa_found &&
  973. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  974. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  975. wpa_found = 1;
  976. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  977. }
  978. if (!rsn_found &&
  979. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  980. rsn_found = 1;
  981. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  982. }
  983. l -= len;
  984. p += len;
  985. }
  986. if (!wpa_found && data->assoc_info.beacon_ies)
  987. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  988. if (!rsn_found && data->assoc_info.beacon_ies)
  989. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  990. if (wpa_found || rsn_found)
  991. wpa_s->ap_ies_from_associnfo = 1;
  992. wpa_s->assoc_freq = data->assoc_info.freq;
  993. return 0;
  994. }
  995. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  996. union wpa_event_data *data)
  997. {
  998. u8 bssid[ETH_ALEN];
  999. int ft_completed;
  1000. int bssid_changed;
  1001. struct wpa_driver_capa capa;
  1002. #ifdef CONFIG_AP
  1003. if (wpa_s->ap_iface) {
  1004. hostapd_notif_assoc(wpa_s->ap_iface->bss[0],
  1005. data->assoc_info.addr,
  1006. data->assoc_info.req_ies,
  1007. data->assoc_info.req_ies_len,
  1008. data->assoc_info.reassoc);
  1009. return;
  1010. }
  1011. #endif /* CONFIG_AP */
  1012. ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  1013. if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0)
  1014. return;
  1015. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  1016. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  1017. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  1018. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  1019. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  1020. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  1021. wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  1022. MACSTR, MAC2STR(bssid));
  1023. random_add_randomness(bssid, ETH_ALEN);
  1024. bssid_changed = os_memcmp(wpa_s->bssid, bssid, ETH_ALEN);
  1025. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  1026. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  1027. if (bssid_changed)
  1028. wpas_notify_bssid_changed(wpa_s);
  1029. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  1030. wpa_clear_keys(wpa_s, bssid);
  1031. }
  1032. if (wpa_supplicant_select_config(wpa_s) < 0) {
  1033. wpa_supplicant_disassociate(
  1034. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1035. return;
  1036. }
  1037. if (wpa_s->current_ssid) {
  1038. struct wpa_bss *bss = NULL;
  1039. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1040. if (ssid->ssid_len > 0)
  1041. bss = wpa_bss_get(wpa_s, bssid,
  1042. ssid->ssid, ssid->ssid_len);
  1043. if (!bss)
  1044. bss = wpa_bss_get_bssid(wpa_s, bssid);
  1045. if (bss)
  1046. wpa_s->current_bss = bss;
  1047. }
  1048. }
  1049. #ifdef CONFIG_SME
  1050. os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN);
  1051. wpa_s->sme.prev_bssid_set = 1;
  1052. #endif /* CONFIG_SME */
  1053. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  1054. if (wpa_s->current_ssid) {
  1055. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  1056. * initialized before association, but for other modes,
  1057. * initialize PC/SC here, if the current configuration needs
  1058. * smartcard or SIM/USIM. */
  1059. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  1060. }
  1061. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  1062. if (wpa_s->l2)
  1063. l2_packet_notify_auth_start(wpa_s->l2);
  1064. /*
  1065. * Set portEnabled first to FALSE in order to get EAP state machine out
  1066. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  1067. * state machine may transit to AUTHENTICATING state based on obsolete
  1068. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  1069. * AUTHENTICATED without ever giving chance to EAP state machine to
  1070. * reset the state.
  1071. */
  1072. if (!ft_completed) {
  1073. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  1074. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  1075. }
  1076. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  1077. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  1078. /* 802.1X::portControl = Auto */
  1079. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  1080. wpa_s->eapol_received = 0;
  1081. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1082. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE ||
  1083. (wpa_s->current_ssid &&
  1084. wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) {
  1085. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1086. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1087. } else if (!ft_completed) {
  1088. /* Timeout for receiving the first EAPOL packet */
  1089. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  1090. }
  1091. wpa_supplicant_cancel_scan(wpa_s);
  1092. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1093. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1094. /*
  1095. * We are done; the driver will take care of RSN 4-way
  1096. * handshake.
  1097. */
  1098. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1099. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1100. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1101. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1102. } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  1103. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1104. /*
  1105. * The driver will take care of RSN 4-way handshake, so we need
  1106. * to allow EAPOL supplicant to complete its work without
  1107. * waiting for WPA supplicant.
  1108. */
  1109. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1110. } else if (ft_completed) {
  1111. /*
  1112. * FT protocol completed - make sure EAPOL state machine ends
  1113. * up in authenticated.
  1114. */
  1115. wpa_supplicant_cancel_auth_timeout(wpa_s);
  1116. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  1117. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  1118. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  1119. }
  1120. if (wpa_s->pending_eapol_rx) {
  1121. struct os_time now, age;
  1122. os_get_time(&now);
  1123. os_time_sub(&now, &wpa_s->pending_eapol_rx_time, &age);
  1124. if (age.sec == 0 && age.usec < 100000 &&
  1125. os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) ==
  1126. 0) {
  1127. wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL "
  1128. "frame that was received just before "
  1129. "association notification");
  1130. wpa_supplicant_rx_eapol(
  1131. wpa_s, wpa_s->pending_eapol_rx_src,
  1132. wpabuf_head(wpa_s->pending_eapol_rx),
  1133. wpabuf_len(wpa_s->pending_eapol_rx));
  1134. }
  1135. wpabuf_free(wpa_s->pending_eapol_rx);
  1136. wpa_s->pending_eapol_rx = NULL;
  1137. }
  1138. #ifdef CONFIG_BGSCAN
  1139. if (wpa_s->current_ssid != wpa_s->bgscan_ssid) {
  1140. bgscan_deinit(wpa_s);
  1141. if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) {
  1142. if (bgscan_init(wpa_s, wpa_s->current_ssid)) {
  1143. wpa_dbg(wpa_s, MSG_DEBUG, "Failed to "
  1144. "initialize bgscan");
  1145. /*
  1146. * Live without bgscan; it is only used as a
  1147. * roaming optimization, so the initial
  1148. * connection is not affected.
  1149. */
  1150. } else
  1151. wpa_s->bgscan_ssid = wpa_s->current_ssid;
  1152. } else
  1153. wpa_s->bgscan_ssid = NULL;
  1154. }
  1155. #endif /* CONFIG_BGSCAN */
  1156. if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  1157. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  1158. wpa_s->current_ssid && wpa_drv_get_capa(wpa_s, &capa) == 0 &&
  1159. capa.flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE) {
  1160. /* Set static WEP keys again */
  1161. wpa_set_wep_keys(wpa_s, wpa_s->current_ssid);
  1162. }
  1163. #ifdef CONFIG_IBSS_RSN
  1164. if (wpa_s->current_ssid &&
  1165. wpa_s->current_ssid->mode == WPAS_MODE_IBSS &&
  1166. wpa_s->key_mgmt != WPA_KEY_MGMT_NONE &&
  1167. wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE)
  1168. ibss_rsn_connected(wpa_s->ibss_rsn);
  1169. #endif /* CONFIG_IBSS_RSN */
  1170. }
  1171. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s,
  1172. u16 reason_code)
  1173. {
  1174. const u8 *bssid;
  1175. int authenticating;
  1176. u8 prev_pending_bssid[ETH_ALEN];
  1177. authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING;
  1178. os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN);
  1179. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  1180. /*
  1181. * At least Host AP driver and a Prism3 card seemed to be
  1182. * generating streams of disconnected events when configuring
  1183. * IBSS for WPA-None. Ignore them for now.
  1184. */
  1185. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in "
  1186. "IBSS/WPA-None mode");
  1187. return;
  1188. }
  1189. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  1190. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  1191. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  1192. "pre-shared key may be incorrect");
  1193. }
  1194. if (!wpa_s->auto_reconnect_disabled ||
  1195. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) {
  1196. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect enabled: try to "
  1197. "reconnect (wps=%d)",
  1198. wpa_s->key_mgmt == WPA_KEY_MGMT_WPS);
  1199. if (wpa_s->wpa_state >= WPA_ASSOCIATING)
  1200. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  1201. } else {
  1202. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Auto connect disabled: do not "
  1203. "try to re-connect");
  1204. wpa_s->reassociate = 0;
  1205. wpa_s->disconnected = 1;
  1206. }
  1207. bssid = wpa_s->bssid;
  1208. if (is_zero_ether_addr(bssid))
  1209. bssid = wpa_s->pending_bssid;
  1210. wpas_connection_failed(wpa_s, bssid);
  1211. wpa_sm_notify_disassoc(wpa_s->wpa);
  1212. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
  1213. " reason=%d",
  1214. MAC2STR(bssid), reason_code);
  1215. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  1216. wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys");
  1217. wpa_s->keys_cleared = 0;
  1218. wpa_clear_keys(wpa_s, wpa_s->bssid);
  1219. }
  1220. wpa_supplicant_mark_disassoc(wpa_s);
  1221. bgscan_deinit(wpa_s);
  1222. wpa_s->bgscan_ssid = NULL;
  1223. if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1224. sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid);
  1225. }
  1226. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1227. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  1228. void *sock_ctx)
  1229. {
  1230. struct wpa_supplicant *wpa_s = eloop_ctx;
  1231. if (!wpa_s->pending_mic_error_report)
  1232. return;
  1233. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report");
  1234. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  1235. wpa_s->pending_mic_error_report = 0;
  1236. }
  1237. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1238. static void
  1239. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  1240. union wpa_event_data *data)
  1241. {
  1242. int pairwise;
  1243. struct os_time t;
  1244. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  1245. pairwise = (data && data->michael_mic_failure.unicast);
  1246. os_get_time(&t);
  1247. if ((wpa_s->last_michael_mic_error &&
  1248. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  1249. wpa_s->pending_mic_error_report) {
  1250. if (wpa_s->pending_mic_error_report) {
  1251. /*
  1252. * Send the pending MIC error report immediately since
  1253. * we are going to start countermeasures and AP better
  1254. * do the same.
  1255. */
  1256. wpa_sm_key_request(wpa_s->wpa, 1,
  1257. wpa_s->pending_mic_error_pairwise);
  1258. }
  1259. /* Send the new MIC error report immediately since we are going
  1260. * to start countermeasures and AP better do the same.
  1261. */
  1262. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1263. /* initialize countermeasures */
  1264. wpa_s->countermeasures = 1;
  1265. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  1266. /*
  1267. * Need to wait for completion of request frame. We do not get
  1268. * any callback for the message completion, so just wait a
  1269. * short while and hope for the best. */
  1270. os_sleep(0, 10000);
  1271. wpa_drv_set_countermeasures(wpa_s, 1);
  1272. wpa_supplicant_deauthenticate(wpa_s,
  1273. WLAN_REASON_MICHAEL_MIC_FAILURE);
  1274. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  1275. wpa_s, NULL);
  1276. eloop_register_timeout(60, 0,
  1277. wpa_supplicant_stop_countermeasures,
  1278. wpa_s, NULL);
  1279. /* TODO: mark the AP rejected for 60 second. STA is
  1280. * allowed to associate with another AP.. */
  1281. } else {
  1282. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  1283. if (wpa_s->mic_errors_seen) {
  1284. /*
  1285. * Reduce the effectiveness of Michael MIC error
  1286. * reports as a means for attacking against TKIP if
  1287. * more than one MIC failure is noticed with the same
  1288. * PTK. We delay the transmission of the reports by a
  1289. * random time between 0 and 60 seconds in order to
  1290. * force the attacker wait 60 seconds before getting
  1291. * the information on whether a frame resulted in a MIC
  1292. * failure.
  1293. */
  1294. u8 rval[4];
  1295. int sec;
  1296. if (os_get_random(rval, sizeof(rval)) < 0)
  1297. sec = os_random() % 60;
  1298. else
  1299. sec = WPA_GET_BE32(rval) % 60;
  1300. wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error "
  1301. "report %d seconds", sec);
  1302. wpa_s->pending_mic_error_report = 1;
  1303. wpa_s->pending_mic_error_pairwise = pairwise;
  1304. eloop_cancel_timeout(
  1305. wpa_supplicant_delayed_mic_error_report,
  1306. wpa_s, NULL);
  1307. eloop_register_timeout(
  1308. sec, os_random() % 1000000,
  1309. wpa_supplicant_delayed_mic_error_report,
  1310. wpa_s, NULL);
  1311. } else {
  1312. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1313. }
  1314. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1315. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  1316. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  1317. }
  1318. wpa_s->last_michael_mic_error = t.sec;
  1319. wpa_s->mic_errors_seen++;
  1320. }
  1321. #ifdef CONFIG_TERMINATE_ONLASTIF
  1322. static int any_interfaces(struct wpa_supplicant *head)
  1323. {
  1324. struct wpa_supplicant *wpa_s;
  1325. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  1326. if (!wpa_s->interface_removed)
  1327. return 1;
  1328. return 0;
  1329. }
  1330. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1331. static void
  1332. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  1333. union wpa_event_data *data)
  1334. {
  1335. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  1336. return;
  1337. switch (data->interface_status.ievent) {
  1338. case EVENT_INTERFACE_ADDED:
  1339. if (!wpa_s->interface_removed)
  1340. break;
  1341. wpa_s->interface_removed = 0;
  1342. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added");
  1343. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  1344. wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the "
  1345. "driver after interface was added");
  1346. }
  1347. break;
  1348. case EVENT_INTERFACE_REMOVED:
  1349. wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed");
  1350. wpa_s->interface_removed = 1;
  1351. wpa_supplicant_mark_disassoc(wpa_s);
  1352. l2_packet_deinit(wpa_s->l2);
  1353. wpa_s->l2 = NULL;
  1354. #ifdef CONFIG_IBSS_RSN
  1355. ibss_rsn_stop(wpa_s->ibss_rsn, NULL);
  1356. #endif /* CONFIG_IBSS_RSN */
  1357. #ifdef CONFIG_TERMINATE_ONLASTIF
  1358. /* check if last interface */
  1359. if (!any_interfaces(wpa_s->global->ifaces))
  1360. eloop_terminate();
  1361. #endif /* CONFIG_TERMINATE_ONLASTIF */
  1362. break;
  1363. }
  1364. }
  1365. #ifdef CONFIG_PEERKEY
  1366. static void
  1367. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  1368. union wpa_event_data *data)
  1369. {
  1370. if (data == NULL)
  1371. return;
  1372. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  1373. }
  1374. #endif /* CONFIG_PEERKEY */
  1375. #ifdef CONFIG_TDLS
  1376. static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s,
  1377. union wpa_event_data *data)
  1378. {
  1379. if (data == NULL)
  1380. return;
  1381. switch (data->tdls.oper) {
  1382. case TDLS_REQUEST_SETUP:
  1383. wpa_tdls_start(wpa_s->wpa, data->tdls.peer);
  1384. break;
  1385. case TDLS_REQUEST_TEARDOWN:
  1386. /* request from driver to add FTIE */
  1387. wpa_tdls_recv_teardown_notify(wpa_s->wpa, data->tdls.peer,
  1388. data->tdls.reason_code);
  1389. break;
  1390. }
  1391. }
  1392. #endif /* CONFIG_TDLS */
  1393. #ifdef CONFIG_IEEE80211R
  1394. static void
  1395. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  1396. union wpa_event_data *data)
  1397. {
  1398. if (data == NULL)
  1399. return;
  1400. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  1401. data->ft_ies.ies_len,
  1402. data->ft_ies.ft_action,
  1403. data->ft_ies.target_ap,
  1404. data->ft_ies.ric_ies,
  1405. data->ft_ies.ric_ies_len) < 0) {
  1406. /* TODO: prevent MLME/driver from trying to associate? */
  1407. }
  1408. }
  1409. #endif /* CONFIG_IEEE80211R */
  1410. #ifdef CONFIG_IBSS_RSN
  1411. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1412. union wpa_event_data *data)
  1413. {
  1414. struct wpa_ssid *ssid;
  1415. if (wpa_s->wpa_state < WPA_ASSOCIATED)
  1416. return;
  1417. if (data == NULL)
  1418. return;
  1419. ssid = wpa_s->current_ssid;
  1420. if (ssid == NULL)
  1421. return;
  1422. if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt))
  1423. return;
  1424. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1425. }
  1426. #endif /* CONFIG_IBSS_RSN */
  1427. #ifdef CONFIG_IEEE80211R
  1428. static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data,
  1429. size_t len)
  1430. {
  1431. const u8 *sta_addr, *target_ap_addr;
  1432. u16 status;
  1433. wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len);
  1434. if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
  1435. return; /* only SME case supported for now */
  1436. if (len < 1 + 2 * ETH_ALEN + 2)
  1437. return;
  1438. if (data[0] != 2)
  1439. return; /* Only FT Action Response is supported for now */
  1440. sta_addr = data + 1;
  1441. target_ap_addr = data + 1 + ETH_ALEN;
  1442. status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN);
  1443. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA "
  1444. MACSTR " TargetAP " MACSTR " status %u",
  1445. MAC2STR(sta_addr), MAC2STR(target_ap_addr), status);
  1446. if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) {
  1447. wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR
  1448. " in FT Action Response", MAC2STR(sta_addr));
  1449. return;
  1450. }
  1451. if (status) {
  1452. wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates "
  1453. "failure (status code %d)", status);
  1454. /* TODO: report error to FT code(?) */
  1455. return;
  1456. }
  1457. if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2,
  1458. len - (1 + 2 * ETH_ALEN + 2), 1,
  1459. target_ap_addr, NULL, 0) < 0)
  1460. return;
  1461. #ifdef CONFIG_SME
  1462. {
  1463. struct wpa_bss *bss;
  1464. bss = wpa_bss_get_bssid(wpa_s, target_ap_addr);
  1465. if (bss)
  1466. wpa_s->sme.freq = bss->freq;
  1467. wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT;
  1468. sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr,
  1469. WLAN_AUTH_FT);
  1470. }
  1471. #endif /* CONFIG_SME */
  1472. }
  1473. #endif /* CONFIG_IEEE80211R */
  1474. static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s,
  1475. struct unprot_deauth *e)
  1476. {
  1477. #ifdef CONFIG_IEEE80211W
  1478. wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame "
  1479. "dropped: " MACSTR " -> " MACSTR
  1480. " (reason code %u)",
  1481. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1482. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1483. #endif /* CONFIG_IEEE80211W */
  1484. }
  1485. static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s,
  1486. struct unprot_disassoc *e)
  1487. {
  1488. #ifdef CONFIG_IEEE80211W
  1489. wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame "
  1490. "dropped: " MACSTR " -> " MACSTR
  1491. " (reason code %u)",
  1492. MAC2STR(e->sa), MAC2STR(e->da), e->reason_code);
  1493. sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code);
  1494. #endif /* CONFIG_IEEE80211W */
  1495. }
  1496. void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
  1497. union wpa_event_data *data)
  1498. {
  1499. struct wpa_supplicant *wpa_s = ctx;
  1500. u16 reason_code = 0;
  1501. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED &&
  1502. event != EVENT_INTERFACE_ENABLED &&
  1503. event != EVENT_INTERFACE_STATUS) {
  1504. wpa_dbg(wpa_s, MSG_DEBUG, "Ignore event %d while interface is "
  1505. "disabled", event);
  1506. return;
  1507. }
  1508. wpa_dbg(wpa_s, MSG_DEBUG, "Event %d received on interface %s",
  1509. event, wpa_s->ifname);
  1510. switch (event) {
  1511. case EVENT_AUTH:
  1512. sme_event_auth(wpa_s, data);
  1513. break;
  1514. case EVENT_ASSOC:
  1515. wpa_supplicant_event_assoc(wpa_s, data);
  1516. break;
  1517. case EVENT_DISASSOC:
  1518. wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification");
  1519. if (data) {
  1520. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1521. data->disassoc_info.reason_code);
  1522. if (data->disassoc_info.addr)
  1523. wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR,
  1524. MAC2STR(data->disassoc_info.addr));
  1525. }
  1526. #ifdef CONFIG_AP
  1527. if (wpa_s->ap_iface && data && data->disassoc_info.addr) {
  1528. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1529. data->disassoc_info.addr);
  1530. break;
  1531. }
  1532. #endif /* CONFIG_AP */
  1533. if (data) {
  1534. reason_code = data->disassoc_info.reason_code;
  1535. wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)",
  1536. data->disassoc_info.ie,
  1537. data->disassoc_info.ie_len);
  1538. #ifdef CONFIG_P2P
  1539. wpas_p2p_disassoc_notif(
  1540. wpa_s, data->disassoc_info.addr, reason_code,
  1541. data->disassoc_info.ie,
  1542. data->disassoc_info.ie_len);
  1543. #endif /* CONFIG_P2P */
  1544. }
  1545. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1546. sme_event_disassoc(wpa_s, data);
  1547. /* fall through */
  1548. case EVENT_DEAUTH:
  1549. if (event == EVENT_DEAUTH) {
  1550. wpa_dbg(wpa_s, MSG_DEBUG,
  1551. "Deauthentication notification");
  1552. if (data) {
  1553. reason_code = data->deauth_info.reason_code;
  1554. wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u",
  1555. data->deauth_info.reason_code);
  1556. if (data->deauth_info.addr) {
  1557. wpa_dbg(wpa_s, MSG_DEBUG, " * address "
  1558. MACSTR,
  1559. MAC2STR(data->deauth_info.
  1560. addr));
  1561. }
  1562. wpa_hexdump(MSG_DEBUG,
  1563. "Deauthentication frame IE(s)",
  1564. data->deauth_info.ie,
  1565. data->deauth_info.ie_len);
  1566. #ifdef CONFIG_P2P
  1567. wpas_p2p_deauth_notif(
  1568. wpa_s, data->deauth_info.addr,
  1569. reason_code,
  1570. data->deauth_info.ie,
  1571. data->deauth_info.ie_len);
  1572. #endif /* CONFIG_P2P */
  1573. }
  1574. }
  1575. #ifdef CONFIG_AP
  1576. if (wpa_s->ap_iface && data && data->deauth_info.addr) {
  1577. hostapd_notif_disassoc(wpa_s->ap_iface->bss[0],
  1578. data->deauth_info.addr);
  1579. break;
  1580. }
  1581. #endif /* CONFIG_AP */
  1582. wpa_supplicant_event_disassoc(wpa_s, reason_code);
  1583. break;
  1584. case EVENT_MICHAEL_MIC_FAILURE:
  1585. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1586. break;
  1587. #ifndef CONFIG_NO_SCAN_PROCESSING
  1588. case EVENT_SCAN_RESULTS:
  1589. wpa_supplicant_event_scan_results(wpa_s, data);
  1590. break;
  1591. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1592. case EVENT_ASSOCINFO:
  1593. wpa_supplicant_event_associnfo(wpa_s, data);
  1594. break;
  1595. case EVENT_INTERFACE_STATUS:
  1596. wpa_supplicant_event_interface_status(wpa_s, data);
  1597. break;
  1598. case EVENT_PMKID_CANDIDATE:
  1599. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1600. break;
  1601. #ifdef CONFIG_PEERKEY
  1602. case EVENT_STKSTART:
  1603. wpa_supplicant_event_stkstart(wpa_s, data);
  1604. break;
  1605. #endif /* CONFIG_PEERKEY */
  1606. #ifdef CONFIG_TDLS
  1607. case EVENT_TDLS:
  1608. wpa_supplicant_event_tdls(wpa_s, data);
  1609. break;
  1610. #endif /* CONFIG_TDLS */
  1611. #ifdef CONFIG_IEEE80211R
  1612. case EVENT_FT_RESPONSE:
  1613. wpa_supplicant_event_ft_response(wpa_s, data);
  1614. break;
  1615. #endif /* CONFIG_IEEE80211R */
  1616. #ifdef CONFIG_IBSS_RSN
  1617. case EVENT_IBSS_RSN_START:
  1618. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1619. break;
  1620. #endif /* CONFIG_IBSS_RSN */
  1621. case EVENT_ASSOC_REJECT:
  1622. if (data->assoc_reject.bssid)
  1623. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1624. "bssid=" MACSTR " status_code=%u",
  1625. MAC2STR(data->assoc_reject.bssid),
  1626. data->assoc_reject.status_code);
  1627. else
  1628. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT
  1629. "status_code=%u",
  1630. data->assoc_reject.status_code);
  1631. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1632. sme_event_assoc_reject(wpa_s, data);
  1633. break;
  1634. case EVENT_AUTH_TIMED_OUT:
  1635. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1636. sme_event_auth_timed_out(wpa_s, data);
  1637. break;
  1638. case EVENT_ASSOC_TIMED_OUT:
  1639. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
  1640. sme_event_assoc_timed_out(wpa_s, data);
  1641. break;
  1642. #ifdef CONFIG_AP
  1643. case EVENT_TX_STATUS:
  1644. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR
  1645. " type=%d stype=%d",
  1646. MAC2STR(data->tx_status.dst),
  1647. data->tx_status.type, data->tx_status.stype);
  1648. if (wpa_s->ap_iface == NULL) {
  1649. #ifdef CONFIG_P2P
  1650. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1651. data->tx_status.stype == WLAN_FC_STYPE_ACTION)
  1652. wpas_send_action_tx_status(
  1653. wpa_s, data->tx_status.dst,
  1654. data->tx_status.data,
  1655. data->tx_status.data_len,
  1656. data->tx_status.ack ?
  1657. P2P_SEND_ACTION_SUCCESS :
  1658. P2P_SEND_ACTION_NO_ACK);
  1659. #endif /* CONFIG_P2P */
  1660. break;
  1661. }
  1662. #ifdef CONFIG_P2P
  1663. wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst="
  1664. MACSTR, MAC2STR(wpa_s->parent->pending_action_dst));
  1665. /*
  1666. * Catch TX status events for Action frames we sent via group
  1667. * interface in GO mode.
  1668. */
  1669. if (data->tx_status.type == WLAN_FC_TYPE_MGMT &&
  1670. data->tx_status.stype == WLAN_FC_STYPE_ACTION &&
  1671. os_memcmp(wpa_s->parent->pending_action_dst,
  1672. data->tx_status.dst, ETH_ALEN) == 0) {
  1673. wpas_send_action_tx_status(
  1674. wpa_s->parent, data->tx_status.dst,
  1675. data->tx_status.data,
  1676. data->tx_status.data_len,
  1677. data->tx_status.ack ?
  1678. P2P_SEND_ACTION_SUCCESS :
  1679. P2P_SEND_ACTION_NO_ACK);
  1680. break;
  1681. }
  1682. #endif /* CONFIG_P2P */
  1683. switch (data->tx_status.type) {
  1684. case WLAN_FC_TYPE_MGMT:
  1685. ap_mgmt_tx_cb(wpa_s, data->tx_status.data,
  1686. data->tx_status.data_len,
  1687. data->tx_status.stype,
  1688. data->tx_status.ack);
  1689. break;
  1690. case WLAN_FC_TYPE_DATA:
  1691. ap_tx_status(wpa_s, data->tx_status.dst,
  1692. data->tx_status.data,
  1693. data->tx_status.data_len,
  1694. data->tx_status.ack);
  1695. break;
  1696. }
  1697. break;
  1698. case EVENT_RX_FROM_UNKNOWN:
  1699. if (wpa_s->ap_iface == NULL)
  1700. break;
  1701. ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.frame,
  1702. data->rx_from_unknown.len);
  1703. break;
  1704. case EVENT_RX_MGMT:
  1705. if (wpa_s->ap_iface == NULL) {
  1706. #ifdef CONFIG_P2P
  1707. u16 fc, stype;
  1708. const struct ieee80211_mgmt *mgmt;
  1709. mgmt = (const struct ieee80211_mgmt *)
  1710. data->rx_mgmt.frame;
  1711. fc = le_to_host16(mgmt->frame_control);
  1712. stype = WLAN_FC_GET_STYPE(fc);
  1713. if (stype == WLAN_FC_STYPE_PROBE_REQ &&
  1714. data->rx_mgmt.frame_len > 24) {
  1715. const u8 *src = mgmt->sa;
  1716. const u8 *ie = mgmt->u.probe_req.variable;
  1717. size_t ie_len = data->rx_mgmt.frame_len -
  1718. (mgmt->u.probe_req.variable -
  1719. data->rx_mgmt.frame);
  1720. wpas_p2p_probe_req_rx(wpa_s, src, ie, ie_len);
  1721. break;
  1722. }
  1723. #endif /* CONFIG_P2P */
  1724. wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received "
  1725. "management frame in non-AP mode");
  1726. break;
  1727. }
  1728. ap_mgmt_rx(wpa_s, &data->rx_mgmt);
  1729. break;
  1730. #endif /* CONFIG_AP */
  1731. case EVENT_RX_ACTION:
  1732. wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR
  1733. " Category=%u DataLen=%d freq=%d MHz",
  1734. MAC2STR(data->rx_action.sa),
  1735. data->rx_action.category, (int) data->rx_action.len,
  1736. data->rx_action.freq);
  1737. #ifdef CONFIG_IEEE80211R
  1738. if (data->rx_action.category == WLAN_ACTION_FT) {
  1739. ft_rx_action(wpa_s, data->rx_action.data,
  1740. data->rx_action.len);
  1741. break;
  1742. }
  1743. #endif /* CONFIG_IEEE80211R */
  1744. #ifdef CONFIG_IEEE80211W
  1745. #ifdef CONFIG_SME
  1746. if (data->rx_action.category == WLAN_ACTION_SA_QUERY) {
  1747. sme_sa_query_rx(wpa_s, data->rx_action.sa,
  1748. data->rx_action.data,
  1749. data->rx_action.len);
  1750. break;
  1751. }
  1752. #endif /* CONFIG_SME */
  1753. #endif /* CONFIG_IEEE80211W */
  1754. #ifdef CONFIG_P2P
  1755. wpas_p2p_rx_action(wpa_s, data->rx_action.da,
  1756. data->rx_action.sa,
  1757. data->rx_action.bssid,
  1758. data->rx_action.category,
  1759. data->rx_action.data,
  1760. data->rx_action.len, data->rx_action.freq);
  1761. #endif /* CONFIG_P2P */
  1762. break;
  1763. case EVENT_RX_PROBE_REQ:
  1764. #ifdef CONFIG_AP
  1765. if (wpa_s->ap_iface) {
  1766. hostapd_probe_req_rx(wpa_s->ap_iface->bss[0],
  1767. data->rx_probe_req.sa,
  1768. data->rx_probe_req.ie,
  1769. data->rx_probe_req.ie_len);
  1770. break;
  1771. }
  1772. #endif /* CONFIG_AP */
  1773. #ifdef CONFIG_P2P
  1774. wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa,
  1775. data->rx_probe_req.ie,
  1776. data->rx_probe_req.ie_len);
  1777. #endif /* CONFIG_P2P */
  1778. break;
  1779. #ifdef CONFIG_P2P
  1780. case EVENT_REMAIN_ON_CHANNEL:
  1781. wpas_p2p_remain_on_channel_cb(
  1782. wpa_s, data->remain_on_channel.freq,
  1783. data->remain_on_channel.duration);
  1784. break;
  1785. case EVENT_CANCEL_REMAIN_ON_CHANNEL:
  1786. wpas_p2p_cancel_remain_on_channel_cb(
  1787. wpa_s, data->remain_on_channel.freq);
  1788. break;
  1789. case EVENT_P2P_DEV_FOUND: {
  1790. struct p2p_peer_info peer_info;
  1791. os_memset(&peer_info, 0, sizeof(peer_info));
  1792. if (data->p2p_dev_found.dev_addr)
  1793. os_memcpy(peer_info.p2p_device_addr,
  1794. data->p2p_dev_found.dev_addr, ETH_ALEN);
  1795. if (data->p2p_dev_found.pri_dev_type)
  1796. os_memcpy(peer_info.pri_dev_type,
  1797. data->p2p_dev_found.pri_dev_type,
  1798. sizeof(peer_info.pri_dev_type));
  1799. if (data->p2p_dev_found.dev_name)
  1800. os_strlcpy(peer_info.device_name,
  1801. data->p2p_dev_found.dev_name,
  1802. sizeof(peer_info.device_name));
  1803. peer_info.config_methods = data->p2p_dev_found.config_methods;
  1804. peer_info.dev_capab = data->p2p_dev_found.dev_capab;
  1805. peer_info.group_capab = data->p2p_dev_found.group_capab;
  1806. /*
  1807. * FIX: new_device=1 is not necessarily correct. We should
  1808. * maintain a P2P peer database in wpa_supplicant and update
  1809. * this information based on whether the peer is truly new.
  1810. */
  1811. wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
  1812. break;
  1813. }
  1814. case EVENT_P2P_GO_NEG_REQ_RX:
  1815. wpas_go_neg_req_rx(wpa_s, data->p2p_go_neg_req_rx.src,
  1816. data->p2p_go_neg_req_rx.dev_passwd_id);
  1817. break;
  1818. case EVENT_P2P_GO_NEG_COMPLETED:
  1819. wpas_go_neg_completed(wpa_s, data->p2p_go_neg_completed.res);
  1820. break;
  1821. case EVENT_P2P_PROV_DISC_REQUEST:
  1822. wpas_prov_disc_req(wpa_s, data->p2p_prov_disc_req.peer,
  1823. data->p2p_prov_disc_req.config_methods,
  1824. data->p2p_prov_disc_req.dev_addr,
  1825. data->p2p_prov_disc_req.pri_dev_type,
  1826. data->p2p_prov_disc_req.dev_name,
  1827. data->p2p_prov_disc_req.supp_config_methods,
  1828. data->p2p_prov_disc_req.dev_capab,
  1829. data->p2p_prov_disc_req.group_capab);
  1830. break;
  1831. case EVENT_P2P_PROV_DISC_RESPONSE:
  1832. wpas_prov_disc_resp(wpa_s, data->p2p_prov_disc_resp.peer,
  1833. data->p2p_prov_disc_resp.config_methods);
  1834. break;
  1835. case EVENT_P2P_SD_REQUEST:
  1836. wpas_sd_request(wpa_s, data->p2p_sd_req.freq,
  1837. data->p2p_sd_req.sa,
  1838. data->p2p_sd_req.dialog_token,
  1839. data->p2p_sd_req.update_indic,
  1840. data->p2p_sd_req.tlvs,
  1841. data->p2p_sd_req.tlvs_len);
  1842. break;
  1843. case EVENT_P2P_SD_RESPONSE:
  1844. wpas_sd_response(wpa_s, data->p2p_sd_resp.sa,
  1845. data->p2p_sd_resp.update_indic,
  1846. data->p2p_sd_resp.tlvs,
  1847. data->p2p_sd_resp.tlvs_len);
  1848. break;
  1849. #endif /* CONFIG_P2P */
  1850. #ifdef CONFIG_CLIENT_MLME
  1851. case EVENT_MLME_RX: {
  1852. struct ieee80211_rx_status rx_status;
  1853. os_memset(&rx_status, 0, sizeof(rx_status));
  1854. rx_status.freq = data->mlme_rx.freq;
  1855. rx_status.channel = data->mlme_rx.channel;
  1856. rx_status.ssi = data->mlme_rx.ssi;
  1857. ieee80211_sta_rx(wpa_s, data->mlme_rx.buf, data->mlme_rx.len,
  1858. &rx_status);
  1859. break;
  1860. }
  1861. #endif /* CONFIG_CLIENT_MLME */
  1862. case EVENT_EAPOL_RX:
  1863. wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src,
  1864. data->eapol_rx.data,
  1865. data->eapol_rx.data_len);
  1866. break;
  1867. case EVENT_SIGNAL_CHANGE:
  1868. bgscan_notify_signal_change(
  1869. wpa_s, data->signal_change.above_threshold,
  1870. data->signal_change.current_signal,
  1871. data->signal_change.current_noise,
  1872. data->signal_change.current_txrate);
  1873. break;
  1874. case EVENT_INTERFACE_ENABLED:
  1875. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled");
  1876. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  1877. #ifdef CONFIG_AP
  1878. if (!wpa_s->ap_iface) {
  1879. wpa_supplicant_set_state(wpa_s,
  1880. WPA_DISCONNECTED);
  1881. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1882. } else
  1883. wpa_supplicant_set_state(wpa_s,
  1884. WPA_COMPLETED);
  1885. #else /* CONFIG_AP */
  1886. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  1887. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1888. #endif /* CONFIG_AP */
  1889. }
  1890. break;
  1891. case EVENT_INTERFACE_DISABLED:
  1892. wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled");
  1893. wpa_supplicant_mark_disassoc(wpa_s);
  1894. wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED);
  1895. break;
  1896. case EVENT_CHANNEL_LIST_CHANGED:
  1897. if (wpa_s->drv_priv == NULL)
  1898. break; /* Ignore event during drv initialization */
  1899. #ifdef CONFIG_P2P
  1900. wpas_p2p_update_channel_list(wpa_s);
  1901. #endif /* CONFIG_P2P */
  1902. break;
  1903. case EVENT_INTERFACE_UNAVAILABLE:
  1904. #ifdef CONFIG_P2P
  1905. wpas_p2p_interface_unavailable(wpa_s);
  1906. #endif /* CONFIG_P2P */
  1907. break;
  1908. case EVENT_BEST_CHANNEL:
  1909. wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received "
  1910. "(%d %d %d)",
  1911. data->best_chan.freq_24, data->best_chan.freq_5,
  1912. data->best_chan.freq_overall);
  1913. wpa_s->best_24_freq = data->best_chan.freq_24;
  1914. wpa_s->best_5_freq = data->best_chan.freq_5;
  1915. wpa_s->best_overall_freq = data->best_chan.freq_overall;
  1916. #ifdef CONFIG_P2P
  1917. wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24,
  1918. data->best_chan.freq_5,
  1919. data->best_chan.freq_overall);
  1920. #endif /* CONFIG_P2P */
  1921. break;
  1922. case EVENT_UNPROT_DEAUTH:
  1923. wpa_supplicant_event_unprot_deauth(wpa_s,
  1924. &data->unprot_deauth);
  1925. break;
  1926. case EVENT_UNPROT_DISASSOC:
  1927. wpa_supplicant_event_unprot_disassoc(wpa_s,
  1928. &data->unprot_disassoc);
  1929. break;
  1930. case EVENT_STATION_LOW_ACK:
  1931. #ifdef CONFIG_AP
  1932. if (wpa_s->ap_iface && data)
  1933. hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0],
  1934. data->low_ack.addr);
  1935. #endif /* CONFIG_AP */
  1936. break;
  1937. case EVENT_IBSS_PEER_LOST:
  1938. #ifdef CONFIG_IBSS_RSN
  1939. ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer);
  1940. #endif /* CONFIG_IBSS_RSN */
  1941. break;
  1942. default:
  1943. wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event);
  1944. break;
  1945. }
  1946. }