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