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