sme.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. * wpa_supplicant - SME
  3. * Copyright (c) 2009-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 "common/ieee802_11_defs.h"
  17. #include "common/ieee802_11_common.h"
  18. #include "eapol_supp/eapol_supp_sm.h"
  19. #include "common/wpa_common.h"
  20. #include "rsn_supp/wpa.h"
  21. #include "rsn_supp/pmksa_cache.h"
  22. #include "config.h"
  23. #include "wpa_supplicant_i.h"
  24. #include "driver_i.h"
  25. #include "wpas_glue.h"
  26. #include "wps_supplicant.h"
  27. #include "p2p_supplicant.h"
  28. #include "notify.h"
  29. #include "blacklist.h"
  30. #include "bss.h"
  31. #include "scan.h"
  32. #include "sme.h"
  33. static int sme_another_bss_in_ess(struct wpa_supplicant *wpa_s)
  34. {
  35. struct wpa_bss *bss, *cbss;
  36. cbss = wpa_s->current_bss;
  37. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  38. if (bss == cbss)
  39. continue;
  40. if (bss->ssid_len == cbss->ssid_len &&
  41. os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 &&
  42. wpa_blacklist_get(wpa_s, bss->bssid) == NULL)
  43. return 1;
  44. }
  45. return 0;
  46. }
  47. static void sme_connection_failed(struct wpa_supplicant *wpa_s,
  48. const u8 *bssid)
  49. {
  50. int timeout;
  51. int count;
  52. /*
  53. * Add the failed BSSID into the blacklist and speed up next scan
  54. * attempt if there could be other APs that could accept association.
  55. * The current blacklist count indicates how many times we have tried
  56. * connecting to this AP and multiple attempts mean that other APs are
  57. * either not available or has already been tried, so that we can start
  58. * increasing the delay here to avoid constant scanning.
  59. */
  60. count = wpa_blacklist_add(wpa_s, bssid);
  61. if (count == 1 && wpa_s->current_bss) {
  62. /*
  63. * This BSS was not in the blacklist before. If there is
  64. * another BSS available for the same ESS, we should try that
  65. * next. Otherwise, we may as well try this one once more
  66. * before allowing other, likely worse, ESSes to be considered.
  67. */
  68. if (sme_another_bss_in_ess(wpa_s)) {
  69. wpa_printf(MSG_DEBUG, "SME: Another BSS in this ESS "
  70. "has been seen; try it next");
  71. wpa_blacklist_add(wpa_s, bssid);
  72. }
  73. }
  74. switch (count) {
  75. case 1:
  76. timeout = 100;
  77. break;
  78. case 2:
  79. timeout = 500;
  80. break;
  81. case 3:
  82. timeout = 1000;
  83. break;
  84. default:
  85. timeout = 5000;
  86. }
  87. /*
  88. * TODO: if more than one possible AP is available in scan results,
  89. * could try the other ones before requesting a new scan.
  90. */
  91. wpa_supplicant_req_scan(wpa_s, timeout / 1000,
  92. 1000 * (timeout % 1000));
  93. }
  94. void sme_authenticate(struct wpa_supplicant *wpa_s,
  95. struct wpa_bss *bss, struct wpa_ssid *ssid)
  96. {
  97. struct wpa_driver_auth_params params;
  98. struct wpa_ssid *old_ssid;
  99. #ifdef CONFIG_IEEE80211R
  100. const u8 *ie;
  101. #endif /* CONFIG_IEEE80211R */
  102. #ifdef CONFIG_IEEE80211R
  103. const u8 *md = NULL;
  104. #endif /* CONFIG_IEEE80211R */
  105. int i, bssid_changed;
  106. if (bss == NULL) {
  107. wpa_printf(MSG_ERROR, "SME: No scan result available for the "
  108. "network");
  109. return;
  110. }
  111. wpa_s->current_bss = bss;
  112. os_memset(&params, 0, sizeof(params));
  113. wpa_s->reassociate = 0;
  114. params.freq = bss->freq;
  115. params.bssid = bss->bssid;
  116. params.ssid = bss->ssid;
  117. params.ssid_len = bss->ssid_len;
  118. if (wpa_s->sme.ssid_len != params.ssid_len ||
  119. os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0)
  120. wpa_s->sme.prev_bssid_set = 0;
  121. wpa_s->sme.freq = params.freq;
  122. os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len);
  123. wpa_s->sme.ssid_len = params.ssid_len;
  124. params.auth_alg = WPA_AUTH_ALG_OPEN;
  125. #ifdef IEEE8021X_EAPOL
  126. if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  127. if (ssid->leap) {
  128. if (ssid->non_leap == 0)
  129. params.auth_alg = WPA_AUTH_ALG_LEAP;
  130. else
  131. params.auth_alg |= WPA_AUTH_ALG_LEAP;
  132. }
  133. }
  134. #endif /* IEEE8021X_EAPOL */
  135. wpa_printf(MSG_DEBUG, "Automatic auth_alg selection: 0x%x",
  136. params.auth_alg);
  137. if (ssid->auth_alg) {
  138. params.auth_alg = ssid->auth_alg;
  139. wpa_printf(MSG_DEBUG, "Overriding auth_alg selection: 0x%x",
  140. params.auth_alg);
  141. }
  142. for (i = 0; i < NUM_WEP_KEYS; i++) {
  143. if (ssid->wep_key_len[i])
  144. params.wep_key[i] = ssid->wep_key[i];
  145. params.wep_key_len[i] = ssid->wep_key_len[i];
  146. }
  147. params.wep_tx_keyidx = ssid->wep_tx_keyidx;
  148. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  149. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  150. os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
  151. if (bssid_changed)
  152. wpas_notify_bssid_changed(wpa_s);
  153. if ((wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
  154. wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
  155. (ssid->key_mgmt & (WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK |
  156. WPA_KEY_MGMT_FT_IEEE8021X |
  157. WPA_KEY_MGMT_FT_PSK |
  158. WPA_KEY_MGMT_IEEE8021X_SHA256 |
  159. WPA_KEY_MGMT_PSK_SHA256))) {
  160. int try_opportunistic;
  161. try_opportunistic = ssid->proactive_key_caching &&
  162. (ssid->proto & WPA_PROTO_RSN);
  163. if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
  164. wpa_s->current_ssid,
  165. try_opportunistic) == 0)
  166. eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
  167. wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie);
  168. if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
  169. wpa_s->sme.assoc_req_ie,
  170. &wpa_s->sme.assoc_req_ie_len)) {
  171. wpa_printf(MSG_WARNING, "SME: Failed to set WPA key "
  172. "management and encryption suites");
  173. return;
  174. }
  175. } else if (ssid->key_mgmt &
  176. (WPA_KEY_MGMT_PSK | WPA_KEY_MGMT_IEEE8021X |
  177. WPA_KEY_MGMT_WPA_NONE | WPA_KEY_MGMT_FT_PSK |
  178. WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_PSK_SHA256 |
  179. WPA_KEY_MGMT_IEEE8021X_SHA256)) {
  180. wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie);
  181. if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
  182. wpa_s->sme.assoc_req_ie,
  183. &wpa_s->sme.assoc_req_ie_len)) {
  184. wpa_printf(MSG_WARNING, "SME: Failed to set WPA key "
  185. "management and encryption suites (no scan "
  186. "results)");
  187. return;
  188. }
  189. #ifdef CONFIG_WPS
  190. } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
  191. struct wpabuf *wps_ie;
  192. wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
  193. if (wps_ie && wpabuf_len(wps_ie) <=
  194. sizeof(wpa_s->sme.assoc_req_ie)) {
  195. wpa_s->sme.assoc_req_ie_len = wpabuf_len(wps_ie);
  196. os_memcpy(wpa_s->sme.assoc_req_ie, wpabuf_head(wps_ie),
  197. wpa_s->sme.assoc_req_ie_len);
  198. } else
  199. wpa_s->sme.assoc_req_ie_len = 0;
  200. wpabuf_free(wps_ie);
  201. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  202. #endif /* CONFIG_WPS */
  203. } else {
  204. wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
  205. wpa_s->sme.assoc_req_ie_len = 0;
  206. }
  207. #ifdef CONFIG_IEEE80211R
  208. ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  209. if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
  210. md = ie + 2;
  211. wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
  212. if (md) {
  213. /* Prepare for the next transition */
  214. wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
  215. }
  216. if (md && ssid->key_mgmt & (WPA_KEY_MGMT_FT_PSK |
  217. WPA_KEY_MGMT_FT_IEEE8021X)) {
  218. if (wpa_s->sme.assoc_req_ie_len + 5 <
  219. sizeof(wpa_s->sme.assoc_req_ie)) {
  220. struct rsn_mdie *mdie;
  221. u8 *pos = wpa_s->sme.assoc_req_ie +
  222. wpa_s->sme.assoc_req_ie_len;
  223. *pos++ = WLAN_EID_MOBILITY_DOMAIN;
  224. *pos++ = sizeof(*mdie);
  225. mdie = (struct rsn_mdie *) pos;
  226. os_memcpy(mdie->mobility_domain, md,
  227. MOBILITY_DOMAIN_ID_LEN);
  228. mdie->ft_capab = md[MOBILITY_DOMAIN_ID_LEN];
  229. wpa_s->sme.assoc_req_ie_len += 5;
  230. }
  231. if (wpa_s->sme.ft_used &&
  232. os_memcmp(md, wpa_s->sme.mobility_domain, 2) == 0 &&
  233. wpa_sm_has_ptk(wpa_s->wpa)) {
  234. wpa_printf(MSG_DEBUG, "SME: Trying to use FT "
  235. "over-the-air");
  236. params.auth_alg = WPA_AUTH_ALG_FT;
  237. params.ie = wpa_s->sme.ft_ies;
  238. params.ie_len = wpa_s->sme.ft_ies_len;
  239. }
  240. }
  241. #endif /* CONFIG_IEEE80211R */
  242. #ifdef CONFIG_IEEE80211W
  243. wpa_s->sme.mfp = ssid->ieee80211w;
  244. if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
  245. const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  246. struct wpa_ie_data _ie;
  247. if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &_ie) == 0 &&
  248. _ie.capabilities &
  249. (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
  250. wpa_printf(MSG_DEBUG, "WPA: Selected AP supports MFP: "
  251. "require MFP");
  252. wpa_s->sme.mfp = MGMT_FRAME_PROTECTION_REQUIRED;
  253. }
  254. }
  255. #endif /* CONFIG_IEEE80211W */
  256. #ifdef CONFIG_P2P
  257. if (wpa_s->global->p2p) {
  258. u8 *pos;
  259. size_t len;
  260. int res;
  261. int p2p_group;
  262. p2p_group = wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE;
  263. pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len;
  264. len = sizeof(wpa_s->sme.assoc_req_ie) -
  265. wpa_s->sme.assoc_req_ie_len;
  266. res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, p2p_group);
  267. if (res >= 0)
  268. wpa_s->sme.assoc_req_ie_len += res;
  269. }
  270. #endif /* CONFIG_P2P */
  271. wpa_supplicant_cancel_scan(wpa_s);
  272. wpa_msg(wpa_s, MSG_INFO, "Trying to authenticate with " MACSTR
  273. " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
  274. wpa_ssid_txt(params.ssid, params.ssid_len), params.freq);
  275. wpa_clear_keys(wpa_s, bss->bssid);
  276. wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
  277. old_ssid = wpa_s->current_ssid;
  278. wpa_s->current_ssid = ssid;
  279. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  280. wpa_supplicant_initiate_eapol(wpa_s);
  281. if (old_ssid != wpa_s->current_ssid)
  282. wpas_notify_network_changed(wpa_s);
  283. wpa_s->sme.auth_alg = params.auth_alg;
  284. if (wpa_drv_authenticate(wpa_s, &params) < 0) {
  285. wpa_msg(wpa_s, MSG_INFO, "Authentication request to the "
  286. "driver failed");
  287. wpa_supplicant_req_scan(wpa_s, 1, 0);
  288. return;
  289. }
  290. /* TODO: add timeout on authentication */
  291. /*
  292. * Association will be started based on the authentication event from
  293. * the driver.
  294. */
  295. }
  296. void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data)
  297. {
  298. struct wpa_ssid *ssid = wpa_s->current_ssid;
  299. if (ssid == NULL) {
  300. wpa_printf(MSG_DEBUG, "SME: Ignore authentication event when "
  301. "network is not selected");
  302. return;
  303. }
  304. if (wpa_s->wpa_state != WPA_AUTHENTICATING) {
  305. wpa_printf(MSG_DEBUG, "SME: Ignore authentication event when "
  306. "not in authenticating state");
  307. return;
  308. }
  309. if (os_memcmp(wpa_s->pending_bssid, data->auth.peer, ETH_ALEN) != 0) {
  310. wpa_printf(MSG_DEBUG, "SME: Ignore authentication with "
  311. "unexpected peer " MACSTR,
  312. MAC2STR(data->auth.peer));
  313. return;
  314. }
  315. wpa_printf(MSG_DEBUG, "SME: Authentication response: peer=" MACSTR
  316. " auth_type=%d status_code=%d",
  317. MAC2STR(data->auth.peer), data->auth.auth_type,
  318. data->auth.status_code);
  319. wpa_hexdump(MSG_MSGDUMP, "SME: Authentication response IEs",
  320. data->auth.ies, data->auth.ies_len);
  321. if (data->auth.status_code != WLAN_STATUS_SUCCESS) {
  322. wpa_printf(MSG_DEBUG, "SME: Authentication failed (status "
  323. "code %d)", data->auth.status_code);
  324. if (data->auth.status_code !=
  325. WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG ||
  326. wpa_s->sme.auth_alg == data->auth.auth_type ||
  327. wpa_s->current_ssid->auth_alg == WPA_AUTH_ALG_LEAP) {
  328. sme_connection_failed(wpa_s, wpa_s->pending_bssid);
  329. return;
  330. }
  331. switch (data->auth.auth_type) {
  332. case WLAN_AUTH_OPEN:
  333. wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_SHARED;
  334. wpa_printf(MSG_DEBUG, "SME: Trying SHARED auth");
  335. wpa_supplicant_associate(wpa_s, wpa_s->current_bss,
  336. wpa_s->current_ssid);
  337. return;
  338. case WLAN_AUTH_SHARED_KEY:
  339. wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_LEAP;
  340. wpa_printf(MSG_DEBUG, "SME: Trying LEAP auth");
  341. wpa_supplicant_associate(wpa_s, wpa_s->current_bss,
  342. wpa_s->current_ssid);
  343. return;
  344. default:
  345. return;
  346. }
  347. }
  348. #ifdef CONFIG_IEEE80211R
  349. if (data->auth.auth_type == WLAN_AUTH_FT) {
  350. union wpa_event_data edata;
  351. os_memset(&edata, 0, sizeof(edata));
  352. edata.ft_ies.ies = data->auth.ies;
  353. edata.ft_ies.ies_len = data->auth.ies_len;
  354. os_memcpy(edata.ft_ies.target_ap, data->auth.peer, ETH_ALEN);
  355. wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &edata);
  356. }
  357. #endif /* CONFIG_IEEE80211R */
  358. sme_associate(wpa_s, ssid->mode, data->auth.peer,
  359. data->auth.auth_type);
  360. }
  361. void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode,
  362. const u8 *bssid, u16 auth_type)
  363. {
  364. struct wpa_driver_associate_params params;
  365. struct ieee802_11_elems elems;
  366. os_memset(&params, 0, sizeof(params));
  367. params.bssid = bssid;
  368. params.ssid = wpa_s->sme.ssid;
  369. params.ssid_len = wpa_s->sme.ssid_len;
  370. params.freq = wpa_s->sme.freq;
  371. params.wpa_ie = wpa_s->sme.assoc_req_ie_len ?
  372. wpa_s->sme.assoc_req_ie : NULL;
  373. params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len;
  374. #ifdef CONFIG_IEEE80211R
  375. if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) {
  376. params.wpa_ie = wpa_s->sme.ft_ies;
  377. params.wpa_ie_len = wpa_s->sme.ft_ies_len;
  378. }
  379. #endif /* CONFIG_IEEE80211R */
  380. params.mode = mode;
  381. params.mgmt_frame_protection = wpa_s->sme.mfp;
  382. if (wpa_s->sme.prev_bssid_set)
  383. params.prev_bssid = wpa_s->sme.prev_bssid;
  384. wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
  385. " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
  386. params.ssid ? wpa_ssid_txt(params.ssid, params.ssid_len) : "",
  387. params.freq);
  388. wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
  389. if (params.wpa_ie == NULL ||
  390. ieee802_11_parse_elems(params.wpa_ie, params.wpa_ie_len, &elems, 0)
  391. < 0) {
  392. wpa_printf(MSG_DEBUG, "SME: Could not parse own IEs?!");
  393. os_memset(&elems, 0, sizeof(elems));
  394. }
  395. if (elems.rsn_ie)
  396. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.rsn_ie - 2,
  397. elems.rsn_ie_len + 2);
  398. else if (elems.wpa_ie)
  399. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.wpa_ie - 2,
  400. elems.wpa_ie_len + 2);
  401. else
  402. wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
  403. if (elems.p2p &&
  404. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
  405. params.p2p = 1;
  406. if (wpa_s->parent->set_sta_uapsd)
  407. params.uapsd = wpa_s->parent->sta_uapsd;
  408. else
  409. params.uapsd = -1;
  410. if (wpa_drv_associate(wpa_s, &params) < 0) {
  411. wpa_msg(wpa_s, MSG_INFO, "Association request to the driver "
  412. "failed");
  413. wpa_supplicant_req_scan(wpa_s, 5, 0);
  414. return;
  415. }
  416. /* TODO: add timeout on association */
  417. }
  418. int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
  419. const u8 *ies, size_t ies_len)
  420. {
  421. if (md == NULL || ies == NULL) {
  422. wpa_printf(MSG_DEBUG, "SME: Remove mobility domain");
  423. os_free(wpa_s->sme.ft_ies);
  424. wpa_s->sme.ft_ies = NULL;
  425. wpa_s->sme.ft_ies_len = 0;
  426. wpa_s->sme.ft_used = 0;
  427. return 0;
  428. }
  429. os_memcpy(wpa_s->sme.mobility_domain, md, MOBILITY_DOMAIN_ID_LEN);
  430. wpa_hexdump(MSG_DEBUG, "SME: FT IEs", ies, ies_len);
  431. os_free(wpa_s->sme.ft_ies);
  432. wpa_s->sme.ft_ies = os_malloc(ies_len);
  433. if (wpa_s->sme.ft_ies == NULL)
  434. return -1;
  435. os_memcpy(wpa_s->sme.ft_ies, ies, ies_len);
  436. wpa_s->sme.ft_ies_len = ies_len;
  437. return 0;
  438. }
  439. void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
  440. union wpa_event_data *data)
  441. {
  442. int bssid_changed;
  443. wpa_printf(MSG_DEBUG, "SME: Association with " MACSTR " failed: "
  444. "status code %d", MAC2STR(wpa_s->pending_bssid),
  445. data->assoc_reject.status_code);
  446. bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
  447. /*
  448. * For now, unconditionally terminate the previous authentication. In
  449. * theory, this should not be needed, but mac80211 gets quite confused
  450. * if the authentication is left pending.. Some roaming cases might
  451. * benefit from using the previous authentication, so this could be
  452. * optimized in the future.
  453. */
  454. if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid,
  455. WLAN_REASON_DEAUTH_LEAVING) < 0) {
  456. wpa_msg(wpa_s, MSG_INFO,
  457. "Deauth request to the driver failed");
  458. }
  459. wpa_s->sme.prev_bssid_set = 0;
  460. sme_connection_failed(wpa_s, wpa_s->pending_bssid);
  461. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  462. os_memset(wpa_s->bssid, 0, ETH_ALEN);
  463. os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
  464. if (bssid_changed)
  465. wpas_notify_bssid_changed(wpa_s);
  466. }
  467. void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s,
  468. union wpa_event_data *data)
  469. {
  470. wpa_printf(MSG_DEBUG, "SME: Authentication timed out");
  471. sme_connection_failed(wpa_s, wpa_s->pending_bssid);
  472. }
  473. void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s,
  474. union wpa_event_data *data)
  475. {
  476. wpa_printf(MSG_DEBUG, "SME: Association timed out");
  477. sme_connection_failed(wpa_s, wpa_s->pending_bssid);
  478. wpa_supplicant_mark_disassoc(wpa_s);
  479. }
  480. void sme_event_disassoc(struct wpa_supplicant *wpa_s,
  481. union wpa_event_data *data)
  482. {
  483. wpa_printf(MSG_DEBUG, "SME: Disassociation event received");
  484. if (wpa_s->sme.prev_bssid_set &&
  485. !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)) {
  486. /*
  487. * cfg80211/mac80211 can get into somewhat confused state if
  488. * the AP only disassociates us and leaves us in authenticated
  489. * state. For now, force the state to be cleared to avoid
  490. * confusing errors if we try to associate with the AP again.
  491. */
  492. wpa_printf(MSG_DEBUG, "SME: Deauthenticate to clear driver "
  493. "state");
  494. wpa_drv_deauthenticate(wpa_s, wpa_s->sme.prev_bssid,
  495. WLAN_REASON_DEAUTH_LEAVING);
  496. }
  497. }