events.c 32 KB

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