sme.c 15 KB

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