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 | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame^] | 181 | ASSERT_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 | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame^] | 185 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 186 | return; |
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); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len, |
| 211 | void *cookie) |
| 212 | { |
| 213 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 214 | |
| 215 | BUG_ON(cookie && wdev != cookie); |
| 216 | |
| 217 | if (cookie) { |
| 218 | /* called within callback */ |
| 219 | __cfg80211_send_disassoc(dev, buf, len); |
| 220 | } else { |
| 221 | wdev_lock(wdev); |
| 222 | __cfg80211_send_disassoc(dev, buf, len); |
| 223 | wdev_unlock(wdev); |
| 224 | } |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 225 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 226 | EXPORT_SYMBOL(cfg80211_send_disassoc); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 227 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 228 | void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 229 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 230 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 231 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 232 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 233 | int i; |
| 234 | bool done = false; |
| 235 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 236 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 237 | |
| 238 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 239 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 240 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 241 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 242 | false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 243 | |
| 244 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { |
| 245 | if (wdev->authtry_bsses[i] && |
| 246 | memcmp(wdev->authtry_bsses[i]->pub.bssid, |
| 247 | addr, ETH_ALEN) == 0) { |
| 248 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 249 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 250 | wdev->authtry_bsses[i] = NULL; |
| 251 | done = true; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | WARN_ON(!done); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 257 | |
| 258 | wdev_unlock(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 259 | } |
| 260 | EXPORT_SYMBOL(cfg80211_send_auth_timeout); |
| 261 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 262 | void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 263 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 264 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 265 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 266 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 267 | int i; |
| 268 | bool done = false; |
| 269 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 270 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 271 | |
| 272 | nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 273 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 274 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 275 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 276 | false); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 277 | |
| 278 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { |
| 279 | if (wdev->auth_bsses[i] && |
| 280 | memcmp(wdev->auth_bsses[i]->pub.bssid, |
| 281 | addr, ETH_ALEN) == 0) { |
| 282 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 283 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 284 | wdev->auth_bsses[i] = NULL; |
| 285 | done = true; |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | WARN_ON(!done); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 291 | |
| 292 | wdev_unlock(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 293 | } |
| 294 | EXPORT_SYMBOL(cfg80211_send_assoc_timeout); |
| 295 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 296 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
| 297 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 298 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 299 | { |
| 300 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 301 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 302 | #ifdef CONFIG_WIRELESS_EXT |
| 303 | union iwreq_data wrqu; |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 304 | char *buf = kmalloc(128, gfp); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 305 | |
| 306 | if (buf) { |
| 307 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" |
| 308 | "keyid=%d %scast addr=%pM)", key_id, |
| 309 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", |
| 310 | addr); |
| 311 | memset(&wrqu, 0, sizeof(wrqu)); |
| 312 | wrqu.data.length = strlen(buf); |
| 313 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); |
| 314 | kfree(buf); |
| 315 | } |
| 316 | #endif |
| 317 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 318 | 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] | 319 | } |
| 320 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 321 | |
| 322 | /* some MLME handling for userspace SME */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 323 | int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 324 | struct net_device *dev, |
| 325 | struct ieee80211_channel *chan, |
| 326 | enum nl80211_auth_type auth_type, |
| 327 | const u8 *bssid, |
| 328 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 329 | const u8 *ie, int ie_len, |
| 330 | const u8 *key, int key_len, int key_idx) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 331 | { |
| 332 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 333 | struct cfg80211_auth_request req; |
| 334 | struct cfg80211_internal_bss *bss; |
| 335 | int i, err, slot = -1, nfree = 0; |
| 336 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 337 | ASSERT_WDEV_LOCK(wdev); |
| 338 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 339 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
| 340 | if (!key || !key_len || key_idx < 0 || key_idx > 4) |
| 341 | return -EINVAL; |
| 342 | |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 343 | if (wdev->current_bss && |
| 344 | memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0) |
| 345 | return -EALREADY; |
| 346 | |
| 347 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 348 | if (wdev->authtry_bsses[i] && |
| 349 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, |
| 350 | ETH_ALEN) == 0) |
| 351 | return -EALREADY; |
| 352 | if (wdev->auth_bsses[i] && |
| 353 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, |
| 354 | ETH_ALEN) == 0) |
| 355 | return -EALREADY; |
| 356 | } |
| 357 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 358 | memset(&req, 0, sizeof(req)); |
| 359 | |
| 360 | req.ie = ie; |
| 361 | req.ie_len = ie_len; |
| 362 | req.auth_type = auth_type; |
| 363 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 364 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 365 | req.key = key; |
| 366 | req.key_len = key_len; |
| 367 | req.key_idx = key_idx; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 368 | if (!req.bss) |
| 369 | return -ENOENT; |
| 370 | |
| 371 | bss = bss_from_pub(req.bss); |
| 372 | |
| 373 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 374 | if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) { |
| 375 | slot = i; |
| 376 | nfree++; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | /* we need one free slot for disassoc and one for this auth */ |
| 381 | if (nfree < 2) { |
| 382 | err = -ENOSPC; |
| 383 | goto out; |
| 384 | } |
| 385 | |
| 386 | wdev->authtry_bsses[slot] = bss; |
| 387 | cfg80211_hold_bss(bss); |
| 388 | |
| 389 | err = rdev->ops->auth(&rdev->wiphy, dev, &req); |
| 390 | if (err) { |
| 391 | wdev->authtry_bsses[slot] = NULL; |
| 392 | cfg80211_unhold_bss(bss); |
| 393 | } |
| 394 | |
| 395 | out: |
| 396 | if (err) |
| 397 | cfg80211_put_bss(req.bss); |
| 398 | return err; |
| 399 | } |
| 400 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 401 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 402 | struct net_device *dev, struct ieee80211_channel *chan, |
| 403 | enum nl80211_auth_type auth_type, const u8 *bssid, |
| 404 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 405 | const u8 *ie, int ie_len, |
| 406 | const u8 *key, int key_len, int key_idx) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 407 | { |
| 408 | int err; |
| 409 | |
| 410 | wdev_lock(dev->ieee80211_ptr); |
| 411 | err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 412 | ssid, ssid_len, ie, ie_len, |
| 413 | key, key_len, key_idx); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 414 | wdev_unlock(dev->ieee80211_ptr); |
| 415 | |
| 416 | return err; |
| 417 | } |
| 418 | |
| 419 | int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 420 | struct net_device *dev, |
| 421 | struct ieee80211_channel *chan, |
| 422 | const u8 *bssid, const u8 *prev_bssid, |
| 423 | const u8 *ssid, int ssid_len, |
| 424 | const u8 *ie, int ie_len, bool use_mfp, |
| 425 | struct cfg80211_crypto_settings *crypt) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 426 | { |
| 427 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 428 | struct cfg80211_assoc_request req; |
| 429 | struct cfg80211_internal_bss *bss; |
| 430 | int i, err, slot = -1; |
| 431 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 432 | ASSERT_WDEV_LOCK(wdev); |
| 433 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 434 | memset(&req, 0, sizeof(req)); |
| 435 | |
| 436 | if (wdev->current_bss) |
| 437 | return -EALREADY; |
| 438 | |
| 439 | req.ie = ie; |
| 440 | req.ie_len = ie_len; |
| 441 | memcpy(&req.crypto, crypt, sizeof(req.crypto)); |
| 442 | req.use_mfp = use_mfp; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 443 | req.prev_bssid = prev_bssid; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 444 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 445 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
| 446 | if (!req.bss) |
| 447 | return -ENOENT; |
| 448 | |
| 449 | bss = bss_from_pub(req.bss); |
| 450 | |
| 451 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 452 | if (bss == wdev->auth_bsses[i]) { |
| 453 | slot = i; |
| 454 | break; |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | if (slot < 0) { |
| 459 | err = -ENOTCONN; |
| 460 | goto out; |
| 461 | } |
| 462 | |
| 463 | err = rdev->ops->assoc(&rdev->wiphy, dev, &req); |
| 464 | out: |
| 465 | /* still a reference in wdev->auth_bsses[slot] */ |
| 466 | cfg80211_put_bss(req.bss); |
| 467 | return err; |
| 468 | } |
| 469 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 470 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 471 | struct net_device *dev, |
| 472 | struct ieee80211_channel *chan, |
| 473 | const u8 *bssid, const u8 *prev_bssid, |
| 474 | const u8 *ssid, int ssid_len, |
| 475 | const u8 *ie, int ie_len, bool use_mfp, |
| 476 | struct cfg80211_crypto_settings *crypt) |
| 477 | { |
| 478 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 479 | int err; |
| 480 | |
| 481 | wdev_lock(wdev); |
| 482 | err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 483 | ssid, ssid_len, ie, ie_len, use_mfp, crypt); |
| 484 | wdev_unlock(wdev); |
| 485 | |
| 486 | return err; |
| 487 | } |
| 488 | |
| 489 | int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 490 | struct net_device *dev, const u8 *bssid, |
| 491 | const u8 *ie, int ie_len, u16 reason) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 492 | { |
| 493 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 494 | struct cfg80211_deauth_request req; |
| 495 | int i; |
| 496 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 497 | ASSERT_WDEV_LOCK(wdev); |
| 498 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 499 | memset(&req, 0, sizeof(req)); |
| 500 | req.reason_code = reason; |
| 501 | req.ie = ie; |
| 502 | req.ie_len = ie_len; |
| 503 | if (wdev->current_bss && |
| 504 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 505 | req.bss = &wdev->current_bss->pub; |
| 506 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 507 | if (wdev->auth_bsses[i] && |
| 508 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) { |
| 509 | req.bss = &wdev->auth_bsses[i]->pub; |
| 510 | break; |
| 511 | } |
| 512 | if (wdev->authtry_bsses[i] && |
| 513 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) { |
| 514 | req.bss = &wdev->authtry_bsses[i]->pub; |
| 515 | break; |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | if (!req.bss) |
| 520 | return -ENOTCONN; |
| 521 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 522 | return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 523 | } |
| 524 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 525 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 526 | struct net_device *dev, const u8 *bssid, |
| 527 | const u8 *ie, int ie_len, u16 reason) |
| 528 | { |
| 529 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 530 | int err; |
| 531 | |
| 532 | wdev_lock(wdev); |
| 533 | err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason); |
| 534 | wdev_unlock(wdev); |
| 535 | |
| 536 | return err; |
| 537 | } |
| 538 | |
| 539 | static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 540 | struct net_device *dev, const u8 *bssid, |
| 541 | const u8 *ie, int ie_len, u16 reason) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 542 | { |
| 543 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 544 | struct cfg80211_disassoc_request req; |
| 545 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 546 | ASSERT_WDEV_LOCK(wdev); |
| 547 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 548 | memset(&req, 0, sizeof(req)); |
| 549 | req.reason_code = reason; |
| 550 | req.ie = ie; |
| 551 | req.ie_len = ie_len; |
| 552 | if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) |
| 553 | req.bss = &wdev->current_bss->pub; |
| 554 | else |
| 555 | return -ENOTCONN; |
| 556 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 557 | return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev); |
| 558 | } |
| 559 | |
| 560 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 561 | struct net_device *dev, const u8 *bssid, |
| 562 | const u8 *ie, int ie_len, u16 reason) |
| 563 | { |
| 564 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 565 | int err; |
| 566 | |
| 567 | wdev_lock(wdev); |
| 568 | err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason); |
| 569 | wdev_unlock(wdev); |
| 570 | |
| 571 | return err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, |
| 575 | struct net_device *dev) |
| 576 | { |
| 577 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 578 | struct cfg80211_deauth_request req; |
| 579 | int i; |
| 580 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 581 | ASSERT_WDEV_LOCK(wdev); |
| 582 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 583 | if (!rdev->ops->deauth) |
| 584 | return; |
| 585 | |
| 586 | memset(&req, 0, sizeof(req)); |
| 587 | req.reason_code = WLAN_REASON_DEAUTH_LEAVING; |
| 588 | req.ie = NULL; |
| 589 | req.ie_len = 0; |
| 590 | |
| 591 | if (wdev->current_bss) { |
| 592 | req.bss = &wdev->current_bss->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 593 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 594 | if (wdev->current_bss) { |
| 595 | cfg80211_unhold_bss(wdev->current_bss); |
| 596 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 597 | wdev->current_bss = NULL; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 602 | if (wdev->auth_bsses[i]) { |
| 603 | req.bss = &wdev->auth_bsses[i]->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 604 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 605 | if (wdev->auth_bsses[i]) { |
| 606 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 607 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 608 | wdev->auth_bsses[i] = NULL; |
| 609 | } |
| 610 | } |
| 611 | if (wdev->authtry_bsses[i]) { |
| 612 | req.bss = &wdev->authtry_bsses[i]->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 613 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 614 | if (wdev->authtry_bsses[i]) { |
| 615 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 616 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 617 | wdev->authtry_bsses[i] = NULL; |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } |