events.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /*
  2. * WPA Supplicant - Driver event processing
  3. * Copyright (c) 2003-2008, 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 "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 "preauth.h"
  25. #include "pmksa_cache.h"
  26. #include "wpa_ctrl.h"
  27. #include "eap_peer/eap.h"
  28. #include "ctrl_iface_dbus.h"
  29. #include "ieee802_11_defs.h"
  30. #include "blacklist.h"
  31. #include "wpas_glue.h"
  32. #include "wps_supplicant.h"
  33. #include "ibss_rsn.h"
  34. #include "sme.h"
  35. static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s)
  36. {
  37. struct wpa_ssid *ssid;
  38. if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid)
  39. return 0;
  40. wpa_printf(MSG_DEBUG, "Select network based on association "
  41. "information");
  42. ssid = wpa_supplicant_get_ssid(wpa_s);
  43. if (ssid == NULL) {
  44. wpa_printf(MSG_INFO, "No network configuration found for the "
  45. "current AP");
  46. return -1;
  47. }
  48. if (ssid->disabled) {
  49. wpa_printf(MSG_DEBUG, "Selected network is disabled");
  50. return -1;
  51. }
  52. wpa_printf(MSG_DEBUG, "Network configuration found for the current "
  53. "AP");
  54. if (ssid->key_mgmt & (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  55. WPA_KEY_MGMT_WPA_NONE |
  56. WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X |
  57. WPA_KEY_MGMT_PSK_SHA256 |
  58. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  59. u8 wpa_ie[80];
  60. size_t wpa_ie_len = sizeof(wpa_ie);
  61. wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  62. wpa_ie, &wpa_ie_len);
  63. } else {
  64. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  65. }
  66. if (wpa_s->current_ssid && wpa_s->current_ssid != ssid)
  67. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  68. wpa_s->current_ssid = ssid;
  69. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  70. wpa_supplicant_initiate_eapol(wpa_s);
  71. return 0;
  72. }
  73. static void wpa_supplicant_stop_countermeasures(void *eloop_ctx,
  74. void *sock_ctx)
  75. {
  76. struct wpa_supplicant *wpa_s = eloop_ctx;
  77. if (wpa_s->countermeasures) {
  78. wpa_s->countermeasures = 0;
  79. wpa_drv_set_countermeasures(wpa_s, 0);
  80. wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped");
  81. wpa_supplicant_req_scan(wpa_s, 0, 0);
  82. }
  83. }
  84. void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s)
  85. {
  86. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  87. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  88. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  89. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  90. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  91. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt))
  92. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  93. wpa_s->ap_ies_from_associnfo = 0;
  94. }
  95. static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
  96. {
  97. struct wpa_ie_data ie;
  98. int pmksa_set = -1;
  99. size_t i;
  100. if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
  101. ie.pmkid == NULL)
  102. return;
  103. for (i = 0; i < ie.num_pmkid; i++) {
  104. pmksa_set = pmksa_cache_set_current(wpa_s->wpa,
  105. ie.pmkid + i * PMKID_LEN,
  106. NULL, NULL, 0);
  107. if (pmksa_set == 0) {
  108. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  109. break;
  110. }
  111. }
  112. wpa_printf(MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from PMKSA "
  113. "cache", pmksa_set == 0 ? "" : "not ");
  114. }
  115. static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s,
  116. union wpa_event_data *data)
  117. {
  118. if (data == NULL) {
  119. wpa_printf(MSG_DEBUG, "RSN: No data in PMKID candidate event");
  120. return;
  121. }
  122. wpa_printf(MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR
  123. " index=%d preauth=%d",
  124. MAC2STR(data->pmkid_candidate.bssid),
  125. data->pmkid_candidate.index,
  126. data->pmkid_candidate.preauth);
  127. pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid,
  128. data->pmkid_candidate.index,
  129. data->pmkid_candidate.preauth);
  130. }
  131. static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s)
  132. {
  133. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  134. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE)
  135. return 0;
  136. #ifdef IEEE8021X_EAPOL
  137. if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  138. wpa_s->current_ssid &&
  139. !(wpa_s->current_ssid->eapol_flags &
  140. (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  141. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) {
  142. /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either
  143. * plaintext or static WEP keys). */
  144. return 0;
  145. }
  146. #endif /* IEEE8021X_EAPOL */
  147. return 1;
  148. }
  149. /**
  150. * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC
  151. * @wpa_s: pointer to wpa_supplicant data
  152. * @ssid: Configuration data for the network
  153. * Returns: 0 on success, -1 on failure
  154. *
  155. * This function is called when starting authentication with a network that is
  156. * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA).
  157. */
  158. int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
  159. struct wpa_ssid *ssid)
  160. {
  161. #ifdef IEEE8021X_EAPOL
  162. int aka = 0, sim = 0, type;
  163. if (ssid->eap.pcsc == NULL || wpa_s->scard != NULL)
  164. return 0;
  165. if (ssid->eap.eap_methods == NULL) {
  166. sim = 1;
  167. aka = 1;
  168. } else {
  169. struct eap_method_type *eap = ssid->eap.eap_methods;
  170. while (eap->vendor != EAP_VENDOR_IETF ||
  171. eap->method != EAP_TYPE_NONE) {
  172. if (eap->vendor == EAP_VENDOR_IETF) {
  173. if (eap->method == EAP_TYPE_SIM)
  174. sim = 1;
  175. else if (eap->method == EAP_TYPE_AKA)
  176. aka = 1;
  177. }
  178. eap++;
  179. }
  180. }
  181. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL)
  182. sim = 0;
  183. if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL)
  184. aka = 0;
  185. if (!sim && !aka) {
  186. wpa_printf(MSG_DEBUG, "Selected network is configured to use "
  187. "SIM, but neither EAP-SIM nor EAP-AKA are enabled");
  188. return 0;
  189. }
  190. wpa_printf(MSG_DEBUG, "Selected network is configured to use SIM "
  191. "(sim=%d aka=%d) - initialize PCSC", sim, aka);
  192. if (sim && aka)
  193. type = SCARD_TRY_BOTH;
  194. else if (aka)
  195. type = SCARD_USIM_ONLY;
  196. else
  197. type = SCARD_GSM_SIM_ONLY;
  198. wpa_s->scard = scard_init(type);
  199. if (wpa_s->scard == NULL) {
  200. wpa_printf(MSG_WARNING, "Failed to initialize SIM "
  201. "(pcsc-lite)");
  202. return -1;
  203. }
  204. wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard);
  205. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  206. #endif /* IEEE8021X_EAPOL */
  207. return 0;
  208. }
  209. #ifndef CONFIG_NO_SCAN_PROCESSING
  210. static int wpa_supplicant_match_privacy(struct wpa_scan_res *bss,
  211. struct wpa_ssid *ssid)
  212. {
  213. int i, privacy = 0;
  214. if (ssid->mixed_cell)
  215. return 1;
  216. #ifdef CONFIG_WPS
  217. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS)
  218. return 1;
  219. #endif /* CONFIG_WPS */
  220. for (i = 0; i < NUM_WEP_KEYS; i++) {
  221. if (ssid->wep_key_len[i]) {
  222. privacy = 1;
  223. break;
  224. }
  225. }
  226. #ifdef IEEE8021X_EAPOL
  227. if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) &&
  228. ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST |
  229. EAPOL_FLAG_REQUIRE_KEY_BROADCAST))
  230. privacy = 1;
  231. #endif /* IEEE8021X_EAPOL */
  232. if (bss->caps & IEEE80211_CAP_PRIVACY)
  233. return privacy;
  234. return !privacy;
  235. }
  236. static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s,
  237. struct wpa_ssid *ssid,
  238. struct wpa_scan_res *bss)
  239. {
  240. struct wpa_ie_data ie;
  241. int proto_match = 0;
  242. const u8 *rsn_ie, *wpa_ie;
  243. int ret;
  244. ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss);
  245. if (ret >= 0)
  246. return ret;
  247. rsn_ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  248. while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) {
  249. proto_match++;
  250. if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) {
  251. wpa_printf(MSG_DEBUG, " skip RSN IE - parse failed");
  252. break;
  253. }
  254. if (!(ie.proto & ssid->proto)) {
  255. wpa_printf(MSG_DEBUG, " skip RSN IE - proto "
  256. "mismatch");
  257. break;
  258. }
  259. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  260. wpa_printf(MSG_DEBUG, " skip RSN IE - PTK cipher "
  261. "mismatch");
  262. break;
  263. }
  264. if (!(ie.group_cipher & ssid->group_cipher)) {
  265. wpa_printf(MSG_DEBUG, " skip RSN IE - GTK cipher "
  266. "mismatch");
  267. break;
  268. }
  269. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  270. wpa_printf(MSG_DEBUG, " skip RSN IE - key mgmt "
  271. "mismatch");
  272. break;
  273. }
  274. #ifdef CONFIG_IEEE80211W
  275. if (!(ie.capabilities & WPA_CAPABILITY_MFPC) &&
  276. ssid->ieee80211w == IEEE80211W_REQUIRED) {
  277. wpa_printf(MSG_DEBUG, " skip RSN IE - no mgmt frame "
  278. "protection");
  279. break;
  280. }
  281. #endif /* CONFIG_IEEE80211W */
  282. wpa_printf(MSG_DEBUG, " selected based on RSN IE");
  283. return 1;
  284. }
  285. wpa_ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  286. while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) {
  287. proto_match++;
  288. if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) {
  289. wpa_printf(MSG_DEBUG, " skip WPA IE - parse failed");
  290. break;
  291. }
  292. if (!(ie.proto & ssid->proto)) {
  293. wpa_printf(MSG_DEBUG, " skip WPA IE - proto "
  294. "mismatch");
  295. break;
  296. }
  297. if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) {
  298. wpa_printf(MSG_DEBUG, " skip WPA IE - PTK cipher "
  299. "mismatch");
  300. break;
  301. }
  302. if (!(ie.group_cipher & ssid->group_cipher)) {
  303. wpa_printf(MSG_DEBUG, " skip WPA IE - GTK cipher "
  304. "mismatch");
  305. break;
  306. }
  307. if (!(ie.key_mgmt & ssid->key_mgmt)) {
  308. wpa_printf(MSG_DEBUG, " skip WPA IE - key mgmt "
  309. "mismatch");
  310. break;
  311. }
  312. wpa_printf(MSG_DEBUG, " selected based on WPA IE");
  313. return 1;
  314. }
  315. if (proto_match == 0)
  316. wpa_printf(MSG_DEBUG, " skip - no WPA/RSN proto match");
  317. return 0;
  318. }
  319. static struct wpa_scan_res *
  320. wpa_supplicant_select_bss_wpa(struct wpa_supplicant *wpa_s,
  321. struct wpa_ssid *group,
  322. struct wpa_ssid **selected_ssid)
  323. {
  324. struct wpa_ssid *ssid;
  325. struct wpa_scan_res *bss;
  326. size_t i;
  327. struct wpa_blacklist *e;
  328. const u8 *ie;
  329. wpa_printf(MSG_DEBUG, "Try to find WPA-enabled AP");
  330. for (i = 0; i < wpa_s->scan_res->num; i++) {
  331. const u8 *ssid_;
  332. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  333. bss = wpa_s->scan_res->res[i];
  334. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  335. ssid_ = ie ? ie + 2 : (u8 *) "";
  336. ssid_len = ie ? ie[1] : 0;
  337. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  338. wpa_ie_len = ie ? ie[1] : 0;
  339. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  340. rsn_ie_len = ie ? ie[1] : 0;
  341. wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  342. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
  343. (int) i, MAC2STR(bss->bssid),
  344. wpa_ssid_txt(ssid_, ssid_len),
  345. wpa_ie_len, rsn_ie_len, bss->caps);
  346. e = wpa_blacklist_get(wpa_s, bss->bssid);
  347. if (e && e->count > 1) {
  348. wpa_printf(MSG_DEBUG, " skip - blacklisted");
  349. continue;
  350. }
  351. if (wpa_ie_len == 0 && rsn_ie_len == 0) {
  352. wpa_printf(MSG_DEBUG, " skip - no WPA/RSN IE");
  353. continue;
  354. }
  355. for (ssid = group; ssid; ssid = ssid->pnext) {
  356. int check_ssid = 1;
  357. if (ssid->disabled) {
  358. wpa_printf(MSG_DEBUG, " skip - disabled");
  359. continue;
  360. }
  361. #ifdef CONFIG_WPS
  362. if (ssid->ssid_len == 0 &&
  363. wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss))
  364. check_ssid = 0;
  365. #endif /* CONFIG_WPS */
  366. if (check_ssid &&
  367. (ssid_len != ssid->ssid_len ||
  368. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  369. wpa_printf(MSG_DEBUG, " skip - "
  370. "SSID mismatch");
  371. continue;
  372. }
  373. if (ssid->bssid_set &&
  374. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
  375. {
  376. wpa_printf(MSG_DEBUG, " skip - "
  377. "BSSID mismatch");
  378. continue;
  379. }
  380. if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss))
  381. continue;
  382. wpa_printf(MSG_DEBUG, " selected WPA AP "
  383. MACSTR " ssid='%s'",
  384. MAC2STR(bss->bssid),
  385. wpa_ssid_txt(ssid_, ssid_len));
  386. *selected_ssid = ssid;
  387. return bss;
  388. }
  389. }
  390. return NULL;
  391. }
  392. static struct wpa_scan_res *
  393. wpa_supplicant_select_bss_non_wpa(struct wpa_supplicant *wpa_s,
  394. struct wpa_ssid *group,
  395. struct wpa_ssid **selected_ssid)
  396. {
  397. struct wpa_ssid *ssid;
  398. struct wpa_scan_res *bss;
  399. size_t i;
  400. struct wpa_blacklist *e;
  401. const u8 *ie;
  402. wpa_printf(MSG_DEBUG, "Try to find non-WPA AP");
  403. for (i = 0; i < wpa_s->scan_res->num; i++) {
  404. const u8 *ssid_;
  405. u8 wpa_ie_len, rsn_ie_len, ssid_len;
  406. bss = wpa_s->scan_res->res[i];
  407. ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
  408. ssid_ = ie ? ie + 2 : (u8 *) "";
  409. ssid_len = ie ? ie[1] : 0;
  410. ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  411. wpa_ie_len = ie ? ie[1] : 0;
  412. ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
  413. rsn_ie_len = ie ? ie[1] : 0;
  414. wpa_printf(MSG_DEBUG, "%d: " MACSTR " ssid='%s' "
  415. "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x",
  416. (int) i, MAC2STR(bss->bssid),
  417. wpa_ssid_txt(ssid_, ssid_len),
  418. wpa_ie_len, rsn_ie_len, bss->caps);
  419. e = wpa_blacklist_get(wpa_s, bss->bssid);
  420. if (e && e->count > 1) {
  421. wpa_printf(MSG_DEBUG, " skip - blacklisted");
  422. continue;
  423. }
  424. for (ssid = group; ssid; ssid = ssid->pnext) {
  425. int check_ssid = ssid->ssid_len != 0;
  426. if (ssid->disabled) {
  427. wpa_printf(MSG_DEBUG, " skip - disabled");
  428. continue;
  429. }
  430. #ifdef CONFIG_WPS
  431. if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  432. /* Only allow wildcard SSID match if an AP
  433. * advertises active WPS operation that matches
  434. * with our mode. */
  435. check_ssid = 1;
  436. if (ssid->ssid_len == 0 &&
  437. wpas_wps_ssid_wildcard_ok(wpa_s, ssid,
  438. bss))
  439. check_ssid = 0;
  440. }
  441. #endif /* CONFIG_WPS */
  442. if (check_ssid &&
  443. (ssid_len != ssid->ssid_len ||
  444. os_memcmp(ssid_, ssid->ssid, ssid_len) != 0)) {
  445. wpa_printf(MSG_DEBUG, " skip - "
  446. "SSID mismatch");
  447. continue;
  448. }
  449. if (ssid->bssid_set &&
  450. os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0)
  451. {
  452. wpa_printf(MSG_DEBUG, " skip - "
  453. "BSSID mismatch");
  454. continue;
  455. }
  456. if (!(ssid->key_mgmt & WPA_KEY_MGMT_NONE) &&
  457. !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) &&
  458. !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA))
  459. {
  460. wpa_printf(MSG_DEBUG, " skip - "
  461. "non-WPA network not allowed");
  462. continue;
  463. }
  464. if ((ssid->key_mgmt &
  465. (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
  466. WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK |
  467. WPA_KEY_MGMT_IEEE8021X_SHA256 |
  468. WPA_KEY_MGMT_PSK_SHA256)) &&
  469. (wpa_ie_len != 0 || rsn_ie_len != 0)) {
  470. wpa_printf(MSG_DEBUG, " skip - "
  471. "WPA network");
  472. continue;
  473. }
  474. if (!wpa_supplicant_match_privacy(bss, ssid)) {
  475. wpa_printf(MSG_DEBUG, " skip - "
  476. "privacy mismatch");
  477. continue;
  478. }
  479. if (bss->caps & IEEE80211_CAP_IBSS) {
  480. wpa_printf(MSG_DEBUG, " skip - "
  481. "IBSS (adhoc) network");
  482. continue;
  483. }
  484. wpa_printf(MSG_DEBUG, " selected non-WPA AP "
  485. MACSTR " ssid='%s'",
  486. MAC2STR(bss->bssid),
  487. wpa_ssid_txt(ssid_, ssid_len));
  488. *selected_ssid = ssid;
  489. return bss;
  490. }
  491. }
  492. return NULL;
  493. }
  494. static struct wpa_scan_res *
  495. wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
  496. struct wpa_ssid **selected_ssid)
  497. {
  498. struct wpa_scan_res *selected;
  499. wpa_printf(MSG_DEBUG, "Selecting BSS from priority group %d",
  500. group->priority);
  501. /* First, try to find WPA-enabled AP */
  502. selected = wpa_supplicant_select_bss_wpa(wpa_s, group, selected_ssid);
  503. if (selected)
  504. return selected;
  505. /* If no WPA-enabled AP found, try to find non-WPA AP, if configuration
  506. * allows this. */
  507. return wpa_supplicant_select_bss_non_wpa(wpa_s, group, selected_ssid);
  508. }
  509. static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
  510. {
  511. int prio, timeout;
  512. struct wpa_scan_res *selected = NULL;
  513. struct wpa_ssid *ssid = NULL;
  514. if (wpa_supplicant_get_scan_results(wpa_s) < 0) {
  515. if (wpa_s->conf->ap_scan == 2)
  516. return;
  517. wpa_printf(MSG_DEBUG, "Failed to get scan results - try "
  518. "scanning again");
  519. timeout = 1;
  520. goto req_scan;
  521. }
  522. /*
  523. * Don't post the results if this was the initial cached
  524. * and there were no results.
  525. */
  526. if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1 &&
  527. wpa_s->scan_res->num == 0) {
  528. wpa_msg(wpa_s, MSG_DEBUG, "Cached scan results are "
  529. "empty - not posting");
  530. } else {
  531. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
  532. wpa_supplicant_dbus_notify_scan_results(wpa_s);
  533. wpas_wps_notify_scan_results(wpa_s);
  534. }
  535. if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s)) ||
  536. wpa_s->disconnected)
  537. return;
  538. while (selected == NULL) {
  539. for (prio = 0; prio < wpa_s->conf->num_prio; prio++) {
  540. selected = wpa_supplicant_select_bss(
  541. wpa_s, wpa_s->conf->pssid[prio], &ssid);
  542. if (selected)
  543. break;
  544. }
  545. if (selected == NULL && wpa_s->blacklist) {
  546. wpa_printf(MSG_DEBUG, "No APs found - clear blacklist "
  547. "and try again");
  548. wpa_blacklist_clear(wpa_s);
  549. wpa_s->blacklist_cleared++;
  550. } else if (selected == NULL) {
  551. break;
  552. }
  553. }
  554. if (selected) {
  555. if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) {
  556. wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP
  557. "PBC session overlap");
  558. timeout = 10;
  559. goto req_scan;
  560. }
  561. /* Do not trigger new association unless the BSSID has changed
  562. * or if reassociation is requested. If we are in process of
  563. * associating with the selected BSSID, do not trigger new
  564. * attempt. */
  565. if (wpa_s->reassociate ||
  566. (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 &&
  567. (wpa_s->wpa_state != WPA_ASSOCIATING ||
  568. os_memcmp(selected->bssid, wpa_s->pending_bssid,
  569. ETH_ALEN) != 0))) {
  570. if (wpa_supplicant_scard_init(wpa_s, ssid)) {
  571. wpa_supplicant_req_scan(wpa_s, 10, 0);
  572. return;
  573. }
  574. wpa_supplicant_associate(wpa_s, selected, ssid);
  575. } else {
  576. wpa_printf(MSG_DEBUG, "Already associated with the "
  577. "selected AP.");
  578. }
  579. rsn_preauth_scan_results(wpa_s->wpa, wpa_s->scan_res);
  580. } else {
  581. wpa_printf(MSG_DEBUG, "No suitable AP found.");
  582. timeout = 5;
  583. goto req_scan;
  584. }
  585. return;
  586. req_scan:
  587. if (wpa_s->scan_res_tried == 1 && wpa_s->conf->ap_scan == 1) {
  588. /*
  589. * Quick recovery if the initial scan results were not
  590. * complete when fetched before the first scan request.
  591. */
  592. wpa_s->scan_res_tried++;
  593. timeout = 0;
  594. }
  595. wpa_supplicant_req_scan(wpa_s, timeout, 0);
  596. }
  597. #endif /* CONFIG_NO_SCAN_PROCESSING */
  598. #ifdef CONFIG_IEEE80211R
  599. static void wpa_assoc_set_ft_params(struct wpa_supplicant *wpa_s,
  600. const u8 *ftie, const u8 *mdie)
  601. {
  602. const u8 *mobility_domain = NULL;
  603. const u8 *r0kh_id = NULL;
  604. size_t r0kh_id_len = 0;
  605. const u8 *r1kh_id = NULL;
  606. struct rsn_ftie *hdr;
  607. const u8 *pos, *end;
  608. if (mdie == NULL || ftie == NULL)
  609. return;
  610. if (mdie[1] >= MOBILITY_DOMAIN_ID_LEN) {
  611. mobility_domain = mdie + 2;
  612. #ifdef CONFIG_SME
  613. wpa_s->sme.ft_used = 1;
  614. os_memcpy(wpa_s->sme.mobility_domain, mobility_domain, 2);
  615. #endif /* CONFIG_SME */
  616. }
  617. if (ftie[1] >= sizeof(struct rsn_ftie)) {
  618. end = ftie + 2 + ftie[1];
  619. hdr = (struct rsn_ftie *) (ftie + 2);
  620. pos = (const u8 *) (hdr + 1);
  621. while (pos + 1 < end) {
  622. if (pos + 2 + pos[1] > end)
  623. break;
  624. if (pos[0] == FTIE_SUBELEM_R1KH_ID &&
  625. pos[1] == FT_R1KH_ID_LEN)
  626. r1kh_id = pos + 2;
  627. else if (pos[0] == FTIE_SUBELEM_R0KH_ID &&
  628. pos[1] >= 1 && pos[1] <= FT_R0KH_ID_MAX_LEN) {
  629. r0kh_id = pos + 2;
  630. r0kh_id_len = pos[1];
  631. }
  632. pos += 2 + pos[1];
  633. }
  634. }
  635. wpa_sm_set_ft_params(wpa_s->wpa, mobility_domain, r0kh_id,
  636. r0kh_id_len, r1kh_id);
  637. }
  638. #endif /* CONFIG_IEEE80211R */
  639. static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
  640. union wpa_event_data *data)
  641. {
  642. int l, len, found = 0, wpa_found, rsn_found;
  643. const u8 *p;
  644. #ifdef CONFIG_IEEE80211R
  645. const u8 *mdie = NULL, *ftie = NULL;
  646. #endif /* CONFIG_IEEE80211R */
  647. wpa_printf(MSG_DEBUG, "Association info event");
  648. if (data->assoc_info.req_ies)
  649. wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies,
  650. data->assoc_info.req_ies_len);
  651. if (data->assoc_info.resp_ies)
  652. wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
  653. data->assoc_info.resp_ies_len);
  654. if (data->assoc_info.beacon_ies)
  655. wpa_hexdump(MSG_DEBUG, "beacon_ies",
  656. data->assoc_info.beacon_ies,
  657. data->assoc_info.beacon_ies_len);
  658. p = data->assoc_info.req_ies;
  659. l = data->assoc_info.req_ies_len;
  660. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  661. while (p && l >= 2) {
  662. len = p[1] + 2;
  663. if (len > l) {
  664. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  665. p, l);
  666. break;
  667. }
  668. if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  669. (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
  670. (p[0] == WLAN_EID_RSN && p[1] >= 2)) {
  671. if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
  672. break;
  673. found = 1;
  674. wpa_find_assoc_pmkid(wpa_s);
  675. break;
  676. }
  677. l -= len;
  678. p += len;
  679. }
  680. if (!found && data->assoc_info.req_ies)
  681. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  682. #ifdef CONFIG_IEEE80211R
  683. p = data->assoc_info.resp_ies;
  684. l = data->assoc_info.resp_ies_len;
  685. /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */
  686. while (p && l >= 2) {
  687. len = p[1] + 2;
  688. if (len > l) {
  689. wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info",
  690. p, l);
  691. break;
  692. }
  693. if (p[0] == WLAN_EID_FAST_BSS_TRANSITION)
  694. ftie = p;
  695. else if (p[0] == WLAN_EID_MOBILITY_DOMAIN)
  696. mdie = p;
  697. l -= len;
  698. p += len;
  699. }
  700. wpa_assoc_set_ft_params(wpa_s, ftie, mdie);
  701. #endif /* CONFIG_IEEE80211R */
  702. /* WPA/RSN IE from Beacon/ProbeResp */
  703. p = data->assoc_info.beacon_ies;
  704. l = data->assoc_info.beacon_ies_len;
  705. /* Go through the IEs and make a copy of the WPA/RSN IEs, if present.
  706. */
  707. wpa_found = rsn_found = 0;
  708. while (p && l >= 2) {
  709. len = p[1] + 2;
  710. if (len > l) {
  711. wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies",
  712. p, l);
  713. break;
  714. }
  715. if (!wpa_found &&
  716. p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 &&
  717. os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) {
  718. wpa_found = 1;
  719. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len);
  720. }
  721. if (!rsn_found &&
  722. p[0] == WLAN_EID_RSN && p[1] >= 2) {
  723. rsn_found = 1;
  724. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len);
  725. }
  726. l -= len;
  727. p += len;
  728. }
  729. if (!wpa_found && data->assoc_info.beacon_ies)
  730. wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0);
  731. if (!rsn_found && data->assoc_info.beacon_ies)
  732. wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0);
  733. if (wpa_found || rsn_found)
  734. wpa_s->ap_ies_from_associnfo = 1;
  735. }
  736. static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s,
  737. union wpa_event_data *data)
  738. {
  739. u8 bssid[ETH_ALEN];
  740. int ft_completed = wpa_ft_is_completed(wpa_s->wpa);
  741. if (data)
  742. wpa_supplicant_event_associnfo(wpa_s, data);
  743. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED);
  744. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
  745. os_memcpy(bssid, wpa_s->bssid, ETH_ALEN);
  746. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME) ||
  747. (wpa_drv_get_bssid(wpa_s, bssid) >= 0 &&
  748. os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0)) {
  749. wpa_msg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID="
  750. MACSTR, MAC2STR(bssid));
  751. os_memcpy(wpa_s->bssid, bssid, ETH_ALEN);
  752. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  753. if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) {
  754. wpa_clear_keys(wpa_s, bssid);
  755. }
  756. if (wpa_supplicant_select_config(wpa_s) < 0) {
  757. wpa_supplicant_disassociate(
  758. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  759. return;
  760. }
  761. }
  762. wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid));
  763. if (wpa_s->current_ssid) {
  764. /* When using scanning (ap_scan=1), SIM PC/SC interface can be
  765. * initialized before association, but for other modes,
  766. * initialize PC/SC here, if the current configuration needs
  767. * smartcard or SIM/USIM. */
  768. wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid);
  769. }
  770. wpa_sm_notify_assoc(wpa_s->wpa, bssid);
  771. l2_packet_notify_auth_start(wpa_s->l2);
  772. /*
  773. * Set portEnabled first to FALSE in order to get EAP state machine out
  774. * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE
  775. * state machine may transit to AUTHENTICATING state based on obsolete
  776. * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to
  777. * AUTHENTICATED without ever giving chance to EAP state machine to
  778. * reset the state.
  779. */
  780. if (!ft_completed) {
  781. eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE);
  782. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  783. }
  784. if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed)
  785. eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
  786. /* 802.1X::portControl = Auto */
  787. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  788. wpa_s->eapol_received = 0;
  789. if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE ||
  790. wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  791. wpa_supplicant_cancel_auth_timeout(wpa_s);
  792. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  793. } else if (!ft_completed) {
  794. /* Timeout for receiving the first EAPOL packet */
  795. wpa_supplicant_req_auth_timeout(wpa_s, 10, 0);
  796. }
  797. wpa_supplicant_cancel_scan(wpa_s);
  798. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) &&
  799. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  800. /*
  801. * We are done; the driver will take care of RSN 4-way
  802. * handshake.
  803. */
  804. wpa_supplicant_cancel_auth_timeout(wpa_s);
  805. wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
  806. eapol_sm_notify_portValid(wpa_s->eapol, TRUE);
  807. eapol_sm_notify_eap_success(wpa_s->eapol, TRUE);
  808. }
  809. }
  810. static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
  811. {
  812. const u8 *bssid;
  813. if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) {
  814. /*
  815. * At least Host AP driver and a Prism3 card seemed to be
  816. * generating streams of disconnected events when configuring
  817. * IBSS for WPA-None. Ignore them for now.
  818. */
  819. wpa_printf(MSG_DEBUG, "Disconnect event - ignore in "
  820. "IBSS/WPA-None mode");
  821. return;
  822. }
  823. if (wpa_s->wpa_state == WPA_4WAY_HANDSHAKE &&
  824. wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) {
  825. wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - "
  826. "pre-shared key may be incorrect");
  827. }
  828. if (wpa_s->wpa_state >= WPA_ASSOCIATED)
  829. wpa_supplicant_req_scan(wpa_s, 0, 100000);
  830. bssid = wpa_s->bssid;
  831. if (is_zero_ether_addr(bssid))
  832. bssid = wpa_s->pending_bssid;
  833. wpa_blacklist_add(wpa_s, bssid);
  834. wpa_sm_notify_disassoc(wpa_s->wpa);
  835. wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "- Disconnect event - "
  836. "remove keys");
  837. if (wpa_supplicant_dynamic_keys(wpa_s)) {
  838. wpa_s->keys_cleared = 0;
  839. wpa_clear_keys(wpa_s, wpa_s->bssid);
  840. }
  841. wpa_supplicant_mark_disassoc(wpa_s);
  842. }
  843. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  844. static void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx,
  845. void *sock_ctx)
  846. {
  847. struct wpa_supplicant *wpa_s = eloop_ctx;
  848. if (!wpa_s->pending_mic_error_report)
  849. return;
  850. wpa_printf(MSG_DEBUG, "WPA: Sending pending MIC error report");
  851. wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise);
  852. wpa_s->pending_mic_error_report = 0;
  853. }
  854. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  855. static void
  856. wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s,
  857. union wpa_event_data *data)
  858. {
  859. int pairwise;
  860. struct os_time t;
  861. wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected");
  862. pairwise = (data && data->michael_mic_failure.unicast);
  863. os_get_time(&t);
  864. if ((wpa_s->last_michael_mic_error &&
  865. t.sec - wpa_s->last_michael_mic_error <= 60) ||
  866. wpa_s->pending_mic_error_report) {
  867. if (wpa_s->pending_mic_error_report) {
  868. /*
  869. * Send the pending MIC error report immediately since
  870. * we are going to start countermeasures and AP better
  871. * do the same.
  872. */
  873. wpa_sm_key_request(wpa_s->wpa, 1,
  874. wpa_s->pending_mic_error_pairwise);
  875. }
  876. /* Send the new MIC error report immediately since we are going
  877. * to start countermeasures and AP better do the same.
  878. */
  879. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  880. /* initialize countermeasures */
  881. wpa_s->countermeasures = 1;
  882. wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started");
  883. /*
  884. * Need to wait for completion of request frame. We do not get
  885. * any callback for the message completion, so just wait a
  886. * short while and hope for the best. */
  887. os_sleep(0, 10000);
  888. wpa_drv_set_countermeasures(wpa_s, 1);
  889. wpa_supplicant_deauthenticate(wpa_s,
  890. WLAN_REASON_MICHAEL_MIC_FAILURE);
  891. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures,
  892. wpa_s, NULL);
  893. eloop_register_timeout(60, 0,
  894. wpa_supplicant_stop_countermeasures,
  895. wpa_s, NULL);
  896. /* TODO: mark the AP rejected for 60 second. STA is
  897. * allowed to associate with another AP.. */
  898. } else {
  899. #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT
  900. if (wpa_s->mic_errors_seen) {
  901. /*
  902. * Reduce the effectiveness of Michael MIC error
  903. * reports as a means for attacking against TKIP if
  904. * more than one MIC failure is noticed with the same
  905. * PTK. We delay the transmission of the reports by a
  906. * random time between 0 and 60 seconds in order to
  907. * force the attacker wait 60 seconds before getting
  908. * the information on whether a frame resulted in a MIC
  909. * failure.
  910. */
  911. u8 rval[4];
  912. int sec;
  913. if (os_get_random(rval, sizeof(rval)) < 0)
  914. sec = os_random() % 60;
  915. else
  916. sec = WPA_GET_BE32(rval) % 60;
  917. wpa_printf(MSG_DEBUG, "WPA: Delay MIC error report %d "
  918. "seconds", sec);
  919. wpa_s->pending_mic_error_report = 1;
  920. wpa_s->pending_mic_error_pairwise = pairwise;
  921. eloop_cancel_timeout(
  922. wpa_supplicant_delayed_mic_error_report,
  923. wpa_s, NULL);
  924. eloop_register_timeout(
  925. sec, os_random() % 1000000,
  926. wpa_supplicant_delayed_mic_error_report,
  927. wpa_s, NULL);
  928. } else {
  929. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  930. }
  931. #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  932. wpa_sm_key_request(wpa_s->wpa, 1, pairwise);
  933. #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */
  934. }
  935. wpa_s->last_michael_mic_error = t.sec;
  936. wpa_s->mic_errors_seen++;
  937. }
  938. #ifdef CONFIG_TERMINATE_ONLASTIF
  939. static int any_interfaces(struct wpa_supplicant *head)
  940. {
  941. struct wpa_supplicant *wpa_s;
  942. for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next)
  943. if (!wpa_s->interface_removed)
  944. return 1;
  945. return 0;
  946. }
  947. #endif /* CONFIG_TERMINATE_ONLASTIF */
  948. static void
  949. wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s,
  950. union wpa_event_data *data)
  951. {
  952. if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0)
  953. return;
  954. switch (data->interface_status.ievent) {
  955. case EVENT_INTERFACE_ADDED:
  956. if (!wpa_s->interface_removed)
  957. break;
  958. wpa_s->interface_removed = 0;
  959. wpa_printf(MSG_DEBUG, "Configured interface was added.");
  960. if (wpa_supplicant_driver_init(wpa_s) < 0) {
  961. wpa_printf(MSG_INFO, "Failed to initialize the driver "
  962. "after interface was added.");
  963. }
  964. break;
  965. case EVENT_INTERFACE_REMOVED:
  966. wpa_printf(MSG_DEBUG, "Configured interface was removed.");
  967. wpa_s->interface_removed = 1;
  968. wpa_supplicant_mark_disassoc(wpa_s);
  969. l2_packet_deinit(wpa_s->l2);
  970. wpa_s->l2 = NULL;
  971. #ifdef CONFIG_TERMINATE_ONLASTIF
  972. /* check if last interface */
  973. if (!any_interfaces(wpa_s->global->ifaces))
  974. eloop_terminate();
  975. #endif /* CONFIG_TERMINATE_ONLASTIF */
  976. break;
  977. }
  978. }
  979. #ifdef CONFIG_PEERKEY
  980. static void
  981. wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s,
  982. union wpa_event_data *data)
  983. {
  984. if (data == NULL)
  985. return;
  986. wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer);
  987. }
  988. #endif /* CONFIG_PEERKEY */
  989. #ifdef CONFIG_IEEE80211R
  990. static void
  991. wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s,
  992. union wpa_event_data *data)
  993. {
  994. if (data == NULL)
  995. return;
  996. if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies,
  997. data->ft_ies.ies_len,
  998. data->ft_ies.ft_action,
  999. data->ft_ies.target_ap,
  1000. data->ft_ies.ric_ies,
  1001. data->ft_ies.ric_ies_len) < 0) {
  1002. /* TODO: prevent MLME/driver from trying to associate? */
  1003. }
  1004. }
  1005. #endif /* CONFIG_IEEE80211R */
  1006. #ifdef CONFIG_IBSS_RSN
  1007. static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s,
  1008. union wpa_event_data *data)
  1009. {
  1010. if (data == NULL)
  1011. return;
  1012. ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer);
  1013. }
  1014. #endif /* CONFIG_IBSS_RSN */
  1015. void wpa_supplicant_event(void *ctx, wpa_event_type event,
  1016. union wpa_event_data *data)
  1017. {
  1018. struct wpa_supplicant *wpa_s = ctx;
  1019. switch (event) {
  1020. case EVENT_AUTH:
  1021. sme_event_auth(wpa_s, data);
  1022. break;
  1023. case EVENT_ASSOC:
  1024. wpa_supplicant_event_assoc(wpa_s, data);
  1025. break;
  1026. case EVENT_DEAUTH:
  1027. case EVENT_DISASSOC:
  1028. wpa_supplicant_event_disassoc(wpa_s);
  1029. break;
  1030. case EVENT_MICHAEL_MIC_FAILURE:
  1031. wpa_supplicant_event_michael_mic_failure(wpa_s, data);
  1032. break;
  1033. #ifndef CONFIG_NO_SCAN_PROCESSING
  1034. case EVENT_SCAN_RESULTS:
  1035. wpa_supplicant_event_scan_results(wpa_s);
  1036. break;
  1037. #endif /* CONFIG_NO_SCAN_PROCESSING */
  1038. case EVENT_ASSOCINFO:
  1039. wpa_supplicant_event_associnfo(wpa_s, data);
  1040. break;
  1041. case EVENT_INTERFACE_STATUS:
  1042. wpa_supplicant_event_interface_status(wpa_s, data);
  1043. break;
  1044. case EVENT_PMKID_CANDIDATE:
  1045. wpa_supplicant_event_pmkid_candidate(wpa_s, data);
  1046. break;
  1047. #ifdef CONFIG_PEERKEY
  1048. case EVENT_STKSTART:
  1049. wpa_supplicant_event_stkstart(wpa_s, data);
  1050. break;
  1051. #endif /* CONFIG_PEERKEY */
  1052. #ifdef CONFIG_IEEE80211R
  1053. case EVENT_FT_RESPONSE:
  1054. wpa_supplicant_event_ft_response(wpa_s, data);
  1055. break;
  1056. #endif /* CONFIG_IEEE80211R */
  1057. #ifdef CONFIG_IBSS_RSN
  1058. case EVENT_IBSS_RSN_START:
  1059. wpa_supplicant_event_ibss_rsn_start(wpa_s, data);
  1060. break;
  1061. #endif /* CONFIG_IBSS_RSN */
  1062. case EVENT_ASSOC_REJECT:
  1063. sme_event_assoc_reject(wpa_s, data);
  1064. break;
  1065. default:
  1066. wpa_printf(MSG_INFO, "Unknown event %d", event);
  1067. break;
  1068. }
  1069. }