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