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