events.c 51 KB

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