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 | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 70 | nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 71 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 72 | if (status_code == WLAN_STATUS_SUCCESS) { |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame^] | 73 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 74 | if (!wdev->auth_bsses[i]) |
| 75 | continue; |
| 76 | if (memcmp(wdev->auth_bsses[i]->pub.bssid, mgmt->bssid, |
| 77 | ETH_ALEN) == 0) { |
| 78 | bss = wdev->auth_bsses[i]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 79 | wdev->auth_bsses[i] = NULL; |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame^] | 80 | /* additional reference to drop hold */ |
| 81 | cfg80211_ref_bss(bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 82 | break; |
| 83 | } |
| 84 | } |
| 85 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame^] | 86 | WARN_ON(!bss); |
| 87 | } |
| 88 | |
| 89 | /* this consumes one bss reference (unless bss is NULL) */ |
| 90 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, |
| 91 | status_code, |
| 92 | status_code == WLAN_STATUS_SUCCESS, |
| 93 | bss ? &bss->pub : NULL); |
| 94 | /* drop hold now, and also reference acquired above */ |
| 95 | if (bss) { |
| 96 | cfg80211_unhold_bss(bss); |
| 97 | cfg80211_put_bss(&bss->pub); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 98 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 99 | |
| 100 | wdev_unlock(wdev); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 101 | } |
| 102 | EXPORT_SYMBOL(cfg80211_send_rx_assoc); |
| 103 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 104 | static void __cfg80211_send_deauth(struct net_device *dev, |
| 105 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 106 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 107 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 108 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 109 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 110 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 111 | const u8 *bssid = mgmt->bssid; |
| 112 | int i; |
| 113 | bool done = false; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 114 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 115 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 116 | |
| 117 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 118 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 119 | if (wdev->current_bss && |
| 120 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 121 | done = true; |
| 122 | cfg80211_unhold_bss(wdev->current_bss); |
| 123 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 124 | wdev->current_bss = NULL; |
| 125 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 126 | if (wdev->auth_bsses[i] && |
| 127 | memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 128 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 129 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 130 | wdev->auth_bsses[i] = NULL; |
| 131 | done = true; |
| 132 | break; |
| 133 | } |
| 134 | if (wdev->authtry_bsses[i] && |
| 135 | memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 136 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 137 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 138 | wdev->authtry_bsses[i] = NULL; |
| 139 | done = true; |
| 140 | break; |
| 141 | } |
| 142 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 143 | |
| 144 | WARN_ON(!done); |
| 145 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 146 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { |
| 147 | u16 reason_code; |
| 148 | bool from_ap; |
| 149 | |
| 150 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 151 | |
| 152 | from_ap = memcmp(mgmt->da, dev->dev_addr, ETH_ALEN) == 0; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 153 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 154 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING) { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 155 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
| 156 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame^] | 157 | false, NULL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | |
| 162 | void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len, |
| 163 | void *cookie) |
| 164 | { |
| 165 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 166 | |
| 167 | BUG_ON(cookie && wdev != cookie); |
| 168 | |
| 169 | if (cookie) { |
| 170 | /* called within callback */ |
| 171 | __cfg80211_send_deauth(dev, buf, len); |
| 172 | } else { |
| 173 | wdev_lock(wdev); |
| 174 | __cfg80211_send_deauth(dev, buf, len); |
| 175 | wdev_unlock(wdev); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 176 | } |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 177 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 178 | EXPORT_SYMBOL(cfg80211_send_deauth); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 179 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 180 | static void __cfg80211_send_disassoc(struct net_device *dev, |
| 181 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 182 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 183 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 184 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 185 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 186 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 187 | const u8 *bssid = mgmt->bssid; |
| 188 | int i; |
| 189 | u16 reason_code; |
| 190 | bool from_ap; |
| 191 | bool done = false; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 192 | |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 193 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 194 | |
| 195 | nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 196 | |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 197 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 198 | return; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 199 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 200 | if (wdev->current_bss && |
| 201 | memcmp(wdev->current_bss, bssid, ETH_ALEN) == 0) { |
| 202 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 203 | if (wdev->authtry_bsses[i] || wdev->auth_bsses[i]) |
| 204 | continue; |
| 205 | wdev->auth_bsses[i] = wdev->current_bss; |
| 206 | wdev->current_bss = NULL; |
| 207 | done = true; |
| 208 | cfg80211_sme_disassoc(dev, i); |
| 209 | break; |
| 210 | } |
| 211 | WARN_ON(!done); |
| 212 | } else |
| 213 | WARN_ON(1); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 214 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 215 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 216 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 217 | |
| 218 | from_ap = memcmp(mgmt->da, dev->dev_addr, ETH_ALEN) == 0; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 219 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len, |
| 223 | void *cookie) |
| 224 | { |
| 225 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 226 | |
| 227 | BUG_ON(cookie && wdev != cookie); |
| 228 | |
| 229 | if (cookie) { |
| 230 | /* called within callback */ |
| 231 | __cfg80211_send_disassoc(dev, buf, len); |
| 232 | } else { |
| 233 | wdev_lock(wdev); |
| 234 | __cfg80211_send_disassoc(dev, buf, len); |
| 235 | wdev_unlock(wdev); |
| 236 | } |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 237 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 238 | EXPORT_SYMBOL(cfg80211_send_disassoc); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 239 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 240 | void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 241 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 242 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 243 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 244 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 245 | int i; |
| 246 | bool done = false; |
| 247 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 248 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 249 | |
| 250 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 251 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 252 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 253 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame^] | 254 | false, NULL); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 255 | |
| 256 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { |
| 257 | if (wdev->authtry_bsses[i] && |
| 258 | memcmp(wdev->authtry_bsses[i]->pub.bssid, |
| 259 | addr, ETH_ALEN) == 0) { |
| 260 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 261 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 262 | wdev->authtry_bsses[i] = NULL; |
| 263 | done = true; |
| 264 | break; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | WARN_ON(!done); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 269 | |
| 270 | wdev_unlock(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 271 | } |
| 272 | EXPORT_SYMBOL(cfg80211_send_auth_timeout); |
| 273 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 274 | void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 275 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 276 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 277 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 278 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 279 | int i; |
| 280 | bool done = false; |
| 281 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 282 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 283 | |
| 284 | nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 285 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 286 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 287 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame^] | 288 | false, NULL); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 289 | |
| 290 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { |
| 291 | if (wdev->auth_bsses[i] && |
| 292 | memcmp(wdev->auth_bsses[i]->pub.bssid, |
| 293 | addr, ETH_ALEN) == 0) { |
| 294 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 295 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 296 | wdev->auth_bsses[i] = NULL; |
| 297 | done = true; |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | WARN_ON(!done); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 303 | |
| 304 | wdev_unlock(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 305 | } |
| 306 | EXPORT_SYMBOL(cfg80211_send_assoc_timeout); |
| 307 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 308 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
| 309 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 310 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 311 | { |
| 312 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 313 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 314 | #ifdef CONFIG_WIRELESS_EXT |
| 315 | union iwreq_data wrqu; |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 316 | char *buf = kmalloc(128, gfp); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 317 | |
| 318 | if (buf) { |
| 319 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" |
| 320 | "keyid=%d %scast addr=%pM)", key_id, |
| 321 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", |
| 322 | addr); |
| 323 | memset(&wrqu, 0, sizeof(wrqu)); |
| 324 | wrqu.data.length = strlen(buf); |
| 325 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); |
| 326 | kfree(buf); |
| 327 | } |
| 328 | #endif |
| 329 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 330 | 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] | 331 | } |
| 332 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 333 | |
| 334 | /* some MLME handling for userspace SME */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 335 | int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 336 | struct net_device *dev, |
| 337 | struct ieee80211_channel *chan, |
| 338 | enum nl80211_auth_type auth_type, |
| 339 | const u8 *bssid, |
| 340 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 341 | const u8 *ie, int ie_len, |
| 342 | const u8 *key, int key_len, int key_idx) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 343 | { |
| 344 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 345 | struct cfg80211_auth_request req; |
| 346 | struct cfg80211_internal_bss *bss; |
| 347 | int i, err, slot = -1, nfree = 0; |
| 348 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 349 | ASSERT_WDEV_LOCK(wdev); |
| 350 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 351 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
| 352 | if (!key || !key_len || key_idx < 0 || key_idx > 4) |
| 353 | return -EINVAL; |
| 354 | |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 355 | if (wdev->current_bss && |
| 356 | memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0) |
| 357 | return -EALREADY; |
| 358 | |
| 359 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 360 | if (wdev->authtry_bsses[i] && |
| 361 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, |
| 362 | ETH_ALEN) == 0) |
| 363 | return -EALREADY; |
| 364 | if (wdev->auth_bsses[i] && |
| 365 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, |
| 366 | ETH_ALEN) == 0) |
| 367 | return -EALREADY; |
| 368 | } |
| 369 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 370 | memset(&req, 0, sizeof(req)); |
| 371 | |
| 372 | req.ie = ie; |
| 373 | req.ie_len = ie_len; |
| 374 | req.auth_type = auth_type; |
| 375 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 376 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 377 | req.key = key; |
| 378 | req.key_len = key_len; |
| 379 | req.key_idx = key_idx; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 380 | if (!req.bss) |
| 381 | return -ENOENT; |
| 382 | |
| 383 | bss = bss_from_pub(req.bss); |
| 384 | |
| 385 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 386 | if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) { |
| 387 | slot = i; |
| 388 | nfree++; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /* we need one free slot for disassoc and one for this auth */ |
| 393 | if (nfree < 2) { |
| 394 | err = -ENOSPC; |
| 395 | goto out; |
| 396 | } |
| 397 | |
| 398 | wdev->authtry_bsses[slot] = bss; |
| 399 | cfg80211_hold_bss(bss); |
| 400 | |
| 401 | err = rdev->ops->auth(&rdev->wiphy, dev, &req); |
| 402 | if (err) { |
| 403 | wdev->authtry_bsses[slot] = NULL; |
| 404 | cfg80211_unhold_bss(bss); |
| 405 | } |
| 406 | |
| 407 | out: |
| 408 | if (err) |
| 409 | cfg80211_put_bss(req.bss); |
| 410 | return err; |
| 411 | } |
| 412 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 413 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 414 | struct net_device *dev, struct ieee80211_channel *chan, |
| 415 | enum nl80211_auth_type auth_type, const u8 *bssid, |
| 416 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 417 | const u8 *ie, int ie_len, |
| 418 | const u8 *key, int key_len, int key_idx) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 419 | { |
| 420 | int err; |
| 421 | |
| 422 | wdev_lock(dev->ieee80211_ptr); |
| 423 | err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 424 | ssid, ssid_len, ie, ie_len, |
| 425 | key, key_len, key_idx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 426 | wdev_unlock(dev->ieee80211_ptr); |
| 427 | |
| 428 | return err; |
| 429 | } |
| 430 | |
| 431 | int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 432 | struct net_device *dev, |
| 433 | struct ieee80211_channel *chan, |
| 434 | const u8 *bssid, const u8 *prev_bssid, |
| 435 | const u8 *ssid, int ssid_len, |
| 436 | const u8 *ie, int ie_len, bool use_mfp, |
| 437 | struct cfg80211_crypto_settings *crypt) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 438 | { |
| 439 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 440 | struct cfg80211_assoc_request req; |
| 441 | struct cfg80211_internal_bss *bss; |
| 442 | int i, err, slot = -1; |
| 443 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 444 | ASSERT_WDEV_LOCK(wdev); |
| 445 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 446 | memset(&req, 0, sizeof(req)); |
| 447 | |
| 448 | if (wdev->current_bss) |
| 449 | return -EALREADY; |
| 450 | |
| 451 | req.ie = ie; |
| 452 | req.ie_len = ie_len; |
| 453 | memcpy(&req.crypto, crypt, sizeof(req.crypto)); |
| 454 | req.use_mfp = use_mfp; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 455 | req.prev_bssid = prev_bssid; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 456 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 457 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 458 | if (!req.bss) |
| 459 | return -ENOENT; |
| 460 | |
| 461 | bss = bss_from_pub(req.bss); |
| 462 | |
| 463 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 464 | if (bss == wdev->auth_bsses[i]) { |
| 465 | slot = i; |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | if (slot < 0) { |
| 471 | err = -ENOTCONN; |
| 472 | goto out; |
| 473 | } |
| 474 | |
| 475 | err = rdev->ops->assoc(&rdev->wiphy, dev, &req); |
| 476 | out: |
| 477 | /* still a reference in wdev->auth_bsses[slot] */ |
| 478 | cfg80211_put_bss(req.bss); |
| 479 | return err; |
| 480 | } |
| 481 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 482 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 483 | struct net_device *dev, |
| 484 | struct ieee80211_channel *chan, |
| 485 | const u8 *bssid, const u8 *prev_bssid, |
| 486 | const u8 *ssid, int ssid_len, |
| 487 | const u8 *ie, int ie_len, bool use_mfp, |
| 488 | struct cfg80211_crypto_settings *crypt) |
| 489 | { |
| 490 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 491 | int err; |
| 492 | |
| 493 | wdev_lock(wdev); |
| 494 | err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 495 | ssid, ssid_len, ie, ie_len, use_mfp, crypt); |
| 496 | wdev_unlock(wdev); |
| 497 | |
| 498 | return err; |
| 499 | } |
| 500 | |
| 501 | int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 502 | struct net_device *dev, const u8 *bssid, |
| 503 | const u8 *ie, int ie_len, u16 reason) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 504 | { |
| 505 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 506 | struct cfg80211_deauth_request req; |
| 507 | int i; |
| 508 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 509 | ASSERT_WDEV_LOCK(wdev); |
| 510 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 511 | memset(&req, 0, sizeof(req)); |
| 512 | req.reason_code = reason; |
| 513 | req.ie = ie; |
| 514 | req.ie_len = ie_len; |
| 515 | if (wdev->current_bss && |
| 516 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 517 | req.bss = &wdev->current_bss->pub; |
| 518 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 519 | if (wdev->auth_bsses[i] && |
| 520 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) { |
| 521 | req.bss = &wdev->auth_bsses[i]->pub; |
| 522 | break; |
| 523 | } |
| 524 | if (wdev->authtry_bsses[i] && |
| 525 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) { |
| 526 | req.bss = &wdev->authtry_bsses[i]->pub; |
| 527 | break; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if (!req.bss) |
| 532 | return -ENOTCONN; |
| 533 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 534 | return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 535 | } |
| 536 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 537 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 538 | struct net_device *dev, const u8 *bssid, |
| 539 | const u8 *ie, int ie_len, u16 reason) |
| 540 | { |
| 541 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 542 | int err; |
| 543 | |
| 544 | wdev_lock(wdev); |
| 545 | err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason); |
| 546 | wdev_unlock(wdev); |
| 547 | |
| 548 | return err; |
| 549 | } |
| 550 | |
| 551 | static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 552 | struct net_device *dev, const u8 *bssid, |
| 553 | const u8 *ie, int ie_len, u16 reason) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 554 | { |
| 555 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 556 | struct cfg80211_disassoc_request req; |
| 557 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 558 | ASSERT_WDEV_LOCK(wdev); |
| 559 | |
Johannes Berg | f9d6b40 | 2009-07-27 10:22:28 +0200 | [diff] [blame] | 560 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 561 | return -ENOTCONN; |
| 562 | |
| 563 | if (WARN_ON(!wdev->current_bss)) |
| 564 | return -ENOTCONN; |
| 565 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 566 | memset(&req, 0, sizeof(req)); |
| 567 | req.reason_code = reason; |
| 568 | req.ie = ie; |
| 569 | req.ie_len = ie_len; |
| 570 | if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) |
| 571 | req.bss = &wdev->current_bss->pub; |
| 572 | else |
| 573 | return -ENOTCONN; |
| 574 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 575 | return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev); |
| 576 | } |
| 577 | |
| 578 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 579 | struct net_device *dev, const u8 *bssid, |
| 580 | const u8 *ie, int ie_len, u16 reason) |
| 581 | { |
| 582 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 583 | int err; |
| 584 | |
| 585 | wdev_lock(wdev); |
| 586 | err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason); |
| 587 | wdev_unlock(wdev); |
| 588 | |
| 589 | return err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, |
| 593 | struct net_device *dev) |
| 594 | { |
| 595 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 596 | struct cfg80211_deauth_request req; |
| 597 | int i; |
| 598 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 599 | ASSERT_WDEV_LOCK(wdev); |
| 600 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 601 | if (!rdev->ops->deauth) |
| 602 | return; |
| 603 | |
| 604 | memset(&req, 0, sizeof(req)); |
| 605 | req.reason_code = WLAN_REASON_DEAUTH_LEAVING; |
| 606 | req.ie = NULL; |
| 607 | req.ie_len = 0; |
| 608 | |
| 609 | if (wdev->current_bss) { |
| 610 | req.bss = &wdev->current_bss->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 611 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 612 | if (wdev->current_bss) { |
| 613 | cfg80211_unhold_bss(wdev->current_bss); |
| 614 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 615 | wdev->current_bss = NULL; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 620 | if (wdev->auth_bsses[i]) { |
| 621 | req.bss = &wdev->auth_bsses[i]->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 622 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 623 | if (wdev->auth_bsses[i]) { |
| 624 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 625 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 626 | wdev->auth_bsses[i] = NULL; |
| 627 | } |
| 628 | } |
| 629 | if (wdev->authtry_bsses[i]) { |
| 630 | req.bss = &wdev->authtry_bsses[i]->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 631 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 632 | if (wdev->authtry_bsses[i]) { |
| 633 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 634 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 635 | wdev->authtry_bsses[i] = NULL; |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |