mlme.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*
  2. * cfg80211 MLME SAP interface
  3. *
  4. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/module.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/nl80211.h>
  10. #include <linux/wireless.h>
  11. #include <net/cfg80211.h>
  12. #include <net/iw_handler.h>
  13. #include "core.h"
  14. #include "nl80211.h"
  15. void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
  16. {
  17. struct wireless_dev *wdev = dev->ieee80211_ptr;
  18. struct wiphy *wiphy = wdev->wiphy;
  19. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  20. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
  21. u8 *bssid = mgmt->bssid;
  22. int i;
  23. u16 status = le16_to_cpu(mgmt->u.auth.status_code);
  24. bool done = false;
  25. wdev_lock(wdev);
  26. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  27. if (wdev->authtry_bsses[i] &&
  28. memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid,
  29. ETH_ALEN) == 0) {
  30. if (status == WLAN_STATUS_SUCCESS) {
  31. wdev->auth_bsses[i] = wdev->authtry_bsses[i];
  32. } else {
  33. cfg80211_unhold_bss(wdev->authtry_bsses[i]);
  34. cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
  35. }
  36. wdev->authtry_bsses[i] = NULL;
  37. done = true;
  38. break;
  39. }
  40. }
  41. WARN_ON(!done);
  42. nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL);
  43. cfg80211_sme_rx_auth(dev, buf, len);
  44. wdev_unlock(wdev);
  45. }
  46. EXPORT_SYMBOL(cfg80211_send_rx_auth);
  47. void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
  48. {
  49. u16 status_code;
  50. struct wireless_dev *wdev = dev->ieee80211_ptr;
  51. struct wiphy *wiphy = wdev->wiphy;
  52. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  53. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
  54. u8 *ie = mgmt->u.assoc_resp.variable;
  55. int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
  56. struct cfg80211_internal_bss *bss = NULL;
  57. wdev_lock(wdev);
  58. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  59. /*
  60. * This is a bit of a hack, we don't notify userspace of
  61. * a (re-)association reply if we tried to send a reassoc
  62. * and got a reject -- we only try again with an assoc
  63. * frame instead of reassoc.
  64. */
  65. if (status_code != WLAN_STATUS_SUCCESS && wdev->conn &&
  66. cfg80211_sme_failed_reassoc(wdev))
  67. goto out;
  68. nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL);
  69. if (status_code == WLAN_STATUS_SUCCESS) {
  70. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  71. if (!wdev->auth_bsses[i])
  72. continue;
  73. if (memcmp(wdev->auth_bsses[i]->pub.bssid, mgmt->bssid,
  74. ETH_ALEN) == 0) {
  75. bss = wdev->auth_bsses[i];
  76. wdev->auth_bsses[i] = NULL;
  77. /* additional reference to drop hold */
  78. cfg80211_ref_bss(bss);
  79. break;
  80. }
  81. }
  82. /*
  83. * We might be coming here because the driver reported
  84. * a successful association at the same time as the
  85. * user requested a deauth. In that case, we will have
  86. * removed the BSS from the auth_bsses list due to the
  87. * deauth request when the assoc response makes it. If
  88. * the two code paths acquire the lock the other way
  89. * around, that's just the standard situation of a
  90. * deauth being requested while connected.
  91. */
  92. if (!bss)
  93. goto out;
  94. } else if (wdev->conn) {
  95. cfg80211_sme_failed_assoc(wdev);
  96. /*
  97. * do not call connect_result() now because the
  98. * sme will schedule work that does it later.
  99. */
  100. goto out;
  101. }
  102. if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) {
  103. /*
  104. * This is for the userspace SME, the CONNECTING
  105. * state will be changed to CONNECTED by
  106. * __cfg80211_connect_result() below.
  107. */
  108. wdev->sme_state = CFG80211_SME_CONNECTING;
  109. }
  110. /* this consumes one bss reference (unless bss is NULL) */
  111. __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
  112. status_code,
  113. status_code == WLAN_STATUS_SUCCESS,
  114. bss ? &bss->pub : NULL);
  115. /* drop hold now, and also reference acquired above */
  116. if (bss) {
  117. cfg80211_unhold_bss(bss);
  118. cfg80211_put_bss(&bss->pub);
  119. }
  120. out:
  121. wdev_unlock(wdev);
  122. }
  123. EXPORT_SYMBOL(cfg80211_send_rx_assoc);
  124. void __cfg80211_send_deauth(struct net_device *dev,
  125. const u8 *buf, size_t len)
  126. {
  127. struct wireless_dev *wdev = dev->ieee80211_ptr;
  128. struct wiphy *wiphy = wdev->wiphy;
  129. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  130. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
  131. const u8 *bssid = mgmt->bssid;
  132. int i;
  133. ASSERT_WDEV_LOCK(wdev);
  134. nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL);
  135. if (wdev->current_bss &&
  136. memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
  137. cfg80211_unhold_bss(wdev->current_bss);
  138. cfg80211_put_bss(&wdev->current_bss->pub);
  139. wdev->current_bss = NULL;
  140. } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
  141. if (wdev->auth_bsses[i] &&
  142. memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
  143. cfg80211_unhold_bss(wdev->auth_bsses[i]);
  144. cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
  145. wdev->auth_bsses[i] = NULL;
  146. break;
  147. }
  148. if (wdev->authtry_bsses[i] &&
  149. memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) {
  150. cfg80211_unhold_bss(wdev->authtry_bsses[i]);
  151. cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
  152. wdev->authtry_bsses[i] = NULL;
  153. break;
  154. }
  155. }
  156. if (wdev->sme_state == CFG80211_SME_CONNECTED) {
  157. u16 reason_code;
  158. bool from_ap;
  159. reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  160. from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0;
  161. __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
  162. } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
  163. __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
  164. WLAN_STATUS_UNSPECIFIED_FAILURE,
  165. false, NULL);
  166. }
  167. }
  168. EXPORT_SYMBOL(__cfg80211_send_deauth);
  169. void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len)
  170. {
  171. struct wireless_dev *wdev = dev->ieee80211_ptr;
  172. wdev_lock(wdev);
  173. __cfg80211_send_deauth(dev, buf, len);
  174. wdev_unlock(wdev);
  175. }
  176. EXPORT_SYMBOL(cfg80211_send_deauth);
  177. void __cfg80211_send_disassoc(struct net_device *dev,
  178. const u8 *buf, size_t len)
  179. {
  180. struct wireless_dev *wdev = dev->ieee80211_ptr;
  181. struct wiphy *wiphy = wdev->wiphy;
  182. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  183. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
  184. const u8 *bssid = mgmt->bssid;
  185. int i;
  186. u16 reason_code;
  187. bool from_ap;
  188. bool done = false;
  189. ASSERT_WDEV_LOCK(wdev);
  190. nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL);
  191. if (wdev->sme_state != CFG80211_SME_CONNECTED)
  192. return;
  193. if (wdev->current_bss &&
  194. memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
  195. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  196. if (wdev->authtry_bsses[i] || wdev->auth_bsses[i])
  197. continue;
  198. wdev->auth_bsses[i] = wdev->current_bss;
  199. wdev->current_bss = NULL;
  200. done = true;
  201. cfg80211_sme_disassoc(dev, i);
  202. break;
  203. }
  204. WARN_ON(!done);
  205. } else
  206. WARN_ON(1);
  207. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  208. from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0;
  209. __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap);
  210. }
  211. EXPORT_SYMBOL(__cfg80211_send_disassoc);
  212. void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
  213. {
  214. struct wireless_dev *wdev = dev->ieee80211_ptr;
  215. wdev_lock(wdev);
  216. __cfg80211_send_disassoc(dev, buf, len);
  217. wdev_unlock(wdev);
  218. }
  219. EXPORT_SYMBOL(cfg80211_send_disassoc);
  220. static void __cfg80211_auth_remove(struct wireless_dev *wdev, const u8 *addr)
  221. {
  222. int i;
  223. bool done = false;
  224. ASSERT_WDEV_LOCK(wdev);
  225. for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
  226. if (wdev->authtry_bsses[i] &&
  227. memcmp(wdev->authtry_bsses[i]->pub.bssid,
  228. addr, ETH_ALEN) == 0) {
  229. cfg80211_unhold_bss(wdev->authtry_bsses[i]);
  230. cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
  231. wdev->authtry_bsses[i] = NULL;
  232. done = true;
  233. break;
  234. }
  235. }
  236. WARN_ON(!done);
  237. }
  238. void __cfg80211_auth_canceled(struct net_device *dev, const u8 *addr)
  239. {
  240. __cfg80211_auth_remove(dev->ieee80211_ptr, addr);
  241. }
  242. EXPORT_SYMBOL(__cfg80211_auth_canceled);
  243. void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
  244. {
  245. struct wireless_dev *wdev = dev->ieee80211_ptr;
  246. struct wiphy *wiphy = wdev->wiphy;
  247. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  248. wdev_lock(wdev);
  249. nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL);
  250. if (wdev->sme_state == CFG80211_SME_CONNECTING)
  251. __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
  252. WLAN_STATUS_UNSPECIFIED_FAILURE,
  253. false, NULL);
  254. __cfg80211_auth_remove(wdev, addr);
  255. wdev_unlock(wdev);
  256. }
  257. EXPORT_SYMBOL(cfg80211_send_auth_timeout);
  258. void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
  259. {
  260. struct wireless_dev *wdev = dev->ieee80211_ptr;
  261. struct wiphy *wiphy = wdev->wiphy;
  262. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  263. int i;
  264. bool done = false;
  265. wdev_lock(wdev);
  266. nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL);
  267. if (wdev->sme_state == CFG80211_SME_CONNECTING)
  268. __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
  269. WLAN_STATUS_UNSPECIFIED_FAILURE,
  270. false, NULL);
  271. for (i = 0; addr && i < MAX_AUTH_BSSES; i++) {
  272. if (wdev->auth_bsses[i] &&
  273. memcmp(wdev->auth_bsses[i]->pub.bssid,
  274. addr, ETH_ALEN) == 0) {
  275. cfg80211_unhold_bss(wdev->auth_bsses[i]);
  276. cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
  277. wdev->auth_bsses[i] = NULL;
  278. done = true;
  279. break;
  280. }
  281. }
  282. WARN_ON(!done);
  283. wdev_unlock(wdev);
  284. }
  285. EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
  286. void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
  287. enum nl80211_key_type key_type, int key_id,
  288. const u8 *tsc, gfp_t gfp)
  289. {
  290. struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
  291. struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
  292. #ifdef CONFIG_CFG80211_WEXT
  293. union iwreq_data wrqu;
  294. char *buf = kmalloc(128, gfp);
  295. if (buf) {
  296. sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
  297. "keyid=%d %scast addr=%pM)", key_id,
  298. key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
  299. addr);
  300. memset(&wrqu, 0, sizeof(wrqu));
  301. wrqu.data.length = strlen(buf);
  302. wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
  303. kfree(buf);
  304. }
  305. #endif
  306. nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
  307. }
  308. EXPORT_SYMBOL(cfg80211_michael_mic_failure);
  309. /* some MLME handling for userspace SME */
  310. int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  311. struct net_device *dev,
  312. struct ieee80211_channel *chan,
  313. enum nl80211_auth_type auth_type,
  314. const u8 *bssid,
  315. const u8 *ssid, int ssid_len,
  316. const u8 *ie, int ie_len,
  317. const u8 *key, int key_len, int key_idx)
  318. {
  319. struct wireless_dev *wdev = dev->ieee80211_ptr;
  320. struct cfg80211_auth_request req;
  321. struct cfg80211_internal_bss *bss;
  322. int i, err, slot = -1, nfree = 0;
  323. ASSERT_WDEV_LOCK(wdev);
  324. if (auth_type == NL80211_AUTHTYPE_SHARED_KEY)
  325. if (!key || !key_len || key_idx < 0 || key_idx > 4)
  326. return -EINVAL;
  327. if (wdev->current_bss &&
  328. memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0)
  329. return -EALREADY;
  330. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  331. if (wdev->authtry_bsses[i] &&
  332. memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid,
  333. ETH_ALEN) == 0)
  334. return -EALREADY;
  335. if (wdev->auth_bsses[i] &&
  336. memcmp(bssid, wdev->auth_bsses[i]->pub.bssid,
  337. ETH_ALEN) == 0)
  338. return -EALREADY;
  339. }
  340. memset(&req, 0, sizeof(req));
  341. req.ie = ie;
  342. req.ie_len = ie_len;
  343. req.auth_type = auth_type;
  344. req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
  345. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  346. req.key = key;
  347. req.key_len = key_len;
  348. req.key_idx = key_idx;
  349. if (!req.bss)
  350. return -ENOENT;
  351. bss = bss_from_pub(req.bss);
  352. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  353. if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) {
  354. slot = i;
  355. nfree++;
  356. }
  357. }
  358. /* we need one free slot for disassoc and one for this auth */
  359. if (nfree < 2) {
  360. err = -ENOSPC;
  361. goto out;
  362. }
  363. wdev->authtry_bsses[slot] = bss;
  364. cfg80211_hold_bss(bss);
  365. err = rdev->ops->auth(&rdev->wiphy, dev, &req);
  366. if (err) {
  367. wdev->authtry_bsses[slot] = NULL;
  368. cfg80211_unhold_bss(bss);
  369. }
  370. out:
  371. if (err)
  372. cfg80211_put_bss(req.bss);
  373. return err;
  374. }
  375. int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
  376. struct net_device *dev, struct ieee80211_channel *chan,
  377. enum nl80211_auth_type auth_type, const u8 *bssid,
  378. const u8 *ssid, int ssid_len,
  379. const u8 *ie, int ie_len,
  380. const u8 *key, int key_len, int key_idx)
  381. {
  382. int err;
  383. wdev_lock(dev->ieee80211_ptr);
  384. err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
  385. ssid, ssid_len, ie, ie_len,
  386. key, key_len, key_idx);
  387. wdev_unlock(dev->ieee80211_ptr);
  388. return err;
  389. }
  390. int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  391. struct net_device *dev,
  392. struct ieee80211_channel *chan,
  393. const u8 *bssid, const u8 *prev_bssid,
  394. const u8 *ssid, int ssid_len,
  395. const u8 *ie, int ie_len, bool use_mfp,
  396. struct cfg80211_crypto_settings *crypt)
  397. {
  398. struct wireless_dev *wdev = dev->ieee80211_ptr;
  399. struct cfg80211_assoc_request req;
  400. struct cfg80211_internal_bss *bss;
  401. int i, err, slot = -1;
  402. bool was_connected = false;
  403. ASSERT_WDEV_LOCK(wdev);
  404. memset(&req, 0, sizeof(req));
  405. if (wdev->current_bss && prev_bssid &&
  406. memcmp(wdev->current_bss->pub.bssid, prev_bssid, ETH_ALEN) == 0) {
  407. /*
  408. * Trying to reassociate: Allow this to proceed and let the old
  409. * association to be dropped when the new one is completed.
  410. */
  411. if (wdev->sme_state == CFG80211_SME_CONNECTED) {
  412. was_connected = true;
  413. wdev->sme_state = CFG80211_SME_CONNECTING;
  414. }
  415. } else if (wdev->current_bss)
  416. return -EALREADY;
  417. req.ie = ie;
  418. req.ie_len = ie_len;
  419. memcpy(&req.crypto, crypt, sizeof(req.crypto));
  420. req.use_mfp = use_mfp;
  421. req.prev_bssid = prev_bssid;
  422. req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len,
  423. WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
  424. if (!req.bss) {
  425. if (was_connected)
  426. wdev->sme_state = CFG80211_SME_CONNECTED;
  427. return -ENOENT;
  428. }
  429. bss = bss_from_pub(req.bss);
  430. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  431. if (bss == wdev->auth_bsses[i]) {
  432. slot = i;
  433. break;
  434. }
  435. }
  436. if (slot < 0) {
  437. err = -ENOTCONN;
  438. goto out;
  439. }
  440. err = rdev->ops->assoc(&rdev->wiphy, dev, &req);
  441. out:
  442. if (err && was_connected)
  443. wdev->sme_state = CFG80211_SME_CONNECTED;
  444. /* still a reference in wdev->auth_bsses[slot] */
  445. cfg80211_put_bss(req.bss);
  446. return err;
  447. }
  448. int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev,
  449. struct net_device *dev,
  450. struct ieee80211_channel *chan,
  451. const u8 *bssid, const u8 *prev_bssid,
  452. const u8 *ssid, int ssid_len,
  453. const u8 *ie, int ie_len, bool use_mfp,
  454. struct cfg80211_crypto_settings *crypt)
  455. {
  456. struct wireless_dev *wdev = dev->ieee80211_ptr;
  457. int err;
  458. wdev_lock(wdev);
  459. err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid,
  460. ssid, ssid_len, ie, ie_len, use_mfp, crypt);
  461. wdev_unlock(wdev);
  462. return err;
  463. }
  464. int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  465. struct net_device *dev, const u8 *bssid,
  466. const u8 *ie, int ie_len, u16 reason)
  467. {
  468. struct wireless_dev *wdev = dev->ieee80211_ptr;
  469. struct cfg80211_deauth_request req;
  470. int i;
  471. ASSERT_WDEV_LOCK(wdev);
  472. memset(&req, 0, sizeof(req));
  473. req.reason_code = reason;
  474. req.ie = ie;
  475. req.ie_len = ie_len;
  476. if (wdev->current_bss &&
  477. memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) {
  478. req.bss = &wdev->current_bss->pub;
  479. } else for (i = 0; i < MAX_AUTH_BSSES; i++) {
  480. if (wdev->auth_bsses[i] &&
  481. memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) {
  482. req.bss = &wdev->auth_bsses[i]->pub;
  483. break;
  484. }
  485. if (wdev->authtry_bsses[i] &&
  486. memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) {
  487. req.bss = &wdev->authtry_bsses[i]->pub;
  488. break;
  489. }
  490. }
  491. if (!req.bss)
  492. return -ENOTCONN;
  493. return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
  494. }
  495. int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev,
  496. struct net_device *dev, const u8 *bssid,
  497. const u8 *ie, int ie_len, u16 reason)
  498. {
  499. struct wireless_dev *wdev = dev->ieee80211_ptr;
  500. int err;
  501. wdev_lock(wdev);
  502. err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason);
  503. wdev_unlock(wdev);
  504. return err;
  505. }
  506. static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  507. struct net_device *dev, const u8 *bssid,
  508. const u8 *ie, int ie_len, u16 reason)
  509. {
  510. struct wireless_dev *wdev = dev->ieee80211_ptr;
  511. struct cfg80211_disassoc_request req;
  512. ASSERT_WDEV_LOCK(wdev);
  513. if (wdev->sme_state != CFG80211_SME_CONNECTED)
  514. return -ENOTCONN;
  515. if (WARN_ON(!wdev->current_bss))
  516. return -ENOTCONN;
  517. memset(&req, 0, sizeof(req));
  518. req.reason_code = reason;
  519. req.ie = ie;
  520. req.ie_len = ie_len;
  521. if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0)
  522. req.bss = &wdev->current_bss->pub;
  523. else
  524. return -ENOTCONN;
  525. return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev);
  526. }
  527. int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev,
  528. struct net_device *dev, const u8 *bssid,
  529. const u8 *ie, int ie_len, u16 reason)
  530. {
  531. struct wireless_dev *wdev = dev->ieee80211_ptr;
  532. int err;
  533. wdev_lock(wdev);
  534. err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason);
  535. wdev_unlock(wdev);
  536. return err;
  537. }
  538. void cfg80211_mlme_down(struct cfg80211_registered_device *rdev,
  539. struct net_device *dev)
  540. {
  541. struct wireless_dev *wdev = dev->ieee80211_ptr;
  542. struct cfg80211_deauth_request req;
  543. int i;
  544. ASSERT_WDEV_LOCK(wdev);
  545. if (!rdev->ops->deauth)
  546. return;
  547. memset(&req, 0, sizeof(req));
  548. req.reason_code = WLAN_REASON_DEAUTH_LEAVING;
  549. req.ie = NULL;
  550. req.ie_len = 0;
  551. if (wdev->current_bss) {
  552. req.bss = &wdev->current_bss->pub;
  553. rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
  554. if (wdev->current_bss) {
  555. cfg80211_unhold_bss(wdev->current_bss);
  556. cfg80211_put_bss(&wdev->current_bss->pub);
  557. wdev->current_bss = NULL;
  558. }
  559. }
  560. for (i = 0; i < MAX_AUTH_BSSES; i++) {
  561. if (wdev->auth_bsses[i]) {
  562. req.bss = &wdev->auth_bsses[i]->pub;
  563. rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
  564. if (wdev->auth_bsses[i]) {
  565. cfg80211_unhold_bss(wdev->auth_bsses[i]);
  566. cfg80211_put_bss(&wdev->auth_bsses[i]->pub);
  567. wdev->auth_bsses[i] = NULL;
  568. }
  569. }
  570. if (wdev->authtry_bsses[i]) {
  571. req.bss = &wdev->authtry_bsses[i]->pub;
  572. rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev);
  573. if (wdev->authtry_bsses[i]) {
  574. cfg80211_unhold_bss(wdev->authtry_bsses[i]);
  575. cfg80211_put_bss(&wdev->authtry_bsses[i]->pub);
  576. wdev->authtry_bsses[i] = NULL;
  577. }
  578. }
  579. }
  580. }