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