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