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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 12 | #include <linux/wireless.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 13 | #include <net/cfg80211.h> |
Johannes Berg | a9a1162 | 2009-07-27 12:01:53 +0200 | [diff] [blame] | 14 | #include <net/iw_handler.h> |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15 | #include "core.h" |
| 16 | #include "nl80211.h" |
| 17 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 18 | 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] | 19 | { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 20 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 21 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 22 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 23 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 24 | u8 *bssid = mgmt->bssid; |
| 25 | int i; |
| 26 | u16 status = le16_to_cpu(mgmt->u.auth.status_code); |
| 27 | bool done = false; |
| 28 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 29 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 30 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 31 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 32 | if (wdev->authtry_bsses[i] && |
| 33 | memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, |
| 34 | ETH_ALEN) == 0) { |
| 35 | if (status == WLAN_STATUS_SUCCESS) { |
| 36 | wdev->auth_bsses[i] = wdev->authtry_bsses[i]; |
| 37 | } else { |
| 38 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 39 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 40 | } |
| 41 | wdev->authtry_bsses[i] = NULL; |
| 42 | done = true; |
| 43 | break; |
| 44 | } |
| 45 | } |
| 46 | |
Johannes Berg | 643f82e | 2010-07-12 14:46:43 +0200 | [diff] [blame] | 47 | if (done) { |
| 48 | nl80211_send_rx_auth(rdev, dev, buf, len, GFP_KERNEL); |
| 49 | cfg80211_sme_rx_auth(dev, buf, len); |
| 50 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 51 | |
| 52 | wdev_unlock(wdev); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 53 | } |
| 54 | EXPORT_SYMBOL(cfg80211_send_rx_auth); |
| 55 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 56 | 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] | 57 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 58 | u16 status_code; |
| 59 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 60 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 61 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 62 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
| 63 | u8 *ie = mgmt->u.assoc_resp.variable; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 64 | int i, ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable); |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 65 | struct cfg80211_internal_bss *bss = NULL; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 66 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 67 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 68 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 69 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 70 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 71 | /* |
| 72 | * This is a bit of a hack, we don't notify userspace of |
| 73 | * a (re-)association reply if we tried to send a reassoc |
| 74 | * and got a reject -- we only try again with an assoc |
| 75 | * frame instead of reassoc. |
| 76 | */ |
| 77 | if (status_code != WLAN_STATUS_SUCCESS && wdev->conn && |
| 78 | cfg80211_sme_failed_reassoc(wdev)) |
| 79 | goto out; |
| 80 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 81 | nl80211_send_rx_assoc(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 82 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 83 | if (status_code == WLAN_STATUS_SUCCESS) { |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 84 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 85 | if (!wdev->auth_bsses[i]) |
| 86 | continue; |
| 87 | if (memcmp(wdev->auth_bsses[i]->pub.bssid, mgmt->bssid, |
| 88 | ETH_ALEN) == 0) { |
| 89 | bss = wdev->auth_bsses[i]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 90 | wdev->auth_bsses[i] = NULL; |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 91 | /* additional reference to drop hold */ |
| 92 | cfg80211_ref_bss(bss); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 93 | break; |
| 94 | } |
| 95 | } |
| 96 | |
Johannes Berg | 3bdb2d4 | 2009-12-23 13:12:05 +0100 | [diff] [blame] | 97 | /* |
| 98 | * We might be coming here because the driver reported |
| 99 | * a successful association at the same time as the |
| 100 | * user requested a deauth. In that case, we will have |
| 101 | * removed the BSS from the auth_bsses list due to the |
| 102 | * deauth request when the assoc response makes it. If |
| 103 | * the two code paths acquire the lock the other way |
| 104 | * around, that's just the standard situation of a |
| 105 | * deauth being requested while connected. |
| 106 | */ |
| 107 | if (!bss) |
| 108 | goto out; |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 109 | } else if (wdev->conn) { |
| 110 | cfg80211_sme_failed_assoc(wdev); |
Johannes Berg | 7d930bc | 2009-10-20 15:08:53 +0900 | [diff] [blame] | 111 | /* |
| 112 | * do not call connect_result() now because the |
| 113 | * sme will schedule work that does it later. |
| 114 | */ |
| 115 | goto out; |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Johannes Berg | ea416a7 | 2009-08-17 12:22:14 +0200 | [diff] [blame] | 118 | if (!wdev->conn && wdev->sme_state == CFG80211_SME_IDLE) { |
| 119 | /* |
| 120 | * This is for the userspace SME, the CONNECTING |
| 121 | * state will be changed to CONNECTED by |
| 122 | * __cfg80211_connect_result() below. |
| 123 | */ |
| 124 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 125 | } |
| 126 | |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 127 | /* this consumes one bss reference (unless bss is NULL) */ |
| 128 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs, |
| 129 | status_code, |
| 130 | status_code == WLAN_STATUS_SUCCESS, |
| 131 | bss ? &bss->pub : NULL); |
| 132 | /* drop hold now, and also reference acquired above */ |
| 133 | if (bss) { |
| 134 | cfg80211_unhold_bss(bss); |
| 135 | cfg80211_put_bss(&bss->pub); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 136 | } |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 137 | |
Johannes Berg | f401a6f | 2009-08-07 14:51:05 +0200 | [diff] [blame] | 138 | out: |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 139 | wdev_unlock(wdev); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 140 | } |
| 141 | EXPORT_SYMBOL(cfg80211_send_rx_assoc); |
| 142 | |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 143 | void __cfg80211_send_deauth(struct net_device *dev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 144 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 145 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 146 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 147 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 148 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 149 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 150 | const u8 *bssid = mgmt->bssid; |
| 151 | int i; |
Johannes Berg | 3f3b6a8 | 2010-08-05 10:20:27 +0200 | [diff] [blame] | 152 | bool found = false, was_current = false; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 153 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 154 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 155 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 156 | if (wdev->current_bss && |
| 157 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 158 | cfg80211_unhold_bss(wdev->current_bss); |
| 159 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 160 | wdev->current_bss = NULL; |
Johannes Berg | 5fba4af | 2009-12-02 12:43:42 +0100 | [diff] [blame] | 161 | found = true; |
Johannes Berg | 3f3b6a8 | 2010-08-05 10:20:27 +0200 | [diff] [blame] | 162 | was_current = true; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 163 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 164 | if (wdev->auth_bsses[i] && |
| 165 | memcmp(wdev->auth_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 166 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 167 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 168 | wdev->auth_bsses[i] = NULL; |
Johannes Berg | 5fba4af | 2009-12-02 12:43:42 +0100 | [diff] [blame] | 169 | found = true; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 170 | break; |
| 171 | } |
| 172 | if (wdev->authtry_bsses[i] && |
| 173 | memcmp(wdev->authtry_bsses[i]->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 174 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 175 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 176 | wdev->authtry_bsses[i] = NULL; |
Johannes Berg | 5fba4af | 2009-12-02 12:43:42 +0100 | [diff] [blame] | 177 | found = true; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 178 | break; |
| 179 | } |
| 180 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 181 | |
Johannes Berg | 5fba4af | 2009-12-02 12:43:42 +0100 | [diff] [blame] | 182 | if (!found) |
| 183 | return; |
| 184 | |
| 185 | nl80211_send_deauth(rdev, dev, buf, len, GFP_KERNEL); |
| 186 | |
Johannes Berg | 3f3b6a8 | 2010-08-05 10:20:27 +0200 | [diff] [blame] | 187 | if (wdev->sme_state == CFG80211_SME_CONNECTED && was_current) { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 188 | u16 reason_code; |
| 189 | bool from_ap; |
| 190 | |
| 191 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 192 | |
Johannes Berg | e458b8a | 2009-08-06 20:41:33 +0200 | [diff] [blame] | 193 | from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 194 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 195 | } else if (wdev->sme_state == CFG80211_SME_CONNECTING) { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 196 | __cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0, |
| 197 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 198 | false, NULL); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 199 | } |
| 200 | } |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 201 | EXPORT_SYMBOL(__cfg80211_send_deauth); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 202 | |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 203 | void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 204 | { |
| 205 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 206 | |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 207 | wdev_lock(wdev); |
| 208 | __cfg80211_send_deauth(dev, buf, len); |
| 209 | wdev_unlock(wdev); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 210 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 211 | EXPORT_SYMBOL(cfg80211_send_deauth); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 212 | |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 213 | void __cfg80211_send_disassoc(struct net_device *dev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 214 | const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 215 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 216 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 217 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 218 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 219 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 220 | const u8 *bssid = mgmt->bssid; |
| 221 | int i; |
| 222 | u16 reason_code; |
| 223 | bool from_ap; |
| 224 | bool done = false; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 225 | |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 226 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 227 | |
| 228 | nl80211_send_disassoc(rdev, dev, buf, len, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 229 | |
Johannes Berg | 596a07c | 2009-07-11 00:17:32 +0200 | [diff] [blame] | 230 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 231 | return; |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 232 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 233 | if (wdev->current_bss && |
Pavel Roskin | b935df0 | 2009-08-06 04:52:42 -0400 | [diff] [blame] | 234 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 235 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 236 | if (wdev->authtry_bsses[i] || wdev->auth_bsses[i]) |
| 237 | continue; |
| 238 | wdev->auth_bsses[i] = wdev->current_bss; |
| 239 | wdev->current_bss = NULL; |
| 240 | done = true; |
| 241 | cfg80211_sme_disassoc(dev, i); |
| 242 | break; |
| 243 | } |
| 244 | WARN_ON(!done); |
| 245 | } else |
| 246 | WARN_ON(1); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 247 | |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 248 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 249 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 250 | |
Johannes Berg | e458b8a | 2009-08-06 20:41:33 +0200 | [diff] [blame] | 251 | from_ap = memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 252 | __cfg80211_disconnected(dev, NULL, 0, reason_code, from_ap); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 253 | } |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 254 | EXPORT_SYMBOL(__cfg80211_send_disassoc); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 255 | |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 256 | void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 257 | { |
| 258 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 259 | |
Holger Schurig | ce470613c | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 260 | wdev_lock(wdev); |
| 261 | __cfg80211_send_disassoc(dev, buf, len); |
| 262 | wdev_unlock(wdev); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 263 | } |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 264 | EXPORT_SYMBOL(cfg80211_send_disassoc); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 265 | |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 266 | static void __cfg80211_auth_remove(struct wireless_dev *wdev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 267 | { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 268 | int i; |
| 269 | bool done = false; |
| 270 | |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 271 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 272 | |
| 273 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { |
| 274 | if (wdev->authtry_bsses[i] && |
| 275 | memcmp(wdev->authtry_bsses[i]->pub.bssid, |
| 276 | addr, ETH_ALEN) == 0) { |
| 277 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 278 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 279 | wdev->authtry_bsses[i] = NULL; |
| 280 | done = true; |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | WARN_ON(!done); |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void __cfg80211_auth_canceled(struct net_device *dev, const u8 *addr) |
| 289 | { |
| 290 | __cfg80211_auth_remove(dev->ieee80211_ptr, addr); |
| 291 | } |
| 292 | EXPORT_SYMBOL(__cfg80211_auth_canceled); |
| 293 | |
| 294 | void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr) |
| 295 | { |
| 296 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 297 | struct wiphy *wiphy = wdev->wiphy; |
| 298 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 299 | |
| 300 | wdev_lock(wdev); |
| 301 | |
| 302 | nl80211_send_auth_timeout(rdev, dev, addr, GFP_KERNEL); |
| 303 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
| 304 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 305 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 306 | false, NULL); |
| 307 | |
| 308 | __cfg80211_auth_remove(wdev, addr); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 309 | |
| 310 | wdev_unlock(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 311 | } |
| 312 | EXPORT_SYMBOL(cfg80211_send_auth_timeout); |
| 313 | |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 314 | void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 315 | { |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 316 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 317 | struct wiphy *wiphy = wdev->wiphy; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 318 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 319 | int i; |
| 320 | bool done = false; |
| 321 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 322 | wdev_lock(wdev); |
Johannes Berg | cb0b4be | 2009-07-07 03:56:07 +0200 | [diff] [blame] | 323 | |
| 324 | nl80211_send_assoc_timeout(rdev, dev, addr, GFP_KERNEL); |
Johannes Berg | 6829c87 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 325 | if (wdev->sme_state == CFG80211_SME_CONNECTING) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 326 | __cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0, |
| 327 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
Johannes Berg | df7fc0f | 2009-07-29 11:23:49 +0200 | [diff] [blame] | 328 | false, NULL); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 329 | |
| 330 | for (i = 0; addr && i < MAX_AUTH_BSSES; i++) { |
| 331 | if (wdev->auth_bsses[i] && |
| 332 | memcmp(wdev->auth_bsses[i]->pub.bssid, |
| 333 | addr, ETH_ALEN) == 0) { |
| 334 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 335 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 336 | wdev->auth_bsses[i] = NULL; |
| 337 | done = true; |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | WARN_ON(!done); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 343 | |
| 344 | wdev_unlock(wdev); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 345 | } |
| 346 | EXPORT_SYMBOL(cfg80211_send_assoc_timeout); |
| 347 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 348 | void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr, |
| 349 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 350 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 351 | { |
| 352 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 353 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 354 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 355 | union iwreq_data wrqu; |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 356 | char *buf = kmalloc(128, gfp); |
Johannes Berg | f58d4ed | 2009-06-19 02:45:21 +0200 | [diff] [blame] | 357 | |
| 358 | if (buf) { |
| 359 | sprintf(buf, "MLME-MICHAELMICFAILURE.indication(" |
| 360 | "keyid=%d %scast addr=%pM)", key_id, |
| 361 | key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni", |
| 362 | addr); |
| 363 | memset(&wrqu, 0, sizeof(wrqu)); |
| 364 | wrqu.data.length = strlen(buf); |
| 365 | wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf); |
| 366 | kfree(buf); |
| 367 | } |
| 368 | #endif |
| 369 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 370 | 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] | 371 | } |
| 372 | EXPORT_SYMBOL(cfg80211_michael_mic_failure); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 373 | |
| 374 | /* some MLME handling for userspace SME */ |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 375 | int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 376 | struct net_device *dev, |
| 377 | struct ieee80211_channel *chan, |
| 378 | enum nl80211_auth_type auth_type, |
| 379 | const u8 *bssid, |
| 380 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 381 | const u8 *ie, int ie_len, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 382 | const u8 *key, int key_len, int key_idx, |
| 383 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 384 | { |
| 385 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 386 | struct cfg80211_auth_request req; |
| 387 | struct cfg80211_internal_bss *bss; |
| 388 | int i, err, slot = -1, nfree = 0; |
| 389 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 390 | ASSERT_WDEV_LOCK(wdev); |
| 391 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 392 | if (auth_type == NL80211_AUTHTYPE_SHARED_KEY) |
| 393 | if (!key || !key_len || key_idx < 0 || key_idx > 4) |
| 394 | return -EINVAL; |
| 395 | |
Johannes Berg | 0a9b5e1 | 2009-07-02 18:26:18 +0200 | [diff] [blame] | 396 | if (wdev->current_bss && |
| 397 | memcmp(bssid, wdev->current_bss->pub.bssid, ETH_ALEN) == 0) |
| 398 | return -EALREADY; |
| 399 | |
| 400 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 401 | if (wdev->authtry_bsses[i] && |
| 402 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, |
| 403 | ETH_ALEN) == 0) |
| 404 | return -EALREADY; |
| 405 | if (wdev->auth_bsses[i] && |
| 406 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, |
| 407 | ETH_ALEN) == 0) |
| 408 | return -EALREADY; |
| 409 | } |
| 410 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 411 | memset(&req, 0, sizeof(req)); |
| 412 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 413 | req.local_state_change = local_state_change; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 414 | req.ie = ie; |
| 415 | req.ie_len = ie_len; |
| 416 | req.auth_type = auth_type; |
| 417 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 418 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 419 | req.key = key; |
| 420 | req.key_len = key_len; |
| 421 | req.key_idx = key_idx; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 422 | if (!req.bss) |
| 423 | return -ENOENT; |
| 424 | |
| 425 | bss = bss_from_pub(req.bss); |
| 426 | |
| 427 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 428 | if (!wdev->auth_bsses[i] && !wdev->authtry_bsses[i]) { |
| 429 | slot = i; |
| 430 | nfree++; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /* we need one free slot for disassoc and one for this auth */ |
| 435 | if (nfree < 2) { |
| 436 | err = -ENOSPC; |
| 437 | goto out; |
| 438 | } |
| 439 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 440 | if (local_state_change) |
| 441 | wdev->auth_bsses[slot] = bss; |
| 442 | else |
| 443 | wdev->authtry_bsses[slot] = bss; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 444 | cfg80211_hold_bss(bss); |
| 445 | |
| 446 | err = rdev->ops->auth(&rdev->wiphy, dev, &req); |
| 447 | if (err) { |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 448 | if (local_state_change) |
| 449 | wdev->auth_bsses[slot] = NULL; |
| 450 | else |
| 451 | wdev->authtry_bsses[slot] = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 452 | cfg80211_unhold_bss(bss); |
| 453 | } |
| 454 | |
| 455 | out: |
| 456 | if (err) |
| 457 | cfg80211_put_bss(req.bss); |
| 458 | return err; |
| 459 | } |
| 460 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 461 | int cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, |
| 462 | struct net_device *dev, struct ieee80211_channel *chan, |
| 463 | enum nl80211_auth_type auth_type, const u8 *bssid, |
| 464 | const u8 *ssid, int ssid_len, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 465 | const u8 *ie, int ie_len, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 466 | const u8 *key, int key_len, int key_idx, |
| 467 | bool local_state_change) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 468 | { |
| 469 | int err; |
| 470 | |
| 471 | wdev_lock(dev->ieee80211_ptr); |
| 472 | err = __cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 473 | ssid, ssid_len, ie, ie_len, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 474 | key, key_len, key_idx, local_state_change); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 475 | wdev_unlock(dev->ieee80211_ptr); |
| 476 | |
| 477 | return err; |
| 478 | } |
| 479 | |
| 480 | int __cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 481 | struct net_device *dev, |
| 482 | struct ieee80211_channel *chan, |
| 483 | const u8 *bssid, const u8 *prev_bssid, |
| 484 | const u8 *ssid, int ssid_len, |
| 485 | const u8 *ie, int ie_len, bool use_mfp, |
| 486 | struct cfg80211_crypto_settings *crypt) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 487 | { |
| 488 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 489 | struct cfg80211_assoc_request req; |
| 490 | struct cfg80211_internal_bss *bss; |
| 491 | int i, err, slot = -1; |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 492 | bool was_connected = false; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 493 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 494 | ASSERT_WDEV_LOCK(wdev); |
| 495 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 496 | memset(&req, 0, sizeof(req)); |
| 497 | |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 498 | if (wdev->current_bss && prev_bssid && |
| 499 | memcmp(wdev->current_bss->pub.bssid, prev_bssid, ETH_ALEN) == 0) { |
| 500 | /* |
| 501 | * Trying to reassociate: Allow this to proceed and let the old |
| 502 | * association to be dropped when the new one is completed. |
| 503 | */ |
| 504 | if (wdev->sme_state == CFG80211_SME_CONNECTED) { |
| 505 | was_connected = true; |
| 506 | wdev->sme_state = CFG80211_SME_CONNECTING; |
| 507 | } |
| 508 | } else if (wdev->current_bss) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 509 | return -EALREADY; |
| 510 | |
| 511 | req.ie = ie; |
| 512 | req.ie_len = ie_len; |
| 513 | memcpy(&req.crypto, crypt, sizeof(req.crypto)); |
| 514 | req.use_mfp = use_mfp; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 515 | req.prev_bssid = prev_bssid; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 516 | req.bss = cfg80211_get_bss(&rdev->wiphy, chan, bssid, ssid, ssid_len, |
| 517 | WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS); |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 518 | if (!req.bss) { |
| 519 | if (was_connected) |
| 520 | wdev->sme_state = CFG80211_SME_CONNECTED; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 521 | return -ENOENT; |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 522 | } |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 523 | |
| 524 | bss = bss_from_pub(req.bss); |
| 525 | |
| 526 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 527 | if (bss == wdev->auth_bsses[i]) { |
| 528 | slot = i; |
| 529 | break; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (slot < 0) { |
| 534 | err = -ENOTCONN; |
| 535 | goto out; |
| 536 | } |
| 537 | |
| 538 | err = rdev->ops->assoc(&rdev->wiphy, dev, &req); |
| 539 | out: |
Jouni Malinen | 24b6b15 | 2009-11-17 21:35:38 +0200 | [diff] [blame] | 540 | if (err && was_connected) |
| 541 | wdev->sme_state = CFG80211_SME_CONNECTED; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 542 | /* still a reference in wdev->auth_bsses[slot] */ |
| 543 | cfg80211_put_bss(req.bss); |
| 544 | return err; |
| 545 | } |
| 546 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 547 | int cfg80211_mlme_assoc(struct cfg80211_registered_device *rdev, |
| 548 | struct net_device *dev, |
| 549 | struct ieee80211_channel *chan, |
| 550 | const u8 *bssid, const u8 *prev_bssid, |
| 551 | const u8 *ssid, int ssid_len, |
| 552 | const u8 *ie, int ie_len, bool use_mfp, |
| 553 | struct cfg80211_crypto_settings *crypt) |
| 554 | { |
| 555 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 556 | int err; |
| 557 | |
| 558 | wdev_lock(wdev); |
| 559 | err = __cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 560 | ssid, ssid_len, ie, ie_len, use_mfp, crypt); |
| 561 | wdev_unlock(wdev); |
| 562 | |
| 563 | return err; |
| 564 | } |
| 565 | |
| 566 | int __cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 567 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 568 | const u8 *ie, int ie_len, u16 reason, |
| 569 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 570 | { |
| 571 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 572 | struct cfg80211_deauth_request req; |
| 573 | int i; |
| 574 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 575 | ASSERT_WDEV_LOCK(wdev); |
| 576 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 577 | memset(&req, 0, sizeof(req)); |
| 578 | req.reason_code = reason; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 579 | req.local_state_change = local_state_change; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 580 | req.ie = ie; |
| 581 | req.ie_len = ie_len; |
| 582 | if (wdev->current_bss && |
| 583 | memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) { |
| 584 | req.bss = &wdev->current_bss->pub; |
| 585 | } else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 586 | if (wdev->auth_bsses[i] && |
| 587 | memcmp(bssid, wdev->auth_bsses[i]->pub.bssid, ETH_ALEN) == 0) { |
| 588 | req.bss = &wdev->auth_bsses[i]->pub; |
| 589 | break; |
| 590 | } |
| 591 | if (wdev->authtry_bsses[i] && |
| 592 | memcmp(bssid, wdev->authtry_bsses[i]->pub.bssid, ETH_ALEN) == 0) { |
| 593 | req.bss = &wdev->authtry_bsses[i]->pub; |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | if (!req.bss) |
| 599 | return -ENOTCONN; |
| 600 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 601 | return rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 602 | } |
| 603 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 604 | int cfg80211_mlme_deauth(struct cfg80211_registered_device *rdev, |
| 605 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 606 | const u8 *ie, int ie_len, u16 reason, |
| 607 | bool local_state_change) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 608 | { |
| 609 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 610 | int err; |
| 611 | |
| 612 | wdev_lock(wdev); |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 613 | err = __cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason, |
| 614 | local_state_change); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 615 | wdev_unlock(wdev); |
| 616 | |
| 617 | return err; |
| 618 | } |
| 619 | |
| 620 | static int __cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 621 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 622 | const u8 *ie, int ie_len, u16 reason, |
| 623 | bool local_state_change) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 624 | { |
| 625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 626 | struct cfg80211_disassoc_request req; |
| 627 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 628 | ASSERT_WDEV_LOCK(wdev); |
| 629 | |
Johannes Berg | f9d6b40 | 2009-07-27 10:22:28 +0200 | [diff] [blame] | 630 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 631 | return -ENOTCONN; |
| 632 | |
| 633 | if (WARN_ON(!wdev->current_bss)) |
| 634 | return -ENOTCONN; |
| 635 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 636 | memset(&req, 0, sizeof(req)); |
| 637 | req.reason_code = reason; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 638 | req.local_state_change = local_state_change; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 639 | req.ie = ie; |
| 640 | req.ie_len = ie_len; |
| 641 | if (memcmp(wdev->current_bss->pub.bssid, bssid, ETH_ALEN) == 0) |
| 642 | req.bss = &wdev->current_bss->pub; |
| 643 | else |
| 644 | return -ENOTCONN; |
| 645 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 646 | return rdev->ops->disassoc(&rdev->wiphy, dev, &req, wdev); |
| 647 | } |
| 648 | |
| 649 | int cfg80211_mlme_disassoc(struct cfg80211_registered_device *rdev, |
| 650 | struct net_device *dev, const u8 *bssid, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 651 | const u8 *ie, int ie_len, u16 reason, |
| 652 | bool local_state_change) |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 653 | { |
| 654 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 655 | int err; |
| 656 | |
| 657 | wdev_lock(wdev); |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 658 | err = __cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason, |
| 659 | local_state_change); |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 660 | wdev_unlock(wdev); |
| 661 | |
| 662 | return err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | void cfg80211_mlme_down(struct cfg80211_registered_device *rdev, |
| 666 | struct net_device *dev) |
| 667 | { |
| 668 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 669 | struct cfg80211_deauth_request req; |
| 670 | int i; |
| 671 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 672 | ASSERT_WDEV_LOCK(wdev); |
| 673 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 674 | if (!rdev->ops->deauth) |
| 675 | return; |
| 676 | |
| 677 | memset(&req, 0, sizeof(req)); |
| 678 | req.reason_code = WLAN_REASON_DEAUTH_LEAVING; |
| 679 | req.ie = NULL; |
| 680 | req.ie_len = 0; |
| 681 | |
| 682 | if (wdev->current_bss) { |
| 683 | req.bss = &wdev->current_bss->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 684 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 685 | if (wdev->current_bss) { |
| 686 | cfg80211_unhold_bss(wdev->current_bss); |
| 687 | cfg80211_put_bss(&wdev->current_bss->pub); |
| 688 | wdev->current_bss = NULL; |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 693 | if (wdev->auth_bsses[i]) { |
| 694 | req.bss = &wdev->auth_bsses[i]->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 695 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 696 | if (wdev->auth_bsses[i]) { |
| 697 | cfg80211_unhold_bss(wdev->auth_bsses[i]); |
| 698 | cfg80211_put_bss(&wdev->auth_bsses[i]->pub); |
| 699 | wdev->auth_bsses[i] = NULL; |
| 700 | } |
| 701 | } |
| 702 | if (wdev->authtry_bsses[i]) { |
| 703 | req.bss = &wdev->authtry_bsses[i]->pub; |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 704 | rdev->ops->deauth(&rdev->wiphy, dev, &req, wdev); |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 705 | if (wdev->authtry_bsses[i]) { |
| 706 | cfg80211_unhold_bss(wdev->authtry_bsses[i]); |
| 707 | cfg80211_put_bss(&wdev->authtry_bsses[i]->pub); |
| 708 | wdev->authtry_bsses[i] = NULL; |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | } |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 713 | |
| 714 | void cfg80211_ready_on_channel(struct net_device *dev, u64 cookie, |
| 715 | struct ieee80211_channel *chan, |
| 716 | enum nl80211_channel_type channel_type, |
| 717 | unsigned int duration, gfp_t gfp) |
| 718 | { |
| 719 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 720 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 721 | |
| 722 | nl80211_send_remain_on_channel(rdev, dev, cookie, chan, channel_type, |
| 723 | duration, gfp); |
| 724 | } |
| 725 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
| 726 | |
| 727 | void cfg80211_remain_on_channel_expired(struct net_device *dev, |
| 728 | u64 cookie, |
| 729 | struct ieee80211_channel *chan, |
| 730 | enum nl80211_channel_type channel_type, |
| 731 | gfp_t gfp) |
| 732 | { |
| 733 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 734 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 735 | |
| 736 | nl80211_send_remain_on_channel_cancel(rdev, dev, cookie, chan, |
| 737 | channel_type, gfp); |
| 738 | } |
| 739 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 740 | |
| 741 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 742 | struct station_info *sinfo, gfp_t gfp) |
| 743 | { |
| 744 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
| 745 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 746 | |
| 747 | nl80211_send_sta_event(rdev, dev, mac_addr, sinfo, gfp); |
| 748 | } |
| 749 | EXPORT_SYMBOL(cfg80211_new_sta); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 750 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 751 | struct cfg80211_mgmt_registration { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 752 | struct list_head list; |
| 753 | |
| 754 | u32 nlpid; |
| 755 | |
| 756 | int match_len; |
| 757 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 758 | __le16 frame_type; |
| 759 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 760 | u8 match[]; |
| 761 | }; |
| 762 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 763 | int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, u32 snd_pid, |
| 764 | u16 frame_type, const u8 *match_data, |
| 765 | int match_len) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 766 | { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 767 | struct wiphy *wiphy = wdev->wiphy; |
| 768 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 769 | struct cfg80211_mgmt_registration *reg, *nreg; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 770 | int err = 0; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 771 | u16 mgmt_type; |
| 772 | |
| 773 | if (!wdev->wiphy->mgmt_stypes) |
| 774 | return -EOPNOTSUPP; |
| 775 | |
| 776 | if ((frame_type & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT) |
| 777 | return -EINVAL; |
| 778 | |
| 779 | if (frame_type & ~(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) |
| 780 | return -EINVAL; |
| 781 | |
| 782 | mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4; |
| 783 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].rx & BIT(mgmt_type))) |
| 784 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 785 | |
| 786 | nreg = kzalloc(sizeof(*reg) + match_len, GFP_KERNEL); |
| 787 | if (!nreg) |
| 788 | return -ENOMEM; |
| 789 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 790 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 791 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 792 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 793 | int mlen = min(match_len, reg->match_len); |
| 794 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 795 | if (frame_type != le16_to_cpu(reg->frame_type)) |
| 796 | continue; |
| 797 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 798 | if (memcmp(reg->match, match_data, mlen) == 0) { |
| 799 | err = -EALREADY; |
| 800 | break; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | if (err) { |
| 805 | kfree(nreg); |
| 806 | goto out; |
| 807 | } |
| 808 | |
| 809 | memcpy(nreg->match, match_data, match_len); |
| 810 | nreg->match_len = match_len; |
| 811 | nreg->nlpid = snd_pid; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 812 | nreg->frame_type = cpu_to_le16(frame_type); |
| 813 | list_add(&nreg->list, &wdev->mgmt_registrations); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 814 | |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 815 | if (rdev->ops->mgmt_frame_register) |
| 816 | rdev->ops->mgmt_frame_register(wiphy, wdev->netdev, |
| 817 | frame_type, true); |
| 818 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 819 | out: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 820 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 821 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 822 | return err; |
| 823 | } |
| 824 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 825 | void cfg80211_mlme_unregister_socket(struct wireless_dev *wdev, u32 nlpid) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 826 | { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 827 | struct wiphy *wiphy = wdev->wiphy; |
| 828 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 829 | struct cfg80211_mgmt_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 830 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 831 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 832 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 833 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 834 | if (reg->nlpid != nlpid) |
| 835 | continue; |
| 836 | |
| 837 | if (rdev->ops->mgmt_frame_register) { |
| 838 | u16 frame_type = le16_to_cpu(reg->frame_type); |
| 839 | |
| 840 | rdev->ops->mgmt_frame_register(wiphy, wdev->netdev, |
| 841 | frame_type, false); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 842 | } |
Johannes Berg | 271733c | 2010-10-13 12:06:23 +0200 | [diff] [blame] | 843 | |
| 844 | list_del(®->list); |
| 845 | kfree(reg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 846 | } |
| 847 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 848 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 849 | } |
| 850 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 851 | void cfg80211_mlme_purge_registrations(struct wireless_dev *wdev) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 852 | { |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 853 | struct cfg80211_mgmt_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 854 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 855 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 856 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 857 | list_for_each_entry_safe(reg, tmp, &wdev->mgmt_registrations, list) { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 858 | list_del(®->list); |
| 859 | kfree(reg); |
| 860 | } |
| 861 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 862 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 863 | } |
| 864 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 865 | int cfg80211_mlme_mgmt_tx(struct cfg80211_registered_device *rdev, |
| 866 | struct net_device *dev, |
| 867 | struct ieee80211_channel *chan, |
| 868 | enum nl80211_channel_type channel_type, |
| 869 | bool channel_type_valid, |
| 870 | const u8 *buf, size_t len, u64 *cookie) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 871 | { |
| 872 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 873 | const struct ieee80211_mgmt *mgmt; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 874 | u16 stype; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 875 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 876 | if (!wdev->wiphy->mgmt_stypes) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 877 | return -EOPNOTSUPP; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 878 | |
| 879 | if (!rdev->ops->mgmt_tx) |
| 880 | return -EOPNOTSUPP; |
| 881 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 882 | if (len < 24 + 1) |
| 883 | return -EINVAL; |
| 884 | |
| 885 | mgmt = (const struct ieee80211_mgmt *) buf; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 886 | |
| 887 | if (!ieee80211_is_mgmt(mgmt->frame_control)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 888 | return -EINVAL; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 889 | |
| 890 | stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; |
| 891 | if (!(wdev->wiphy->mgmt_stypes[wdev->iftype].tx & BIT(stype >> 4))) |
| 892 | return -EINVAL; |
| 893 | |
| 894 | if (ieee80211_is_action(mgmt->frame_control) && |
| 895 | mgmt->u.action.category != WLAN_CATEGORY_PUBLIC) { |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 896 | int err = 0; |
| 897 | |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 898 | wdev_lock(wdev); |
| 899 | |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 900 | switch (wdev->iftype) { |
| 901 | case NL80211_IFTYPE_ADHOC: |
| 902 | case NL80211_IFTYPE_STATION: |
| 903 | case NL80211_IFTYPE_P2P_CLIENT: |
| 904 | if (!wdev->current_bss) { |
| 905 | err = -ENOTCONN; |
| 906 | break; |
| 907 | } |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 908 | |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 909 | if (memcmp(wdev->current_bss->pub.bssid, |
| 910 | mgmt->bssid, ETH_ALEN)) { |
| 911 | err = -ENOTCONN; |
| 912 | break; |
| 913 | } |
| 914 | |
| 915 | /* |
| 916 | * check for IBSS DA must be done by driver as |
| 917 | * cfg80211 doesn't track the stations |
| 918 | */ |
| 919 | if (wdev->iftype == NL80211_IFTYPE_ADHOC) |
| 920 | break; |
| 921 | |
| 922 | /* for station, check that DA is the AP */ |
| 923 | if (memcmp(wdev->current_bss->pub.bssid, |
| 924 | mgmt->da, ETH_ALEN)) { |
| 925 | err = -ENOTCONN; |
| 926 | break; |
| 927 | } |
| 928 | break; |
| 929 | case NL80211_IFTYPE_AP: |
| 930 | case NL80211_IFTYPE_P2P_GO: |
| 931 | case NL80211_IFTYPE_AP_VLAN: |
| 932 | if (memcmp(mgmt->bssid, dev->dev_addr, ETH_ALEN)) |
| 933 | err = -EINVAL; |
| 934 | break; |
| 935 | default: |
| 936 | err = -EOPNOTSUPP; |
| 937 | break; |
| 938 | } |
Johannes Berg | fe100ac | 2010-08-09 15:52:03 +0200 | [diff] [blame] | 939 | wdev_unlock(wdev); |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 940 | |
| 941 | if (err) |
| 942 | return err; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | if (memcmp(mgmt->sa, dev->dev_addr, ETH_ALEN) != 0) |
| 946 | return -EINVAL; |
| 947 | |
| 948 | /* Transmit the Action frame as requested by user space */ |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 949 | return rdev->ops->mgmt_tx(&rdev->wiphy, dev, chan, channel_type, |
| 950 | channel_type_valid, buf, len, cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 951 | } |
| 952 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 953 | bool cfg80211_rx_mgmt(struct net_device *dev, int freq, const u8 *buf, |
| 954 | size_t len, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 955 | { |
| 956 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 957 | struct wiphy *wiphy = wdev->wiphy; |
| 958 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 959 | struct cfg80211_mgmt_registration *reg; |
| 960 | const struct ieee80211_txrx_stypes *stypes = |
| 961 | &wiphy->mgmt_stypes[wdev->iftype]; |
| 962 | struct ieee80211_mgmt *mgmt = (void *)buf; |
| 963 | const u8 *data; |
| 964 | int data_len; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 965 | bool result = false; |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 966 | __le16 ftype = mgmt->frame_control & |
| 967 | cpu_to_le16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE); |
| 968 | u16 stype; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 969 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 970 | stype = (le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE) >> 4; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 971 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 972 | if (!(stypes->rx & BIT(stype))) |
| 973 | return false; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 974 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 975 | data = buf + ieee80211_hdrlen(mgmt->frame_control); |
| 976 | data_len = len - ieee80211_hdrlen(mgmt->frame_control); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 977 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 978 | spin_lock_bh(&wdev->mgmt_registrations_lock); |
| 979 | |
| 980 | list_for_each_entry(reg, &wdev->mgmt_registrations, list) { |
| 981 | if (reg->frame_type != ftype) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 982 | continue; |
| 983 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 984 | if (reg->match_len > data_len) |
| 985 | continue; |
| 986 | |
| 987 | if (memcmp(reg->match, data, reg->match_len)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 988 | continue; |
| 989 | |
| 990 | /* found match! */ |
| 991 | |
| 992 | /* Indicate the received Action frame to user space */ |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 993 | if (nl80211_send_mgmt(rdev, dev, reg->nlpid, freq, |
| 994 | buf, len, gfp)) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 995 | continue; |
| 996 | |
| 997 | result = true; |
| 998 | break; |
| 999 | } |
| 1000 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1001 | spin_unlock_bh(&wdev->mgmt_registrations_lock); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 1002 | |
| 1003 | return result; |
| 1004 | } |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1005 | EXPORT_SYMBOL(cfg80211_rx_mgmt); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 1006 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1007 | void cfg80211_mgmt_tx_status(struct net_device *dev, u64 cookie, |
| 1008 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 1009 | { |
| 1010 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1011 | struct wiphy *wiphy = wdev->wiphy; |
| 1012 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 1013 | |
| 1014 | /* Indicate TX status of the Action frame to user space */ |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1015 | nl80211_send_mgmt_tx_status(rdev, dev, cookie, buf, len, ack, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 1016 | } |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1017 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 1018 | |
| 1019 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 1020 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 1021 | gfp_t gfp) |
| 1022 | { |
| 1023 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 1024 | struct wiphy *wiphy = wdev->wiphy; |
| 1025 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 1026 | |
| 1027 | /* Indicate roaming trigger event to user space */ |
| 1028 | nl80211_send_cqm_rssi_notify(rdev, dev, rssi_event, gfp); |
| 1029 | } |
| 1030 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |