Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2 | /* |
| 3 | * This is the new netlink-based wireless configuration interface. |
| 4 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 7 | * Copyright 2015-2017 Intel Deutschland GmbH |
Shaul Triebitz | 7e8d6f1 | 2020-01-31 13:12:54 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2020 Intel Corporation |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/if.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15 | #include <linux/list.h> |
| 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/ieee80211.h> |
| 18 | #include <linux/nl80211.h> |
| 19 | #include <linux/rtnetlink.h> |
| 20 | #include <linux/netlink.h> |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 21 | #include <linux/nospec.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 22 | #include <linux/etherdevice.h> |
Johannes Berg | e3ae39e | 2020-02-24 09:38:15 +0100 | [diff] [blame] | 23 | #include <linux/if_vlan.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include <net/genetlink.h> |
| 26 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 27 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 28 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | #include "core.h" |
| 30 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 31 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 32 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 33 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 34 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 35 | struct genl_info *info, |
| 36 | struct cfg80211_crypto_settings *settings, |
| 37 | int cipher_limit); |
| 38 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 40 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 42 | /* multicast groups */ |
| 43 | enum nl80211_multicast_groups { |
| 44 | NL80211_MCGRP_CONFIG, |
| 45 | NL80211_MCGRP_SCAN, |
| 46 | NL80211_MCGRP_REGULATORY, |
| 47 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 48 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 49 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 51 | }; |
| 52 | |
| 53 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 54 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 55 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 56 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 57 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 58 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 59 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 60 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 61 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 62 | #endif |
| 63 | }; |
| 64 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 65 | /* returns ERR_PTR values */ |
| 66 | static struct wireless_dev * |
| 67 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 69 | struct cfg80211_registered_device *rdev; |
| 70 | struct wireless_dev *result = NULL; |
| 71 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 72 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 73 | u64 wdev_id; |
| 74 | int wiphy_idx = -1; |
| 75 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 77 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 78 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 79 | if (!have_ifidx && !have_wdev_id) |
| 80 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 81 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 82 | if (have_ifidx) |
| 83 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 84 | if (have_wdev_id) { |
| 85 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 86 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 90 | struct wireless_dev *wdev; |
| 91 | |
| 92 | if (wiphy_net(&rdev->wiphy) != netns) |
| 93 | continue; |
| 94 | |
| 95 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 96 | continue; |
| 97 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 98 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 99 | if (have_ifidx && wdev->netdev && |
| 100 | wdev->netdev->ifindex == ifidx) { |
| 101 | result = wdev; |
| 102 | break; |
| 103 | } |
| 104 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 105 | result = wdev; |
| 106 | break; |
| 107 | } |
| 108 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 109 | |
| 110 | if (result) |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | if (result) |
| 115 | return result; |
| 116 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 119 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 122 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 123 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 124 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 125 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 126 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 127 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 128 | !attrs[NL80211_ATTR_IFINDEX] && |
| 129 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 130 | return ERR_PTR(-EINVAL); |
| 131 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 132 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 133 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 134 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 135 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 136 | if (attrs[NL80211_ATTR_WDEV]) { |
| 137 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 138 | struct wireless_dev *wdev; |
| 139 | bool found = false; |
| 140 | |
| 141 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 142 | if (tmp) { |
| 143 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 144 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 145 | if (wdev->identifier != (u32)wdev_id) |
| 146 | continue; |
| 147 | found = true; |
| 148 | break; |
| 149 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | |
| 151 | if (!found) |
| 152 | tmp = NULL; |
| 153 | |
| 154 | if (rdev && tmp != rdev) |
| 155 | return ERR_PTR(-EINVAL); |
| 156 | rdev = tmp; |
| 157 | } |
| 158 | } |
| 159 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 160 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 161 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 162 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 163 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 164 | if (netdev) { |
| 165 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 166 | tmp = wiphy_to_rdev( |
| 167 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 168 | else |
| 169 | tmp = NULL; |
| 170 | |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 171 | /* not wireless device -- return error */ |
| 172 | if (!tmp) |
| 173 | return ERR_PTR(-EINVAL); |
| 174 | |
| 175 | /* mismatch -- return error */ |
| 176 | if (rdev && tmp != rdev) |
| 177 | return ERR_PTR(-EINVAL); |
| 178 | |
| 179 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 183 | if (!rdev) |
| 184 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | if (netns != wiphy_net(&rdev->wiphy)) |
| 187 | return ERR_PTR(-ENODEV); |
| 188 | |
| 189 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * This function returns a pointer to the driver |
| 194 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | * |
| 196 | * The result of this can be a PTR_ERR and hence must |
| 197 | * be checked with IS_ERR() for errors. |
| 198 | */ |
| 199 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 200 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 202 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 205 | static int validate_beacon_head(const struct nlattr *attr, |
| 206 | struct netlink_ext_ack *extack) |
| 207 | { |
| 208 | const u8 *data = nla_data(attr); |
| 209 | unsigned int len = nla_len(attr); |
| 210 | const struct element *elem; |
| 211 | const struct ieee80211_mgmt *mgmt = (void *)data; |
| 212 | unsigned int fixedlen = offsetof(struct ieee80211_mgmt, |
| 213 | u.beacon.variable); |
| 214 | |
| 215 | if (len < fixedlen) |
| 216 | goto err; |
| 217 | |
| 218 | if (ieee80211_hdrlen(mgmt->frame_control) != |
| 219 | offsetof(struct ieee80211_mgmt, u.beacon)) |
| 220 | goto err; |
| 221 | |
| 222 | data += fixedlen; |
| 223 | len -= fixedlen; |
| 224 | |
| 225 | for_each_element(elem, data, len) { |
| 226 | /* nothing */ |
| 227 | } |
| 228 | |
| 229 | if (for_each_element_completed(elem, data, len)) |
| 230 | return 0; |
| 231 | |
| 232 | err: |
| 233 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); |
| 234 | return -EINVAL; |
| 235 | } |
| 236 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 237 | static int validate_ie_attr(const struct nlattr *attr, |
| 238 | struct netlink_ext_ack *extack) |
| 239 | { |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 240 | const u8 *data = nla_data(attr); |
| 241 | unsigned int len = nla_len(attr); |
Jouni Malinen | 7388afe | 2019-02-11 16:29:04 +0200 | [diff] [blame] | 242 | const struct element *elem; |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 243 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 244 | for_each_element(elem, data, len) { |
| 245 | /* nothing */ |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 248 | if (for_each_element_completed(elem, data, len)) |
| 249 | return 0; |
| 250 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 251 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 252 | return -EINVAL; |
| 253 | } |
| 254 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 255 | /* policy for the attributes */ |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 256 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; |
| 257 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 258 | static const struct nla_policy |
| 259 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 260 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 261 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 262 | .len = U8_MAX }, |
| 263 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 264 | .len = U8_MAX }, |
| 265 | }; |
| 266 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 267 | static const struct nla_policy |
| 268 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 269 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 270 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 271 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 272 | NLA_POLICY_MAX(NLA_U8, 15), |
| 273 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 274 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 275 | NLA_POLICY_MAX(NLA_U8, 15), |
| 276 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
Aviya Erenfeld | ea18709 | 2019-02-06 13:17:08 +0200 | [diff] [blame] | 277 | NLA_POLICY_MAX(NLA_U8, 31), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 278 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 279 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 280 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 281 | [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, |
| 282 | [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | static const struct nla_policy |
| 286 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 287 | [NL80211_PMSR_TYPE_FTM] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 288 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | static const struct nla_policy |
| 292 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 293 | [NL80211_PMSR_REQ_ATTR_DATA] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 294 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 295 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 296 | }; |
| 297 | |
| 298 | static const struct nla_policy |
| 299 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
| 300 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 301 | [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 302 | [NL80211_PMSR_PEER_ATTR_REQ] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 303 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 304 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 305 | }; |
| 306 | |
| 307 | static const struct nla_policy |
| 308 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 309 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 310 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 311 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 312 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 313 | [NL80211_PMSR_ATTR_PEERS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 314 | NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 315 | }; |
| 316 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 317 | static const struct nla_policy |
| 318 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { |
| 319 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = |
| 320 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 321 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = |
| 322 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 323 | }; |
| 324 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 325 | static const struct nla_policy |
| 326 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { |
| 327 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), |
| 328 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 329 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, |
| 330 | }; |
| 331 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 332 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 333 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 334 | .len = NL80211_MAX_SUPP_RATES }, |
| 335 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 336 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 337 | [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), |
| 338 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
| 339 | }; |
| 340 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 341 | static const struct nla_policy |
| 342 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 343 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
| 344 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 345 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 346 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 347 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
| 348 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 349 | [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 350 | [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 351 | [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = |
| 352 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 353 | [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = |
| 354 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 355 | [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = |
| 356 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 357 | [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = |
| 358 | NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), |
| 359 | [NL80211_TID_CONFIG_ATTR_TX_RATE] = |
| 360 | NLA_POLICY_NESTED(nl80211_txattr_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 361 | }; |
| 362 | |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 363 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 6d4dd4e | 2019-07-31 10:58:20 +0200 | [diff] [blame] | 364 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 365 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 366 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 367 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 368 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 369 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 370 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 371 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 372 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
| 373 | NL80211_EDMG_CHANNELS_MIN, |
| 374 | NL80211_EDMG_CHANNELS_MAX), |
| 375 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, |
| 376 | NL80211_EDMG_BW_CONFIG_MIN, |
| 377 | NL80211_EDMG_BW_CONFIG_MAX), |
| 378 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 379 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 380 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 381 | [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 382 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 383 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 384 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 385 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 386 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 387 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 388 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 389 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 390 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 391 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 392 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 393 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 394 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 395 | [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| 396 | [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 397 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 398 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 399 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 400 | .len = WLAN_MAX_KEY_LEN }, |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 401 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 402 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 403 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 404 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 405 | [NL80211_ATTR_KEY_TYPE] = |
| 406 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 407 | |
| 408 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 409 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 410 | [NL80211_ATTR_BEACON_HEAD] = |
| 411 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, |
| 412 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 413 | [NL80211_ATTR_BEACON_TAIL] = |
| 414 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 415 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 416 | [NL80211_ATTR_STA_AID] = |
| 417 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 418 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 419 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 420 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 421 | .len = NL80211_MAX_SUPP_RATES }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 422 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 423 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 424 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
| 425 | NLA_POLICY_RANGE(NLA_U8, |
| 426 | NL80211_TX_POWER_AUTOMATIC, |
| 427 | NL80211_TX_POWER_FIXED), |
| 428 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 429 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 430 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 431 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 432 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Markus Theil | 1fab1b8 | 2019-10-29 10:30:03 +0100 | [diff] [blame] | 433 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 434 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 435 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 436 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 437 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 438 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 439 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 440 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 441 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 442 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 443 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 444 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 445 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 446 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 447 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 448 | [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN), |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 449 | |
| 450 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 451 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 452 | validate_ie_attr, |
| 453 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 454 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 455 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 456 | |
| 457 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 458 | .len = IEEE80211_MAX_SSID_LEN }, |
| 459 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 460 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 461 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 462 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 463 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 464 | NL80211_MFP_NO, |
| 465 | NL80211_MFP_OPTIONAL), |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 466 | [NL80211_ATTR_STA_FLAGS2] = { |
| 467 | .len = sizeof(struct nl80211_sta_flag_update), |
| 468 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 469 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 470 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 471 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 472 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 473 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
Sergey Matyukevich | ea75080 | 2020-02-13 13:16:16 +0000 | [diff] [blame] | 474 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 475 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 476 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 477 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 478 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 479 | [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 480 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 481 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 482 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 483 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 484 | .len = IEEE80211_MAX_DATA_LEN }, |
| 485 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 486 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 487 | NL80211_PS_DISABLED, |
| 488 | NL80211_PS_ENABLED), |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 489 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 490 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 491 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 492 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 493 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 494 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 495 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 496 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 497 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 498 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 499 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 500 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 501 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 502 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
Jakub Kicinski | 056e937 | 2020-03-02 21:10:57 -0800 | [diff] [blame] | 503 | [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, |
| 504 | [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 505 | [NL80211_ATTR_MESH_PEER_AID] = |
| 506 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 507 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 508 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 509 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 510 | [NL80211_ATTR_HIDDEN_SSID] = |
| 511 | NLA_POLICY_RANGE(NLA_U32, |
| 512 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 513 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 514 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 515 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 516 | IEEE80211_MAX_DATA_LEN), |
| 517 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 518 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 519 | IEEE80211_MAX_DATA_LEN), |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 520 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 521 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 522 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 523 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 524 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 525 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 526 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 527 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 528 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 529 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 530 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 531 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 532 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 533 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 534 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 535 | .len = NL80211_HT_CAPABILITY_LEN |
| 536 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 537 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 538 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 539 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 540 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 541 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 542 | |
| 543 | /* need to include at least Auth Transaction and Status Code */ |
| 544 | [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), |
| 545 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 546 | [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN), |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 547 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 548 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 549 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 550 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 551 | NLA_POLICY_RANGE(NLA_U32, |
| 552 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 553 | NL80211_MESH_POWER_MAX), |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 554 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 555 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 556 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 557 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 558 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 559 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 560 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 561 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 562 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 563 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 564 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 565 | .len = IEEE80211_MAX_DATA_LEN }, |
Jakub Kicinski | 0e1a1d8 | 2020-03-02 21:10:56 -0800 | [diff] [blame] | 566 | [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 567 | [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = |
| 568 | NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 569 | [NL80211_ATTR_PEER_AID] = |
| 570 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 571 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 572 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 573 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 574 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
| 575 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 576 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame^] | 577 | /* |
| 578 | * The value of the Length field of the Supported Operating |
| 579 | * Classes element is between 2 and 253. |
| 580 | */ |
| 581 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = |
| 582 | NLA_POLICY_RANGE(NLA_BINARY, 2, 253), |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 583 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 584 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 585 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 586 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 587 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame^] | 588 | [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, |
| 589 | IEEE80211_QOS_MAP_LEN_MIN, |
| 590 | IEEE80211_QOS_MAP_LEN_MAX), |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 591 | [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 592 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 593 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 594 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 595 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 596 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 597 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 598 | [NL80211_ATTR_USER_PRIO] = |
| 599 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 600 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 601 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Jakub Kicinski | 5cde05c | 2020-03-02 21:10:58 -0800 | [diff] [blame] | 602 | [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 603 | [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 604 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 605 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 606 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 607 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 608 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 609 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 610 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 611 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 612 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 613 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 614 | }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 615 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 616 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 617 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 618 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 619 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 620 | .len = FILS_MAX_KEK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 621 | [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN), |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 622 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 623 | [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 624 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 625 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 626 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 627 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 628 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 629 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 630 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 631 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 632 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 633 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 634 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 635 | .len = FILS_ERP_MAX_RRK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 636 | [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 637 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 638 | [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN), |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 639 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 640 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 641 | |
| 642 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 643 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 644 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame^] | 645 | [NL80211_ATTR_HE_CAPABILITY] = |
| 646 | NLA_POLICY_RANGE(NLA_BINARY, |
| 647 | NL80211_HE_MIN_CAPABILITY_LEN, |
| 648 | NL80211_HE_MAX_CAPABILITY_LEN), |
Johannes Berg | 0e012b4 | 2020-04-12 00:40:30 +0200 | [diff] [blame] | 649 | [NL80211_ATTR_FTM_RESPONDER] = |
| 650 | NLA_POLICY_NESTED(nl80211_ftm_responder_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 651 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 652 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 653 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 654 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 655 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
| 656 | .len = SAE_PASSWORD_MAX_LEN }, |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 657 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 658 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 659 | [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2), |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 660 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 661 | [NL80211_ATTR_TID_CONFIG] = |
| 662 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), |
Markus Theil | 5631d96 | 2020-03-12 10:10:53 +0100 | [diff] [blame] | 663 | [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 664 | [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), |
| 665 | [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 666 | [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 667 | [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 668 | [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, |
Johannes Berg | 8140860 | 2020-08-18 10:17:31 +0200 | [diff] [blame] | 669 | [NL80211_ATTR_HE_6GHZ_CAPABILITY] = |
| 670 | NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 671 | }; |
| 672 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 673 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 674 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 675 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 676 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 677 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 678 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 679 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 680 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 681 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 682 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 683 | [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 684 | }; |
| 685 | |
| 686 | /* policy for the key default flags */ |
| 687 | static const struct nla_policy |
| 688 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 689 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 690 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 691 | }; |
| 692 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 693 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 694 | /* policy for WoWLAN attributes */ |
| 695 | static const struct nla_policy |
| 696 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 697 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 698 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 699 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 700 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 701 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 702 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 703 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 704 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 705 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 706 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | static const struct nla_policy |
| 710 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 711 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 712 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 713 | [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 714 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 715 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 716 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 717 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 718 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 719 | }, |
| 720 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 721 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 722 | }, |
| 723 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 724 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
| 725 | [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 726 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 727 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 728 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 729 | /* policy for coalesce rule attributes */ |
| 730 | static const struct nla_policy |
| 731 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 732 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 733 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 734 | NLA_POLICY_RANGE(NLA_U32, |
| 735 | NL80211_COALESCE_CONDITION_MATCH, |
| 736 | NL80211_COALESCE_CONDITION_NO_MATCH), |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 737 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 738 | }; |
| 739 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 740 | /* policy for GTK rekey offload attributes */ |
| 741 | static const struct nla_policy |
| 742 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 743 | [NL80211_REKEY_DATA_KEK] = { |
| 744 | .type = NLA_BINARY, |
| 745 | .len = NL80211_KEK_EXT_LEN |
| 746 | }, |
| 747 | [NL80211_REKEY_DATA_KCK] = { |
| 748 | .type = NLA_BINARY, |
| 749 | .len = NL80211_KCK_EXT_LEN |
| 750 | }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 751 | [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN), |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 752 | [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 753 | }; |
| 754 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 755 | static const struct nla_policy |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 756 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { |
| 757 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, |
| 758 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, |
Arend van Spriel | e548a1c | 2019-08-02 13:31:02 +0200 | [diff] [blame] | 759 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 760 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
| 761 | }; |
| 762 | |
| 763 | static const struct nla_policy |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 764 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 765 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 766 | .len = IEEE80211_MAX_SSID_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 767 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Thomas Pedersen | 88e920b | 2012-06-21 11:09:54 -0700 | [diff] [blame] | 768 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 769 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
| 770 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 771 | }; |
| 772 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 773 | static const struct nla_policy |
| 774 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 775 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 776 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 777 | }; |
| 778 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 779 | static const struct nla_policy |
| 780 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 781 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 782 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 783 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 784 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 785 | }, |
| 786 | }; |
| 787 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 788 | /* policy for NAN function attributes */ |
| 789 | static const struct nla_policy |
| 790 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 791 | [NL80211_NAN_FUNC_TYPE] = |
| 792 | NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 793 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 794 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 795 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 796 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 797 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 798 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 799 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 800 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 801 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 802 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 803 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 804 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 805 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 806 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 807 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 808 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 809 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 810 | }; |
| 811 | |
| 812 | /* policy for Service Response Filter attributes */ |
| 813 | static const struct nla_policy |
| 814 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 815 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 816 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 817 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 818 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 819 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 820 | }; |
| 821 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 822 | /* policy for packet pattern attributes */ |
| 823 | static const struct nla_policy |
| 824 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 825 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 826 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 827 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 828 | }; |
| 829 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 830 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 831 | struct cfg80211_registered_device **rdev, |
| 832 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 833 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 834 | int err; |
| 835 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 836 | if (!cb->args[0]) { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 837 | struct nlattr **attrbuf; |
| 838 | |
| 839 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 840 | GFP_KERNEL); |
| 841 | if (!attrbuf) |
| 842 | return -ENOMEM; |
| 843 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 844 | err = nlmsg_parse_deprecated(cb->nlh, |
| 845 | GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 846 | attrbuf, nl80211_fam.maxattr, |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 847 | nl80211_policy, NULL); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 848 | if (err) { |
| 849 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 850 | return err; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 851 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 852 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 853 | *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk), |
| 854 | attrbuf); |
| 855 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 856 | if (IS_ERR(*wdev)) |
| 857 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 858 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 859 | /* 0 is the first index - add 1 to parse only once */ |
| 860 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 861 | cb->args[1] = (*wdev)->identifier; |
| 862 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 863 | /* subtract the 1 again here */ |
| 864 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 865 | struct wireless_dev *tmp; |
| 866 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 867 | if (!wiphy) |
| 868 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 869 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 870 | *wdev = NULL; |
| 871 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 872 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 873 | if (tmp->identifier == cb->args[1]) { |
| 874 | *wdev = tmp; |
| 875 | break; |
| 876 | } |
| 877 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 878 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 879 | if (!*wdev) |
| 880 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 881 | } |
| 882 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 883 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 884 | } |
| 885 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 886 | /* message building helper */ |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 887 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 888 | int flags, u8 cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 889 | { |
| 890 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 891 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 892 | } |
| 893 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 894 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 895 | const struct ieee80211_reg_rule *rule) |
| 896 | { |
| 897 | int j; |
| 898 | struct nlattr *nl_wmm_rules = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 899 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 900 | |
| 901 | if (!nl_wmm_rules) |
| 902 | goto nla_put_failure; |
| 903 | |
| 904 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 905 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 906 | |
| 907 | if (!nl_wmm_rule) |
| 908 | goto nla_put_failure; |
| 909 | |
| 910 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 911 | rule->wmm_rule.client[j].cw_min) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 912 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 913 | rule->wmm_rule.client[j].cw_max) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 914 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 915 | rule->wmm_rule.client[j].aifsn) || |
Haim Dreyfuss | d3c89bb | 2018-08-21 09:22:19 +0300 | [diff] [blame] | 916 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 917 | rule->wmm_rule.client[j].cot)) |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 918 | goto nla_put_failure; |
| 919 | |
| 920 | nla_nest_end(msg, nl_wmm_rule); |
| 921 | } |
| 922 | nla_nest_end(msg, nl_wmm_rules); |
| 923 | |
| 924 | return 0; |
| 925 | |
| 926 | nla_put_failure: |
| 927 | return -ENOBUFS; |
| 928 | } |
| 929 | |
| 930 | static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 931 | struct ieee80211_channel *chan, |
| 932 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 933 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 934 | /* Some channels must be completely excluded from the |
| 935 | * list to protect old user-space tools from breaking |
| 936 | */ |
| 937 | if (!large && chan->flags & |
| 938 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 939 | return 0; |
| 940 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 941 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 942 | chan->center_freq)) |
| 943 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 944 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 945 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) |
| 946 | goto nla_put_failure; |
| 947 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 948 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 949 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 950 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 951 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 952 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 953 | goto nla_put_failure; |
| 954 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 955 | goto nla_put_failure; |
| 956 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 957 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 958 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 959 | goto nla_put_failure; |
| 960 | if (large) { |
| 961 | u32 time; |
| 962 | |
| 963 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 964 | |
| 965 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 966 | chan->dfs_state)) |
| 967 | goto nla_put_failure; |
| 968 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 969 | time)) |
| 970 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 971 | if (nla_put_u32(msg, |
| 972 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 973 | chan->dfs_cac_ms)) |
| 974 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 975 | } |
| 976 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 977 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 978 | if (large) { |
| 979 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 980 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 981 | goto nla_put_failure; |
| 982 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 983 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 984 | goto nla_put_failure; |
| 985 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 986 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 987 | goto nla_put_failure; |
| 988 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 989 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 990 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 991 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 992 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 993 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 994 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 995 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 996 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 997 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 998 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 999 | goto nla_put_failure; |
| 1000 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 1001 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 1002 | goto nla_put_failure; |
Haim Dreyfuss | 1e61d82 | 2020-01-21 10:12:13 +0200 | [diff] [blame] | 1003 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
| 1004 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) |
| 1005 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1006 | } |
| 1007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1008 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 1009 | DBM_TO_MBM(chan->max_power))) |
| 1010 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1011 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1012 | if (large) { |
| 1013 | const struct ieee80211_reg_rule *rule = |
Haim Dreyfuss | b88d26d | 2018-08-21 09:22:20 +0300 | [diff] [blame] | 1014 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1015 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1016 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1017 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 1018 | goto nla_put_failure; |
| 1019 | } |
| 1020 | } |
| 1021 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1022 | return 0; |
| 1023 | |
| 1024 | nla_put_failure: |
| 1025 | return -ENOBUFS; |
| 1026 | } |
| 1027 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1028 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 1029 | struct cfg80211_txq_stats *txqstats, |
| 1030 | int attrtype) |
| 1031 | { |
| 1032 | struct nlattr *txqattr; |
| 1033 | |
| 1034 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 1035 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 1036 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 1037 | return false; \ |
| 1038 | } while (0) |
| 1039 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1040 | txqattr = nla_nest_start_noflag(msg, attrtype); |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1041 | if (!txqattr) |
| 1042 | return false; |
| 1043 | |
| 1044 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 1045 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 1046 | PUT_TXQVAL_U32(FLOWS, flows); |
| 1047 | PUT_TXQVAL_U32(DROPS, drops); |
| 1048 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 1049 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 1050 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 1051 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 1052 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 1053 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 1054 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 1055 | nla_nest_end(msg, txqattr); |
| 1056 | |
| 1057 | #undef PUT_TXQVAL_U32 |
| 1058 | return true; |
| 1059 | } |
| 1060 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1061 | /* netlink command implementations */ |
| 1062 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1063 | struct key_parse { |
| 1064 | struct key_params p; |
| 1065 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1066 | int type; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1067 | bool def, defmgmt, defbeacon; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1068 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1069 | }; |
| 1070 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1071 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 1072 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1073 | { |
| 1074 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1075 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
| 1076 | nl80211_key_policy, |
| 1077 | info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1078 | if (err) |
| 1079 | return err; |
| 1080 | |
| 1081 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 1082 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1083 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1084 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1085 | if (k->def) { |
| 1086 | k->def_uni = true; |
| 1087 | k->def_multi = true; |
| 1088 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1089 | if (k->defmgmt || k->defbeacon) |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1090 | k->def_multi = true; |
| 1091 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1092 | if (tb[NL80211_KEY_IDX]) |
| 1093 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 1094 | |
| 1095 | if (tb[NL80211_KEY_DATA]) { |
| 1096 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 1097 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 1098 | } |
| 1099 | |
| 1100 | if (tb[NL80211_KEY_SEQ]) { |
| 1101 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 1102 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 1103 | } |
| 1104 | |
| 1105 | if (tb[NL80211_KEY_CIPHER]) |
| 1106 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 1107 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1108 | if (tb[NL80211_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1109 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1110 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1111 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 1112 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1113 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1114 | err = nla_parse_nested_deprecated(kdt, |
| 1115 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1116 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 1117 | nl80211_key_default_policy, |
| 1118 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1119 | if (err) |
| 1120 | return err; |
| 1121 | |
| 1122 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1123 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1124 | } |
| 1125 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 1126 | if (tb[NL80211_KEY_MODE]) |
| 1127 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); |
| 1128 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 1133 | { |
| 1134 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1135 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1136 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1137 | } |
| 1138 | |
| 1139 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1140 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1141 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1142 | } |
| 1143 | |
| 1144 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1145 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1146 | |
| 1147 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1148 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1149 | |
| 1150 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1151 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1152 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1153 | if (k->def) { |
| 1154 | k->def_uni = true; |
| 1155 | k->def_multi = true; |
| 1156 | } |
| 1157 | if (k->defmgmt) |
| 1158 | k->def_multi = true; |
| 1159 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1160 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1161 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1162 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1163 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1164 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1165 | int err = nla_parse_nested_deprecated(kdt, |
| 1166 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1167 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 1168 | nl80211_key_default_policy, |
| 1169 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1170 | if (err) |
| 1171 | return err; |
| 1172 | |
| 1173 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1174 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1175 | } |
| 1176 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1177 | return 0; |
| 1178 | } |
| 1179 | |
| 1180 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1181 | { |
| 1182 | int err; |
| 1183 | |
| 1184 | memset(k, 0, sizeof(*k)); |
| 1185 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1186 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1187 | |
| 1188 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1189 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1190 | else |
| 1191 | err = nl80211_parse_key_old(info, k); |
| 1192 | |
| 1193 | if (err) |
| 1194 | return err; |
| 1195 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1196 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
| 1197 | (k->defbeacon ? 1 : 0) > 1) { |
| 1198 | GENL_SET_ERR_MSG(info, |
| 1199 | "key with multiple default flags is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1200 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1201 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1202 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1203 | if (k->defmgmt || k->defbeacon) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1204 | if (k->def_uni || !k->def_multi) { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1205 | GENL_SET_ERR_MSG(info, |
| 1206 | "defmgmt/defbeacon key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1207 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1208 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1211 | if (k->idx != -1) { |
| 1212 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1213 | if (k->idx < 4 || k->idx > 5) { |
| 1214 | GENL_SET_ERR_MSG(info, |
| 1215 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1216 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1217 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1218 | } else if (k->defbeacon) { |
| 1219 | if (k->idx < 6 || k->idx > 7) { |
| 1220 | GENL_SET_ERR_MSG(info, |
| 1221 | "defbeacon key idx not 6 or 7"); |
| 1222 | return -EINVAL; |
| 1223 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1224 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1225 | if (k->idx < 0 || k->idx > 3) { |
| 1226 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1227 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1228 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1229 | } else { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1230 | if (k->idx < 0 || k->idx > 7) { |
| 1231 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1232 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1233 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1240 | static struct cfg80211_cached_keys * |
| 1241 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1242 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1243 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1244 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1245 | struct key_parse parse; |
| 1246 | struct nlattr *key; |
| 1247 | struct cfg80211_cached_keys *result; |
| 1248 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1249 | bool have_key = false; |
| 1250 | |
| 1251 | nla_for_each_nested(key, keys, rem) { |
| 1252 | have_key = true; |
| 1253 | break; |
| 1254 | } |
| 1255 | |
| 1256 | if (!have_key) |
| 1257 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1258 | |
| 1259 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1260 | if (!result) |
| 1261 | return ERR_PTR(-ENOMEM); |
| 1262 | |
| 1263 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1264 | |
| 1265 | nla_for_each_nested(key, keys, rem) { |
| 1266 | memset(&parse, 0, sizeof(parse)); |
| 1267 | parse.idx = -1; |
| 1268 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1269 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1270 | if (err) |
| 1271 | goto error; |
| 1272 | err = -EINVAL; |
| 1273 | if (!parse.p.key) |
| 1274 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1275 | if (parse.idx < 0 || parse.idx > 3) { |
| 1276 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1277 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1278 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1279 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1280 | if (def) { |
| 1281 | GENL_SET_ERR_MSG(info, |
| 1282 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1283 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1284 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1285 | def = 1; |
| 1286 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1287 | if (!parse.def_uni || !parse.def_multi) |
| 1288 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1289 | } else if (parse.defmgmt) |
| 1290 | goto error; |
| 1291 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1292 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1293 | if (err) |
| 1294 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1295 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1296 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1297 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1298 | err = -EINVAL; |
| 1299 | goto error; |
| 1300 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1301 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1302 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1303 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1304 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1305 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1306 | /* must be WEP key if we got here */ |
| 1307 | if (no_ht) |
| 1308 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1311 | if (result->def < 0) { |
| 1312 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1313 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1314 | goto error; |
| 1315 | } |
| 1316 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1317 | return result; |
| 1318 | error: |
| 1319 | kfree(result); |
| 1320 | return ERR_PTR(err); |
| 1321 | } |
| 1322 | |
| 1323 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1324 | { |
| 1325 | ASSERT_WDEV_LOCK(wdev); |
| 1326 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1327 | switch (wdev->iftype) { |
| 1328 | case NL80211_IFTYPE_AP: |
| 1329 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1330 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1331 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1332 | break; |
| 1333 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1334 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1335 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1336 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1337 | return -ENOLINK; |
| 1338 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1339 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1340 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1341 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1342 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1343 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1344 | case NL80211_IFTYPE_WDS: |
| 1345 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1346 | return -EINVAL; |
| 1347 | } |
| 1348 | |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1352 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1353 | u32 freq) |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1354 | { |
| 1355 | struct ieee80211_channel *chan; |
| 1356 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1357 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1358 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1359 | return NULL; |
| 1360 | return chan; |
| 1361 | } |
| 1362 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1363 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1364 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1365 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1366 | int i; |
| 1367 | |
| 1368 | if (!nl_modes) |
| 1369 | goto nla_put_failure; |
| 1370 | |
| 1371 | i = 0; |
| 1372 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1373 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1374 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1375 | ifmodes >>= 1; |
| 1376 | i++; |
| 1377 | } |
| 1378 | |
| 1379 | nla_nest_end(msg, nl_modes); |
| 1380 | return 0; |
| 1381 | |
| 1382 | nla_put_failure: |
| 1383 | return -ENOBUFS; |
| 1384 | } |
| 1385 | |
| 1386 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1387 | struct sk_buff *msg, |
| 1388 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1389 | { |
| 1390 | struct nlattr *nl_combis; |
| 1391 | int i, j; |
| 1392 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1393 | nl_combis = nla_nest_start_noflag(msg, |
| 1394 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1395 | if (!nl_combis) |
| 1396 | goto nla_put_failure; |
| 1397 | |
| 1398 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1399 | const struct ieee80211_iface_combination *c; |
| 1400 | struct nlattr *nl_combi, *nl_limits; |
| 1401 | |
| 1402 | c = &wiphy->iface_combinations[i]; |
| 1403 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1404 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1405 | if (!nl_combi) |
| 1406 | goto nla_put_failure; |
| 1407 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1408 | nl_limits = nla_nest_start_noflag(msg, |
| 1409 | NL80211_IFACE_COMB_LIMITS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1410 | if (!nl_limits) |
| 1411 | goto nla_put_failure; |
| 1412 | |
| 1413 | for (j = 0; j < c->n_limits; j++) { |
| 1414 | struct nlattr *nl_limit; |
| 1415 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1416 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1417 | if (!nl_limit) |
| 1418 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1419 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1420 | c->limits[j].max)) |
| 1421 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1422 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1423 | c->limits[j].types)) |
| 1424 | goto nla_put_failure; |
| 1425 | nla_nest_end(msg, nl_limit); |
| 1426 | } |
| 1427 | |
| 1428 | nla_nest_end(msg, nl_limits); |
| 1429 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1430 | if (c->beacon_int_infra_match && |
| 1431 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1432 | goto nla_put_failure; |
| 1433 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1434 | c->num_different_channels) || |
| 1435 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1436 | c->max_interfaces)) |
| 1437 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1438 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1439 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1440 | c->radar_detect_widths) || |
| 1441 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1442 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1443 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1444 | if (c->beacon_int_min_gcd && |
| 1445 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1446 | c->beacon_int_min_gcd)) |
| 1447 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1448 | |
| 1449 | nla_nest_end(msg, nl_combi); |
| 1450 | } |
| 1451 | |
| 1452 | nla_nest_end(msg, nl_combis); |
| 1453 | |
| 1454 | return 0; |
| 1455 | nla_put_failure: |
| 1456 | return -ENOBUFS; |
| 1457 | } |
| 1458 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1459 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1460 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1461 | struct sk_buff *msg) |
| 1462 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1463 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1464 | struct nlattr *nl_tcp; |
| 1465 | |
| 1466 | if (!tcp) |
| 1467 | return 0; |
| 1468 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1469 | nl_tcp = nla_nest_start_noflag(msg, |
| 1470 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1471 | if (!nl_tcp) |
| 1472 | return -ENOBUFS; |
| 1473 | |
| 1474 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1475 | tcp->data_payload_max)) |
| 1476 | return -ENOBUFS; |
| 1477 | |
| 1478 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1479 | tcp->data_payload_max)) |
| 1480 | return -ENOBUFS; |
| 1481 | |
| 1482 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1483 | return -ENOBUFS; |
| 1484 | |
| 1485 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1486 | sizeof(*tcp->tok), tcp->tok)) |
| 1487 | return -ENOBUFS; |
| 1488 | |
| 1489 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1490 | tcp->data_interval_max)) |
| 1491 | return -ENOBUFS; |
| 1492 | |
| 1493 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1494 | tcp->wake_payload_max)) |
| 1495 | return -ENOBUFS; |
| 1496 | |
| 1497 | nla_nest_end(msg, nl_tcp); |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1501 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1502 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1503 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1504 | { |
| 1505 | struct nlattr *nl_wowlan; |
| 1506 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1507 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1508 | return 0; |
| 1509 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1510 | nl_wowlan = nla_nest_start_noflag(msg, |
| 1511 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1512 | if (!nl_wowlan) |
| 1513 | return -ENOBUFS; |
| 1514 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1515 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1516 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1517 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1518 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1519 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1520 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1521 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1522 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1523 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1524 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1525 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1526 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1527 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1528 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1529 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1530 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1531 | return -ENOBUFS; |
| 1532 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1533 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1534 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1535 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1536 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1537 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1538 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1539 | }; |
| 1540 | |
| 1541 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1542 | sizeof(pat), &pat)) |
| 1543 | return -ENOBUFS; |
| 1544 | } |
| 1545 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1546 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1547 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1548 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1549 | return -ENOBUFS; |
| 1550 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1551 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1552 | return -ENOBUFS; |
| 1553 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1554 | nla_nest_end(msg, nl_wowlan); |
| 1555 | |
| 1556 | return 0; |
| 1557 | } |
| 1558 | #endif |
| 1559 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1560 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1561 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1562 | { |
| 1563 | struct nl80211_coalesce_rule_support rule; |
| 1564 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1565 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1566 | return 0; |
| 1567 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1568 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1569 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1570 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1571 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1572 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1573 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1574 | |
| 1575 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1576 | return -ENOBUFS; |
| 1577 | |
| 1578 | return 0; |
| 1579 | } |
| 1580 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1581 | static int |
| 1582 | nl80211_send_iftype_data(struct sk_buff *msg, |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1583 | const struct ieee80211_supported_band *sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1584 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1585 | { |
| 1586 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1587 | |
| 1588 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1589 | iftdata->types_mask)) |
| 1590 | return -ENOBUFS; |
| 1591 | |
| 1592 | if (he_cap->has_he) { |
| 1593 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1594 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1595 | he_cap->he_cap_elem.mac_cap_info) || |
| 1596 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1597 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1598 | he_cap->he_cap_elem.phy_cap_info) || |
| 1599 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1600 | sizeof(he_cap->he_mcs_nss_supp), |
| 1601 | &he_cap->he_mcs_nss_supp) || |
| 1602 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1603 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1604 | return -ENOBUFS; |
| 1605 | } |
| 1606 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1607 | if (sband->band == NL80211_BAND_6GHZ && |
| 1608 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, |
| 1609 | sizeof(iftdata->he_6ghz_capa), |
| 1610 | &iftdata->he_6ghz_capa)) |
| 1611 | return -ENOBUFS; |
| 1612 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1613 | return 0; |
| 1614 | } |
| 1615 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1616 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
| 1617 | struct ieee80211_supported_band *sband) |
| 1618 | { |
| 1619 | struct nlattr *nl_rates, *nl_rate; |
| 1620 | struct ieee80211_rate *rate; |
| 1621 | int i; |
| 1622 | |
| 1623 | /* add HT info */ |
| 1624 | if (sband->ht_cap.ht_supported && |
| 1625 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1626 | sizeof(sband->ht_cap.mcs), |
| 1627 | &sband->ht_cap.mcs) || |
| 1628 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1629 | sband->ht_cap.cap) || |
| 1630 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1631 | sband->ht_cap.ampdu_factor) || |
| 1632 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1633 | sband->ht_cap.ampdu_density))) |
| 1634 | return -ENOBUFS; |
| 1635 | |
| 1636 | /* add VHT info */ |
| 1637 | if (sband->vht_cap.vht_supported && |
| 1638 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1639 | sizeof(sband->vht_cap.vht_mcs), |
| 1640 | &sband->vht_cap.vht_mcs) || |
| 1641 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1642 | sband->vht_cap.cap))) |
| 1643 | return -ENOBUFS; |
| 1644 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1645 | if (sband->n_iftype_data) { |
| 1646 | struct nlattr *nl_iftype_data = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1647 | nla_nest_start_noflag(msg, |
| 1648 | NL80211_BAND_ATTR_IFTYPE_DATA); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1649 | int err; |
| 1650 | |
| 1651 | if (!nl_iftype_data) |
| 1652 | return -ENOBUFS; |
| 1653 | |
| 1654 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1655 | struct nlattr *iftdata; |
| 1656 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1657 | iftdata = nla_nest_start_noflag(msg, i + 1); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1658 | if (!iftdata) |
| 1659 | return -ENOBUFS; |
| 1660 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1661 | err = nl80211_send_iftype_data(msg, sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1662 | &sband->iftype_data[i]); |
| 1663 | if (err) |
| 1664 | return err; |
| 1665 | |
| 1666 | nla_nest_end(msg, iftdata); |
| 1667 | } |
| 1668 | |
| 1669 | nla_nest_end(msg, nl_iftype_data); |
| 1670 | } |
| 1671 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1672 | /* add EDMG info */ |
| 1673 | if (sband->edmg_cap.channels && |
| 1674 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
| 1675 | sband->edmg_cap.channels) || |
| 1676 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, |
| 1677 | sband->edmg_cap.bw_config))) |
| 1678 | |
| 1679 | return -ENOBUFS; |
| 1680 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1681 | /* add bitrates */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1682 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1683 | if (!nl_rates) |
| 1684 | return -ENOBUFS; |
| 1685 | |
| 1686 | for (i = 0; i < sband->n_bitrates; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1687 | nl_rate = nla_nest_start_noflag(msg, i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1688 | if (!nl_rate) |
| 1689 | return -ENOBUFS; |
| 1690 | |
| 1691 | rate = &sband->bitrates[i]; |
| 1692 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1693 | rate->bitrate)) |
| 1694 | return -ENOBUFS; |
| 1695 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1696 | nla_put_flag(msg, |
| 1697 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1698 | return -ENOBUFS; |
| 1699 | |
| 1700 | nla_nest_end(msg, nl_rate); |
| 1701 | } |
| 1702 | |
| 1703 | nla_nest_end(msg, nl_rates); |
| 1704 | |
| 1705 | return 0; |
| 1706 | } |
| 1707 | |
| 1708 | static int |
| 1709 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1710 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1711 | { |
| 1712 | u16 stypes; |
| 1713 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1714 | enum nl80211_iftype ift; |
| 1715 | int i; |
| 1716 | |
| 1717 | if (!mgmt_stypes) |
| 1718 | return 0; |
| 1719 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1720 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1721 | if (!nl_ifs) |
| 1722 | return -ENOBUFS; |
| 1723 | |
| 1724 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1725 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1726 | if (!nl_ftypes) |
| 1727 | return -ENOBUFS; |
| 1728 | i = 0; |
| 1729 | stypes = mgmt_stypes[ift].tx; |
| 1730 | while (stypes) { |
| 1731 | if ((stypes & 1) && |
| 1732 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1733 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1734 | return -ENOBUFS; |
| 1735 | stypes >>= 1; |
| 1736 | i++; |
| 1737 | } |
| 1738 | nla_nest_end(msg, nl_ftypes); |
| 1739 | } |
| 1740 | |
| 1741 | nla_nest_end(msg, nl_ifs); |
| 1742 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1743 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1744 | if (!nl_ifs) |
| 1745 | return -ENOBUFS; |
| 1746 | |
| 1747 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1748 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1749 | if (!nl_ftypes) |
| 1750 | return -ENOBUFS; |
| 1751 | i = 0; |
| 1752 | stypes = mgmt_stypes[ift].rx; |
| 1753 | while (stypes) { |
| 1754 | if ((stypes & 1) && |
| 1755 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1756 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1757 | return -ENOBUFS; |
| 1758 | stypes >>= 1; |
| 1759 | i++; |
| 1760 | } |
| 1761 | nla_nest_end(msg, nl_ftypes); |
| 1762 | } |
| 1763 | nla_nest_end(msg, nl_ifs); |
| 1764 | |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1768 | #define CMD(op, n) \ |
| 1769 | do { \ |
| 1770 | if (rdev->ops->op) { \ |
| 1771 | i++; \ |
| 1772 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1773 | goto nla_put_failure; \ |
| 1774 | } \ |
| 1775 | } while (0) |
| 1776 | |
| 1777 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1778 | struct sk_buff *msg) |
| 1779 | { |
| 1780 | int i = 0; |
| 1781 | |
| 1782 | /* |
| 1783 | * do *NOT* add anything into this function, new things need to be |
| 1784 | * advertised only to new versions of userspace that can deal with |
| 1785 | * the split (and they can't possibly care about new features... |
| 1786 | */ |
| 1787 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1788 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1789 | CMD(add_key, NEW_KEY); |
| 1790 | CMD(start_ap, START_AP); |
| 1791 | CMD(add_station, NEW_STATION); |
| 1792 | CMD(add_mpath, NEW_MPATH); |
| 1793 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1794 | CMD(change_bss, SET_BSS); |
| 1795 | CMD(auth, AUTHENTICATE); |
| 1796 | CMD(assoc, ASSOCIATE); |
| 1797 | CMD(deauth, DEAUTHENTICATE); |
| 1798 | CMD(disassoc, DISASSOCIATE); |
| 1799 | CMD(join_ibss, JOIN_IBSS); |
| 1800 | CMD(join_mesh, JOIN_MESH); |
| 1801 | CMD(set_pmksa, SET_PMKSA); |
| 1802 | CMD(del_pmksa, DEL_PMKSA); |
| 1803 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1804 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1805 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1806 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1807 | CMD(mgmt_tx, FRAME); |
| 1808 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1809 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1810 | i++; |
| 1811 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1812 | goto nla_put_failure; |
| 1813 | } |
| 1814 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1815 | rdev->ops->join_mesh) { |
| 1816 | i++; |
| 1817 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1818 | goto nla_put_failure; |
| 1819 | } |
| 1820 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1821 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1822 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1823 | CMD(tdls_oper, TDLS_OPER); |
| 1824 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1825 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1826 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1827 | CMD(probe_client, PROBE_CLIENT); |
| 1828 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1829 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1830 | i++; |
| 1831 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1832 | goto nla_put_failure; |
| 1833 | } |
| 1834 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1835 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1836 | #ifdef CONFIG_NL80211_TESTMODE |
| 1837 | CMD(testmode_cmd, TESTMODE); |
| 1838 | #endif |
| 1839 | |
| 1840 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1841 | i++; |
| 1842 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1843 | goto nla_put_failure; |
| 1844 | } |
| 1845 | |
| 1846 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1847 | i++; |
| 1848 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1849 | goto nla_put_failure; |
| 1850 | } |
| 1851 | |
| 1852 | return i; |
| 1853 | nla_put_failure: |
| 1854 | return -ENOBUFS; |
| 1855 | } |
| 1856 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1857 | static int |
| 1858 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 1859 | struct sk_buff *msg) |
| 1860 | { |
| 1861 | struct nlattr *ftm; |
| 1862 | |
| 1863 | if (!cap->ftm.supported) |
| 1864 | return 0; |
| 1865 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1866 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1867 | if (!ftm) |
| 1868 | return -ENOBUFS; |
| 1869 | |
| 1870 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 1871 | return -ENOBUFS; |
| 1872 | if (cap->ftm.non_asap && |
| 1873 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 1874 | return -ENOBUFS; |
| 1875 | if (cap->ftm.request_lci && |
| 1876 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 1877 | return -ENOBUFS; |
| 1878 | if (cap->ftm.request_civicloc && |
| 1879 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 1880 | return -ENOBUFS; |
| 1881 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 1882 | cap->ftm.preambles)) |
| 1883 | return -ENOBUFS; |
| 1884 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 1885 | cap->ftm.bandwidths)) |
| 1886 | return -ENOBUFS; |
| 1887 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 1888 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 1889 | cap->ftm.max_bursts_exponent)) |
| 1890 | return -ENOBUFS; |
| 1891 | if (cap->ftm.max_ftms_per_burst && |
| 1892 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 1893 | cap->ftm.max_ftms_per_burst)) |
| 1894 | return -ENOBUFS; |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 1895 | if (cap->ftm.trigger_based && |
| 1896 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) |
| 1897 | return -ENOBUFS; |
| 1898 | if (cap->ftm.non_trigger_based && |
| 1899 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) |
| 1900 | return -ENOBUFS; |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1901 | |
| 1902 | nla_nest_end(msg, ftm); |
| 1903 | return 0; |
| 1904 | } |
| 1905 | |
| 1906 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 1907 | struct sk_buff *msg) |
| 1908 | { |
| 1909 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 1910 | struct nlattr *pmsr, *caps; |
| 1911 | |
| 1912 | if (!cap) |
| 1913 | return 0; |
| 1914 | |
| 1915 | /* |
| 1916 | * we don't need to clean up anything here since the caller |
| 1917 | * will genlmsg_cancel() if we fail |
| 1918 | */ |
| 1919 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1920 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1921 | if (!pmsr) |
| 1922 | return -ENOBUFS; |
| 1923 | |
| 1924 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 1925 | return -ENOBUFS; |
| 1926 | |
| 1927 | if (cap->report_ap_tsf && |
| 1928 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 1929 | return -ENOBUFS; |
| 1930 | |
| 1931 | if (cap->randomize_mac_addr && |
| 1932 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 1933 | return -ENOBUFS; |
| 1934 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1935 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1936 | if (!caps) |
| 1937 | return -ENOBUFS; |
| 1938 | |
| 1939 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 1940 | return -ENOBUFS; |
| 1941 | |
| 1942 | nla_nest_end(msg, caps); |
| 1943 | nla_nest_end(msg, pmsr); |
| 1944 | |
| 1945 | return 0; |
| 1946 | } |
| 1947 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 1948 | static int |
| 1949 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, |
| 1950 | struct sk_buff *msg) |
| 1951 | { |
| 1952 | int i; |
| 1953 | struct nlattr *nested, *nested_akms; |
| 1954 | const struct wiphy_iftype_akm_suites *iftype_akms; |
| 1955 | |
| 1956 | if (!rdev->wiphy.num_iftype_akm_suites || |
| 1957 | !rdev->wiphy.iftype_akm_suites) |
| 1958 | return 0; |
| 1959 | |
| 1960 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); |
| 1961 | if (!nested) |
| 1962 | return -ENOBUFS; |
| 1963 | |
| 1964 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { |
| 1965 | nested_akms = nla_nest_start(msg, i + 1); |
| 1966 | if (!nested_akms) |
| 1967 | return -ENOBUFS; |
| 1968 | |
| 1969 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; |
| 1970 | |
| 1971 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, |
| 1972 | iftype_akms->iftypes_mask)) |
| 1973 | return -ENOBUFS; |
| 1974 | |
| 1975 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, |
| 1976 | sizeof(u32) * iftype_akms->n_akm_suites, |
| 1977 | iftype_akms->akm_suites)) { |
| 1978 | return -ENOBUFS; |
| 1979 | } |
| 1980 | nla_nest_end(msg, nested_akms); |
| 1981 | } |
| 1982 | |
| 1983 | nla_nest_end(msg, nested); |
| 1984 | |
| 1985 | return 0; |
| 1986 | } |
| 1987 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 1988 | static int |
| 1989 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, |
| 1990 | struct sk_buff *msg) |
| 1991 | { |
| 1992 | struct nlattr *supp; |
| 1993 | |
| 1994 | if (!rdev->wiphy.tid_config_support.vif && |
| 1995 | !rdev->wiphy.tid_config_support.peer) |
| 1996 | return 0; |
| 1997 | |
| 1998 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); |
| 1999 | if (!supp) |
| 2000 | return -ENOSPC; |
| 2001 | |
| 2002 | if (rdev->wiphy.tid_config_support.vif && |
| 2003 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, |
| 2004 | rdev->wiphy.tid_config_support.vif, |
| 2005 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2006 | goto fail; |
| 2007 | |
| 2008 | if (rdev->wiphy.tid_config_support.peer && |
| 2009 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, |
| 2010 | rdev->wiphy.tid_config_support.peer, |
| 2011 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2012 | goto fail; |
| 2013 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 2014 | /* for now we just use the same value ... makes more sense */ |
| 2015 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, |
| 2016 | rdev->wiphy.tid_config_support.max_retry)) |
| 2017 | goto fail; |
| 2018 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, |
| 2019 | rdev->wiphy.tid_config_support.max_retry)) |
| 2020 | goto fail; |
| 2021 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2022 | nla_nest_end(msg, supp); |
| 2023 | |
| 2024 | return 0; |
| 2025 | fail: |
| 2026 | nla_nest_cancel(msg, supp); |
| 2027 | return -ENOBUFS; |
| 2028 | } |
| 2029 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2030 | struct nl80211_dump_wiphy_state { |
| 2031 | s64 filter_wiphy; |
| 2032 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2033 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2034 | bool split; |
| 2035 | }; |
| 2036 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2037 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2038 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2039 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2040 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2041 | { |
| 2042 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2043 | struct nlattr *nl_bands, *nl_band; |
| 2044 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2045 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2046 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2047 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2048 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2049 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2050 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2051 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2052 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2053 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2054 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2055 | return -ENOBUFS; |
| 2056 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2057 | if (WARN_ON(!state)) |
| 2058 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2059 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2060 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2061 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2062 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2063 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2064 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2065 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2066 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2067 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 2068 | goto finish; |
| 2069 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2070 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2071 | case 0: |
| 2072 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2073 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2074 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2075 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2076 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2077 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2078 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2079 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2080 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2081 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2082 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2083 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2084 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2085 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2086 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2087 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2088 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2089 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2090 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 2091 | rdev->wiphy.max_match_sets) || |
| 2092 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 2093 | rdev->wiphy.max_sched_scan_plans) || |
| 2094 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 2095 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 2096 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 2097 | rdev->wiphy.max_sched_scan_plan_iterations)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2098 | goto nla_put_failure; |
| 2099 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2100 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2101 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 2102 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2103 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2104 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 2105 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2106 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2107 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 2108 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2109 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2110 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 2111 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2112 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2113 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 2114 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2115 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2116 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2117 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2118 | state->split_start++; |
| 2119 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2120 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2121 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2122 | case 1: |
| 2123 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2124 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 2125 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 2126 | goto nla_put_failure; |
| 2127 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2128 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2129 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2130 | goto nla_put_failure; |
| 2131 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2132 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2133 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 2134 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2135 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2136 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2137 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2138 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2139 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2140 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2141 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2142 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2143 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2144 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2145 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 2146 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2147 | if ((rdev->wiphy.available_antennas_tx || |
| 2148 | rdev->wiphy.available_antennas_rx) && |
| 2149 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2150 | u32 tx_ant = 0, rx_ant = 0; |
| 2151 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2152 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2153 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2154 | if (!res) { |
| 2155 | if (nla_put_u32(msg, |
| 2156 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 2157 | tx_ant) || |
| 2158 | nla_put_u32(msg, |
| 2159 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 2160 | rx_ant)) |
| 2161 | goto nla_put_failure; |
| 2162 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2163 | } |
| 2164 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2165 | state->split_start++; |
| 2166 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2167 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2168 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2169 | case 2: |
| 2170 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2171 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2172 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2173 | state->split_start++; |
| 2174 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2175 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2176 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2177 | case 3: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2178 | nl_bands = nla_nest_start_noflag(msg, |
| 2179 | NL80211_ATTR_WIPHY_BANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2180 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2181 | goto nla_put_failure; |
| 2182 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2183 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2184 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2185 | struct ieee80211_supported_band *sband; |
| 2186 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2187 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2188 | |
| 2189 | if (!sband) |
| 2190 | continue; |
| 2191 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2192 | nl_band = nla_nest_start_noflag(msg, band); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2193 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2194 | goto nla_put_failure; |
| 2195 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2196 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2197 | case 0: |
| 2198 | if (nl80211_send_band_rateinfo(msg, sband)) |
| 2199 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2200 | state->chan_start++; |
| 2201 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2202 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2203 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2204 | default: |
| 2205 | /* add frequencies */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2206 | nl_freqs = nla_nest_start_noflag(msg, |
| 2207 | NL80211_BAND_ATTR_FREQS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2208 | if (!nl_freqs) |
| 2209 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2210 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2211 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2212 | i < sband->n_channels; |
| 2213 | i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2214 | nl_freq = nla_nest_start_noflag(msg, |
| 2215 | i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2216 | if (!nl_freq) |
| 2217 | goto nla_put_failure; |
| 2218 | |
| 2219 | chan = &sband->channels[i]; |
| 2220 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2221 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 2222 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2223 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2224 | goto nla_put_failure; |
| 2225 | |
| 2226 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2227 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2228 | break; |
| 2229 | } |
| 2230 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2231 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2232 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2233 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2234 | nla_nest_end(msg, nl_freqs); |
| 2235 | } |
| 2236 | |
| 2237 | nla_nest_end(msg, nl_band); |
| 2238 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2239 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2240 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2241 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2242 | band--; |
| 2243 | break; |
| 2244 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2245 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2246 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2247 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2248 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2249 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2250 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2251 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2252 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2253 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2254 | if (state->band_start == 0 && state->chan_start == 0) |
| 2255 | state->split_start++; |
| 2256 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2257 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2258 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2259 | case 4: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2260 | nl_cmds = nla_nest_start_noflag(msg, |
| 2261 | NL80211_ATTR_SUPPORTED_COMMANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2262 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2263 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2264 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 2265 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 2266 | if (i < 0) |
| 2267 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2268 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2269 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2270 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2271 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 2272 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 2273 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 2274 | if (rdev->wiphy.features & |
| 2275 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 2276 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 2277 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 2278 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Matthew Wang | 7010998 | 2019-08-22 10:48:06 -0700 | [diff] [blame] | 2279 | CMD(update_ft_ies, UPDATE_FT_IES); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2280 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2281 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2282 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2283 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2284 | state->split_start++; |
| 2285 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2286 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2287 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2288 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2289 | if (rdev->ops->remain_on_channel && |
| 2290 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2291 | nla_put_u32(msg, |
| 2292 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2293 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2294 | goto nla_put_failure; |
| 2295 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2296 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2297 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2298 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2299 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2300 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2301 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2302 | state->split_start++; |
| 2303 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2304 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2305 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2306 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 2307 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2308 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2309 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2310 | state->split_start++; |
| 2311 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2312 | break; |
| 2313 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2314 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2315 | #endif |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2316 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2317 | case 7: |
| 2318 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2319 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2320 | goto nla_put_failure; |
| 2321 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2322 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2323 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2324 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2325 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2326 | state->split_start++; |
| 2327 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2328 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2329 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2330 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2331 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2332 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2333 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2334 | goto nla_put_failure; |
| 2335 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2336 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2337 | /* |
| 2338 | * We can only add the per-channel limit information if the |
| 2339 | * dump is split, otherwise it makes it too big. Therefore |
| 2340 | * only advertise it in that case. |
| 2341 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2342 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2343 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2344 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2345 | goto nla_put_failure; |
| 2346 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2347 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2348 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2349 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2350 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2351 | goto nla_put_failure; |
| 2352 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2353 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2354 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2355 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2356 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2357 | goto nla_put_failure; |
| 2358 | |
| 2359 | /* |
| 2360 | * Any information below this point is only available to |
| 2361 | * applications that can deal with it being split. This |
| 2362 | * helps ensure that newly added capabilities don't break |
| 2363 | * older tools by overrunning their buffers. |
| 2364 | * |
| 2365 | * We still increment split_start so that in the split |
| 2366 | * case we'll continue with more data in the next round, |
| 2367 | * but break unconditionally so unsplit data stops here. |
| 2368 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2369 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2370 | break; |
| 2371 | case 9: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2372 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2373 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2374 | rdev->wiphy.extended_capabilities_len, |
| 2375 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2376 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2377 | rdev->wiphy.extended_capabilities_len, |
| 2378 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2379 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2380 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2381 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2382 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2383 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2384 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2385 | goto nla_put_failure; |
| 2386 | |
Denis Kenzior | ae6fa4d | 2019-07-22 06:33:12 -0500 | [diff] [blame] | 2387 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 2388 | rdev->wiphy.perm_addr)) |
| 2389 | goto nla_put_failure; |
| 2390 | |
| 2391 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && |
| 2392 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, |
| 2393 | rdev->wiphy.addr_mask)) |
| 2394 | goto nla_put_failure; |
| 2395 | |
| 2396 | if (rdev->wiphy.n_addresses > 1) { |
| 2397 | void *attr; |
| 2398 | |
| 2399 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 2400 | if (!attr) |
| 2401 | goto nla_put_failure; |
| 2402 | |
| 2403 | for (i = 0; i < rdev->wiphy.n_addresses; i++) |
| 2404 | if (nla_put(msg, i + 1, ETH_ALEN, |
| 2405 | rdev->wiphy.addresses[i].addr)) |
| 2406 | goto nla_put_failure; |
| 2407 | |
| 2408 | nla_nest_end(msg, attr); |
| 2409 | } |
| 2410 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2411 | state->split_start++; |
| 2412 | break; |
| 2413 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2414 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2415 | goto nla_put_failure; |
| 2416 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2417 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2418 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2419 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2420 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2421 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2422 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2423 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2424 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2425 | goto nla_put_failure; |
| 2426 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2427 | state->split_start++; |
| 2428 | break; |
| 2429 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2430 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2431 | const struct nl80211_vendor_cmd_info *info; |
| 2432 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2433 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2434 | nested = nla_nest_start_noflag(msg, |
| 2435 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2436 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2437 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2438 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2439 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2440 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2441 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2442 | goto nla_put_failure; |
| 2443 | } |
| 2444 | nla_nest_end(msg, nested); |
| 2445 | } |
| 2446 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2447 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2448 | const struct nl80211_vendor_cmd_info *info; |
| 2449 | struct nlattr *nested; |
| 2450 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2451 | nested = nla_nest_start_noflag(msg, |
| 2452 | NL80211_ATTR_VENDOR_EVENTS); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2453 | if (!nested) |
| 2454 | goto nla_put_failure; |
| 2455 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2456 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2457 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2458 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2459 | goto nla_put_failure; |
| 2460 | } |
| 2461 | nla_nest_end(msg, nested); |
| 2462 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 2463 | state->split_start++; |
| 2464 | break; |
| 2465 | case 12: |
| 2466 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2467 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2468 | rdev->wiphy.max_num_csa_counters)) |
| 2469 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2470 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 2471 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2472 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2473 | goto nla_put_failure; |
| 2474 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 2475 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2476 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2477 | rdev->wiphy.max_sched_scan_reqs)) |
| 2478 | goto nla_put_failure; |
| 2479 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2480 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2481 | sizeof(rdev->wiphy.ext_features), |
| 2482 | rdev->wiphy.ext_features)) |
| 2483 | goto nla_put_failure; |
| 2484 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2485 | if (rdev->wiphy.bss_select_support) { |
| 2486 | struct nlattr *nested; |
| 2487 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2488 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2489 | nested = nla_nest_start_noflag(msg, |
| 2490 | NL80211_ATTR_BSS_SELECT); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2491 | if (!nested) |
| 2492 | goto nla_put_failure; |
| 2493 | |
| 2494 | i = 0; |
| 2495 | while (bss_select_support) { |
| 2496 | if ((bss_select_support & 1) && |
| 2497 | nla_put_flag(msg, i)) |
| 2498 | goto nla_put_failure; |
| 2499 | i++; |
| 2500 | bss_select_support >>= 1; |
| 2501 | } |
| 2502 | nla_nest_end(msg, nested); |
| 2503 | } |
| 2504 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2505 | state->split_start++; |
| 2506 | break; |
| 2507 | case 13: |
| 2508 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2509 | rdev->wiphy.iftype_ext_capab) { |
| 2510 | struct nlattr *nested_ext_capab, *nested; |
| 2511 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2512 | nested = nla_nest_start_noflag(msg, |
| 2513 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2514 | if (!nested) |
| 2515 | goto nla_put_failure; |
| 2516 | |
| 2517 | for (i = state->capa_start; |
| 2518 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2519 | const struct wiphy_iftype_ext_capab *capab; |
| 2520 | |
| 2521 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2522 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2523 | nested_ext_capab = nla_nest_start_noflag(msg, |
| 2524 | i); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2525 | if (!nested_ext_capab || |
| 2526 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2527 | capab->iftype) || |
| 2528 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2529 | capab->extended_capabilities_len, |
| 2530 | capab->extended_capabilities) || |
| 2531 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2532 | capab->extended_capabilities_len, |
| 2533 | capab->extended_capabilities_mask)) |
| 2534 | goto nla_put_failure; |
| 2535 | |
| 2536 | nla_nest_end(msg, nested_ext_capab); |
| 2537 | if (state->split) |
| 2538 | break; |
| 2539 | } |
| 2540 | nla_nest_end(msg, nested); |
| 2541 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2542 | state->capa_start = i + 1; |
| 2543 | break; |
| 2544 | } |
| 2545 | } |
| 2546 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2547 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2548 | rdev->wiphy.nan_supported_bands)) |
| 2549 | goto nla_put_failure; |
| 2550 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2551 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2552 | NL80211_EXT_FEATURE_TXQS)) { |
| 2553 | struct cfg80211_txq_stats txqstats = {}; |
| 2554 | int res; |
| 2555 | |
| 2556 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2557 | if (!res && |
| 2558 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2559 | NL80211_ATTR_TXQ_STATS)) |
| 2560 | goto nla_put_failure; |
| 2561 | |
| 2562 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2563 | rdev->wiphy.txq_limit)) |
| 2564 | goto nla_put_failure; |
| 2565 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2566 | rdev->wiphy.txq_memory_limit)) |
| 2567 | goto nla_put_failure; |
| 2568 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2569 | rdev->wiphy.txq_quantum)) |
| 2570 | goto nla_put_failure; |
| 2571 | } |
| 2572 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2573 | state->split_start++; |
| 2574 | break; |
| 2575 | case 14: |
| 2576 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2577 | goto nla_put_failure; |
| 2578 | |
Veerendranath Jakkam | ab4dfa2 | 2018-12-19 22:52:25 +0530 | [diff] [blame] | 2579 | state->split_start++; |
| 2580 | break; |
| 2581 | case 15: |
| 2582 | if (rdev->wiphy.akm_suites && |
| 2583 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2584 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2585 | rdev->wiphy.akm_suites)) |
| 2586 | goto nla_put_failure; |
| 2587 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2588 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
| 2589 | goto nla_put_failure; |
| 2590 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2591 | if (nl80211_put_tid_config_support(rdev, msg)) |
| 2592 | goto nla_put_failure; |
| 2593 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2594 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2595 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2596 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2597 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2598 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2599 | genlmsg_end(msg, hdr); |
| 2600 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2601 | |
| 2602 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2603 | genlmsg_cancel(msg, hdr); |
| 2604 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2605 | } |
| 2606 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2607 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2608 | struct netlink_callback *cb, |
| 2609 | struct nl80211_dump_wiphy_state *state) |
| 2610 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2611 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 2612 | int ret; |
| 2613 | |
| 2614 | if (!tb) |
| 2615 | return -ENOMEM; |
| 2616 | |
| 2617 | ret = nlmsg_parse_deprecated(cb->nlh, |
| 2618 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2619 | tb, nl80211_fam.maxattr, |
| 2620 | nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2621 | /* ignore parse errors for backward compatibility */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2622 | if (ret) { |
| 2623 | ret = 0; |
| 2624 | goto out; |
| 2625 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2626 | |
| 2627 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2628 | if (tb[NL80211_ATTR_WIPHY]) |
| 2629 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2630 | if (tb[NL80211_ATTR_WDEV]) |
| 2631 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2632 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2633 | struct net_device *netdev; |
| 2634 | struct cfg80211_registered_device *rdev; |
| 2635 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2636 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2637 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2638 | if (!netdev) { |
| 2639 | ret = -ENODEV; |
| 2640 | goto out; |
| 2641 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2642 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2643 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2644 | netdev->ieee80211_ptr->wiphy); |
| 2645 | state->filter_wiphy = rdev->wiphy_idx; |
| 2646 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2647 | } |
| 2648 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2649 | ret = 0; |
| 2650 | out: |
| 2651 | kfree(tb); |
| 2652 | return ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2653 | } |
| 2654 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2655 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2656 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2657 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2658 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2659 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2660 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2661 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2662 | if (!state) { |
| 2663 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2664 | if (!state) { |
| 2665 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2666 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2667 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2668 | state->filter_wiphy = -1; |
| 2669 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2670 | if (ret) { |
| 2671 | kfree(state); |
| 2672 | rtnl_unlock(); |
| 2673 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2674 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2675 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2676 | } |
| 2677 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2678 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2679 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2680 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2681 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2682 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2683 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2684 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2685 | continue; |
| 2686 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2687 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2688 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2689 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2690 | NETLINK_CB(cb->skb).portid, |
| 2691 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2692 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2693 | if (ret < 0) { |
| 2694 | /* |
| 2695 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2696 | * or EMSGSIZE returned), this SKB is still |
| 2697 | * empty (so it's not too big because another |
| 2698 | * wiphy dataset is already in the skb) and |
| 2699 | * we've not tried to adjust the dump allocation |
| 2700 | * yet ... then adjust the alloc size to be |
| 2701 | * bigger, and return 1 but with the empty skb. |
| 2702 | * This results in an empty message being RX'ed |
| 2703 | * in userspace, but that is ignored. |
| 2704 | * |
| 2705 | * We can then retry with the larger buffer. |
| 2706 | */ |
| 2707 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2708 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2709 | cb->min_dump_alloc < 4096) { |
| 2710 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2711 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2712 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2713 | return 1; |
| 2714 | } |
| 2715 | idx--; |
| 2716 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2717 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2718 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2719 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2720 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2721 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2722 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2723 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2724 | |
| 2725 | return skb->len; |
| 2726 | } |
| 2727 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2728 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2729 | { |
| 2730 | kfree((void *)cb->args[0]); |
| 2731 | return 0; |
| 2732 | } |
| 2733 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2734 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2735 | { |
| 2736 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2738 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2739 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2740 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2741 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2742 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2743 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2744 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2745 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2746 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2747 | nlmsg_free(msg); |
| 2748 | return -ENOBUFS; |
| 2749 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2750 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2751 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2752 | } |
| 2753 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2754 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2755 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2756 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2757 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2758 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2759 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2760 | }; |
| 2761 | |
| 2762 | static int parse_txq_params(struct nlattr *tb[], |
| 2763 | struct ieee80211_txq_params *txq_params) |
| 2764 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2765 | u8 ac; |
| 2766 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2767 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2768 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2769 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2770 | return -EINVAL; |
| 2771 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2772 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2773 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2774 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2775 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2776 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2777 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2778 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2779 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2780 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2781 | return 0; |
| 2782 | } |
| 2783 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2784 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2785 | { |
| 2786 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2787 | * You can only set the channel explicitly for WDS interfaces, |
| 2788 | * all others have their channel managed via their respective |
| 2789 | * "establish a connection" command (connect, join, ...) |
| 2790 | * |
| 2791 | * For AP/GO and mesh mode, the channel can be set with the |
| 2792 | * channel userspace API, but is only stored and passed to the |
| 2793 | * low-level driver when the AP starts or the mesh is joined. |
| 2794 | * This is for backward compatibility, userspace can also give |
| 2795 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2796 | * |
| 2797 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2798 | * whatever else is going on, so they have their own special |
| 2799 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2800 | */ |
| 2801 | return !wdev || |
| 2802 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2803 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2804 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2805 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2806 | } |
| 2807 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2808 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2809 | struct genl_info *info, |
| 2810 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2811 | { |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2812 | struct netlink_ext_ack *extack = info->extack; |
| 2813 | struct nlattr **attrs = info->attrs; |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2814 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2815 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2816 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2817 | return -EINVAL; |
| 2818 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2819 | control_freq = MHZ_TO_KHZ( |
| 2820 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2821 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 2822 | control_freq += |
| 2823 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2824 | |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 2825 | memset(chandef, 0, sizeof(*chandef)); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2826 | chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2827 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2828 | chandef->center_freq1 = KHZ_TO_MHZ(control_freq); |
| 2829 | chandef->freq1_offset = control_freq % 1000; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2830 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2831 | |
| 2832 | /* Primary channel not allowed */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2833 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 2834 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 2835 | "Channel is disabled"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2836 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2837 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2838 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2839 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2840 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2841 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2842 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2843 | |
| 2844 | switch (chantype) { |
| 2845 | case NL80211_CHAN_NO_HT: |
| 2846 | case NL80211_CHAN_HT20: |
| 2847 | case NL80211_CHAN_HT40PLUS: |
| 2848 | case NL80211_CHAN_HT40MINUS: |
| 2849 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2850 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2851 | /* user input for center_freq is incorrect */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2852 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2853 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 2854 | NL_SET_ERR_MSG_ATTR(extack, |
| 2855 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 2856 | "bad center frequency 1"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2857 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2858 | } |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2859 | /* center_freq2 must be zero */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2860 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2861 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 2862 | NL_SET_ERR_MSG_ATTR(extack, |
| 2863 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 2864 | "center frequency 2 can't be used"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2865 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2866 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2867 | break; |
| 2868 | default: |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2869 | NL_SET_ERR_MSG_ATTR(extack, |
| 2870 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2871 | "invalid channel type"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2872 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2873 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2874 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2875 | chandef->width = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2876 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2877 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2878 | chandef->center_freq1 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2879 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2880 | if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) |
| 2881 | chandef->freq1_offset = nla_get_u32( |
| 2882 | attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); |
| 2883 | else |
| 2884 | chandef->freq1_offset = 0; |
| 2885 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2886 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2887 | chandef->center_freq2 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2888 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2889 | } |
| 2890 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 2891 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 2892 | chandef->edmg.channels = |
| 2893 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 2894 | |
| 2895 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 2896 | chandef->edmg.bw_config = |
| 2897 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 2898 | } else { |
| 2899 | chandef->edmg.bw_config = 0; |
| 2900 | chandef->edmg.channels = 0; |
| 2901 | } |
| 2902 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2903 | if (!cfg80211_chandef_valid(chandef)) { |
| 2904 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2905 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2906 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2907 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2908 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2909 | IEEE80211_CHAN_DISABLED)) { |
| 2910 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2911 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2912 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2913 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2914 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2915 | chandef->width == NL80211_CHAN_WIDTH_10) && |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2916 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 2917 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2918 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2919 | } |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2920 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2921 | return 0; |
| 2922 | } |
| 2923 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2924 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2925 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2926 | struct genl_info *info) |
| 2927 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2928 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2929 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2930 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2931 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2932 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2933 | if (dev) |
| 2934 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2935 | if (!nl80211_can_set_dev_channel(wdev)) |
| 2936 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2937 | if (wdev) |
| 2938 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2939 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2940 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 2941 | if (result) |
| 2942 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2943 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2944 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2945 | case NL80211_IFTYPE_AP: |
| 2946 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 2947 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 2948 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2949 | result = -EINVAL; |
| 2950 | break; |
| 2951 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2952 | if (wdev->beacon_interval) { |
| 2953 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 2954 | !(rdev->wiphy.features & |
| 2955 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 2956 | result = -EBUSY; |
| 2957 | break; |
| 2958 | } |
| 2959 | |
| 2960 | /* Only allow dynamic channel width changes */ |
| 2961 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 2962 | result = -EBUSY; |
| 2963 | break; |
| 2964 | } |
| 2965 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 2966 | if (result) |
| 2967 | break; |
| 2968 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2969 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2970 | result = 0; |
| 2971 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2972 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2973 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2974 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2975 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2976 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2977 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 2978 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2979 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2980 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2981 | |
| 2982 | return result; |
| 2983 | } |
| 2984 | |
| 2985 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 2986 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2987 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2988 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2989 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 2990 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2991 | } |
| 2992 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2993 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 2994 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 2995 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 2996 | struct net_device *dev = info->user_ptr[1]; |
| 2997 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2998 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 2999 | |
| 3000 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3001 | return -EINVAL; |
| 3002 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3003 | if (netif_running(dev)) |
| 3004 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3005 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3006 | if (!rdev->ops->set_wds_peer) |
| 3007 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3008 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3009 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 3010 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3011 | |
| 3012 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3013 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3014 | } |
| 3015 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3016 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 3017 | { |
| 3018 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3019 | struct net_device *netdev = NULL; |
| 3020 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 3021 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3022 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3023 | u32 changed; |
| 3024 | u8 retry_short = 0, retry_long = 0; |
| 3025 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3026 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3027 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3028 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3029 | ASSERT_RTNL(); |
| 3030 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3031 | /* |
| 3032 | * Try to find the wiphy and netdev. Normally this |
| 3033 | * function shouldn't need the netdev, but this is |
| 3034 | * done for backward compatibility -- previously |
| 3035 | * setting the channel was done per wiphy, but now |
| 3036 | * it is per netdev. Previous userland like hostapd |
| 3037 | * also passed a netdev to set_wiphy, so that it is |
| 3038 | * possible to let that go to the right netdev! |
| 3039 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3040 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3041 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 3042 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 3043 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3044 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3045 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 3046 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3047 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3048 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3049 | } |
| 3050 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3051 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 3052 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 3053 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3054 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3055 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3056 | wdev = NULL; |
| 3057 | netdev = NULL; |
| 3058 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 3059 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3060 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3061 | |
| 3062 | /* |
| 3063 | * end workaround code, by now the rdev is available |
| 3064 | * and locked, and wdev may or may not be NULL. |
| 3065 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3066 | |
| 3067 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3068 | result = cfg80211_dev_rename( |
| 3069 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3070 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3071 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3072 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3073 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3074 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 3075 | struct ieee80211_txq_params txq_params; |
| 3076 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 3077 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3078 | if (!rdev->ops->set_txq_params) |
| 3079 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3080 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3081 | if (!netdev) |
| 3082 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 3083 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3084 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3085 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3086 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3087 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3088 | if (!netif_running(netdev)) |
| 3089 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 3090 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3091 | nla_for_each_nested(nl_txq_params, |
| 3092 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 3093 | rem_txq_params) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3094 | result = nla_parse_nested_deprecated(tb, |
| 3095 | NL80211_TXQ_ATTR_MAX, |
| 3096 | nl_txq_params, |
| 3097 | txq_params_policy, |
| 3098 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 3099 | if (result) |
| 3100 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3101 | result = parse_txq_params(tb, &txq_params); |
| 3102 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3103 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3104 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3105 | result = rdev_set_txq_params(rdev, netdev, |
| 3106 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3107 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3108 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3112 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3113 | result = __nl80211_set_channel( |
| 3114 | rdev, |
| 3115 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 3116 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3117 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3118 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3119 | } |
| 3120 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3121 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3122 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3123 | enum nl80211_tx_power_setting type; |
| 3124 | int idx, mbm = 0; |
| 3125 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3126 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 3127 | txp_wdev = NULL; |
| 3128 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3129 | if (!rdev->ops->set_tx_power) |
| 3130 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3131 | |
| 3132 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 3133 | type = nla_get_u32(info->attrs[idx]); |
| 3134 | |
| 3135 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3136 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 3137 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3138 | |
| 3139 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 3140 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 3141 | mbm = nla_get_u32(info->attrs[idx]); |
| 3142 | } |
| 3143 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3144 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3145 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3146 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3147 | } |
| 3148 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3149 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 3150 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 3151 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3152 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3153 | if ((!rdev->wiphy.available_antennas_tx && |
| 3154 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3155 | !rdev->ops->set_antenna) |
| 3156 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3157 | |
| 3158 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 3159 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 3160 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3161 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3162 | * available antenna masks, except for the "all" mask */ |
| 3163 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3164 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 3165 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3166 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3167 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 3168 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3169 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3170 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3171 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3172 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3173 | } |
| 3174 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3175 | changed = 0; |
| 3176 | |
| 3177 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 3178 | retry_short = nla_get_u8( |
| 3179 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3180 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3181 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 3182 | } |
| 3183 | |
| 3184 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 3185 | retry_long = nla_get_u8( |
| 3186 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3187 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3188 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 3189 | } |
| 3190 | |
| 3191 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 3192 | frag_threshold = nla_get_u32( |
| 3193 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3194 | if (frag_threshold < 256) |
| 3195 | return -EINVAL; |
| 3196 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3197 | if (frag_threshold != (u32) -1) { |
| 3198 | /* |
| 3199 | * Fragments (apart from the last one) are required to |
| 3200 | * have even length. Make the fragmentation code |
| 3201 | * simpler by stripping LSB should someone try to use |
| 3202 | * odd threshold value. |
| 3203 | */ |
| 3204 | frag_threshold &= ~0x1; |
| 3205 | } |
| 3206 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 3207 | } |
| 3208 | |
| 3209 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 3210 | rts_threshold = nla_get_u32( |
| 3211 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 3212 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 3213 | } |
| 3214 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3215 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3216 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 3217 | return -EINVAL; |
| 3218 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3219 | coverage_class = nla_get_u8( |
| 3220 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 3221 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 3222 | } |
| 3223 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3224 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 3225 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 3226 | return -EOPNOTSUPP; |
| 3227 | |
| 3228 | changed |= WIPHY_PARAM_DYN_ACK; |
| 3229 | } |
| 3230 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3231 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 3232 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3233 | NL80211_EXT_FEATURE_TXQS)) |
| 3234 | return -EOPNOTSUPP; |
| 3235 | txq_limit = nla_get_u32( |
| 3236 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 3237 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 3238 | } |
| 3239 | |
| 3240 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 3241 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3242 | NL80211_EXT_FEATURE_TXQS)) |
| 3243 | return -EOPNOTSUPP; |
| 3244 | txq_memory_limit = nla_get_u32( |
| 3245 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 3246 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 3247 | } |
| 3248 | |
| 3249 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 3250 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3251 | NL80211_EXT_FEATURE_TXQS)) |
| 3252 | return -EOPNOTSUPP; |
| 3253 | txq_quantum = nla_get_u32( |
| 3254 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 3255 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 3256 | } |
| 3257 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3258 | if (changed) { |
| 3259 | u8 old_retry_short, old_retry_long; |
| 3260 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3261 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3262 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3263 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3264 | if (!rdev->ops->set_wiphy_params) |
| 3265 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3266 | |
| 3267 | old_retry_short = rdev->wiphy.retry_short; |
| 3268 | old_retry_long = rdev->wiphy.retry_long; |
| 3269 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 3270 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3271 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3272 | old_txq_limit = rdev->wiphy.txq_limit; |
| 3273 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 3274 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3275 | |
| 3276 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 3277 | rdev->wiphy.retry_short = retry_short; |
| 3278 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 3279 | rdev->wiphy.retry_long = retry_long; |
| 3280 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 3281 | rdev->wiphy.frag_threshold = frag_threshold; |
| 3282 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 3283 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3284 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 3285 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3286 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 3287 | rdev->wiphy.txq_limit = txq_limit; |
| 3288 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 3289 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 3290 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 3291 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3292 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3293 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3294 | if (result) { |
| 3295 | rdev->wiphy.retry_short = old_retry_short; |
| 3296 | rdev->wiphy.retry_long = old_retry_long; |
| 3297 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 3298 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3299 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3300 | rdev->wiphy.txq_limit = old_txq_limit; |
| 3301 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 3302 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 3303 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3304 | } |
| 3305 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3306 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3307 | } |
| 3308 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3309 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 3310 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3311 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 3312 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 3313 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3314 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3315 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 3316 | chandef->chan->center_freq)) |
| 3317 | return -ENOBUFS; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3318 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 3319 | chandef->chan->freq_offset)) |
| 3320 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3321 | switch (chandef->width) { |
| 3322 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3323 | case NL80211_CHAN_WIDTH_20: |
| 3324 | case NL80211_CHAN_WIDTH_40: |
| 3325 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3326 | cfg80211_get_chandef_type(chandef))) |
| 3327 | return -ENOBUFS; |
| 3328 | break; |
| 3329 | default: |
| 3330 | break; |
| 3331 | } |
| 3332 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 3333 | return -ENOBUFS; |
| 3334 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 3335 | return -ENOBUFS; |
| 3336 | if (chandef->center_freq2 && |
| 3337 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3338 | return -ENOBUFS; |
| 3339 | return 0; |
| 3340 | } |
| 3341 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3342 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 3343 | struct cfg80211_registered_device *rdev, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3344 | struct wireless_dev *wdev, |
| 3345 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3346 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3347 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3348 | void *hdr; |
| 3349 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3350 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3351 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3352 | cmd != NL80211_CMD_SET_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3353 | |
| 3354 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3355 | if (!hdr) |
| 3356 | return -1; |
| 3357 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3358 | if (dev && |
| 3359 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3360 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3361 | goto nla_put_failure; |
| 3362 | |
| 3363 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3364 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 3365 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3366 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3367 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3368 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3369 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 3370 | (cfg80211_rdev_list_generation << 2)) || |
| 3371 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3372 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3373 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3374 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3375 | int ret; |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 3376 | struct cfg80211_chan_def chandef = {}; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3377 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3378 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3379 | if (ret == 0) { |
| 3380 | if (nl80211_send_chandef(msg, &chandef)) |
| 3381 | goto nla_put_failure; |
| 3382 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 3383 | } |
| 3384 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 3385 | if (rdev->ops->get_tx_power) { |
| 3386 | int dbm, ret; |
| 3387 | |
| 3388 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3389 | if (ret == 0 && |
| 3390 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3391 | DBM_TO_MBM(dbm))) |
| 3392 | goto nla_put_failure; |
| 3393 | } |
| 3394 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3395 | wdev_lock(wdev); |
| 3396 | switch (wdev->iftype) { |
| 3397 | case NL80211_IFTYPE_AP: |
| 3398 | if (wdev->ssid_len && |
| 3399 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3400 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3401 | break; |
| 3402 | case NL80211_IFTYPE_STATION: |
| 3403 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3404 | case NL80211_IFTYPE_ADHOC: { |
| 3405 | const u8 *ssid_ie; |
| 3406 | if (!wdev->current_bss) |
| 3407 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3408 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3409 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3410 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3411 | if (ssid_ie && |
| 3412 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3413 | goto nla_put_failure_rcu_locked; |
| 3414 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3415 | break; |
| 3416 | } |
| 3417 | default: |
| 3418 | /* nothing */ |
| 3419 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3420 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3421 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3422 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3423 | if (rdev->ops->get_txq_stats) { |
| 3424 | struct cfg80211_txq_stats txqstats = {}; |
| 3425 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3426 | |
| 3427 | if (ret == 0 && |
| 3428 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3429 | NL80211_ATTR_TXQ_STATS)) |
| 3430 | goto nla_put_failure; |
| 3431 | } |
| 3432 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3433 | genlmsg_end(msg, hdr); |
| 3434 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3435 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3436 | nla_put_failure_rcu_locked: |
| 3437 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3438 | nla_put_failure_locked: |
| 3439 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3440 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3441 | genlmsg_cancel(msg, hdr); |
| 3442 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3446 | { |
| 3447 | int wp_idx = 0; |
| 3448 | int if_idx = 0; |
| 3449 | int wp_start = cb->args[0]; |
| 3450 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3451 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3452 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3453 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3454 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3455 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3456 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3457 | if (!cb->args[2]) { |
| 3458 | struct nl80211_dump_wiphy_state state = { |
| 3459 | .filter_wiphy = -1, |
| 3460 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3461 | |
| 3462 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3463 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3464 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3465 | |
| 3466 | filter_wiphy = state.filter_wiphy; |
| 3467 | |
| 3468 | /* |
| 3469 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3470 | * value needed to determine that parsing is necessary. |
| 3471 | */ |
| 3472 | if (filter_wiphy >= 0) |
| 3473 | cb->args[2] = filter_wiphy + 1; |
| 3474 | else |
| 3475 | cb->args[2] = -1; |
| 3476 | } else if (cb->args[2] > 0) { |
| 3477 | filter_wiphy = cb->args[2] - 1; |
| 3478 | } |
| 3479 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3480 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3481 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3482 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3483 | if (wp_idx < wp_start) { |
| 3484 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3485 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3486 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3487 | |
| 3488 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3489 | continue; |
| 3490 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3491 | if_idx = 0; |
| 3492 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3493 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3494 | if (if_idx < if_start) { |
| 3495 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3496 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3497 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3498 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3499 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3500 | rdev, wdev, |
| 3501 | NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3502 | goto out; |
| 3503 | } |
| 3504 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3505 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3506 | |
| 3507 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3508 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3509 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3510 | cb->args[0] = wp_idx; |
| 3511 | cb->args[1] = if_idx; |
| 3512 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3513 | ret = skb->len; |
| 3514 | out_unlock: |
| 3515 | rtnl_unlock(); |
| 3516 | |
| 3517 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3521 | { |
| 3522 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3524 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3525 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3526 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3527 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3528 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3529 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3530 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3531 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3532 | nlmsg_free(msg); |
| 3533 | return -ENOBUFS; |
| 3534 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3535 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3536 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3537 | } |
| 3538 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3539 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3540 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3541 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3542 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3543 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3544 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3545 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3546 | }; |
| 3547 | |
| 3548 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3549 | { |
| 3550 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3551 | int flag; |
| 3552 | |
| 3553 | *mntrflags = 0; |
| 3554 | |
| 3555 | if (!nla) |
| 3556 | return -EINVAL; |
| 3557 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3558 | if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL)) |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3559 | return -EINVAL; |
| 3560 | |
| 3561 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3562 | if (flags[flag]) |
| 3563 | *mntrflags |= (1<<flag); |
| 3564 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3565 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3566 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3567 | return 0; |
| 3568 | } |
| 3569 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3570 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3571 | enum nl80211_iftype type, |
| 3572 | struct genl_info *info, |
| 3573 | struct vif_params *params) |
| 3574 | { |
| 3575 | bool change = false; |
| 3576 | int err; |
| 3577 | |
| 3578 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3579 | if (type != NL80211_IFTYPE_MONITOR) |
| 3580 | return -EINVAL; |
| 3581 | |
| 3582 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3583 | ¶ms->flags); |
| 3584 | if (err) |
| 3585 | return err; |
| 3586 | |
| 3587 | change = true; |
| 3588 | } |
| 3589 | |
| 3590 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3591 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3592 | return -EOPNOTSUPP; |
| 3593 | |
| 3594 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3595 | const u8 *mumimo_groups; |
| 3596 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3597 | |
| 3598 | if (type != NL80211_IFTYPE_MONITOR) |
| 3599 | return -EINVAL; |
| 3600 | |
| 3601 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3602 | return -EOPNOTSUPP; |
| 3603 | |
| 3604 | mumimo_groups = |
| 3605 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3606 | |
| 3607 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3608 | if ((mumimo_groups[0] & BIT(0)) || |
| 3609 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3610 | return -EINVAL; |
| 3611 | |
| 3612 | params->vht_mumimo_groups = mumimo_groups; |
| 3613 | change = true; |
| 3614 | } |
| 3615 | |
| 3616 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3617 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3618 | |
| 3619 | if (type != NL80211_IFTYPE_MONITOR) |
| 3620 | return -EINVAL; |
| 3621 | |
| 3622 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3623 | return -EOPNOTSUPP; |
| 3624 | |
| 3625 | params->vht_mumimo_follow_addr = |
| 3626 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3627 | change = true; |
| 3628 | } |
| 3629 | |
| 3630 | return change ? 1 : 0; |
| 3631 | } |
| 3632 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3633 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3634 | struct net_device *netdev, u8 use_4addr, |
| 3635 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3636 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3637 | if (!use_4addr) { |
Julian Wiedmann | 2e92a2d | 2020-02-20 09:00:07 +0100 | [diff] [blame] | 3638 | if (netdev && netif_is_bridge_port(netdev)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3639 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3640 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3641 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3642 | |
| 3643 | switch (iftype) { |
| 3644 | case NL80211_IFTYPE_AP_VLAN: |
| 3645 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3646 | return 0; |
| 3647 | break; |
| 3648 | case NL80211_IFTYPE_STATION: |
| 3649 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3650 | return 0; |
| 3651 | break; |
| 3652 | default: |
| 3653 | break; |
| 3654 | } |
| 3655 | |
| 3656 | return -EOPNOTSUPP; |
| 3657 | } |
| 3658 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3659 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3660 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3661 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3662 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3663 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3664 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3665 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3666 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3667 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3668 | memset(¶ms, 0, sizeof(params)); |
| 3669 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3670 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3671 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3672 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3673 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3674 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3675 | change = true; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3676 | } |
| 3677 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3678 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3679 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3680 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3681 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3682 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3683 | if (netif_running(dev)) |
| 3684 | return -EBUSY; |
| 3685 | |
| 3686 | wdev_lock(wdev); |
| 3687 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3688 | IEEE80211_MAX_MESH_ID_LEN); |
| 3689 | wdev->mesh_id_up_len = |
| 3690 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3691 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3692 | wdev->mesh_id_up_len); |
| 3693 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3694 | } |
| 3695 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3696 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3697 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3698 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3699 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3700 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3701 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3702 | } else { |
| 3703 | params.use_4addr = -1; |
| 3704 | } |
| 3705 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3706 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3707 | if (err < 0) |
| 3708 | return err; |
| 3709 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3710 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3711 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3712 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3713 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3714 | else |
| 3715 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3716 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3717 | if (!err && params.use_4addr != -1) |
| 3718 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3719 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3720 | if (change && !err) { |
| 3721 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3722 | |
| 3723 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3724 | } |
| 3725 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3726 | return err; |
| 3727 | } |
| 3728 | |
| 3729 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3730 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3732 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3733 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3734 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3735 | int err; |
| 3736 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3737 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3738 | /* to avoid failing a new interface creation due to pending removal */ |
| 3739 | cfg80211_destroy_ifaces(rdev); |
| 3740 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3741 | memset(¶ms, 0, sizeof(params)); |
| 3742 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3743 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3744 | return -EINVAL; |
| 3745 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 3746 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3747 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3748 | |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3749 | if (!rdev->ops->add_virtual_intf) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3750 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3751 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3752 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 3753 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3754 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 3755 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3756 | ETH_ALEN); |
| 3757 | if (!is_valid_ether_addr(params.macaddr)) |
| 3758 | return -EADDRNOTAVAIL; |
| 3759 | } |
| 3760 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3761 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3762 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3763 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3764 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3765 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3766 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3767 | |
Manikanta Pubbisetty | e6f4051 | 2019-07-22 12:44:50 +0530 | [diff] [blame] | 3768 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3769 | return -EOPNOTSUPP; |
| 3770 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3771 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3772 | if (err < 0) |
| 3773 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3774 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 3775 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3776 | if (!msg) |
| 3777 | return -ENOMEM; |
| 3778 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3779 | wdev = rdev_add_virtual_intf(rdev, |
| 3780 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3781 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3782 | if (WARN_ON(!wdev)) { |
| 3783 | nlmsg_free(msg); |
| 3784 | return -EPROTO; |
| 3785 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3786 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3787 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3788 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3789 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3790 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3791 | wdev->owner_nlportid = info->snd_portid; |
| 3792 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3793 | switch (type) { |
| 3794 | case NL80211_IFTYPE_MESH_POINT: |
| 3795 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3796 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3797 | wdev_lock(wdev); |
| 3798 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3799 | IEEE80211_MAX_MESH_ID_LEN); |
| 3800 | wdev->mesh_id_up_len = |
| 3801 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3802 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3803 | wdev->mesh_id_up_len); |
| 3804 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3805 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3806 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3807 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3808 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3809 | * P2P Device and NAN do not have a netdev, so don't go |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3810 | * through the netdev notifier and must be added here |
| 3811 | */ |
Johannes Berg | e4d4216 | 2018-09-13 14:12:03 +0200 | [diff] [blame] | 3812 | cfg80211_init_wdev(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3813 | break; |
| 3814 | default: |
| 3815 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3816 | } |
| 3817 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3818 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3819 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3820 | nlmsg_free(msg); |
| 3821 | return -ENOBUFS; |
| 3822 | } |
| 3823 | |
| 3824 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3828 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3829 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3830 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3831 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3832 | if (!rdev->ops->del_virtual_intf) |
| 3833 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3834 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3835 | /* |
| 3836 | * If we remove a wireless device without a netdev then clear |
| 3837 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3838 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3839 | * since the wdev has been freed, unlike with a netdev where |
| 3840 | * we need the dev_put() for the netdev to really be freed. |
| 3841 | */ |
| 3842 | if (!wdev->netdev) |
| 3843 | info->user_ptr[1] = NULL; |
| 3844 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3845 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3846 | } |
| 3847 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3848 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3849 | { |
| 3850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3851 | struct net_device *dev = info->user_ptr[1]; |
| 3852 | u16 noack_map; |
| 3853 | |
| 3854 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3855 | return -EINVAL; |
| 3856 | |
| 3857 | if (!rdev->ops->set_noack_map) |
| 3858 | return -EOPNOTSUPP; |
| 3859 | |
| 3860 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3861 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3862 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3865 | struct get_key_cookie { |
| 3866 | struct sk_buff *msg; |
| 3867 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3868 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3869 | }; |
| 3870 | |
| 3871 | static void get_key_callback(void *c, struct key_params *params) |
| 3872 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3873 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3874 | struct get_key_cookie *cookie = c; |
| 3875 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3876 | if ((params->key && |
| 3877 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3878 | params->key_len, params->key)) || |
| 3879 | (params->seq && |
| 3880 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3881 | params->seq_len, params->seq)) || |
| 3882 | (params->cipher && |
| 3883 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3884 | params->cipher))) |
| 3885 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3886 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 3887 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3888 | if (!key) |
| 3889 | goto nla_put_failure; |
| 3890 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3891 | if ((params->key && |
| 3892 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3893 | params->key_len, params->key)) || |
| 3894 | (params->seq && |
| 3895 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3896 | params->seq_len, params->seq)) || |
| 3897 | (params->cipher && |
| 3898 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3899 | params->cipher))) |
| 3900 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3901 | |
Andrew Zaborowski | efdfce7 | 2018-09-24 18:10:22 +0200 | [diff] [blame] | 3902 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3903 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3904 | |
| 3905 | nla_nest_end(cookie->msg, key); |
| 3906 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3907 | return; |
| 3908 | nla_put_failure: |
| 3909 | cookie->error = 1; |
| 3910 | } |
| 3911 | |
| 3912 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3913 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3915 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3916 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3917 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3918 | const u8 *mac_addr = NULL; |
| 3919 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3920 | struct get_key_cookie cookie = { |
| 3921 | .error = 0, |
| 3922 | }; |
| 3923 | void *hdr; |
| 3924 | struct sk_buff *msg; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 3925 | bool bigtk_support = false; |
| 3926 | |
| 3927 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 3928 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
| 3929 | bigtk_support = true; |
| 3930 | |
| 3931 | if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || |
| 3932 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && |
| 3933 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 3934 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) |
| 3935 | bigtk_support = true; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3936 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3937 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3938 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 3939 | |
| 3940 | if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { |
| 3941 | GENL_SET_ERR_MSG(info, "BIGTK not supported"); |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3942 | return -EINVAL; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 3943 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 3944 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3945 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3946 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3947 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3948 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3949 | pairwise = !!mac_addr; |
| 3950 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 3951 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3952 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3953 | if (kt != NL80211_KEYTYPE_GROUP && |
| 3954 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 3955 | return -EINVAL; |
| 3956 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 3957 | } |
| 3958 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3959 | if (!rdev->ops->get_key) |
| 3960 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3961 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 3962 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 3963 | return -ENOENT; |
| 3964 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3966 | if (!msg) |
| 3967 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3968 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3969 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3970 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 3971 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 3972 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3973 | |
| 3974 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3975 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3976 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3977 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 3978 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3979 | goto nla_put_failure; |
| 3980 | if (mac_addr && |
| 3981 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 3982 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3983 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3984 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 3985 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3986 | |
| 3987 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3988 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3989 | |
| 3990 | if (cookie.error) |
| 3991 | goto nla_put_failure; |
| 3992 | |
| 3993 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3994 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3995 | |
| 3996 | nla_put_failure: |
| 3997 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 3998 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3999 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4000 | return err; |
| 4001 | } |
| 4002 | |
| 4003 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 4004 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4005 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4006 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4007 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4008 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4009 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4010 | err = nl80211_parse_key(info, &key); |
| 4011 | if (err) |
| 4012 | return err; |
| 4013 | |
| 4014 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4015 | return -EINVAL; |
| 4016 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4017 | /* Only support setting default key and |
| 4018 | * Extended Key ID action NL80211_KEY_SET_TX. |
| 4019 | */ |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4020 | if (!key.def && !key.defmgmt && !key.defbeacon && |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4021 | !(key.p.mode == NL80211_KEY_SET_TX)) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4022 | return -EINVAL; |
| 4023 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4024 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4025 | |
| 4026 | if (key.def) { |
| 4027 | if (!rdev->ops->set_default_key) { |
| 4028 | err = -EOPNOTSUPP; |
| 4029 | goto out; |
| 4030 | } |
| 4031 | |
| 4032 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4033 | if (err) |
| 4034 | goto out; |
| 4035 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4036 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4037 | key.def_uni, key.def_multi); |
| 4038 | |
| 4039 | if (err) |
| 4040 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4041 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4042 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4043 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4044 | #endif |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4045 | } else if (key.defmgmt) { |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4046 | if (key.def_uni || !key.def_multi) { |
| 4047 | err = -EINVAL; |
| 4048 | goto out; |
| 4049 | } |
| 4050 | |
| 4051 | if (!rdev->ops->set_default_mgmt_key) { |
| 4052 | err = -EOPNOTSUPP; |
| 4053 | goto out; |
| 4054 | } |
| 4055 | |
| 4056 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4057 | if (err) |
| 4058 | goto out; |
| 4059 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4060 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4061 | if (err) |
| 4062 | goto out; |
| 4063 | |
| 4064 | #ifdef CONFIG_CFG80211_WEXT |
| 4065 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 4066 | #endif |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4067 | } else if (key.defbeacon) { |
| 4068 | if (key.def_uni || !key.def_multi) { |
| 4069 | err = -EINVAL; |
| 4070 | goto out; |
| 4071 | } |
| 4072 | |
| 4073 | if (!rdev->ops->set_default_beacon_key) { |
| 4074 | err = -EOPNOTSUPP; |
| 4075 | goto out; |
| 4076 | } |
| 4077 | |
| 4078 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4079 | if (err) |
| 4080 | goto out; |
| 4081 | |
| 4082 | err = rdev_set_default_beacon_key(rdev, dev, key.idx); |
| 4083 | if (err) |
| 4084 | goto out; |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4085 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
| 4086 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4087 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
| 4088 | u8 *mac_addr = NULL; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4089 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4090 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4091 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4092 | |
| 4093 | if (!mac_addr || key.idx < 0 || key.idx > 1) { |
| 4094 | err = -EINVAL; |
| 4095 | goto out; |
| 4096 | } |
| 4097 | |
| 4098 | err = rdev_add_key(rdev, dev, key.idx, |
| 4099 | NL80211_KEYTYPE_PAIRWISE, |
| 4100 | mac_addr, &key.p); |
| 4101 | } else { |
| 4102 | err = -EINVAL; |
| 4103 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4104 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4105 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4106 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4107 | return err; |
| 4108 | } |
| 4109 | |
| 4110 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 4111 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4113 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4114 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4115 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4116 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4117 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4118 | err = nl80211_parse_key(info, &key); |
| 4119 | if (err) |
| 4120 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4121 | |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4122 | if (!key.p.key) { |
| 4123 | GENL_SET_ERR_MSG(info, "no key"); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4124 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4125 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4126 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4127 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4128 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4129 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4130 | if (key.type == -1) { |
| 4131 | if (mac_addr) |
| 4132 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4133 | else |
| 4134 | key.type = NL80211_KEYTYPE_GROUP; |
| 4135 | } |
| 4136 | |
| 4137 | /* for now */ |
| 4138 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4139 | key.type != NL80211_KEYTYPE_GROUP) { |
| 4140 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4141 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4142 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4143 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 4144 | if (key.type == NL80211_KEYTYPE_GROUP && |
| 4145 | info->attrs[NL80211_ATTR_VLAN_ID]) |
| 4146 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 4147 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4148 | if (!rdev->ops->add_key) |
| 4149 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4150 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4151 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 4152 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4153 | mac_addr)) { |
| 4154 | GENL_SET_ERR_MSG(info, "key setting validation failed"); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4155 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4156 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4157 | |
| 4158 | wdev_lock(dev->ieee80211_ptr); |
| 4159 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4160 | if (err) |
| 4161 | GENL_SET_ERR_MSG(info, "key not allowed"); |
| 4162 | if (!err) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4163 | err = rdev_add_key(rdev, dev, key.idx, |
| 4164 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4165 | mac_addr, &key.p); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4166 | if (err) |
| 4167 | GENL_SET_ERR_MSG(info, "key addition failed"); |
| 4168 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4169 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4170 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4171 | return err; |
| 4172 | } |
| 4173 | |
| 4174 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 4175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4177 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4178 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4179 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4180 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4181 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4182 | err = nl80211_parse_key(info, &key); |
| 4183 | if (err) |
| 4184 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4185 | |
| 4186 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4187 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4188 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4189 | if (key.type == -1) { |
| 4190 | if (mac_addr) |
| 4191 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4192 | else |
| 4193 | key.type = NL80211_KEYTYPE_GROUP; |
| 4194 | } |
| 4195 | |
| 4196 | /* for now */ |
| 4197 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 4198 | key.type != NL80211_KEYTYPE_GROUP) |
| 4199 | return -EINVAL; |
| 4200 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4201 | if (!rdev->ops->del_key) |
| 4202 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4203 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4204 | wdev_lock(dev->ieee80211_ptr); |
| 4205 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4206 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4207 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4208 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4209 | err = -ENOENT; |
| 4210 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4211 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4212 | err = rdev_del_key(rdev, dev, key.idx, |
| 4213 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4214 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4215 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4216 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4217 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4218 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4219 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4220 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4221 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 4222 | } |
| 4223 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4224 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4225 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4226 | return err; |
| 4227 | } |
| 4228 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4229 | /* This function returns an error or the number of nested attributes */ |
| 4230 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 4231 | { |
| 4232 | struct nlattr *attr; |
| 4233 | int n_entries = 0, tmp; |
| 4234 | |
| 4235 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 4236 | if (nla_len(attr) != ETH_ALEN) |
| 4237 | return -EINVAL; |
| 4238 | |
| 4239 | n_entries++; |
| 4240 | } |
| 4241 | |
| 4242 | return n_entries; |
| 4243 | } |
| 4244 | |
| 4245 | /* |
| 4246 | * This function parses ACL information and allocates memory for ACL data. |
| 4247 | * On successful return, the calling function is responsible to free the |
| 4248 | * ACL buffer returned by this function. |
| 4249 | */ |
| 4250 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 4251 | struct genl_info *info) |
| 4252 | { |
| 4253 | enum nl80211_acl_policy acl_policy; |
| 4254 | struct nlattr *attr; |
| 4255 | struct cfg80211_acl_data *acl; |
| 4256 | int i = 0, n_entries, tmp; |
| 4257 | |
| 4258 | if (!wiphy->max_acl_mac_addrs) |
| 4259 | return ERR_PTR(-EOPNOTSUPP); |
| 4260 | |
| 4261 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 4262 | return ERR_PTR(-EINVAL); |
| 4263 | |
| 4264 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 4265 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 4266 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 4267 | return ERR_PTR(-EINVAL); |
| 4268 | |
| 4269 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 4270 | return ERR_PTR(-EINVAL); |
| 4271 | |
| 4272 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 4273 | if (n_entries < 0) |
| 4274 | return ERR_PTR(n_entries); |
| 4275 | |
| 4276 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 4277 | return ERR_PTR(-ENOTSUPP); |
| 4278 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 4279 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4280 | if (!acl) |
| 4281 | return ERR_PTR(-ENOMEM); |
| 4282 | |
| 4283 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 4284 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 4285 | i++; |
| 4286 | } |
| 4287 | |
| 4288 | acl->n_acl_entries = n_entries; |
| 4289 | acl->acl_policy = acl_policy; |
| 4290 | |
| 4291 | return acl; |
| 4292 | } |
| 4293 | |
| 4294 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 4295 | { |
| 4296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4297 | struct net_device *dev = info->user_ptr[1]; |
| 4298 | struct cfg80211_acl_data *acl; |
| 4299 | int err; |
| 4300 | |
| 4301 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4302 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4303 | return -EOPNOTSUPP; |
| 4304 | |
| 4305 | if (!dev->ieee80211_ptr->beacon_interval) |
| 4306 | return -EINVAL; |
| 4307 | |
| 4308 | acl = parse_acl_data(&rdev->wiphy, info); |
| 4309 | if (IS_ERR(acl)) |
| 4310 | return PTR_ERR(acl); |
| 4311 | |
| 4312 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 4313 | |
| 4314 | kfree(acl); |
| 4315 | |
| 4316 | return err; |
| 4317 | } |
| 4318 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4319 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4320 | u8 *rates, u8 rates_len) |
| 4321 | { |
| 4322 | u8 i; |
| 4323 | u32 mask = 0; |
| 4324 | |
| 4325 | for (i = 0; i < rates_len; i++) { |
| 4326 | int rate = (rates[i] & 0x7f) * 5; |
| 4327 | int ridx; |
| 4328 | |
| 4329 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4330 | struct ieee80211_rate *srate = |
| 4331 | &sband->bitrates[ridx]; |
| 4332 | if (rate == srate->bitrate) { |
| 4333 | mask |= 1 << ridx; |
| 4334 | break; |
| 4335 | } |
| 4336 | } |
| 4337 | if (ridx == sband->n_bitrates) |
| 4338 | return 0; /* rate not found */ |
| 4339 | } |
| 4340 | |
| 4341 | return mask; |
| 4342 | } |
| 4343 | |
| 4344 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4345 | u8 *rates, u8 rates_len, |
| 4346 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 4347 | { |
| 4348 | u8 i; |
| 4349 | |
| 4350 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 4351 | |
| 4352 | for (i = 0; i < rates_len; i++) { |
| 4353 | int ridx, rbit; |
| 4354 | |
| 4355 | ridx = rates[i] / 8; |
| 4356 | rbit = BIT(rates[i] % 8); |
| 4357 | |
| 4358 | /* check validity */ |
| 4359 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 4360 | return false; |
| 4361 | |
| 4362 | /* check availability */ |
Masashi Honma | 30fe6d5 | 2018-09-25 11:15:00 +0900 | [diff] [blame] | 4363 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4364 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 4365 | mcs[ridx] |= rbit; |
| 4366 | else |
| 4367 | return false; |
| 4368 | } |
| 4369 | |
| 4370 | return true; |
| 4371 | } |
| 4372 | |
| 4373 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 4374 | { |
| 4375 | u16 mcs_mask = 0; |
| 4376 | |
| 4377 | switch (vht_mcs_map) { |
| 4378 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 4379 | break; |
| 4380 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 4381 | mcs_mask = 0x00FF; |
| 4382 | break; |
| 4383 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 4384 | mcs_mask = 0x01FF; |
| 4385 | break; |
| 4386 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 4387 | mcs_mask = 0x03FF; |
| 4388 | break; |
| 4389 | default: |
| 4390 | break; |
| 4391 | } |
| 4392 | |
| 4393 | return mcs_mask; |
| 4394 | } |
| 4395 | |
| 4396 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 4397 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 4398 | { |
| 4399 | u8 nss; |
| 4400 | |
| 4401 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 4402 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 4403 | vht_mcs_map >>= 2; |
| 4404 | } |
| 4405 | } |
| 4406 | |
| 4407 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 4408 | struct nl80211_txrate_vht *txrate, |
| 4409 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 4410 | { |
| 4411 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4412 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 4413 | u8 i; |
| 4414 | |
| 4415 | if (!sband->vht_cap.vht_supported) |
| 4416 | return false; |
| 4417 | |
| 4418 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4419 | |
| 4420 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4421 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4422 | |
| 4423 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4424 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4425 | mcs[i] = txrate->mcs[i]; |
| 4426 | else |
| 4427 | return false; |
| 4428 | } |
| 4429 | |
| 4430 | return true; |
| 4431 | } |
| 4432 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4433 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4434 | struct nlattr *attrs[], |
| 4435 | enum nl80211_attrs attr, |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4436 | struct cfg80211_bitrate_mask *mask) |
| 4437 | { |
| 4438 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4439 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4440 | int rem, i; |
| 4441 | struct nlattr *tx_rates; |
| 4442 | struct ieee80211_supported_band *sband; |
| 4443 | u16 vht_tx_mcs_map; |
| 4444 | |
| 4445 | memset(mask, 0, sizeof(*mask)); |
| 4446 | /* Default to all rates enabled */ |
| 4447 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
| 4448 | sband = rdev->wiphy.bands[i]; |
| 4449 | |
| 4450 | if (!sband) |
| 4451 | continue; |
| 4452 | |
| 4453 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4454 | memcpy(mask->control[i].ht_mcs, |
| 4455 | sband->ht_cap.mcs.rx_mask, |
| 4456 | sizeof(mask->control[i].ht_mcs)); |
| 4457 | |
| 4458 | if (!sband->vht_cap.vht_supported) |
| 4459 | continue; |
| 4460 | |
| 4461 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4462 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 4463 | } |
| 4464 | |
| 4465 | /* if no rates are given set it back to the defaults */ |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4466 | if (!attrs[attr]) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4467 | goto out; |
| 4468 | |
| 4469 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4470 | * directly to the enum nl80211_band values used in cfg80211. |
| 4471 | */ |
| 4472 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4473 | nla_for_each_nested(tx_rates, attrs[attr], rem) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4474 | enum nl80211_band band = nla_type(tx_rates); |
| 4475 | int err; |
| 4476 | |
| 4477 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4478 | return -EINVAL; |
| 4479 | sband = rdev->wiphy.bands[band]; |
| 4480 | if (sband == NULL) |
| 4481 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4482 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
| 4483 | tx_rates, |
| 4484 | nl80211_txattr_policy, |
| 4485 | info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4486 | if (err) |
| 4487 | return err; |
| 4488 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4489 | mask->control[band].legacy = rateset_to_mask( |
| 4490 | sband, |
| 4491 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4492 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4493 | if ((mask->control[band].legacy == 0) && |
| 4494 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4495 | return -EINVAL; |
| 4496 | } |
| 4497 | if (tb[NL80211_TXRATE_HT]) { |
| 4498 | if (!ht_rateset_to_mask( |
| 4499 | sband, |
| 4500 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4501 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4502 | mask->control[band].ht_mcs)) |
| 4503 | return -EINVAL; |
| 4504 | } |
| 4505 | if (tb[NL80211_TXRATE_VHT]) { |
| 4506 | if (!vht_set_mcs_mask( |
| 4507 | sband, |
| 4508 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4509 | mask->control[band].vht_mcs)) |
| 4510 | return -EINVAL; |
| 4511 | } |
| 4512 | if (tb[NL80211_TXRATE_GI]) { |
| 4513 | mask->control[band].gi = |
| 4514 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4515 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4516 | return -EINVAL; |
| 4517 | } |
| 4518 | |
| 4519 | if (mask->control[band].legacy == 0) { |
| 4520 | /* don't allow empty legacy rates if HT or VHT |
| 4521 | * are not even supported. |
| 4522 | */ |
| 4523 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
| 4524 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) |
| 4525 | return -EINVAL; |
| 4526 | |
| 4527 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4528 | if (mask->control[band].ht_mcs[i]) |
| 4529 | goto out; |
| 4530 | |
| 4531 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4532 | if (mask->control[band].vht_mcs[i]) |
| 4533 | goto out; |
| 4534 | |
| 4535 | /* legacy and mcs rates may not be both empty */ |
| 4536 | return -EINVAL; |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | out: |
| 4541 | return 0; |
| 4542 | } |
| 4543 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4544 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4545 | enum nl80211_band band, |
| 4546 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4547 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4548 | u32 count_ht, count_vht, i; |
| 4549 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4550 | |
| 4551 | /* Allow only one rate */ |
| 4552 | if (hweight32(rate) > 1) |
| 4553 | return -EINVAL; |
| 4554 | |
| 4555 | count_ht = 0; |
| 4556 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4557 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4558 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4559 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4560 | count_ht++; |
| 4561 | if (count_ht > 1) |
| 4562 | return -EINVAL; |
| 4563 | } |
| 4564 | if (count_ht && rate) |
| 4565 | return -EINVAL; |
| 4566 | } |
| 4567 | |
| 4568 | count_vht = 0; |
| 4569 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4570 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4571 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4572 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4573 | count_vht++; |
| 4574 | if (count_vht > 1) |
| 4575 | return -EINVAL; |
| 4576 | } |
| 4577 | if (count_vht && rate) |
| 4578 | return -EINVAL; |
| 4579 | } |
| 4580 | |
| 4581 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 4582 | return -EINVAL; |
| 4583 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4584 | if (rate && |
| 4585 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4586 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 4587 | return -EINVAL; |
| 4588 | if (count_ht && |
| 4589 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4590 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 4591 | return -EINVAL; |
| 4592 | if (count_vht && |
| 4593 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4594 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 4595 | return -EINVAL; |
| 4596 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4597 | return 0; |
| 4598 | } |
| 4599 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4600 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 4601 | struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4602 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4603 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4604 | bool haveinfo = false; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4605 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4606 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4607 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4608 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4609 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4610 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4611 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4612 | if (!bcn->head_len) |
| 4613 | return -EINVAL; |
| 4614 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4615 | } |
| 4616 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4617 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4618 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4619 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4620 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4621 | } |
| 4622 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4623 | if (!haveinfo) |
| 4624 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4625 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4626 | if (attrs[NL80211_ATTR_IE]) { |
| 4627 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4628 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4629 | } |
| 4630 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4631 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4632 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4633 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4634 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4635 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4636 | } |
| 4637 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4638 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4639 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4640 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4641 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4642 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4643 | } |
| 4644 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4645 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4646 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4647 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 4648 | } |
| 4649 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4650 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 4651 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 4652 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4653 | err = nla_parse_nested_deprecated(tb, |
| 4654 | NL80211_FTM_RESP_ATTR_MAX, |
| 4655 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 4656 | NULL, NULL); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4657 | if (err) |
| 4658 | return err; |
| 4659 | |
| 4660 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 4661 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4662 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 4663 | bcn->ftm_responder = 1; |
| 4664 | else |
| 4665 | return -EOPNOTSUPP; |
| 4666 | |
| 4667 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 4668 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4669 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4670 | } |
| 4671 | |
| 4672 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 4673 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4674 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4675 | } |
| 4676 | } else { |
| 4677 | bcn->ftm_responder = -1; |
| 4678 | } |
| 4679 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4680 | return 0; |
| 4681 | } |
| 4682 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4683 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
| 4684 | struct ieee80211_he_obss_pd *he_obss_pd) |
| 4685 | { |
| 4686 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; |
| 4687 | int err; |
| 4688 | |
| 4689 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, |
| 4690 | he_obss_pd_policy, NULL); |
| 4691 | if (err) |
| 4692 | return err; |
| 4693 | |
| 4694 | if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] || |
| 4695 | !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) |
| 4696 | return -EINVAL; |
| 4697 | |
| 4698 | he_obss_pd->min_offset = |
| 4699 | nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); |
| 4700 | he_obss_pd->max_offset = |
| 4701 | nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); |
| 4702 | |
| 4703 | if (he_obss_pd->min_offset >= he_obss_pd->max_offset) |
| 4704 | return -EINVAL; |
| 4705 | |
| 4706 | he_obss_pd->enable = true; |
| 4707 | |
| 4708 | return 0; |
| 4709 | } |
| 4710 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4711 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
| 4712 | struct cfg80211_he_bss_color *he_bss_color) |
| 4713 | { |
| 4714 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; |
| 4715 | int err; |
| 4716 | |
| 4717 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, |
| 4718 | he_bss_color_policy, NULL); |
| 4719 | if (err) |
| 4720 | return err; |
| 4721 | |
| 4722 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) |
| 4723 | return -EINVAL; |
| 4724 | |
| 4725 | he_bss_color->color = |
| 4726 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 4727 | he_bss_color->enabled = |
| 4728 | !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4729 | he_bss_color->partial = |
| 4730 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); |
| 4731 | |
| 4732 | return 0; |
| 4733 | } |
| 4734 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4735 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 4736 | const u8 *rates) |
| 4737 | { |
| 4738 | int i; |
| 4739 | |
| 4740 | if (!rates) |
| 4741 | return; |
| 4742 | |
| 4743 | for (i = 0; i < rates[1]; i++) { |
| 4744 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 4745 | params->ht_required = true; |
| 4746 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 4747 | params->vht_required = true; |
Ilan Peer | 2a39259 | 2020-03-26 15:09:35 +0200 | [diff] [blame] | 4748 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) |
| 4749 | params->he_required = true; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4750 | } |
| 4751 | } |
| 4752 | |
| 4753 | /* |
| 4754 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 4755 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 4756 | * benefit of drivers that rebuild IEs in the firmware. |
| 4757 | */ |
| 4758 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 4759 | { |
| 4760 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 4761 | size_t ies_len = bcn->tail_len; |
| 4762 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4763 | const u8 *rates; |
| 4764 | const u8 *cap; |
| 4765 | |
| 4766 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 4767 | nl80211_check_ap_rate_selectors(params, rates); |
| 4768 | |
| 4769 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 4770 | nl80211_check_ap_rate_selectors(params, rates); |
| 4771 | |
| 4772 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 4773 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 4774 | params->ht_cap = (void *)(cap + 2); |
| 4775 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 4776 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 4777 | params->vht_cap = (void *)(cap + 2); |
Shaul Triebitz | 244eb9a | 2018-08-31 11:31:14 +0300 | [diff] [blame] | 4778 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 4779 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) |
| 4780 | params->he_cap = (void *)(cap + 3); |
Shaul Triebitz | 7e8d6f1 | 2020-01-31 13:12:54 +0200 | [diff] [blame] | 4781 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); |
| 4782 | if (cap && cap[1] >= sizeof(*params->he_oper) + 1) |
| 4783 | params->he_oper = (void *)(cap + 3); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 4784 | } |
| 4785 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4786 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 4787 | struct cfg80211_ap_settings *params) |
| 4788 | { |
| 4789 | struct wireless_dev *wdev; |
| 4790 | bool ret = false; |
| 4791 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 4792 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4793 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 4794 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 4795 | continue; |
| 4796 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4797 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4798 | continue; |
| 4799 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4800 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4801 | ret = true; |
| 4802 | break; |
| 4803 | } |
| 4804 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4805 | return ret; |
| 4806 | } |
| 4807 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4808 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 4809 | enum nl80211_auth_type auth_type, |
| 4810 | enum nl80211_commands cmd) |
| 4811 | { |
| 4812 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 4813 | return false; |
| 4814 | |
| 4815 | switch (cmd) { |
| 4816 | case NL80211_CMD_AUTHENTICATE: |
| 4817 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 4818 | auth_type == NL80211_AUTHTYPE_SAE) |
| 4819 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4820 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4821 | NL80211_EXT_FEATURE_FILS_STA) && |
| 4822 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4823 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4824 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 4825 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4826 | return true; |
| 4827 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4828 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 4829 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4830 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4831 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4832 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 4833 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 4834 | /* FILS with SK PFS or PK not supported yet */ |
| 4835 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4836 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4837 | return false; |
| 4838 | if (!wiphy_ext_feature_isset( |
| 4839 | &rdev->wiphy, |
| 4840 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 4841 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 4842 | return false; |
| 4843 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4844 | case NL80211_CMD_START_AP: |
| 4845 | /* SAE not supported yet */ |
| 4846 | if (auth_type == NL80211_AUTHTYPE_SAE) |
| 4847 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 4848 | /* FILS not supported yet */ |
| 4849 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 4850 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 4851 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 4852 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4853 | return true; |
| 4854 | default: |
| 4855 | return false; |
| 4856 | } |
| 4857 | } |
| 4858 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4859 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 4860 | { |
| 4861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4862 | struct net_device *dev = info->user_ptr[1]; |
| 4863 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4864 | struct cfg80211_ap_settings params; |
| 4865 | int err; |
| 4866 | |
| 4867 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4868 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4869 | return -EOPNOTSUPP; |
| 4870 | |
| 4871 | if (!rdev->ops->start_ap) |
| 4872 | return -EOPNOTSUPP; |
| 4873 | |
| 4874 | if (wdev->beacon_interval) |
| 4875 | return -EALREADY; |
| 4876 | |
| 4877 | memset(¶ms, 0, sizeof(params)); |
| 4878 | |
| 4879 | /* these are required for START_AP */ |
| 4880 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 4881 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 4882 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 4883 | return -EINVAL; |
| 4884 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4885 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4886 | if (err) |
| 4887 | return err; |
| 4888 | |
| 4889 | params.beacon_interval = |
| 4890 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 4891 | params.dtim_period = |
| 4892 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 4893 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 4894 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 4895 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4896 | if (err) |
| 4897 | return err; |
| 4898 | |
| 4899 | /* |
| 4900 | * In theory, some of these attributes should be required here |
| 4901 | * but since they were not used when the command was originally |
| 4902 | * added, keep them optional for old user space programs to let |
| 4903 | * them continue to work with drivers that do not need the |
| 4904 | * additional information -- drivers must check! |
| 4905 | */ |
| 4906 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 4907 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 4908 | params.ssid_len = |
| 4909 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 4910 | if (params.ssid_len == 0) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4911 | return -EINVAL; |
| 4912 | } |
| 4913 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 4914 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4915 | params.hidden_ssid = nla_get_u32( |
| 4916 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4917 | |
| 4918 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 4919 | |
| 4920 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 4921 | params.auth_type = nla_get_u32( |
| 4922 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 4923 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 4924 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4925 | return -EINVAL; |
| 4926 | } else |
| 4927 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 4928 | |
| 4929 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 4930 | NL80211_MAX_NR_CIPHER_SUITES); |
| 4931 | if (err) |
| 4932 | return err; |
| 4933 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 4934 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 4935 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 4936 | return -EOPNOTSUPP; |
| 4937 | params.inactivity_timeout = nla_get_u16( |
| 4938 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 4939 | } |
| 4940 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4941 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 4942 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4943 | return -EINVAL; |
| 4944 | params.p2p_ctwindow = |
| 4945 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4946 | if (params.p2p_ctwindow != 0 && |
| 4947 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 4948 | return -EINVAL; |
| 4949 | } |
| 4950 | |
| 4951 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 4952 | u8 tmp; |
| 4953 | |
| 4954 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4955 | return -EINVAL; |
| 4956 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 4957 | params.p2p_opp_ps = tmp; |
| 4958 | if (params.p2p_opp_ps != 0 && |
| 4959 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 4960 | return -EINVAL; |
| 4961 | } |
| 4962 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4963 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 4964 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 4965 | if (err) |
| 4966 | return err; |
| 4967 | } else if (wdev->preset_chandef.chan) { |
| 4968 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 4969 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4970 | return -EINVAL; |
| 4971 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 4972 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 4973 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 4974 | return -EINVAL; |
| 4975 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4976 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4977 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 4978 | NL80211_ATTR_TX_RATES, |
| 4979 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4980 | if (err) |
| 4981 | return err; |
| 4982 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4983 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 4984 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4985 | if (err) |
| 4986 | return err; |
| 4987 | } |
| 4988 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 4989 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 4990 | params.smps_mode = |
| 4991 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 4992 | switch (params.smps_mode) { |
| 4993 | case NL80211_SMPS_OFF: |
| 4994 | break; |
| 4995 | case NL80211_SMPS_STATIC: |
| 4996 | if (!(rdev->wiphy.features & |
| 4997 | NL80211_FEATURE_STATIC_SMPS)) |
| 4998 | return -EINVAL; |
| 4999 | break; |
| 5000 | case NL80211_SMPS_DYNAMIC: |
| 5001 | if (!(rdev->wiphy.features & |
| 5002 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 5003 | return -EINVAL; |
| 5004 | break; |
| 5005 | default: |
| 5006 | return -EINVAL; |
| 5007 | } |
| 5008 | } else { |
| 5009 | params.smps_mode = NL80211_SMPS_OFF; |
| 5010 | } |
| 5011 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 5012 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 5013 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 5014 | return -EOPNOTSUPP; |
| 5015 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 5016 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 5017 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 5018 | if (IS_ERR(params.acl)) |
| 5019 | return PTR_ERR(params.acl); |
| 5020 | } |
| 5021 | |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 5022 | params.twt_responder = |
| 5023 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
| 5024 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5025 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
| 5026 | err = nl80211_parse_he_obss_pd( |
| 5027 | info->attrs[NL80211_ATTR_HE_OBSS_PD], |
| 5028 | ¶ms.he_obss_pd); |
Luca Coelho | bc7a39b | 2020-06-26 12:49:39 +0300 | [diff] [blame] | 5029 | if (err) |
| 5030 | goto out; |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5031 | } |
| 5032 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5033 | if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
| 5034 | err = nl80211_parse_he_bss_color( |
| 5035 | info->attrs[NL80211_ATTR_HE_BSS_COLOR], |
| 5036 | ¶ms.he_bss_color); |
| 5037 | if (err) |
Luca Coelho | 60a0121 | 2020-06-26 12:49:40 +0300 | [diff] [blame] | 5038 | goto out; |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5039 | } |
| 5040 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5041 | nl80211_calculate_ap_params(¶ms); |
| 5042 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 5043 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
| 5044 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 5045 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5046 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5047 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5048 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5049 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5050 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5051 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 5052 | wdev->ssid_len = params.ssid_len; |
| 5053 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 5054 | |
| 5055 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 5056 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5057 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5058 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5059 | |
Johannes Berg | 9951ebf | 2020-02-21 10:41:43 +0100 | [diff] [blame] | 5060 | out: |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5061 | kfree(params.acl); |
| 5062 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 5063 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5064 | } |
| 5065 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5066 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 5067 | { |
| 5068 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5069 | struct net_device *dev = info->user_ptr[1]; |
| 5070 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5071 | struct cfg80211_beacon_data params; |
| 5072 | int err; |
| 5073 | |
| 5074 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5075 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5076 | return -EOPNOTSUPP; |
| 5077 | |
| 5078 | if (!rdev->ops->change_beacon) |
| 5079 | return -EOPNOTSUPP; |
| 5080 | |
| 5081 | if (!wdev->beacon_interval) |
| 5082 | return -EINVAL; |
| 5083 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5084 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5085 | if (err) |
| 5086 | return err; |
| 5087 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5088 | wdev_lock(wdev); |
| 5089 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 5090 | wdev_unlock(wdev); |
| 5091 | |
| 5092 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5096 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5097 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5098 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5099 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 5100 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5101 | } |
| 5102 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5103 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 5104 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 5105 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 5106 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 5107 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 5108 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 5109 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5110 | }; |
| 5111 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5112 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5113 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5114 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5115 | { |
| 5116 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5117 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5118 | int flag; |
| 5119 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5120 | /* |
| 5121 | * Try parsing the new attribute first so userspace |
| 5122 | * can specify both for older kernels. |
| 5123 | */ |
| 5124 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 5125 | if (nla) { |
| 5126 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5127 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5128 | sta_flags = nla_data(nla); |
| 5129 | params->sta_flags_mask = sta_flags->mask; |
| 5130 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5131 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5132 | if ((params->sta_flags_mask | |
| 5133 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 5134 | return -EINVAL; |
| 5135 | return 0; |
| 5136 | } |
| 5137 | |
| 5138 | /* if present, parse the old attribute */ |
| 5139 | |
| 5140 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5141 | if (!nla) |
| 5142 | return 0; |
| 5143 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5144 | if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5145 | return -EINVAL; |
| 5146 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5147 | /* |
| 5148 | * Only allow certain flags for interface types so that |
| 5149 | * other attributes are silently ignored. Remember that |
| 5150 | * this is backward compatibility code with old userspace |
| 5151 | * and shouldn't be hit in other cases anyway. |
| 5152 | */ |
| 5153 | switch (iftype) { |
| 5154 | case NL80211_IFTYPE_AP: |
| 5155 | case NL80211_IFTYPE_AP_VLAN: |
| 5156 | case NL80211_IFTYPE_P2P_GO: |
| 5157 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5158 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5159 | BIT(NL80211_STA_FLAG_WME) | |
| 5160 | BIT(NL80211_STA_FLAG_MFP); |
| 5161 | break; |
| 5162 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5163 | case NL80211_IFTYPE_STATION: |
| 5164 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5165 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5166 | break; |
| 5167 | case NL80211_IFTYPE_MESH_POINT: |
| 5168 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5169 | BIT(NL80211_STA_FLAG_MFP) | |
| 5170 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
Bernd Edlinger | 5cf3006 | 2018-07-08 09:57:22 +0000 | [diff] [blame] | 5171 | break; |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5172 | default: |
| 5173 | return -EINVAL; |
| 5174 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5175 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5176 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 5177 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5178 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5179 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5180 | /* no longer support new API additions in old API */ |
| 5181 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 5182 | return -EINVAL; |
| 5183 | } |
| 5184 | } |
| 5185 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5186 | return 0; |
| 5187 | } |
| 5188 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 5189 | bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr) |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5190 | { |
| 5191 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5192 | u32 bitrate; |
| 5193 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 5194 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5195 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5196 | rate = nla_nest_start_noflag(msg, attr); |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5197 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5198 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5199 | |
| 5200 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 5201 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5202 | /* report 16-bit bitrate only if we can */ |
| 5203 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5204 | if (bitrate > 0 && |
| 5205 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 5206 | return false; |
| 5207 | if (bitrate_compat > 0 && |
| 5208 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 5209 | return false; |
| 5210 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5211 | switch (info->bw) { |
| 5212 | case RATE_INFO_BW_5: |
| 5213 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 5214 | break; |
| 5215 | case RATE_INFO_BW_10: |
| 5216 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 5217 | break; |
| 5218 | default: |
| 5219 | WARN_ON(1); |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 5220 | fallthrough; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5221 | case RATE_INFO_BW_20: |
| 5222 | rate_flg = 0; |
| 5223 | break; |
| 5224 | case RATE_INFO_BW_40: |
| 5225 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 5226 | break; |
| 5227 | case RATE_INFO_BW_80: |
| 5228 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 5229 | break; |
| 5230 | case RATE_INFO_BW_160: |
| 5231 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 5232 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5233 | case RATE_INFO_BW_HE_RU: |
| 5234 | rate_flg = 0; |
| 5235 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5236 | } |
| 5237 | |
| 5238 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 5239 | return false; |
| 5240 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5241 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 5242 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 5243 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5244 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5245 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5246 | return false; |
| 5247 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 5248 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 5249 | return false; |
| 5250 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 5251 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5252 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5253 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5254 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5255 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 5256 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 5257 | return false; |
| 5258 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 5259 | return false; |
| 5260 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 5261 | return false; |
| 5262 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 5263 | return false; |
| 5264 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 5265 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 5266 | info->he_ru_alloc)) |
| 5267 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5268 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5269 | |
| 5270 | nla_nest_end(msg, rate); |
| 5271 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5272 | } |
| 5273 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5274 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 5275 | int id) |
| 5276 | { |
| 5277 | void *attr; |
| 5278 | int i = 0; |
| 5279 | |
| 5280 | if (!mask) |
| 5281 | return true; |
| 5282 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5283 | attr = nla_nest_start_noflag(msg, id); |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5284 | if (!attr) |
| 5285 | return false; |
| 5286 | |
| 5287 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 5288 | if (!(mask & BIT(i))) |
| 5289 | continue; |
| 5290 | |
| 5291 | if (nla_put_u8(msg, i, signal[i])) |
| 5292 | return false; |
| 5293 | } |
| 5294 | |
| 5295 | nla_nest_end(msg, attr); |
| 5296 | |
| 5297 | return true; |
| 5298 | } |
| 5299 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5300 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 5301 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5302 | struct cfg80211_registered_device *rdev, |
| 5303 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5304 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5305 | { |
| 5306 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5307 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5308 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5309 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5310 | if (!hdr) { |
| 5311 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5312 | return -1; |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5313 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5314 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5315 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5316 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 5317 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 5318 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5319 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5320 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5321 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5322 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5323 | |
| 5324 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5325 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5326 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5327 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 5328 | sinfo->memb)) \ |
| 5329 | goto nla_put_failure; \ |
| 5330 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5331 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5332 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5333 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 5334 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 5335 | goto nla_put_failure; \ |
| 5336 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5337 | |
| 5338 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 5339 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
Ben Greear | 6c7a003 | 2019-08-09 11:00:00 -0700 | [diff] [blame] | 5340 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5341 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5342 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 5343 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5344 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5345 | (u32)sinfo->rx_bytes)) |
| 5346 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5347 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5348 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 5349 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5350 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 5351 | (u32)sinfo->tx_bytes)) |
| 5352 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5353 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5354 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 5355 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5356 | PUT_SINFO(LLID, llid, u16); |
| 5357 | PUT_SINFO(PLID, plid, u16); |
| 5358 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5359 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5360 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 5361 | |
| 5362 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 5363 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5364 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5365 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5366 | switch (rdev->wiphy.signal_type) { |
| 5367 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5368 | PUT_SINFO(SIGNAL, signal, u8); |
| 5369 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5370 | break; |
| 5371 | default: |
| 5372 | break; |
| 5373 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5374 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5375 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5376 | sinfo->chain_signal, |
| 5377 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 5378 | goto nla_put_failure; |
| 5379 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5380 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5381 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5382 | sinfo->chain_signal_avg, |
| 5383 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 5384 | goto nla_put_failure; |
| 5385 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5386 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5387 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 5388 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5389 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5390 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5391 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5392 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 5393 | NL80211_STA_INFO_RX_BITRATE)) |
| 5394 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5395 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5396 | |
| 5397 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 5398 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 5399 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 5400 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 5401 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
Narayanraddi Masti | ab60633 | 2019-02-07 12:16:05 -0800 | [diff] [blame] | 5402 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5403 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 5404 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 5405 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 5406 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
Bob Copeland | dbdaee7 | 2018-10-25 15:48:53 -0400 | [diff] [blame] | 5407 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
Markus Theil | 1303a51 | 2020-06-11 16:02:38 +0200 | [diff] [blame] | 5408 | PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5409 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5410 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5411 | bss_param = nla_nest_start_noflag(msg, |
| 5412 | NL80211_STA_INFO_BSS_PARAM); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5413 | if (!bss_param) |
| 5414 | goto nla_put_failure; |
| 5415 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5416 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 5417 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 5418 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 5419 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 5420 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 5421 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 5422 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 5423 | sinfo->bss_param.dtim_period) || |
| 5424 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 5425 | sinfo->bss_param.beacon_interval)) |
| 5426 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5427 | |
| 5428 | nla_nest_end(msg, bss_param); |
| 5429 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5430 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5431 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 5432 | sizeof(struct nl80211_sta_flag_update), |
| 5433 | &sinfo->sta_flags)) |
| 5434 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5435 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5436 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 5437 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 5438 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 5439 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Ankita Bajaj | 0d4e14a | 2018-09-27 18:01:57 +0300 | [diff] [blame] | 5440 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 5441 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 5442 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
Balaji Pothunoori | 9c06602 | 2018-07-19 18:56:27 +0530 | [diff] [blame] | 5443 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 5444 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 5445 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 5446 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5447 | |
| 5448 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5449 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5450 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 5451 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5452 | struct nlattr *tidsattr; |
| 5453 | int tid; |
| 5454 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5455 | tidsattr = nla_nest_start_noflag(msg, |
| 5456 | NL80211_STA_INFO_TID_STATS); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5457 | if (!tidsattr) |
| 5458 | goto nla_put_failure; |
| 5459 | |
| 5460 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 5461 | struct cfg80211_tid_stats *tidstats; |
| 5462 | struct nlattr *tidattr; |
| 5463 | |
| 5464 | tidstats = &sinfo->pertid[tid]; |
| 5465 | |
| 5466 | if (!tidstats->filled) |
| 5467 | continue; |
| 5468 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5469 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5470 | if (!tidattr) |
| 5471 | goto nla_put_failure; |
| 5472 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5473 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5474 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5475 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 5476 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5477 | goto nla_put_failure; \ |
| 5478 | } while (0) |
| 5479 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5480 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 5481 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 5482 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 5483 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5484 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5485 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 5486 | if ((tidstats->filled & |
| 5487 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 5488 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 5489 | NL80211_TID_STATS_TXQ_STATS)) |
| 5490 | goto nla_put_failure; |
| 5491 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5492 | nla_nest_end(msg, tidattr); |
| 5493 | } |
| 5494 | |
| 5495 | nla_nest_end(msg, tidsattr); |
| 5496 | } |
| 5497 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5498 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5499 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5500 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5501 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 5502 | sinfo->assoc_req_ies)) |
| 5503 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 5504 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5505 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5506 | genlmsg_end(msg, hdr); |
| 5507 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5508 | |
| 5509 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5510 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5511 | genlmsg_cancel(msg, hdr); |
| 5512 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5513 | } |
| 5514 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5515 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5516 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5517 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5518 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5519 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5520 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5521 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5522 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5523 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5524 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5525 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 5526 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5527 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5528 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5529 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5530 | if (!wdev->netdev) { |
| 5531 | err = -EINVAL; |
| 5532 | goto out_err; |
| 5533 | } |
| 5534 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5535 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5536 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5537 | goto out_err; |
| 5538 | } |
| 5539 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5540 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5541 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5542 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5543 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5544 | if (err == -ENOENT) |
| 5545 | break; |
| 5546 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5547 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5548 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5549 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5550 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5551 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5552 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5553 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5554 | goto out; |
| 5555 | |
| 5556 | sta_idx++; |
| 5557 | } |
| 5558 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5559 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5560 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5561 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5562 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5563 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5564 | |
| 5565 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5566 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5567 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5568 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 5569 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5571 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5572 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5573 | struct sk_buff *msg; |
| 5574 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5575 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5576 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5577 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5578 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5579 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5580 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5581 | |
| 5582 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5583 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5584 | if (!rdev->ops->get_station) |
| 5585 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5586 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5587 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5588 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5589 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5590 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5592 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 5593 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5594 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5595 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5596 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5597 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 5598 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5599 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5600 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5601 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5602 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5603 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5604 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5605 | } |
| 5606 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5607 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 5608 | struct station_parameters *params, |
| 5609 | enum cfg80211_station_type statype) |
| 5610 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5611 | if (params->listen_interval != -1 && |
| 5612 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5613 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5614 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5615 | if (params->support_p2p_ps != -1 && |
| 5616 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5617 | return -EINVAL; |
| 5618 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 5619 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5620 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 5621 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5622 | return -EINVAL; |
| 5623 | |
| 5624 | /* When you run into this, adjust the code below for the new flag */ |
| 5625 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5626 | |
| 5627 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5628 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 5629 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5630 | /* |
| 5631 | * No ignoring the TDLS flag here -- the userspace mesh |
| 5632 | * code doesn't have the bug of including TDLS in the |
| 5633 | * mask everywhere. |
| 5634 | */ |
| 5635 | if (params->sta_flags_mask & |
| 5636 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5637 | BIT(NL80211_STA_FLAG_MFP) | |
| 5638 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5639 | return -EINVAL; |
| 5640 | break; |
| 5641 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5642 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5643 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5644 | return -EINVAL; |
| 5645 | /* ignore since it can't change */ |
| 5646 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5647 | break; |
| 5648 | default: |
| 5649 | /* disallow mesh-specific things */ |
| 5650 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 5651 | return -EINVAL; |
| 5652 | if (params->local_pm) |
| 5653 | return -EINVAL; |
| 5654 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5655 | return -EINVAL; |
| 5656 | } |
| 5657 | |
| 5658 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5659 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 5660 | /* TDLS can't be set, ... */ |
| 5661 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 5662 | return -EINVAL; |
| 5663 | /* |
| 5664 | * ... but don't bother the driver with it. This works around |
| 5665 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 5666 | * TLDS_PEER flag in the mask even for AP mode. |
| 5667 | */ |
| 5668 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5669 | } |
| 5670 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5671 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5672 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5673 | /* reject other things that can't change */ |
| 5674 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 5675 | return -EINVAL; |
| 5676 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 5677 | return -EINVAL; |
| 5678 | if (params->supported_rates) |
| 5679 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5680 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 5681 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5682 | return -EINVAL; |
| 5683 | } |
| 5684 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5685 | if (statype != CFG80211_STA_AP_CLIENT && |
| 5686 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5687 | if (params->vlan) |
| 5688 | return -EINVAL; |
| 5689 | } |
| 5690 | |
| 5691 | switch (statype) { |
| 5692 | case CFG80211_STA_AP_MLME_CLIENT: |
| 5693 | /* Use this only for authorizing/unauthorizing a station */ |
| 5694 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5695 | return -EOPNOTSUPP; |
| 5696 | break; |
| 5697 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5698 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5699 | /* accept only the listed bits */ |
| 5700 | if (params->sta_flags_mask & |
| 5701 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5702 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5703 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5704 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5705 | BIT(NL80211_STA_FLAG_WME) | |
| 5706 | BIT(NL80211_STA_FLAG_MFP))) |
| 5707 | return -EINVAL; |
| 5708 | |
| 5709 | /* but authenticated/associated only if driver handles it */ |
| 5710 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 5711 | params->sta_flags_mask & |
| 5712 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5713 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 5714 | return -EINVAL; |
| 5715 | break; |
| 5716 | case CFG80211_STA_IBSS: |
| 5717 | case CFG80211_STA_AP_STA: |
| 5718 | /* reject any changes other than AUTHORIZED */ |
| 5719 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 5720 | return -EINVAL; |
| 5721 | break; |
| 5722 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5723 | /* reject any changes other than AUTHORIZED or WME */ |
| 5724 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5725 | BIT(NL80211_STA_FLAG_WME))) |
| 5726 | return -EINVAL; |
| 5727 | /* force (at least) rates when authorizing */ |
| 5728 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 5729 | !params->supported_rates) |
| 5730 | return -EINVAL; |
| 5731 | break; |
| 5732 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5733 | /* reject any changes */ |
| 5734 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5735 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5736 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5737 | return -EINVAL; |
| 5738 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5739 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 5740 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 5741 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5742 | return -EINVAL; |
| 5743 | break; |
| 5744 | } |
| 5745 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 5746 | /* |
| 5747 | * Older kernel versions ignored this attribute entirely, so don't |
| 5748 | * reject attempts to update it but mark it as unused instead so the |
| 5749 | * driver won't look at the data. |
| 5750 | */ |
| 5751 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 5752 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 5753 | params->opmode_notif_used = false; |
| 5754 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5755 | return 0; |
| 5756 | } |
| 5757 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 5758 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5759 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 5760 | * Get vlan interface making sure it is running and on the right wiphy. |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5761 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5762 | static struct net_device *get_vlan(struct genl_info *info, |
| 5763 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5764 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 5765 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5766 | struct net_device *v; |
| 5767 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5768 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5769 | if (!vlanattr) |
| 5770 | return NULL; |
| 5771 | |
| 5772 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 5773 | if (!v) |
| 5774 | return ERR_PTR(-ENODEV); |
| 5775 | |
| 5776 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 5777 | ret = -EINVAL; |
| 5778 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5779 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5780 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5781 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 5782 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5783 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5784 | ret = -EINVAL; |
| 5785 | goto error; |
| 5786 | } |
| 5787 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 5788 | if (!netif_running(v)) { |
| 5789 | ret = -ENETDOWN; |
| 5790 | goto error; |
| 5791 | } |
| 5792 | |
| 5793 | return v; |
| 5794 | error: |
| 5795 | dev_put(v); |
| 5796 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5797 | } |
| 5798 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 5799 | static const struct nla_policy |
| 5800 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5801 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 5802 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 5803 | }; |
| 5804 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5805 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 5806 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5807 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5808 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 5809 | struct nlattr *nla; |
| 5810 | int err; |
| 5811 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5812 | /* parse WME attributes if present */ |
| 5813 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 5814 | return 0; |
| 5815 | |
| 5816 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5817 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
| 5818 | nl80211_sta_wme_policy, |
| 5819 | info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 5820 | if (err) |
| 5821 | return err; |
| 5822 | |
| 5823 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 5824 | params->uapsd_queues = nla_get_u8( |
| 5825 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 5826 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 5827 | return -EINVAL; |
| 5828 | |
| 5829 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 5830 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 5831 | |
| 5832 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 5833 | return -EINVAL; |
| 5834 | |
| 5835 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 5836 | |
| 5837 | return 0; |
| 5838 | } |
| 5839 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5840 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 5841 | struct station_parameters *params) |
| 5842 | { |
| 5843 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 5844 | params->supported_channels = |
| 5845 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5846 | params->supported_channels_len = |
| 5847 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 5848 | /* |
| 5849 | * Need to include at least one (first channel, number of |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 5850 | * channels) tuple for each subband (checked in policy), |
| 5851 | * and must have proper tuples for the rest of the data as well. |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5852 | */ |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5853 | if (params->supported_channels_len % 2) |
| 5854 | return -EINVAL; |
| 5855 | } |
| 5856 | |
| 5857 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 5858 | params->supported_oper_classes = |
| 5859 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 5860 | params->supported_oper_classes_len = |
| 5861 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5862 | } |
| 5863 | return 0; |
| 5864 | } |
| 5865 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5866 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 5867 | struct station_parameters *params) |
| 5868 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5869 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5870 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 5871 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 5872 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5873 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 5874 | params->ht_capa = |
| 5875 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 5876 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 5877 | params->vht_capa = |
| 5878 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5879 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 5880 | params->he_capa = |
| 5881 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 5882 | params->he_capa_len = |
| 5883 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5884 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5885 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 5886 | err = nl80211_parse_sta_channel_info(info, params); |
| 5887 | if (err) |
| 5888 | return err; |
| 5889 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 5890 | return nl80211_parse_sta_wme(info, params); |
| 5891 | } |
| 5892 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 5893 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
| 5894 | struct station_parameters *params) |
| 5895 | { |
| 5896 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5897 | int idx; |
| 5898 | |
| 5899 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { |
| 5900 | if (!rdev->ops->set_tx_power || |
| 5901 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5902 | NL80211_EXT_FEATURE_STA_TX_PWR)) |
| 5903 | return -EOPNOTSUPP; |
| 5904 | |
| 5905 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; |
| 5906 | params->txpwr.type = nla_get_u8(info->attrs[idx]); |
| 5907 | |
| 5908 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { |
| 5909 | idx = NL80211_ATTR_STA_TX_POWER; |
| 5910 | |
| 5911 | if (info->attrs[idx]) |
| 5912 | params->txpwr.power = |
| 5913 | nla_get_s16(info->attrs[idx]); |
| 5914 | else |
| 5915 | return -EINVAL; |
| 5916 | } |
| 5917 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; |
| 5918 | } |
| 5919 | |
| 5920 | return 0; |
| 5921 | } |
| 5922 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5923 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 5924 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5926 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5927 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5928 | u8 *mac_addr; |
| 5929 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5930 | |
| 5931 | memset(¶ms, 0, sizeof(params)); |
| 5932 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5933 | if (!rdev->ops->change_station) |
| 5934 | return -EOPNOTSUPP; |
| 5935 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5936 | /* |
| 5937 | * AID and listen_interval properties can be set only for unassociated |
| 5938 | * station. Include these parameters here and will check them in |
| 5939 | * cfg80211_check_station_change(). |
| 5940 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 5941 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 5942 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5943 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 5944 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 5945 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 5946 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5947 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 5948 | params.listen_interval = |
| 5949 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 5950 | else |
| 5951 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5952 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5953 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 5954 | params.support_p2p_ps = |
| 5955 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 5956 | else |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5957 | params.support_p2p_ps = -1; |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5958 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5959 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5960 | return -EINVAL; |
| 5961 | |
| 5962 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5963 | |
| 5964 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 5965 | params.supported_rates = |
| 5966 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5967 | params.supported_rates_len = |
| 5968 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 5969 | } |
| 5970 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 5971 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 5972 | params.capability = |
| 5973 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 5974 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 5975 | } |
| 5976 | |
| 5977 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 5978 | params.ext_capab = |
| 5979 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5980 | params.ext_capab_len = |
| 5981 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 5982 | } |
| 5983 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5984 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5985 | return -EINVAL; |
| 5986 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5987 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5988 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5989 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5990 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5991 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5992 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5993 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5994 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 5995 | params.peer_aid = nla_get_u16( |
| 5996 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 5997 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 5998 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 5999 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6000 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 6001 | params.local_pm = nla_get_u32( |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6002 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 6003 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 6004 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6005 | params.opmode_notif_used = true; |
| 6006 | params.opmode_notif = |
| 6007 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6008 | } |
| 6009 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6010 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6011 | params.he_6ghz_capa = |
| 6012 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6013 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6014 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6015 | params.airtime_weight = |
| 6016 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6017 | |
| 6018 | if (params.airtime_weight && |
| 6019 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6020 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6021 | return -EOPNOTSUPP; |
| 6022 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6023 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6024 | if (err) |
| 6025 | return err; |
| 6026 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6027 | /* Include parameters for TDLS peer (will check later) */ |
| 6028 | err = nl80211_set_station_tdls(info, ¶ms); |
| 6029 | if (err) |
| 6030 | return err; |
| 6031 | |
| 6032 | params.vlan = get_vlan(info, rdev); |
| 6033 | if (IS_ERR(params.vlan)) |
| 6034 | return PTR_ERR(params.vlan); |
| 6035 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6036 | switch (dev->ieee80211_ptr->iftype) { |
| 6037 | case NL80211_IFTYPE_AP: |
| 6038 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6039 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6040 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6041 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6042 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6043 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6044 | break; |
| 6045 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6046 | err = -EOPNOTSUPP; |
| 6047 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 6048 | } |
| 6049 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6050 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6051 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6052 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6053 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6054 | if (params.vlan) |
| 6055 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6056 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6057 | return err; |
| 6058 | } |
| 6059 | |
| 6060 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 6061 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6063 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6064 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6065 | struct station_parameters params; |
| 6066 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6067 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6068 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6069 | |
| 6070 | memset(¶ms, 0, sizeof(params)); |
| 6071 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6072 | if (!rdev->ops->add_station) |
| 6073 | return -EOPNOTSUPP; |
| 6074 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6075 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6076 | return -EINVAL; |
| 6077 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6078 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6079 | return -EINVAL; |
| 6080 | |
| 6081 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 6082 | return -EINVAL; |
| 6083 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6084 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 6085 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 6086 | return -EINVAL; |
| 6087 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6088 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6089 | params.supported_rates = |
| 6090 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6091 | params.supported_rates_len = |
| 6092 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6093 | params.listen_interval = |
| 6094 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6095 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6096 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6097 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6098 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6099 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6100 | params.support_p2p_ps = |
| 6101 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6102 | } else { |
| 6103 | /* |
| 6104 | * if not specified, assume it's supported for P2P GO interface, |
| 6105 | * and is NOT supported for AP interface |
| 6106 | */ |
| 6107 | params.support_p2p_ps = |
| 6108 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 6109 | } |
| 6110 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6111 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6112 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6113 | else |
| 6114 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6115 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6116 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6117 | params.capability = |
| 6118 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6119 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6120 | } |
| 6121 | |
| 6122 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6123 | params.ext_capab = |
| 6124 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6125 | params.ext_capab_len = |
| 6126 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6127 | } |
| 6128 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 6129 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6130 | params.ht_capa = |
| 6131 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6132 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 6133 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6134 | params.vht_capa = |
| 6135 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6136 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6137 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6138 | params.he_capa = |
| 6139 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6140 | params.he_capa_len = |
| 6141 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6142 | } |
| 6143 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6144 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6145 | params.he_6ghz_capa = |
| 6146 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
| 6147 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 6148 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6149 | params.opmode_notif_used = true; |
| 6150 | params.opmode_notif = |
| 6151 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6152 | } |
| 6153 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6154 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6155 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6156 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6157 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6158 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6159 | params.airtime_weight = |
| 6160 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6161 | |
| 6162 | if (params.airtime_weight && |
| 6163 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6164 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6165 | return -EOPNOTSUPP; |
| 6166 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6167 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6168 | if (err) |
| 6169 | return err; |
| 6170 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6171 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 6172 | if (err) |
| 6173 | return err; |
| 6174 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6175 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 6176 | if (err) |
| 6177 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6178 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6179 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6180 | return -EINVAL; |
| 6181 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6182 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 6183 | * as userspace might just pass through the capabilities from the IEs |
| 6184 | * directly, rather than enforcing this restriction and returning an |
| 6185 | * error in this case. |
| 6186 | */ |
| 6187 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 6188 | params.ht_capa = NULL; |
| 6189 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6190 | |
| 6191 | /* HE requires WME */ |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6192 | if (params.he_capa_len || params.he_6ghz_capa) |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6193 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6194 | } |
| 6195 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6196 | /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ |
| 6197 | if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) |
| 6198 | return -EINVAL; |
| 6199 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6200 | /* When you run into this, adjust the code below for the new flag */ |
| 6201 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6202 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6203 | switch (dev->ieee80211_ptr->iftype) { |
| 6204 | case NL80211_IFTYPE_AP: |
| 6205 | case NL80211_IFTYPE_AP_VLAN: |
| 6206 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6207 | /* ignore WME attributes if iface/sta is not capable */ |
| 6208 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 6209 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 6210 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6211 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6212 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6213 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6214 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6215 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6216 | /* but don't bother the driver with it */ |
| 6217 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6218 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6219 | /* allow authenticated/associated only if driver handles it */ |
| 6220 | if (!(rdev->wiphy.features & |
| 6221 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6222 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6223 | return -EINVAL; |
| 6224 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6225 | /* Older userspace, or userspace wanting to be compatible with |
| 6226 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 6227 | * and assoc flags in the mask, but assumes the station will be |
| 6228 | * added as associated anyway since this was the required driver |
| 6229 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 6230 | * introduced. |
| 6231 | * In order to not bother drivers with this quirk in the API |
| 6232 | * set the flags in both the mask and set for new stations in |
| 6233 | * this case. |
| 6234 | */ |
| 6235 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 6236 | params.sta_flags_mask |= auth_assoc; |
| 6237 | params.sta_flags_set |= auth_assoc; |
| 6238 | } |
| 6239 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6240 | /* must be last in here for error handling */ |
| 6241 | params.vlan = get_vlan(info, rdev); |
| 6242 | if (IS_ERR(params.vlan)) |
| 6243 | return PTR_ERR(params.vlan); |
| 6244 | break; |
| 6245 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6246 | /* ignore uAPSD data */ |
| 6247 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6248 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6249 | /* associated is disallowed */ |
| 6250 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 6251 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6252 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6253 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6254 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6255 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6256 | break; |
| 6257 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 6258 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6259 | /* ignore uAPSD data */ |
| 6260 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6261 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6262 | /* these are disallowed */ |
| 6263 | if (params.sta_flags_mask & |
| 6264 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6265 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6266 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6267 | /* Only TDLS peers can be added */ |
| 6268 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6269 | return -EINVAL; |
| 6270 | /* Can only add if TDLS ... */ |
| 6271 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 6272 | return -EOPNOTSUPP; |
| 6273 | /* ... with external setup is supported */ |
| 6274 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 6275 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6276 | /* |
| 6277 | * Older wpa_supplicant versions always mark the TDLS peer |
| 6278 | * as authorized, but it shouldn't yet be. |
| 6279 | */ |
| 6280 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6281 | break; |
| 6282 | default: |
| 6283 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6284 | } |
| 6285 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6286 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6287 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6288 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6289 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6290 | if (params.vlan) |
| 6291 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6292 | return err; |
| 6293 | } |
| 6294 | |
| 6295 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 6296 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6298 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6299 | struct station_del_parameters params; |
| 6300 | |
| 6301 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6302 | |
| 6303 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6304 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6305 | |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6306 | switch (dev->ieee80211_ptr->iftype) { |
| 6307 | case NL80211_IFTYPE_AP: |
| 6308 | case NL80211_IFTYPE_AP_VLAN: |
| 6309 | case NL80211_IFTYPE_MESH_POINT: |
| 6310 | case NL80211_IFTYPE_P2P_GO: |
| 6311 | /* always accept these */ |
| 6312 | break; |
| 6313 | case NL80211_IFTYPE_ADHOC: |
| 6314 | /* conditionally accept */ |
| 6315 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 6316 | NL80211_EXT_FEATURE_DEL_IBSS_STA)) |
| 6317 | break; |
Nicolas Cavallari | edafcf4 | 2020-03-05 14:57:53 +0100 | [diff] [blame] | 6318 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6319 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6320 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6321 | } |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 6322 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6323 | if (!rdev->ops->del_station) |
| 6324 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6325 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 6326 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 6327 | params.subtype = |
| 6328 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 6329 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 6330 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 6331 | return -EINVAL; |
| 6332 | } else { |
| 6333 | /* Default to Deauthentication frame */ |
| 6334 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 6335 | } |
| 6336 | |
| 6337 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 6338 | params.reason_code = |
| 6339 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6340 | if (params.reason_code == 0) |
| 6341 | return -EINVAL; /* 0 is reserved */ |
| 6342 | } else { |
| 6343 | /* Default to reason code 2 */ |
| 6344 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 6345 | } |
| 6346 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6347 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6348 | } |
| 6349 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6350 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6351 | int flags, struct net_device *dev, |
| 6352 | u8 *dst, u8 *next_hop, |
| 6353 | struct mpath_info *pinfo) |
| 6354 | { |
| 6355 | void *hdr; |
| 6356 | struct nlattr *pinfoattr; |
| 6357 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 6358 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6359 | if (!hdr) |
| 6360 | return -1; |
| 6361 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6362 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6363 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 6364 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 6365 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 6366 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 6367 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6368 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6369 | if (!pinfoattr) |
| 6370 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6371 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 6372 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 6373 | pinfo->frame_qlen)) |
| 6374 | goto nla_put_failure; |
| 6375 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 6376 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 6377 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 6378 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 6379 | pinfo->metric)) || |
| 6380 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 6381 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 6382 | pinfo->exptime)) || |
| 6383 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 6384 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 6385 | pinfo->flags)) || |
| 6386 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 6387 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 6388 | pinfo->discovery_timeout)) || |
| 6389 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 6390 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 6391 | pinfo->discovery_retries)) || |
| 6392 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 6393 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 6394 | pinfo->hop_count)) || |
| 6395 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 6396 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 6397 | pinfo->path_change_count))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6398 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6399 | |
| 6400 | nla_nest_end(msg, pinfoattr); |
| 6401 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6402 | genlmsg_end(msg, hdr); |
| 6403 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6404 | |
| 6405 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 6406 | genlmsg_cancel(msg, hdr); |
| 6407 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6411 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6412 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6413 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6414 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6415 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6416 | u8 dst[ETH_ALEN]; |
| 6417 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6418 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6419 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6420 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6421 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6422 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6423 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6424 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6425 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6426 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6427 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6428 | goto out_err; |
| 6429 | } |
| 6430 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6431 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6432 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 6433 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6434 | } |
| 6435 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6436 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6437 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6438 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6439 | if (err == -ENOENT) |
| 6440 | break; |
| 6441 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6442 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6443 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6444 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6445 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6446 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6447 | &pinfo) < 0) |
| 6448 | goto out; |
| 6449 | |
| 6450 | path_idx++; |
| 6451 | } |
| 6452 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6453 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6454 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6455 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6456 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6457 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6458 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6462 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6463 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6464 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6465 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6466 | struct mpath_info pinfo; |
| 6467 | struct sk_buff *msg; |
| 6468 | u8 *dst = NULL; |
| 6469 | u8 next_hop[ETH_ALEN]; |
| 6470 | |
| 6471 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6472 | |
| 6473 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6474 | return -EINVAL; |
| 6475 | |
| 6476 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6477 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6478 | if (!rdev->ops->get_mpath) |
| 6479 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6480 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6481 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6482 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6483 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6484 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6485 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6486 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6487 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6488 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6489 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6490 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6491 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6492 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6493 | dev, dst, next_hop, &pinfo) < 0) { |
| 6494 | nlmsg_free(msg); |
| 6495 | return -ENOBUFS; |
| 6496 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6497 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6498 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6499 | } |
| 6500 | |
| 6501 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6502 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6503 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6504 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6505 | u8 *dst = NULL; |
| 6506 | u8 *next_hop = NULL; |
| 6507 | |
| 6508 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6509 | return -EINVAL; |
| 6510 | |
| 6511 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6512 | return -EINVAL; |
| 6513 | |
| 6514 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6515 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6516 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6517 | if (!rdev->ops->change_mpath) |
| 6518 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6519 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6520 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6521 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6522 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6523 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6524 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6525 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6526 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6527 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6529 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6530 | u8 *dst = NULL; |
| 6531 | u8 *next_hop = NULL; |
| 6532 | |
| 6533 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6534 | return -EINVAL; |
| 6535 | |
| 6536 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6537 | return -EINVAL; |
| 6538 | |
| 6539 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6540 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6541 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6542 | if (!rdev->ops->add_mpath) |
| 6543 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6544 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6545 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6546 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6547 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6548 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6549 | } |
| 6550 | |
| 6551 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6552 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6553 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6554 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6555 | u8 *dst = NULL; |
| 6556 | |
| 6557 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6558 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6559 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6560 | if (!rdev->ops->del_mpath) |
| 6561 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6562 | |
Miaoqing Pan | b501426 | 2019-09-26 16:16:50 +0800 | [diff] [blame] | 6563 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6564 | return -EOPNOTSUPP; |
| 6565 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6566 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6567 | } |
| 6568 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6569 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 6570 | { |
| 6571 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6572 | int err; |
| 6573 | struct net_device *dev = info->user_ptr[1]; |
| 6574 | struct mpath_info pinfo; |
| 6575 | struct sk_buff *msg; |
| 6576 | u8 *dst = NULL; |
| 6577 | u8 mpp[ETH_ALEN]; |
| 6578 | |
| 6579 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6580 | |
| 6581 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6582 | return -EINVAL; |
| 6583 | |
| 6584 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6585 | |
| 6586 | if (!rdev->ops->get_mpp) |
| 6587 | return -EOPNOTSUPP; |
| 6588 | |
| 6589 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6590 | return -EOPNOTSUPP; |
| 6591 | |
| 6592 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 6593 | if (err) |
| 6594 | return err; |
| 6595 | |
| 6596 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6597 | if (!msg) |
| 6598 | return -ENOMEM; |
| 6599 | |
| 6600 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6601 | dev, dst, mpp, &pinfo) < 0) { |
| 6602 | nlmsg_free(msg); |
| 6603 | return -ENOBUFS; |
| 6604 | } |
| 6605 | |
| 6606 | return genlmsg_reply(msg, info); |
| 6607 | } |
| 6608 | |
| 6609 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 6610 | struct netlink_callback *cb) |
| 6611 | { |
| 6612 | struct mpath_info pinfo; |
| 6613 | struct cfg80211_registered_device *rdev; |
| 6614 | struct wireless_dev *wdev; |
| 6615 | u8 dst[ETH_ALEN]; |
| 6616 | u8 mpp[ETH_ALEN]; |
| 6617 | int path_idx = cb->args[2]; |
| 6618 | int err; |
| 6619 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6620 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6621 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6622 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6623 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6624 | |
| 6625 | if (!rdev->ops->dump_mpp) { |
| 6626 | err = -EOPNOTSUPP; |
| 6627 | goto out_err; |
| 6628 | } |
| 6629 | |
| 6630 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6631 | err = -EOPNOTSUPP; |
| 6632 | goto out_err; |
| 6633 | } |
| 6634 | |
| 6635 | while (1) { |
| 6636 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 6637 | mpp, &pinfo); |
| 6638 | if (err == -ENOENT) |
| 6639 | break; |
| 6640 | if (err) |
| 6641 | goto out_err; |
| 6642 | |
| 6643 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6644 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6645 | wdev->netdev, dst, mpp, |
| 6646 | &pinfo) < 0) |
| 6647 | goto out; |
| 6648 | |
| 6649 | path_idx++; |
| 6650 | } |
| 6651 | |
| 6652 | out: |
| 6653 | cb->args[2] = path_idx; |
| 6654 | err = skb->len; |
| 6655 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6656 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6657 | return err; |
| 6658 | } |
| 6659 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6660 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 6661 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6662 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6663 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6664 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6665 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6666 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6667 | |
| 6668 | memset(¶ms, 0, sizeof(params)); |
| 6669 | /* default to not changing parameters */ |
| 6670 | params.use_cts_prot = -1; |
| 6671 | params.use_short_preamble = -1; |
| 6672 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6673 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6674 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6675 | params.p2p_ctwindow = -1; |
| 6676 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6677 | |
| 6678 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 6679 | params.use_cts_prot = |
| 6680 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 6681 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 6682 | params.use_short_preamble = |
| 6683 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 6684 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 6685 | params.use_short_slot_time = |
| 6686 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 6687 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6688 | params.basic_rates = |
| 6689 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6690 | params.basic_rates_len = |
| 6691 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6692 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6693 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 6694 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6695 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 6696 | params.ht_opmode = |
| 6697 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6698 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6699 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 6700 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6701 | return -EINVAL; |
| 6702 | params.p2p_ctwindow = |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6703 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6704 | if (params.p2p_ctwindow != 0 && |
| 6705 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 6706 | return -EINVAL; |
| 6707 | } |
| 6708 | |
| 6709 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 6710 | u8 tmp; |
| 6711 | |
| 6712 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6713 | return -EINVAL; |
| 6714 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6715 | params.p2p_opp_ps = tmp; |
| 6716 | if (params.p2p_opp_ps && |
| 6717 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 6718 | return -EINVAL; |
| 6719 | } |
| 6720 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6721 | if (!rdev->ops->change_bss) |
| 6722 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6723 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6724 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6725 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6726 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6727 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6728 | wdev_lock(wdev); |
| 6729 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 6730 | wdev_unlock(wdev); |
| 6731 | |
| 6732 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6733 | } |
| 6734 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6735 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 6736 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6737 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6738 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6739 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6740 | u32 owner_nlportid; |
| 6741 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6742 | /* |
| 6743 | * You should only get this when cfg80211 hasn't yet initialized |
| 6744 | * completely when built-in to the kernel right between the time |
| 6745 | * window between nl80211_init() and regulatory_init(), if that is |
| 6746 | * even possible. |
| 6747 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 6748 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 6749 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 6750 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6751 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 6752 | user_reg_hint_type = |
| 6753 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 6754 | else |
| 6755 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 6756 | |
| 6757 | switch (user_reg_hint_type) { |
| 6758 | case NL80211_USER_REG_HINT_USER: |
| 6759 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 6760 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 6761 | return -EINVAL; |
| 6762 | |
| 6763 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 6764 | return regulatory_hint_user(data, user_reg_hint_type); |
| 6765 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 6766 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 6767 | owner_nlportid = info->snd_portid; |
| 6768 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 6769 | } else { |
| 6770 | owner_nlportid = 0; |
| 6771 | is_indoor = true; |
| 6772 | } |
| 6773 | |
| 6774 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 6775 | default: |
| 6776 | return -EINVAL; |
| 6777 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 6778 | } |
| 6779 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 6780 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 6781 | { |
| 6782 | return reg_reload_regdb(); |
| 6783 | } |
| 6784 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6785 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6786 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6787 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6788 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6789 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6790 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 6791 | struct mesh_config cur_params; |
| 6792 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6793 | void *hdr; |
| 6794 | struct nlattr *pinfoattr; |
| 6795 | struct sk_buff *msg; |
| 6796 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6797 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6798 | return -EOPNOTSUPP; |
| 6799 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6800 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6801 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 6802 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6803 | wdev_lock(wdev); |
| 6804 | /* If not connected, get default parameters */ |
| 6805 | if (!wdev->mesh_id_len) |
| 6806 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 6807 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6808 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 6809 | wdev_unlock(wdev); |
| 6810 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6811 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6812 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6813 | |
| 6814 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6815 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6816 | if (!msg) |
| 6817 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6818 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6819 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6820 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6821 | goto out; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6822 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6823 | if (!pinfoattr) |
| 6824 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6825 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6826 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 6827 | cur_params.dot11MeshRetryTimeout) || |
| 6828 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6829 | cur_params.dot11MeshConfirmTimeout) || |
| 6830 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6831 | cur_params.dot11MeshHoldingTimeout) || |
| 6832 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6833 | cur_params.dot11MeshMaxPeerLinks) || |
| 6834 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 6835 | cur_params.dot11MeshMaxRetries) || |
| 6836 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 6837 | cur_params.dot11MeshTTL) || |
| 6838 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 6839 | cur_params.element_ttl) || |
| 6840 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 6841 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 6842 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 6843 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6844 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 6845 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 6846 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 6847 | cur_params.path_refresh_time) || |
| 6848 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 6849 | cur_params.min_discovery_timeout) || |
| 6850 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 6851 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 6852 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 6853 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 6854 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 6855 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 6856 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 6857 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 6858 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 6859 | cur_params.dot11MeshHWMPRootMode) || |
| 6860 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 6861 | cur_params.dot11MeshHWMPRannInterval) || |
| 6862 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 6863 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 6864 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 6865 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 6866 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 6867 | cur_params.rssi_threshold) || |
| 6868 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6869 | cur_params.ht_opmode) || |
| 6870 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 6871 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 6872 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 6873 | cur_params.dot11MeshHWMProotInterval) || |
| 6874 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6875 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 6876 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 6877 | cur_params.power_mode) || |
| 6878 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6879 | cur_params.dot11MeshAwakeWindowDuration) || |
| 6880 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6881 | cur_params.plink_timeout) || |
| 6882 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 6883 | cur_params.dot11MeshConnectedToMeshGate) || |
| 6884 | nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 6885 | cur_params.dot11MeshNolearn) || |
| 6886 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, |
| 6887 | cur_params.dot11MeshConnectedToAuthServer)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6888 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6889 | nla_nest_end(msg, pinfoattr); |
| 6890 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6891 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6892 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6893 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 6894 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 6895 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6896 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6897 | } |
| 6898 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6899 | static const struct nla_policy |
| 6900 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 6901 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 6902 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6903 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 6904 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6905 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 6906 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 6907 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 6908 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 6909 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 6910 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 6911 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 6912 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6913 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 6914 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6915 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 6916 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6917 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6918 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6919 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 6920 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6921 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 6922 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6923 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 6924 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6925 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 6926 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 6927 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6928 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6929 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 6930 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 6931 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 6932 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 6933 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6934 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 6935 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6936 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 6937 | NLA_POLICY_MIN(NLA_U16, 1), |
| 6938 | [NL80211_MESHCONF_POWER_MODE] = |
| 6939 | NLA_POLICY_RANGE(NLA_U32, |
| 6940 | NL80211_MESH_POWER_ACTIVE, |
| 6941 | NL80211_MESH_POWER_MAX), |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6942 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 6943 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 6944 | [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 6945 | [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 6946 | [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6947 | }; |
| 6948 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6949 | static const struct nla_policy |
| 6950 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 6951 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6952 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 6953 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 6954 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 6955 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 6956 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 6957 | [NL80211_MESH_SETUP_IE] = |
| 6958 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 6959 | IEEE80211_MAX_DATA_LEN), |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 6960 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 6961 | }; |
| 6962 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6963 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6964 | struct mesh_config *cfg, |
| 6965 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6966 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6967 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6968 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 6969 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6970 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6971 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 6972 | do { \ |
| 6973 | if (tb[attr]) { \ |
| 6974 | cfg->param = fn(tb[attr]); \ |
| 6975 | mask |= BIT((attr) - 1); \ |
| 6976 | } \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 6977 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 6978 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 6979 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6980 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 6981 | if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack)) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6982 | return -EINVAL; |
| 6983 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 6984 | /* This makes sure that there aren't more than 32 mesh config |
| 6985 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 6986 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 6987 | |
| 6988 | /* Fill in the params struct */ |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6989 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 6990 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 6991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 6992 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 6993 | nla_get_u16); |
| 6994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 6995 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 6996 | nla_get_u16); |
| 6997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 6998 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 6999 | nla_get_u16); |
| 7000 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 7001 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 7002 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 7003 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 7004 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 7005 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 7006 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 7007 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7008 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7010 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7011 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7012 | nla_get_u32); |
| 7013 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 7014 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7015 | nla_get_u8); |
| 7016 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 7017 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7018 | nla_get_u32); |
| 7019 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 7020 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 7021 | return -EINVAL; |
| 7022 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 7023 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7024 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7025 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7026 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7027 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7028 | nla_get_u32); |
| 7029 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 7030 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 7031 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 7032 | return -EINVAL; |
| 7033 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7034 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7035 | nla_get_u16); |
| 7036 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7037 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7038 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7039 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7040 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7041 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7042 | nla_get_u16); |
| 7043 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 7044 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 7045 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 7046 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7047 | nla_get_u16); |
| 7048 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7049 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7050 | nla_get_u8); |
| 7051 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 7052 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 7053 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 7054 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 7055 | nla_get_s32); |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7056 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 7057 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 7058 | nla_get_u8); |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7059 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, |
| 7060 | NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7061 | nla_get_u8); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7062 | /* |
| 7063 | * Check HT operation mode based on |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7064 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7065 | */ |
| 7066 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 7067 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 7068 | |
| 7069 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 7070 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 7071 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 7072 | return -EINVAL; |
| 7073 | |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7074 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 7075 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7076 | |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7077 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 7078 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7079 | } |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7080 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7081 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 7082 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7083 | nla_get_u32); |
| 7084 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 7085 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 7086 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 7087 | return -EINVAL; |
| 7088 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 7089 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7090 | nla_get_u16); |
| 7091 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 7092 | mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7093 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7094 | nla_get_u16); |
| 7095 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 7096 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 7097 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 7098 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 7099 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 7100 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7101 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, |
| 7102 | NL80211_MESHCONF_NOLEARN, nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7103 | if (mask_out) |
| 7104 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7105 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7106 | return 0; |
| 7107 | |
| 7108 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 7109 | } |
| 7110 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7111 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 7112 | struct mesh_setup *setup) |
| 7113 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7115 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 7116 | |
| 7117 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 7118 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7119 | if (nla_parse_nested_deprecated(tb, NL80211_MESH_SETUP_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_SETUP], nl80211_mesh_setup_params_policy, info->extack)) |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7120 | return -EINVAL; |
| 7121 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7122 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 7123 | setup->sync_method = |
| 7124 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 7125 | IEEE80211_SYNC_METHOD_VENDOR : |
| 7126 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 7127 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7128 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 7129 | setup->path_sel_proto = |
| 7130 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 7131 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 7132 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 7133 | |
| 7134 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 7135 | setup->path_metric = |
| 7136 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 7137 | IEEE80211_PATH_METRIC_VENDOR : |
| 7138 | IEEE80211_PATH_METRIC_AIRTIME; |
| 7139 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7140 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7141 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7142 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7143 | setup->ie = nla_data(ieattr); |
| 7144 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7145 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7146 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 7147 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 7148 | return -EINVAL; |
| 7149 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7150 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 7151 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7152 | if (setup->is_secure) |
| 7153 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7154 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7155 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 7156 | if (!setup->user_mpm) |
| 7157 | return -EINVAL; |
| 7158 | setup->auth_id = |
| 7159 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 7160 | } |
| 7161 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7162 | return 0; |
| 7163 | } |
| 7164 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7165 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7166 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7167 | { |
| 7168 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7169 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7170 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7171 | struct mesh_config cfg; |
| 7172 | u32 mask; |
| 7173 | int err; |
| 7174 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7175 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7176 | return -EOPNOTSUPP; |
| 7177 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7178 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7179 | return -EOPNOTSUPP; |
| 7180 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7181 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7182 | if (err) |
| 7183 | return err; |
| 7184 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7185 | wdev_lock(wdev); |
| 7186 | if (!wdev->mesh_id_len) |
| 7187 | err = -ENOLINK; |
| 7188 | |
| 7189 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7190 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7191 | |
| 7192 | wdev_unlock(wdev); |
| 7193 | |
| 7194 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7195 | } |
| 7196 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7197 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 7198 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7199 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7200 | struct nlattr *nl_reg_rules; |
| 7201 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7202 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7203 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 7204 | (regdom->dfs_region && |
| 7205 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7206 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7207 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7208 | nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7209 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7210 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7211 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7212 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7213 | struct nlattr *nl_reg_rule; |
| 7214 | const struct ieee80211_reg_rule *reg_rule; |
| 7215 | const struct ieee80211_freq_range *freq_range; |
| 7216 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7217 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7218 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7219 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7220 | freq_range = ®_rule->freq_range; |
| 7221 | power_rule = ®_rule->power_rule; |
| 7222 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7223 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7224 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7225 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7226 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7227 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 7228 | if (!max_bandwidth_khz) |
| 7229 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 7230 | reg_rule); |
| 7231 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7232 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 7233 | reg_rule->flags) || |
| 7234 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 7235 | freq_range->start_freq_khz) || |
| 7236 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 7237 | freq_range->end_freq_khz) || |
| 7238 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7239 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7240 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 7241 | power_rule->max_antenna_gain) || |
| 7242 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 7243 | power_rule->max_eirp) || |
| 7244 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 7245 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7246 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7247 | |
| 7248 | nla_nest_end(msg, nl_reg_rule); |
| 7249 | } |
| 7250 | |
| 7251 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7252 | return 0; |
| 7253 | |
| 7254 | nla_put_failure: |
| 7255 | return -EMSGSIZE; |
| 7256 | } |
| 7257 | |
| 7258 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 7259 | { |
| 7260 | const struct ieee80211_regdomain *regdom = NULL; |
| 7261 | struct cfg80211_registered_device *rdev; |
| 7262 | struct wiphy *wiphy = NULL; |
| 7263 | struct sk_buff *msg; |
| 7264 | void *hdr; |
| 7265 | |
| 7266 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7267 | if (!msg) |
| 7268 | return -ENOBUFS; |
| 7269 | |
| 7270 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7271 | NL80211_CMD_GET_REG); |
| 7272 | if (!hdr) |
| 7273 | goto put_failure; |
| 7274 | |
| 7275 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7276 | bool self_managed; |
| 7277 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7278 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 7279 | if (IS_ERR(rdev)) { |
| 7280 | nlmsg_free(msg); |
| 7281 | return PTR_ERR(rdev); |
| 7282 | } |
| 7283 | |
| 7284 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7285 | self_managed = wiphy->regulatory_flags & |
| 7286 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7287 | regdom = get_wiphy_regdom(wiphy); |
| 7288 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7289 | /* a self-managed-reg device must have a private regdom */ |
| 7290 | if (WARN_ON(!regdom && self_managed)) { |
| 7291 | nlmsg_free(msg); |
| 7292 | return -EINVAL; |
| 7293 | } |
| 7294 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7295 | if (regdom && |
| 7296 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7297 | goto nla_put_failure; |
| 7298 | } |
| 7299 | |
| 7300 | if (!wiphy && reg_last_request_cell_base() && |
| 7301 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7302 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7303 | goto nla_put_failure; |
| 7304 | |
| 7305 | rcu_read_lock(); |
| 7306 | |
| 7307 | if (!regdom) |
| 7308 | regdom = rcu_dereference(cfg80211_regdomain); |
| 7309 | |
| 7310 | if (nl80211_put_regdom(regdom, msg)) |
| 7311 | goto nla_put_failure_rcu; |
| 7312 | |
| 7313 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7314 | |
| 7315 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7316 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7317 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7318 | nla_put_failure_rcu: |
| 7319 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7320 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7321 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7322 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7323 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7324 | } |
| 7325 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7326 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 7327 | u32 seq, int flags, struct wiphy *wiphy, |
| 7328 | const struct ieee80211_regdomain *regdom) |
| 7329 | { |
| 7330 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 7331 | NL80211_CMD_GET_REG); |
| 7332 | |
| 7333 | if (!hdr) |
| 7334 | return -1; |
| 7335 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 7336 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7337 | |
| 7338 | if (nl80211_put_regdom(regdom, msg)) |
| 7339 | goto nla_put_failure; |
| 7340 | |
| 7341 | if (!wiphy && reg_last_request_cell_base() && |
| 7342 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7343 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7344 | goto nla_put_failure; |
| 7345 | |
| 7346 | if (wiphy && |
| 7347 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7348 | goto nla_put_failure; |
| 7349 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7350 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 7351 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 7352 | goto nla_put_failure; |
| 7353 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7354 | genlmsg_end(msg, hdr); |
| 7355 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7356 | |
| 7357 | nla_put_failure: |
| 7358 | genlmsg_cancel(msg, hdr); |
| 7359 | return -EMSGSIZE; |
| 7360 | } |
| 7361 | |
| 7362 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 7363 | struct netlink_callback *cb) |
| 7364 | { |
| 7365 | const struct ieee80211_regdomain *regdom = NULL; |
| 7366 | struct cfg80211_registered_device *rdev; |
| 7367 | int err, reg_idx, start = cb->args[2]; |
| 7368 | |
| 7369 | rtnl_lock(); |
| 7370 | |
| 7371 | if (cfg80211_regdomain && start == 0) { |
| 7372 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7373 | NLM_F_MULTI, NULL, |
| 7374 | rtnl_dereference(cfg80211_regdomain)); |
| 7375 | if (err < 0) |
| 7376 | goto out_err; |
| 7377 | } |
| 7378 | |
| 7379 | /* the global regdom is idx 0 */ |
| 7380 | reg_idx = 1; |
| 7381 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 7382 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 7383 | if (!regdom) |
| 7384 | continue; |
| 7385 | |
| 7386 | if (++reg_idx <= start) |
| 7387 | continue; |
| 7388 | |
| 7389 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7390 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 7391 | if (err < 0) { |
| 7392 | reg_idx--; |
| 7393 | break; |
| 7394 | } |
| 7395 | } |
| 7396 | |
| 7397 | cb->args[2] = reg_idx; |
| 7398 | err = skb->len; |
| 7399 | out_err: |
| 7400 | rtnl_unlock(); |
| 7401 | return err; |
| 7402 | } |
| 7403 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7404 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 7405 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 7406 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 7407 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 7408 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 7409 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 7410 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 7411 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 7412 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 7413 | }; |
| 7414 | |
| 7415 | static int parse_reg_rule(struct nlattr *tb[], |
| 7416 | struct ieee80211_reg_rule *reg_rule) |
| 7417 | { |
| 7418 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 7419 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 7420 | |
| 7421 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 7422 | return -EINVAL; |
| 7423 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 7424 | return -EINVAL; |
| 7425 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 7426 | return -EINVAL; |
| 7427 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 7428 | return -EINVAL; |
| 7429 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 7430 | return -EINVAL; |
| 7431 | |
| 7432 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 7433 | |
| 7434 | freq_range->start_freq_khz = |
| 7435 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 7436 | freq_range->end_freq_khz = |
| 7437 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 7438 | freq_range->max_bandwidth_khz = |
| 7439 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 7440 | |
| 7441 | power_rule->max_eirp = |
| 7442 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 7443 | |
| 7444 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 7445 | power_rule->max_antenna_gain = |
| 7446 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 7447 | |
| 7448 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 7449 | reg_rule->dfs_cac_ms = |
| 7450 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 7451 | |
| 7452 | return 0; |
| 7453 | } |
| 7454 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7455 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7456 | { |
| 7457 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 7458 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7459 | char *alpha2; |
| 7460 | int rem_reg_rules, r; |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7461 | u32 num_rules = 0, rule_idx = 0; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 7462 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7463 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7464 | |
| 7465 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7466 | return -EINVAL; |
| 7467 | |
| 7468 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 7469 | return -EINVAL; |
| 7470 | |
| 7471 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7472 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7473 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 7474 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 7475 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7476 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 7477 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7478 | num_rules++; |
| 7479 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 7480 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7481 | } |
| 7482 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 7483 | if (!reg_is_valid_request(alpha2)) |
| 7484 | return -EINVAL; |
| 7485 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7486 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 7487 | if (!rd) |
| 7488 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7489 | |
| 7490 | rd->n_reg_rules = num_rules; |
| 7491 | rd->alpha2[0] = alpha2[0]; |
| 7492 | rd->alpha2[1] = alpha2[1]; |
| 7493 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7494 | /* |
| 7495 | * Disable DFS master mode if the DFS region was |
| 7496 | * not supported or known on this kernel. |
| 7497 | */ |
| 7498 | if (reg_supported_dfs_region(dfs_region)) |
| 7499 | rd->dfs_region = dfs_region; |
| 7500 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7501 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
Johannes Berg | 1a91931 | 2012-12-03 17:21:11 +0100 | [diff] [blame] | 7502 | rem_reg_rules) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7503 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
| 7504 | nl_reg_rule, reg_rule_policy, |
| 7505 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7506 | if (r) |
| 7507 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7508 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 7509 | if (r) |
| 7510 | goto bad_reg; |
| 7511 | |
| 7512 | rule_idx++; |
| 7513 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7514 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 7515 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7516 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7517 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7518 | } |
| 7519 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 7520 | /* set_regdom takes ownership of rd */ |
| 7521 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 7522 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7523 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7524 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7525 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7526 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7527 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7528 | static int validate_scan_freqs(struct nlattr *freqs) |
| 7529 | { |
| 7530 | struct nlattr *attr1, *attr2; |
| 7531 | int n_channels = 0, tmp1, tmp2; |
| 7532 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 7533 | nla_for_each_nested(attr1, freqs, tmp1) |
| 7534 | if (nla_len(attr1) != sizeof(u32)) |
| 7535 | return 0; |
| 7536 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7537 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 7538 | n_channels++; |
| 7539 | /* |
| 7540 | * Some hardware has a limited channel list for |
| 7541 | * scanning, and it is pretty much nonsensical |
| 7542 | * to scan for a channel twice, so disallow that |
| 7543 | * and don't require drivers to check that the |
| 7544 | * channel list they get isn't longer than what |
| 7545 | * they can scan, as long as they can scan all |
| 7546 | * the channels they registered at once. |
| 7547 | */ |
| 7548 | nla_for_each_nested(attr2, freqs, tmp2) |
| 7549 | if (attr1 != attr2 && |
| 7550 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 7551 | return 0; |
| 7552 | } |
| 7553 | |
| 7554 | return n_channels; |
| 7555 | } |
| 7556 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7557 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7558 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7559 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7560 | } |
| 7561 | |
| 7562 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 7563 | struct cfg80211_bss_selection *bss_select) |
| 7564 | { |
| 7565 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 7566 | struct nlattr *nest; |
| 7567 | int err; |
| 7568 | bool found = false; |
| 7569 | int i; |
| 7570 | |
| 7571 | /* only process one nested attribute */ |
| 7572 | nest = nla_data(nla); |
| 7573 | if (!nla_ok(nest, nla_len(nest))) |
| 7574 | return -EINVAL; |
| 7575 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7576 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
| 7577 | nest, nl80211_bss_select_policy, |
| 7578 | NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7579 | if (err) |
| 7580 | return err; |
| 7581 | |
| 7582 | /* only one attribute may be given */ |
| 7583 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 7584 | if (attr[i]) { |
| 7585 | if (found) |
| 7586 | return -EINVAL; |
| 7587 | found = true; |
| 7588 | } |
| 7589 | } |
| 7590 | |
| 7591 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 7592 | |
| 7593 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 7594 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 7595 | |
| 7596 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 7597 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 7598 | bss_select->param.band_pref = |
| 7599 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 7600 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 7601 | return -EINVAL; |
| 7602 | } |
| 7603 | |
| 7604 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 7605 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 7606 | |
| 7607 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 7608 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 7609 | bss_select->param.adjust.band = adj_param->band; |
| 7610 | bss_select->param.adjust.delta = adj_param->delta; |
| 7611 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 7612 | return -EINVAL; |
| 7613 | } |
| 7614 | |
| 7615 | /* user-space did not provide behaviour attribute */ |
| 7616 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 7617 | return -EINVAL; |
| 7618 | |
| 7619 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 7620 | return -EINVAL; |
| 7621 | |
| 7622 | return 0; |
| 7623 | } |
| 7624 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 7625 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 7626 | u8 *mac_addr, u8 *mac_addr_mask) |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7627 | { |
| 7628 | int i; |
| 7629 | |
| 7630 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 7631 | eth_zero_addr(mac_addr); |
| 7632 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7633 | mac_addr[0] = 0x2; |
| 7634 | mac_addr_mask[0] = 0x3; |
| 7635 | |
| 7636 | return 0; |
| 7637 | } |
| 7638 | |
| 7639 | /* need both or none */ |
| 7640 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 7641 | return -EINVAL; |
| 7642 | |
| 7643 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 7644 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 7645 | |
| 7646 | /* don't allow or configure an mcast address */ |
| 7647 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 7648 | is_multicast_ether_addr(mac_addr)) |
| 7649 | return -EINVAL; |
| 7650 | |
| 7651 | /* |
| 7652 | * allow users to pass a MAC address that has bits set outside |
| 7653 | * of the mask, but don't bother drivers with having to deal |
| 7654 | * with such bits |
| 7655 | */ |
| 7656 | for (i = 0; i < ETH_ALEN; i++) |
| 7657 | mac_addr[i] &= mac_addr_mask[i]; |
| 7658 | |
| 7659 | return 0; |
| 7660 | } |
| 7661 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7662 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 7663 | { |
| 7664 | ASSERT_WDEV_LOCK(wdev); |
| 7665 | |
| 7666 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 7667 | return true; |
| 7668 | |
| 7669 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 7670 | return true; |
| 7671 | |
| 7672 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 7673 | } |
| 7674 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7675 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 7676 | enum nl80211_ext_feature_index feat) |
| 7677 | { |
| 7678 | if (!(flags & flag)) |
| 7679 | return true; |
| 7680 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 7681 | return true; |
| 7682 | return false; |
| 7683 | } |
| 7684 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7685 | static int |
| 7686 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 7687 | void *request, struct nlattr **attrs, |
| 7688 | bool is_sched_scan) |
| 7689 | { |
| 7690 | u8 *mac_addr, *mac_addr_mask; |
| 7691 | u32 *flags; |
| 7692 | enum nl80211_feature_flags randomness_flag; |
| 7693 | |
| 7694 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 7695 | return 0; |
| 7696 | |
| 7697 | if (is_sched_scan) { |
| 7698 | struct cfg80211_sched_scan_request *req = request; |
| 7699 | |
| 7700 | randomness_flag = wdev ? |
| 7701 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 7702 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7703 | flags = &req->flags; |
| 7704 | mac_addr = req->mac_addr; |
| 7705 | mac_addr_mask = req->mac_addr_mask; |
| 7706 | } else { |
| 7707 | struct cfg80211_scan_request *req = request; |
| 7708 | |
| 7709 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 7710 | flags = &req->flags; |
| 7711 | mac_addr = req->mac_addr; |
| 7712 | mac_addr_mask = req->mac_addr_mask; |
| 7713 | } |
| 7714 | |
| 7715 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 7716 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 7717 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 7718 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7719 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7720 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 7721 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 7722 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7723 | NL80211_SCAN_FLAG_LOW_POWER, |
| 7724 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 7725 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7726 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 7727 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 7728 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7729 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 7730 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 7731 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7732 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 7733 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 7734 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7735 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 7736 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 7737 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7738 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 7739 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 7740 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7741 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 7742 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 7743 | !nl80211_check_scan_feat(wiphy, *flags, |
| 7744 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 7745 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7746 | return -EOPNOTSUPP; |
| 7747 | |
| 7748 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 7749 | int err; |
| 7750 | |
| 7751 | if (!(wiphy->features & randomness_flag) || |
| 7752 | (wdev && wdev->current_bss)) |
| 7753 | return -EOPNOTSUPP; |
| 7754 | |
| 7755 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 7756 | if (err) |
| 7757 | return err; |
| 7758 | } |
| 7759 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7760 | return 0; |
| 7761 | } |
| 7762 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7763 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 7764 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7766 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7767 | struct cfg80211_scan_request *request; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7768 | struct nlattr *scan_freqs = NULL; |
| 7769 | bool scan_freqs_khz = false; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7770 | struct nlattr *attr; |
| 7771 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7772 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7773 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7774 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7775 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7776 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 7777 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 7778 | return -EOPNOTSUPP; |
| 7779 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7780 | if (!rdev->ops->scan) |
| 7781 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7782 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7783 | if (rdev->scan_req || rdev->scan_msg) |
| 7784 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7785 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7786 | if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { |
| 7787 | if (!wiphy_ext_feature_isset(wiphy, |
| 7788 | NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) |
| 7789 | return -EOPNOTSUPP; |
| 7790 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; |
| 7791 | scan_freqs_khz = true; |
| 7792 | } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) |
| 7793 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; |
| 7794 | |
| 7795 | if (scan_freqs) { |
| 7796 | n_channels = validate_scan_freqs(scan_freqs); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7797 | if (!n_channels) |
| 7798 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7799 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 7800 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7801 | } |
| 7802 | |
| 7803 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 7804 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 7805 | n_ssids++; |
| 7806 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7807 | if (n_ssids > wiphy->max_scan_ssids) |
| 7808 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7809 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7810 | if (info->attrs[NL80211_ATTR_IE]) |
| 7811 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 7812 | else |
| 7813 | ie_len = 0; |
| 7814 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7815 | if (ie_len > wiphy->max_scan_ie_len) |
| 7816 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 7817 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7818 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 7819 | + sizeof(*request->ssids) * n_ssids |
| 7820 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7821 | + ie_len, GFP_KERNEL); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 7822 | if (!request) |
| 7823 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7824 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7825 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 7826 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7827 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7828 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7829 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7830 | request->ie = (void *)(request->ssids + n_ssids); |
| 7831 | else |
| 7832 | request->ie = (void *)(request->channels + n_channels); |
| 7833 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7834 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7835 | i = 0; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7836 | if (scan_freqs) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7837 | /* user specified, bail out if channel not found */ |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7838 | nla_for_each_nested(attr, scan_freqs, tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7839 | struct ieee80211_channel *chan; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7840 | int freq = nla_get_u32(attr); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7841 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7842 | if (!scan_freqs_khz) |
| 7843 | freq = MHZ_TO_KHZ(freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7844 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 7845 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7846 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7847 | err = -EINVAL; |
| 7848 | goto out_free; |
| 7849 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7850 | |
| 7851 | /* ignore disabled channels */ |
| 7852 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7853 | continue; |
| 7854 | |
| 7855 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7856 | i++; |
| 7857 | } |
| 7858 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7859 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7860 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7861 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7862 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7863 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 7864 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7865 | if (!wiphy->bands[band]) |
| 7866 | continue; |
| 7867 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7868 | struct ieee80211_channel *chan; |
| 7869 | |
| 7870 | chan = &wiphy->bands[band]->channels[j]; |
| 7871 | |
| 7872 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 7873 | continue; |
| 7874 | |
| 7875 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7876 | i++; |
| 7877 | } |
| 7878 | } |
| 7879 | } |
| 7880 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 7881 | if (!i) { |
| 7882 | err = -EINVAL; |
| 7883 | goto out_free; |
| 7884 | } |
| 7885 | |
| 7886 | request->n_channels = i; |
| 7887 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7888 | wdev_lock(wdev); |
| 7889 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 7890 | struct ieee80211_channel *chan; |
| 7891 | |
| 7892 | if (request->n_channels != 1) { |
| 7893 | wdev_unlock(wdev); |
| 7894 | err = -EBUSY; |
| 7895 | goto out_free; |
| 7896 | } |
| 7897 | |
| 7898 | chan = request->channels[0]; |
| 7899 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 7900 | wdev_unlock(wdev); |
| 7901 | err = -EBUSY; |
| 7902 | goto out_free; |
| 7903 | } |
| 7904 | } |
| 7905 | wdev_unlock(wdev); |
| 7906 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7907 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 7908 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7909 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7910 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7911 | err = -EINVAL; |
| 7912 | goto out_free; |
| 7913 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 7914 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7915 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7916 | i++; |
| 7917 | } |
| 7918 | } |
| 7919 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7920 | if (info->attrs[NL80211_ATTR_IE]) { |
| 7921 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 7922 | memcpy((void *)request->ie, |
| 7923 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 7924 | request->ie_len); |
| 7925 | } |
| 7926 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7927 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 7928 | if (wiphy->bands[i]) |
| 7929 | request->rates[i] = |
| 7930 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7931 | |
| 7932 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 7933 | nla_for_each_nested(attr, |
| 7934 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 7935 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7936 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7937 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7938 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7939 | err = -EINVAL; |
| 7940 | goto out_free; |
| 7941 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 7942 | |
| 7943 | if (!wiphy->bands[band]) |
| 7944 | continue; |
| 7945 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 7946 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 7947 | nla_data(attr), |
| 7948 | nla_len(attr), |
| 7949 | &request->rates[band]); |
| 7950 | if (err) |
| 7951 | goto out_free; |
| 7952 | } |
| 7953 | } |
| 7954 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 7955 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 7956 | if (!wiphy_ext_feature_isset(wiphy, |
| 7957 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 7958 | err = -EOPNOTSUPP; |
| 7959 | goto out_free; |
| 7960 | } |
| 7961 | |
| 7962 | request->duration = |
| 7963 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 7964 | request->duration_mandatory = |
| 7965 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 7966 | } |
| 7967 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7968 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 7969 | false); |
| 7970 | if (err) |
| 7971 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 7972 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 7973 | request->no_cck = |
| 7974 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 7975 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 7976 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 7977 | * BSSID to scan for. This was problematic because that same attribute |
| 7978 | * was already used for another purpose (local random MAC address). The |
| 7979 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 7980 | * compatibility with older userspace components, also use the |
| 7981 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 7982 | * the specific BSSID use case instead of the random MAC address |
| 7983 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 7984 | */ |
| 7985 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 7986 | memcpy(request->bssid, |
| 7987 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 7988 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 7989 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 7990 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 7991 | ETH_ALEN); |
| 7992 | else |
| 7993 | eth_broadcast_addr(request->bssid); |
| 7994 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 7995 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7996 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 7997 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 7998 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 7999 | rdev->scan_req = request; |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 8000 | err = rdev_scan(rdev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8001 | |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8002 | if (err) |
| 8003 | goto out_free; |
| 8004 | |
| 8005 | nl80211_send_scan_start(rdev, wdev); |
| 8006 | if (wdev->netdev) |
| 8007 | dev_hold(wdev->netdev); |
| 8008 | |
| 8009 | return 0; |
| 8010 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8011 | out_free: |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8012 | rdev->scan_req = NULL; |
| 8013 | kfree(request); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 8014 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8015 | return err; |
| 8016 | } |
| 8017 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 8018 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 8019 | { |
| 8020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8021 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8022 | |
| 8023 | if (!rdev->ops->abort_scan) |
| 8024 | return -EOPNOTSUPP; |
| 8025 | |
| 8026 | if (rdev->scan_msg) |
| 8027 | return 0; |
| 8028 | |
| 8029 | if (!rdev->scan_req) |
| 8030 | return -ENOENT; |
| 8031 | |
| 8032 | rdev_abort_scan(rdev, wdev); |
| 8033 | return 0; |
| 8034 | } |
| 8035 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8036 | static int |
| 8037 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 8038 | struct cfg80211_sched_scan_request *request, |
| 8039 | struct nlattr **attrs) |
| 8040 | { |
| 8041 | int tmp, err, i = 0; |
| 8042 | struct nlattr *attr; |
| 8043 | |
| 8044 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8045 | u32 interval; |
| 8046 | |
| 8047 | /* |
| 8048 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 8049 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8050 | * case one scan plan will be set with the specified scan |
| 8051 | * interval and infinite number of iterations. |
| 8052 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8053 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 8054 | if (!interval) |
| 8055 | return -EINVAL; |
| 8056 | |
| 8057 | request->scan_plans[0].interval = |
| 8058 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 8059 | if (!request->scan_plans[0].interval) |
| 8060 | return -EINVAL; |
| 8061 | |
| 8062 | if (request->scan_plans[0].interval > |
| 8063 | wiphy->max_sched_scan_plan_interval) |
| 8064 | request->scan_plans[0].interval = |
| 8065 | wiphy->max_sched_scan_plan_interval; |
| 8066 | |
| 8067 | return 0; |
| 8068 | } |
| 8069 | |
| 8070 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 8071 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 8072 | |
| 8073 | if (WARN_ON(i >= n_plans)) |
| 8074 | return -EINVAL; |
| 8075 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8076 | err = nla_parse_nested_deprecated(plan, |
| 8077 | NL80211_SCHED_SCAN_PLAN_MAX, |
| 8078 | attr, nl80211_plan_policy, |
| 8079 | NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8080 | if (err) |
| 8081 | return err; |
| 8082 | |
| 8083 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 8084 | return -EINVAL; |
| 8085 | |
| 8086 | request->scan_plans[i].interval = |
| 8087 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 8088 | if (!request->scan_plans[i].interval || |
| 8089 | request->scan_plans[i].interval > |
| 8090 | wiphy->max_sched_scan_plan_interval) |
| 8091 | return -EINVAL; |
| 8092 | |
| 8093 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 8094 | request->scan_plans[i].iterations = |
| 8095 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 8096 | if (!request->scan_plans[i].iterations || |
| 8097 | (request->scan_plans[i].iterations > |
| 8098 | wiphy->max_sched_scan_plan_iterations)) |
| 8099 | return -EINVAL; |
| 8100 | } else if (i < n_plans - 1) { |
| 8101 | /* |
| 8102 | * All scan plans but the last one must specify |
| 8103 | * a finite number of iterations |
| 8104 | */ |
| 8105 | return -EINVAL; |
| 8106 | } |
| 8107 | |
| 8108 | i++; |
| 8109 | } |
| 8110 | |
| 8111 | /* |
| 8112 | * The last scan plan must not specify the number of |
| 8113 | * iterations, it is supposed to run infinitely |
| 8114 | */ |
| 8115 | if (request->scan_plans[n_plans - 1].iterations) |
| 8116 | return -EINVAL; |
| 8117 | |
| 8118 | return 0; |
| 8119 | } |
| 8120 | |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8121 | static int |
| 8122 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, |
| 8123 | struct cfg80211_match_set *match_sets, |
| 8124 | struct nlattr *tb_band_rssi, |
| 8125 | s32 rssi_thold) |
| 8126 | { |
| 8127 | struct nlattr *attr; |
| 8128 | int i, tmp, ret = 0; |
| 8129 | |
| 8130 | if (!wiphy_ext_feature_isset(wiphy, |
| 8131 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { |
| 8132 | if (tb_band_rssi) |
| 8133 | ret = -EOPNOTSUPP; |
| 8134 | else |
| 8135 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8136 | match_sets->per_band_rssi_thold[i] = |
| 8137 | NL80211_SCAN_RSSI_THOLD_OFF; |
| 8138 | return ret; |
| 8139 | } |
| 8140 | |
| 8141 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8142 | match_sets->per_band_rssi_thold[i] = rssi_thold; |
| 8143 | |
| 8144 | nla_for_each_nested(attr, tb_band_rssi, tmp) { |
| 8145 | enum nl80211_band band = nla_type(attr); |
| 8146 | |
| 8147 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 8148 | return -EINVAL; |
| 8149 | |
| 8150 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); |
| 8151 | } |
| 8152 | |
| 8153 | return 0; |
| 8154 | } |
| 8155 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8156 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8157 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8158 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8159 | { |
| 8160 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8161 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8162 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8163 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8164 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8165 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8166 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8167 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8168 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8169 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8170 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8171 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8172 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8173 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8174 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8175 | } |
| 8176 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8177 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8178 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8179 | tmp) |
| 8180 | n_ssids++; |
| 8181 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 8182 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8183 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8184 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8185 | /* |
| 8186 | * First, count the number of 'real' matchsets. Due to an issue with |
| 8187 | * the old implementation, matchsets containing only the RSSI attribute |
| 8188 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 8189 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 8190 | * all APs with a strong RSSI. This is needed to be compatible with |
| 8191 | * older userspace that treated a matchset with only the RSSI as the |
| 8192 | * global RSSI for all other matchsets - if there are other matchsets. |
| 8193 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8194 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8195 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8196 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8197 | tmp) { |
| 8198 | struct nlattr *rssi; |
| 8199 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8200 | err = nla_parse_nested_deprecated(tb, |
| 8201 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8202 | attr, |
| 8203 | nl80211_match_policy, |
| 8204 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8205 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8206 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8207 | |
| 8208 | /* SSID and BSSID are mutually exclusive */ |
| 8209 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 8210 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 8211 | return ERR_PTR(-EINVAL); |
| 8212 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8213 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8214 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 8215 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8216 | n_match_sets++; |
| 8217 | continue; |
| 8218 | } |
| 8219 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8220 | if (rssi) |
| 8221 | default_match_rssi = nla_get_s32(rssi); |
| 8222 | } |
| 8223 | } |
| 8224 | |
| 8225 | /* However, if there's no other matchset, add the RSSI one */ |
| 8226 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 8227 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8228 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8229 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8230 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8231 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8232 | if (attrs[NL80211_ATTR_IE]) |
| 8233 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8234 | else |
| 8235 | ie_len = 0; |
| 8236 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 8237 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8238 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 8239 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8240 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8241 | /* |
| 8242 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 8243 | * each scan plan already specifies its own interval |
| 8244 | */ |
| 8245 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8246 | return ERR_PTR(-EINVAL); |
| 8247 | |
| 8248 | nla_for_each_nested(attr, |
| 8249 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 8250 | n_plans++; |
| 8251 | } else { |
| 8252 | /* |
| 8253 | * The scan interval attribute is kept for backward |
| 8254 | * compatibility. If no scan plans are specified and sched scan |
| 8255 | * interval is specified, one scan plan will be set with this |
| 8256 | * scan interval and infinite number of iterations. |
| 8257 | */ |
| 8258 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8259 | return ERR_PTR(-EINVAL); |
| 8260 | |
| 8261 | n_plans = 1; |
| 8262 | } |
| 8263 | |
| 8264 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 8265 | return ERR_PTR(-EINVAL); |
| 8266 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8267 | if (!wiphy_ext_feature_isset( |
| 8268 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 8269 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 8270 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 8271 | return ERR_PTR(-EINVAL); |
| 8272 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8273 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8274 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8275 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8276 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8277 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8278 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8279 | if (!request) |
| 8280 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8281 | |
| 8282 | if (n_ssids) |
| 8283 | request->ssids = (void *)&request->channels[n_channels]; |
| 8284 | request->n_ssids = n_ssids; |
| 8285 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8286 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8287 | request->ie = (void *)(request->ssids + n_ssids); |
| 8288 | else |
| 8289 | request->ie = (void *)(request->channels + n_channels); |
| 8290 | } |
| 8291 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8292 | if (n_match_sets) { |
| 8293 | if (request->ie) |
| 8294 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8295 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8296 | request->match_sets = |
| 8297 | (void *)(request->ssids + n_ssids); |
| 8298 | else |
| 8299 | request->match_sets = |
| 8300 | (void *)(request->channels + n_channels); |
| 8301 | } |
| 8302 | request->n_match_sets = n_match_sets; |
| 8303 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8304 | if (n_match_sets) |
| 8305 | request->scan_plans = (void *)(request->match_sets + |
| 8306 | n_match_sets); |
| 8307 | else if (request->ie) |
| 8308 | request->scan_plans = (void *)(request->ie + ie_len); |
| 8309 | else if (n_ssids) |
| 8310 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 8311 | else |
| 8312 | request->scan_plans = (void *)(request->channels + n_channels); |
| 8313 | |
| 8314 | request->n_scan_plans = n_plans; |
| 8315 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8316 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8317 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8318 | /* user specified, bail out if channel not found */ |
| 8319 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8320 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8321 | tmp) { |
| 8322 | struct ieee80211_channel *chan; |
| 8323 | |
| 8324 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 8325 | |
| 8326 | if (!chan) { |
| 8327 | err = -EINVAL; |
| 8328 | goto out_free; |
| 8329 | } |
| 8330 | |
| 8331 | /* ignore disabled channels */ |
| 8332 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8333 | continue; |
| 8334 | |
| 8335 | request->channels[i] = chan; |
| 8336 | i++; |
| 8337 | } |
| 8338 | } else { |
| 8339 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8340 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8341 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8342 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8343 | if (!wiphy->bands[band]) |
| 8344 | continue; |
| 8345 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 8346 | struct ieee80211_channel *chan; |
| 8347 | |
| 8348 | chan = &wiphy->bands[band]->channels[j]; |
| 8349 | |
| 8350 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8351 | continue; |
| 8352 | |
| 8353 | request->channels[i] = chan; |
| 8354 | i++; |
| 8355 | } |
| 8356 | } |
| 8357 | } |
| 8358 | |
| 8359 | if (!i) { |
| 8360 | err = -EINVAL; |
| 8361 | goto out_free; |
| 8362 | } |
| 8363 | |
| 8364 | request->n_channels = i; |
| 8365 | |
| 8366 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8367 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8368 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8369 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8370 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8371 | err = -EINVAL; |
| 8372 | goto out_free; |
| 8373 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8374 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8375 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 8376 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8377 | i++; |
| 8378 | } |
| 8379 | } |
| 8380 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8381 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8382 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8383 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8384 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8385 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8386 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8387 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8388 | err = nla_parse_nested_deprecated(tb, |
| 8389 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8390 | attr, |
| 8391 | nl80211_match_policy, |
| 8392 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8393 | if (err) |
| 8394 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 8395 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8396 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8397 | |
| 8398 | if (!ssid && !bssid) { |
| 8399 | i++; |
| 8400 | continue; |
| 8401 | } |
| 8402 | |
| 8403 | if (WARN_ON(i >= n_match_sets)) { |
| 8404 | /* this indicates a programming error, |
| 8405 | * the loop above should have verified |
| 8406 | * things properly |
| 8407 | */ |
| 8408 | err = -EINVAL; |
| 8409 | goto out_free; |
| 8410 | } |
| 8411 | |
| 8412 | if (ssid) { |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8413 | memcpy(request->match_sets[i].ssid.ssid, |
| 8414 | nla_data(ssid), nla_len(ssid)); |
| 8415 | request->match_sets[i].ssid.ssid_len = |
| 8416 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8417 | } |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 8418 | if (bssid) |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8419 | memcpy(request->match_sets[i].bssid, |
| 8420 | nla_data(bssid), ETH_ALEN); |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8421 | |
| 8422 | /* special attribute - old implementation w/a */ |
| 8423 | request->match_sets[i].rssi_thold = default_match_rssi; |
| 8424 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8425 | if (rssi) |
| 8426 | request->match_sets[i].rssi_thold = |
| 8427 | nla_get_s32(rssi); |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8428 | |
| 8429 | /* Parse per band RSSI attribute */ |
| 8430 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, |
| 8431 | &request->match_sets[i], |
| 8432 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], |
| 8433 | request->match_sets[i].rssi_thold); |
| 8434 | if (err) |
| 8435 | goto out_free; |
| 8436 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8437 | i++; |
| 8438 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8439 | |
| 8440 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 8441 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8442 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 8443 | |
| 8444 | request->min_rssi_thold = INT_MAX; |
| 8445 | for (i = 0; i < n_match_sets; i++) |
| 8446 | request->min_rssi_thold = |
| 8447 | min(request->match_sets[i].rssi_thold, |
| 8448 | request->min_rssi_thold); |
| 8449 | } else { |
| 8450 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8451 | } |
| 8452 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 8453 | if (ie_len) { |
| 8454 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8455 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8456 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8457 | request->ie_len); |
| 8458 | } |
| 8459 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8460 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 8461 | if (err) |
| 8462 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8463 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 8464 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 8465 | request->delay = |
| 8466 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 8467 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8468 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 8469 | request->relative_rssi = nla_get_s8( |
| 8470 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 8471 | request->relative_rssi_set = true; |
| 8472 | } |
| 8473 | |
| 8474 | if (request->relative_rssi_set && |
| 8475 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 8476 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 8477 | |
| 8478 | rssi_adjust = nla_data( |
| 8479 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 8480 | request->rssi_adjust.band = rssi_adjust->band; |
| 8481 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 8482 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 8483 | err = -EINVAL; |
| 8484 | goto out_free; |
| 8485 | } |
| 8486 | } |
| 8487 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8488 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 8489 | if (err) |
| 8490 | goto out_free; |
| 8491 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8492 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8493 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8494 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8495 | |
| 8496 | out_free: |
| 8497 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8498 | return ERR_PTR(err); |
| 8499 | } |
| 8500 | |
| 8501 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 8502 | struct genl_info *info) |
| 8503 | { |
| 8504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8505 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8506 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8507 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8508 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8509 | int err; |
| 8510 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8511 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8512 | return -EOPNOTSUPP; |
| 8513 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8514 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 8515 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 8516 | if (err) |
| 8517 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8518 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8519 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8520 | info->attrs, |
| 8521 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8522 | |
| 8523 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8524 | if (err) |
| 8525 | goto out_err; |
| 8526 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8527 | /* leave request id zero for legacy request |
| 8528 | * or if driver does not support multi-scheduled scan |
| 8529 | */ |
Denis Kenzior | 2fd351a | 2019-10-08 11:43:50 -0500 | [diff] [blame] | 8530 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
| 8531 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8532 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8533 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8534 | if (err) |
| 8535 | goto out_free; |
| 8536 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8537 | sched_scan_req->dev = dev; |
| 8538 | sched_scan_req->wiphy = &rdev->wiphy; |
| 8539 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 8540 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 8541 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 8542 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8543 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8544 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 8545 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8546 | return 0; |
| 8547 | |
| 8548 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8549 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8550 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8551 | return err; |
| 8552 | } |
| 8553 | |
| 8554 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 8555 | struct genl_info *info) |
| 8556 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8557 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8558 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8559 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8560 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8561 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8562 | return -EOPNOTSUPP; |
| 8563 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8564 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 8565 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8566 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 8567 | } |
| 8568 | |
| 8569 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 8570 | struct cfg80211_sched_scan_request, |
| 8571 | list); |
| 8572 | if (!req || req->reqid || |
| 8573 | (req->owner_nlportid && |
| 8574 | req->owner_nlportid != info->snd_portid)) |
| 8575 | return -ENOENT; |
| 8576 | |
| 8577 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8578 | } |
| 8579 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8580 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 8581 | struct genl_info *info) |
| 8582 | { |
| 8583 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8584 | struct net_device *dev = info->user_ptr[1]; |
| 8585 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8586 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8587 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8588 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8589 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8590 | int err; |
| 8591 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8592 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8593 | if (dfs_region == NL80211_DFS_UNSET) |
| 8594 | return -EINVAL; |
| 8595 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8596 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8597 | if (err) |
| 8598 | return err; |
| 8599 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 8600 | if (netif_carrier_ok(dev)) |
| 8601 | return -EBUSY; |
| 8602 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8603 | if (wdev->cac_started) |
| 8604 | return -EBUSY; |
| 8605 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8606 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8607 | if (err < 0) |
| 8608 | return err; |
| 8609 | |
| 8610 | if (err == 0) |
| 8611 | return -EINVAL; |
| 8612 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8613 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8614 | return -EINVAL; |
| 8615 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8616 | /* CAC start is offloaded to HW and can't be started manually */ |
| 8617 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 8618 | return -EOPNOTSUPP; |
| 8619 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8620 | if (!rdev->ops->start_radar_detection) |
| 8621 | return -EOPNOTSUPP; |
| 8622 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8623 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 8624 | if (WARN_ON(!cac_time_ms)) |
| 8625 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 8626 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8627 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8628 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 8629 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8630 | wdev->cac_started = true; |
| 8631 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8632 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8633 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8634 | return err; |
| 8635 | } |
| 8636 | |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8637 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 8638 | struct genl_info *info) |
| 8639 | { |
| 8640 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8641 | struct net_device *dev = info->user_ptr[1]; |
| 8642 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8643 | struct wiphy *wiphy = wdev->wiphy; |
| 8644 | struct cfg80211_chan_def chandef; |
| 8645 | enum nl80211_dfs_regions dfs_region; |
| 8646 | int err; |
| 8647 | |
| 8648 | dfs_region = reg_get_dfs_region(wiphy); |
| 8649 | if (dfs_region == NL80211_DFS_UNSET) { |
| 8650 | GENL_SET_ERR_MSG(info, |
| 8651 | "DFS Region is not set. Unexpected Radar indication"); |
| 8652 | return -EINVAL; |
| 8653 | } |
| 8654 | |
| 8655 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8656 | if (err) { |
| 8657 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 8658 | return err; |
| 8659 | } |
| 8660 | |
| 8661 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8662 | if (err < 0) { |
| 8663 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 8664 | return err; |
| 8665 | } |
| 8666 | |
| 8667 | if (err == 0) { |
| 8668 | GENL_SET_ERR_MSG(info, |
| 8669 | "Unexpected Radar indication for chandef/iftype"); |
| 8670 | return -EINVAL; |
| 8671 | } |
| 8672 | |
| 8673 | /* Do not process this notification if radar is already detected |
| 8674 | * by kernel on this channel, and return success. |
| 8675 | */ |
| 8676 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 8677 | return 0; |
| 8678 | |
| 8679 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 8680 | |
| 8681 | cfg80211_sched_dfs_chan_update(rdev); |
| 8682 | |
Luca Coelho | a680fe4 | 2019-04-17 09:34:40 +0300 | [diff] [blame] | 8683 | rdev->radar_chandef = chandef; |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8684 | |
| 8685 | /* Propagate this notification to other radios as well */ |
| 8686 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 8687 | |
| 8688 | return 0; |
| 8689 | } |
| 8690 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8691 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 8692 | { |
| 8693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8694 | struct net_device *dev = info->user_ptr[1]; |
| 8695 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8696 | struct cfg80211_csa_settings params; |
| 8697 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 8698 | * function is called under RTNL lock, so this should not be a problem. |
| 8699 | */ |
| 8700 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8701 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8702 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8703 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8704 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8705 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8706 | |
| 8707 | if (!rdev->ops->channel_switch || |
| 8708 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 8709 | return -EOPNOTSUPP; |
| 8710 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8711 | switch (dev->ieee80211_ptr->iftype) { |
| 8712 | case NL80211_IFTYPE_AP: |
| 8713 | case NL80211_IFTYPE_P2P_GO: |
| 8714 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8715 | /* For all modes except AP the handle_dfs flag needs to be |
| 8716 | * supplied to tell the kernel that userspace will handle radar |
| 8717 | * events when they happen. Otherwise a switch to a channel |
| 8718 | * requiring DFS will be rejected. |
| 8719 | */ |
| 8720 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8721 | |
| 8722 | /* useless if AP is not running */ |
| 8723 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8724 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8725 | break; |
| 8726 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8727 | if (!wdev->ssid_len) |
| 8728 | return -ENOTCONN; |
| 8729 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 8730 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 8731 | if (!wdev->mesh_id_len) |
| 8732 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8733 | break; |
| 8734 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8735 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8736 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8737 | |
| 8738 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | c177db2 | 2018-10-30 09:17:44 +0100 | [diff] [blame] | 8739 | params.beacon_csa.ftm_responder = -1; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8740 | |
| 8741 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 8742 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 8743 | return -EINVAL; |
| 8744 | |
| 8745 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 8746 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8747 | return -EINVAL; |
| 8748 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8749 | /* Even though the attribute is u32, the specification says |
| 8750 | * u8, so let's make sure we don't overflow. |
| 8751 | */ |
| 8752 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 8753 | if (cs_count > 255) |
| 8754 | return -EINVAL; |
| 8755 | |
| 8756 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8757 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8758 | if (!need_new_beacon) |
| 8759 | goto skip_beacons; |
| 8760 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8761 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8762 | if (err) |
| 8763 | return err; |
| 8764 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8765 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
| 8766 | info->attrs[NL80211_ATTR_CSA_IES], |
| 8767 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8768 | if (err) |
| 8769 | return err; |
| 8770 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 8771 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8772 | if (err) |
| 8773 | return err; |
| 8774 | |
| 8775 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) |
| 8776 | return -EINVAL; |
| 8777 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8778 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 8779 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8780 | return -EINVAL; |
| 8781 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8782 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 8783 | if (rdev->wiphy.max_num_csa_counters && |
| 8784 | (params.n_counter_offsets_beacon > |
| 8785 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8786 | return -EINVAL; |
| 8787 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8788 | params.counter_offsets_beacon = |
| 8789 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
| 8790 | |
| 8791 | /* sanity checks - counters should fit and be the same */ |
| 8792 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 8793 | u16 offset = params.counter_offsets_beacon[i]; |
| 8794 | |
| 8795 | if (offset >= params.beacon_csa.tail_len) |
| 8796 | return -EINVAL; |
| 8797 | |
| 8798 | if (params.beacon_csa.tail[offset] != params.count) |
| 8799 | return -EINVAL; |
| 8800 | } |
| 8801 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8802 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8803 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8804 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8805 | return -EINVAL; |
| 8806 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8807 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 8808 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 8809 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8810 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8811 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8812 | |
| 8813 | params.counter_offsets_presp = |
| 8814 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
| 8815 | |
| 8816 | /* sanity checks - counters should fit and be the same */ |
| 8817 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 8818 | u16 offset = params.counter_offsets_presp[i]; |
| 8819 | |
| 8820 | if (offset >= params.beacon_csa.probe_resp_len) |
| 8821 | return -EINVAL; |
| 8822 | |
| 8823 | if (params.beacon_csa.probe_resp[offset] != |
| 8824 | params.count) |
| 8825 | return -EINVAL; |
| 8826 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8827 | } |
| 8828 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8829 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8830 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 8831 | if (err) |
| 8832 | return err; |
| 8833 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 8834 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 8835 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8836 | return -EINVAL; |
| 8837 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8838 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 8839 | ¶ms.chandef, |
| 8840 | wdev->iftype); |
| 8841 | if (err < 0) |
| 8842 | return err; |
| 8843 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8844 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 8845 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8846 | if (need_handle_dfs_flag && |
| 8847 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 8848 | return -EINVAL; |
| 8849 | } |
| 8850 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8851 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8852 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 8853 | params.block_tx = true; |
| 8854 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 8855 | wdev_lock(wdev); |
| 8856 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 8857 | wdev_unlock(wdev); |
| 8858 | |
| 8859 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8860 | } |
| 8861 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8862 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 8863 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8864 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8865 | struct wireless_dev *wdev, |
| 8866 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8867 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8868 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8869 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8870 | void *hdr; |
| 8871 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8872 | |
| 8873 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8874 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 8875 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8876 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 8877 | if (!hdr) |
| 8878 | return -1; |
| 8879 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 8880 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 8881 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8882 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 8883 | goto nla_put_failure; |
| 8884 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8885 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 8886 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8887 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 8888 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 8889 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8890 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 8891 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8892 | if (!bss) |
| 8893 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8894 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8895 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8896 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8897 | |
| 8898 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8899 | /* indicate whether we have probe response data or not */ |
| 8900 | if (rcu_access_pointer(res->proberesp_ies) && |
| 8901 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 8902 | goto fail_unlock_rcu; |
| 8903 | |
| 8904 | /* this pointer prefers to be pointed to probe response data |
| 8905 | * but is always valid |
| 8906 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8907 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8908 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8909 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 8910 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8911 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8912 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 8913 | ies->len, ies->data)) |
| 8914 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8915 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8916 | |
| 8917 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8918 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 8919 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8920 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 8921 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8922 | goto fail_unlock_rcu; |
| 8923 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 8924 | ies->len, ies->data)) |
| 8925 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 8926 | } |
| 8927 | rcu_read_unlock(); |
| 8928 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8929 | if (res->beacon_interval && |
| 8930 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 8931 | goto nla_put_failure; |
| 8932 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 8933 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 8934 | nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, |
| 8935 | res->channel->freq_offset) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 8936 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8937 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 8938 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 8939 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8940 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8941 | if (intbss->parent_tsf && |
| 8942 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 8943 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 8944 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 8945 | intbss->parent_bssid))) |
| 8946 | goto nla_put_failure; |
| 8947 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8948 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 8949 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 8950 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 8951 | goto nla_put_failure; |
| 8952 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 8953 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 8954 | intbss->pub.chain_signal, |
| 8955 | NL80211_BSS_CHAIN_SIGNAL)) |
| 8956 | goto nla_put_failure; |
| 8957 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 8958 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8959 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8960 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 8961 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8962 | break; |
| 8963 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8964 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 8965 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8966 | break; |
| 8967 | default: |
| 8968 | break; |
| 8969 | } |
| 8970 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8971 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 8972 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8973 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8974 | if (intbss == wdev->current_bss && |
| 8975 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8976 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 8977 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8978 | break; |
| 8979 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 8980 | if (intbss == wdev->current_bss && |
| 8981 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 8982 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 8983 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 8984 | break; |
| 8985 | default: |
| 8986 | break; |
| 8987 | } |
| 8988 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8989 | nla_nest_end(msg, bss); |
| 8990 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8991 | genlmsg_end(msg, hdr); |
| 8992 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8993 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 8994 | fail_unlock_rcu: |
| 8995 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8996 | nla_put_failure: |
| 8997 | genlmsg_cancel(msg, hdr); |
| 8998 | return -EMSGSIZE; |
| 8999 | } |
| 9000 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9001 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9002 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9003 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9004 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9005 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9006 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9007 | int err; |
| 9008 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9009 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9010 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9011 | if (err) { |
| 9012 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9013 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9014 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9015 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9016 | wdev_lock(wdev); |
| 9017 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 9018 | |
| 9019 | /* |
| 9020 | * dump_scan will be called multiple times to break up the scan results |
| 9021 | * into multiple messages. It is unlikely that any more bss-es will be |
| 9022 | * expired after the first call, so only call only call this on the |
| 9023 | * first dump_scan invocation. |
| 9024 | */ |
| 9025 | if (start == 0) |
| 9026 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9027 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9028 | cb->seq = rdev->bss_generation; |
| 9029 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9030 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9031 | if (++idx <= start) |
| 9032 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9033 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9034 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9035 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9036 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9037 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9038 | } |
| 9039 | } |
| 9040 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9041 | spin_unlock_bh(&rdev->bss_lock); |
| 9042 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9043 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9044 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9045 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9046 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9047 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9048 | } |
| 9049 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9050 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9051 | int flags, struct net_device *dev, |
| 9052 | bool allow_radio_stats, |
| 9053 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9054 | { |
| 9055 | void *hdr; |
| 9056 | struct nlattr *infoattr; |
| 9057 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9058 | /* skip radio stats if userspace didn't request them */ |
| 9059 | if (!survey->channel && !allow_radio_stats) |
| 9060 | return 0; |
| 9061 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9062 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9063 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 9064 | if (!hdr) |
| 9065 | return -ENOMEM; |
| 9066 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9067 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 9068 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9069 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9070 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9071 | if (!infoattr) |
| 9072 | goto nla_put_failure; |
| 9073 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9074 | if (survey->channel && |
| 9075 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9076 | survey->channel->center_freq)) |
| 9077 | goto nla_put_failure; |
| 9078 | |
| 9079 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 9080 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 9081 | goto nla_put_failure; |
| 9082 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 9083 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 9084 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9085 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9086 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 9087 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9088 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9089 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9090 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 9091 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9092 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9093 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9094 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 9095 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9096 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9097 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9098 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 9099 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9100 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9101 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9102 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 9103 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9104 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9105 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9106 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 9107 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9108 | goto nla_put_failure; |
Felix Fietkau | c8cd6e7 | 2019-08-28 12:20:42 +0200 | [diff] [blame] | 9109 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
| 9110 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, |
| 9111 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) |
| 9112 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9113 | |
| 9114 | nla_nest_end(msg, infoattr); |
| 9115 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9116 | genlmsg_end(msg, hdr); |
| 9117 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9118 | |
| 9119 | nla_put_failure: |
| 9120 | genlmsg_cancel(msg, hdr); |
| 9121 | return -EMSGSIZE; |
| 9122 | } |
| 9123 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9124 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9125 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9126 | struct nlattr **attrbuf; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9127 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9128 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9129 | struct wireless_dev *wdev; |
| 9130 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9131 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9132 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9133 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9134 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 9135 | if (!attrbuf) |
| 9136 | return -ENOMEM; |
| 9137 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9138 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9139 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9140 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9141 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9142 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9143 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9144 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9145 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9146 | if (!wdev->netdev) { |
| 9147 | res = -EINVAL; |
| 9148 | goto out_err; |
| 9149 | } |
| 9150 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9151 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9152 | res = -EOPNOTSUPP; |
| 9153 | goto out_err; |
| 9154 | } |
| 9155 | |
| 9156 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9157 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9158 | if (res == -ENOENT) |
| 9159 | break; |
| 9160 | if (res) |
| 9161 | goto out_err; |
| 9162 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9163 | /* don't send disabled channels, but do send non-channel data */ |
| 9164 | if (survey.channel && |
| 9165 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 9166 | survey_idx++; |
| 9167 | continue; |
| 9168 | } |
| 9169 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9170 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9171 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9172 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9173 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9174 | goto out; |
| 9175 | survey_idx++; |
| 9176 | } |
| 9177 | |
| 9178 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9179 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9180 | res = skb->len; |
| 9181 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9182 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9183 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9184 | return res; |
| 9185 | } |
| 9186 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9187 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 9188 | { |
| 9189 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
Chung-Hsien Hsu | cc3e14c | 2019-05-09 09:49:05 +0000 | [diff] [blame] | 9190 | NL80211_WPA_VERSION_2 | |
| 9191 | NL80211_WPA_VERSION_3)); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9192 | } |
| 9193 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9194 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 9195 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9197 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9198 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9199 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 9200 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9201 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9202 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9203 | bool local_state_change; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9204 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9205 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9206 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9207 | return -EINVAL; |
| 9208 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 9209 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 9210 | return -EINVAL; |
| 9211 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9212 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 9213 | return -EINVAL; |
| 9214 | |
| 9215 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9216 | return -EINVAL; |
| 9217 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9218 | err = nl80211_parse_key(info, &key); |
| 9219 | if (err) |
| 9220 | return err; |
| 9221 | |
| 9222 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 9223 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 9224 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9225 | if (!key.p.key || !key.p.key_len) |
| 9226 | return -EINVAL; |
| 9227 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 9228 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 9229 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 9230 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 9231 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 9232 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9233 | return -EINVAL; |
| 9234 | } else { |
| 9235 | key.p.key_len = 0; |
| 9236 | key.p.key = NULL; |
| 9237 | } |
| 9238 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9239 | if (key.idx >= 0) { |
| 9240 | int i; |
| 9241 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9242 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9243 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 9244 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 9245 | ok = true; |
| 9246 | break; |
| 9247 | } |
| 9248 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9249 | if (!ok) |
| 9250 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9251 | } |
| 9252 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9253 | if (!rdev->ops->auth) |
| 9254 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9255 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9256 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9257 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9258 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9259 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9260 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9261 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9262 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9263 | freq += |
| 9264 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9265 | |
| 9266 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9267 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9268 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9269 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9270 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9271 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9272 | |
| 9273 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9274 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9275 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9276 | } |
| 9277 | |
| 9278 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9279 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9280 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9281 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9282 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 9283 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 9284 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 9285 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9286 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9287 | return -EINVAL; |
| 9288 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9289 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9290 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 9291 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 9292 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 9293 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9294 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9295 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 9296 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9297 | } |
| 9298 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9299 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9300 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 9301 | /* |
| 9302 | * Since we no longer track auth state, ignore |
| 9303 | * requests to only change local state. |
| 9304 | */ |
| 9305 | if (local_state_change) |
| 9306 | return 0; |
| 9307 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9308 | wdev_lock(dev->ieee80211_ptr); |
| 9309 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 9310 | ssid, ssid_len, ie, ie_len, |
| 9311 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9312 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9313 | wdev_unlock(dev->ieee80211_ptr); |
| 9314 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9315 | } |
| 9316 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9317 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 9318 | struct genl_info *info) |
| 9319 | { |
| 9320 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9321 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 9322 | return -EINVAL; |
| 9323 | } |
| 9324 | |
| 9325 | if (!rdev->ops->tx_control_port || |
| 9326 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9327 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 9328 | return -EOPNOTSUPP; |
| 9329 | |
| 9330 | return 0; |
| 9331 | } |
| 9332 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9333 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 9334 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9335 | struct cfg80211_crypto_settings *settings, |
| 9336 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9337 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 9338 | memset(settings, 0, sizeof(*settings)); |
| 9339 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9340 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 9341 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9342 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 9343 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9344 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9345 | proto = nla_get_u16( |
| 9346 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 9347 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 9348 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 9349 | proto != ETH_P_PAE) |
| 9350 | return -EINVAL; |
| 9351 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 9352 | settings->control_port_no_encrypt = true; |
| 9353 | } else |
| 9354 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 9355 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9356 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9357 | int r = validate_pae_over_nl80211(rdev, info); |
| 9358 | |
| 9359 | if (r < 0) |
| 9360 | return r; |
| 9361 | |
| 9362 | settings->control_port_over_nl80211 = true; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 9363 | |
| 9364 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) |
| 9365 | settings->control_port_no_preauth = true; |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9366 | } |
| 9367 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9368 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 9369 | void *data; |
| 9370 | int len, i; |
| 9371 | |
| 9372 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9373 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9374 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 9375 | |
| 9376 | if (len % sizeof(u32)) |
| 9377 | return -EINVAL; |
| 9378 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9379 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9380 | return -EINVAL; |
| 9381 | |
| 9382 | memcpy(settings->ciphers_pairwise, data, len); |
| 9383 | |
| 9384 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9385 | if (!cfg80211_supported_cipher_suite( |
| 9386 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9387 | settings->ciphers_pairwise[i])) |
| 9388 | return -EINVAL; |
| 9389 | } |
| 9390 | |
| 9391 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 9392 | settings->cipher_group = |
| 9393 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9394 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 9395 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9396 | return -EINVAL; |
| 9397 | } |
| 9398 | |
| 9399 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 9400 | settings->wpa_versions = |
| 9401 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 9402 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 9403 | return -EINVAL; |
| 9404 | } |
| 9405 | |
| 9406 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 9407 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 9408 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9409 | |
| 9410 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9411 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9412 | settings->n_akm_suites = len / sizeof(u32); |
| 9413 | |
| 9414 | if (len % sizeof(u32)) |
| 9415 | return -EINVAL; |
| 9416 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 9417 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 9418 | return -EINVAL; |
| 9419 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9420 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9421 | } |
| 9422 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9423 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9424 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 9425 | return -EINVAL; |
| 9426 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | f966227 | 2020-06-23 08:49:35 -0500 | [diff] [blame] | 9427 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && |
| 9428 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9429 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9430 | return -EINVAL; |
| 9431 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9432 | } |
| 9433 | |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 9434 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
| 9435 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9436 | NL80211_EXT_FEATURE_SAE_OFFLOAD)) |
| 9437 | return -EINVAL; |
| 9438 | settings->sae_pwd = |
| 9439 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9440 | settings->sae_pwd_len = |
| 9441 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9442 | } |
| 9443 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9444 | return 0; |
| 9445 | } |
| 9446 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9447 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 9448 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9449 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9450 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9451 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9452 | struct cfg80211_assoc_request req = {}; |
| 9453 | const u8 *bssid, *ssid; |
| 9454 | int err, ssid_len = 0; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9455 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9456 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9457 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9458 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9459 | return -EPERM; |
| 9460 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9461 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9462 | !info->attrs[NL80211_ATTR_SSID] || |
| 9463 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9464 | return -EINVAL; |
| 9465 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9466 | if (!rdev->ops->assoc) |
| 9467 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9468 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9469 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9470 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9471 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9472 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9473 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9474 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9475 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9476 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9477 | freq += |
| 9478 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9479 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9480 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9481 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9482 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9483 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9484 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9485 | |
| 9486 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9487 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9488 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9489 | } |
| 9490 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9491 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9492 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9493 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9494 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9495 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9496 | else if (mfp != NL80211_MFP_NO) |
| 9497 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9498 | } |
| 9499 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9500 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9501 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9502 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9503 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9504 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9505 | |
| 9506 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9507 | memcpy(&req.ht_capa_mask, |
| 9508 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9509 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9510 | |
| 9511 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9512 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9513 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9514 | memcpy(&req.ht_capa, |
| 9515 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9516 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9517 | } |
| 9518 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9519 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9520 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9521 | |
| 9522 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9523 | memcpy(&req.vht_capa_mask, |
| 9524 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9525 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9526 | |
| 9527 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9528 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9529 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9530 | memcpy(&req.vht_capa, |
| 9531 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9532 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9533 | } |
| 9534 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9535 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9536 | if (!((rdev->wiphy.features & |
| 9537 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9538 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9539 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9540 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9541 | return -EINVAL; |
| 9542 | req.flags |= ASSOC_REQ_USE_RRM; |
| 9543 | } |
| 9544 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 9545 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 9546 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9547 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9548 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 9549 | return -EINVAL; |
| 9550 | req.fils_nonces = |
| 9551 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 9552 | } |
| 9553 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9554 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9555 | if (!err) { |
| 9556 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9557 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9558 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 9559 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9560 | |
| 9561 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9562 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 9563 | info->snd_portid; |
| 9564 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9565 | bssid, ETH_ALEN); |
| 9566 | } |
| 9567 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9568 | wdev_unlock(dev->ieee80211_ptr); |
| 9569 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9570 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9571 | return err; |
| 9572 | } |
| 9573 | |
| 9574 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 9575 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9576 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9577 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9578 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9579 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9580 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9581 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9582 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9583 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9584 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9585 | return -EPERM; |
| 9586 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9587 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9588 | return -EINVAL; |
| 9589 | |
| 9590 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9591 | return -EINVAL; |
| 9592 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9593 | if (!rdev->ops->deauth) |
| 9594 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9595 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9596 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9597 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9598 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9599 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9600 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9601 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9602 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9603 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9604 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9605 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9606 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9607 | |
| 9608 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9609 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9610 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9611 | } |
| 9612 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9613 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9614 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9615 | wdev_lock(dev->ieee80211_ptr); |
| 9616 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9617 | local_state_change); |
| 9618 | wdev_unlock(dev->ieee80211_ptr); |
| 9619 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9620 | } |
| 9621 | |
| 9622 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 9623 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9625 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9626 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9627 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9628 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9629 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9630 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9631 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9632 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9633 | return -EPERM; |
| 9634 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9635 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9636 | return -EINVAL; |
| 9637 | |
| 9638 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9639 | return -EINVAL; |
| 9640 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9641 | if (!rdev->ops->disassoc) |
| 9642 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9643 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9644 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9645 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9646 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9647 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9648 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9649 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9650 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9651 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9652 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9653 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9654 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9655 | |
| 9656 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9657 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9658 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9659 | } |
| 9660 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9661 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9662 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9663 | wdev_lock(dev->ieee80211_ptr); |
| 9664 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9665 | local_state_change); |
| 9666 | wdev_unlock(dev->ieee80211_ptr); |
| 9667 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9668 | } |
| 9669 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9670 | static bool |
| 9671 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9672 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9673 | int rateval) |
| 9674 | { |
| 9675 | struct wiphy *wiphy = &rdev->wiphy; |
| 9676 | bool found = false; |
| 9677 | int band, i; |
| 9678 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9679 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9680 | struct ieee80211_supported_band *sband; |
| 9681 | |
| 9682 | sband = wiphy->bands[band]; |
| 9683 | if (!sband) |
| 9684 | continue; |
| 9685 | |
| 9686 | for (i = 0; i < sband->n_bitrates; i++) { |
| 9687 | if (sband->bitrates[i].bitrate == rateval) { |
| 9688 | mcast_rate[band] = i + 1; |
| 9689 | found = true; |
| 9690 | break; |
| 9691 | } |
| 9692 | } |
| 9693 | } |
| 9694 | |
| 9695 | return found; |
| 9696 | } |
| 9697 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9698 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9699 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9700 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9701 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9702 | struct cfg80211_ibss_params ibss; |
| 9703 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9704 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9705 | int err; |
| 9706 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9707 | memset(&ibss, 0, sizeof(ibss)); |
| 9708 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9709 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9710 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 9711 | return -EINVAL; |
| 9712 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9713 | ibss.beacon_interval = 100; |
| 9714 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9715 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9716 | ibss.beacon_interval = |
| 9717 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9718 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 9719 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 9720 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 9721 | if (err) |
| 9722 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 9723 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9724 | if (!rdev->ops->join_ibss) |
| 9725 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9726 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9727 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9728 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9729 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 9730 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9731 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9732 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9733 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 9734 | |
| 9735 | if (!is_valid_ether_addr(ibss.bssid)) |
| 9736 | return -EINVAL; |
| 9737 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9738 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9739 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9740 | |
| 9741 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9742 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9743 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9744 | } |
| 9745 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9746 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 9747 | if (err) |
| 9748 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9749 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 9750 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 9751 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9752 | return -EINVAL; |
| 9753 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9754 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 9755 | case NL80211_CHAN_WIDTH_5: |
| 9756 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9757 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 9758 | break; |
| 9759 | case NL80211_CHAN_WIDTH_20: |
| 9760 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 9761 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9762 | return -EINVAL; |
| 9763 | break; |
| 9764 | case NL80211_CHAN_WIDTH_80: |
| 9765 | case NL80211_CHAN_WIDTH_80P80: |
| 9766 | case NL80211_CHAN_WIDTH_160: |
| 9767 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 9768 | return -EINVAL; |
| 9769 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 9770 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 9771 | return -EINVAL; |
| 9772 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9773 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9774 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 9775 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 9776 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9777 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9778 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9779 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9780 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 9781 | u8 *rates = |
| 9782 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9783 | int n_rates = |
| 9784 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 9785 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 9786 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9787 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 9788 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 9789 | &ibss.basic_rates); |
| 9790 | if (err) |
| 9791 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9792 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9793 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 9794 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9795 | memcpy(&ibss.ht_capa_mask, |
| 9796 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9797 | sizeof(ibss.ht_capa_mask)); |
| 9798 | |
| 9799 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 9800 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 9801 | return -EINVAL; |
| 9802 | memcpy(&ibss.ht_capa, |
| 9803 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9804 | sizeof(ibss.ht_capa)); |
| 9805 | } |
| 9806 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9807 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 9808 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 9809 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 9810 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 9811 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9812 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9813 | bool no_ht = false; |
| 9814 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 9815 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9816 | if (IS_ERR(connkeys)) |
| 9817 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9818 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 9819 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 9820 | no_ht) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 9821 | kfree_sensitive(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 9822 | return -EINVAL; |
| 9823 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9824 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9825 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 9826 | ibss.control_port = |
| 9827 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 9828 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9829 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9830 | int r = validate_pae_over_nl80211(rdev, info); |
| 9831 | |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 9832 | if (r < 0) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 9833 | kfree_sensitive(connkeys); |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9834 | return r; |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 9835 | } |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 9836 | |
| 9837 | ibss.control_port_over_nl80211 = true; |
| 9838 | } |
| 9839 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 9840 | ibss.userspace_handles_dfs = |
| 9841 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 9842 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9843 | wdev_lock(dev->ieee80211_ptr); |
| 9844 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9845 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 9846 | kfree_sensitive(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 9847 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 9848 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 9849 | wdev_unlock(dev->ieee80211_ptr); |
| 9850 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9851 | return err; |
| 9852 | } |
| 9853 | |
| 9854 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 9855 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9856 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9857 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9858 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9859 | if (!rdev->ops->leave_ibss) |
| 9860 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9861 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 9863 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9864 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9865 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 9866 | } |
| 9867 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9868 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 9869 | { |
| 9870 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9871 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9872 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9873 | u32 nla_rate; |
| 9874 | int err; |
| 9875 | |
| 9876 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 9877 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 9878 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9879 | return -EOPNOTSUPP; |
| 9880 | |
| 9881 | if (!rdev->ops->set_mcast_rate) |
| 9882 | return -EOPNOTSUPP; |
| 9883 | |
| 9884 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 9885 | |
| 9886 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 9887 | return -EINVAL; |
| 9888 | |
| 9889 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 9890 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 9891 | return -EINVAL; |
| 9892 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9893 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9894 | |
| 9895 | return err; |
| 9896 | } |
| 9897 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9898 | static struct sk_buff * |
| 9899 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9900 | struct wireless_dev *wdev, int approxlen, |
| 9901 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9902 | enum nl80211_attrs attr, |
| 9903 | const struct nl80211_vendor_cmd_info *info, |
| 9904 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9905 | { |
| 9906 | struct sk_buff *skb; |
| 9907 | void *hdr; |
| 9908 | struct nlattr *data; |
| 9909 | |
| 9910 | skb = nlmsg_new(approxlen + 100, gfp); |
| 9911 | if (!skb) |
| 9912 | return NULL; |
| 9913 | |
| 9914 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 9915 | if (!hdr) { |
| 9916 | kfree_skb(skb); |
| 9917 | return NULL; |
| 9918 | } |
| 9919 | |
| 9920 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 9921 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 9922 | |
| 9923 | if (info) { |
| 9924 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 9925 | info->vendor_id)) |
| 9926 | goto nla_put_failure; |
| 9927 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 9928 | info->subcmd)) |
| 9929 | goto nla_put_failure; |
| 9930 | } |
| 9931 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9932 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9933 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 9934 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9935 | goto nla_put_failure; |
| 9936 | if (wdev->netdev && |
| 9937 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 9938 | wdev->netdev->ifindex)) |
| 9939 | goto nla_put_failure; |
| 9940 | } |
| 9941 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9942 | data = nla_nest_start_noflag(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 9943 | if (!data) |
| 9944 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 9945 | |
| 9946 | ((void **)skb->cb)[0] = rdev; |
| 9947 | ((void **)skb->cb)[1] = hdr; |
| 9948 | ((void **)skb->cb)[2] = data; |
| 9949 | |
| 9950 | return skb; |
| 9951 | |
| 9952 | nla_put_failure: |
| 9953 | kfree_skb(skb); |
| 9954 | return NULL; |
| 9955 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 9956 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9957 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 9958 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9959 | enum nl80211_commands cmd, |
| 9960 | enum nl80211_attrs attr, |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9961 | unsigned int portid, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9962 | int vendor_event_idx, |
| 9963 | int approxlen, gfp_t gfp) |
| 9964 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 9965 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9966 | const struct nl80211_vendor_cmd_info *info; |
| 9967 | |
| 9968 | switch (cmd) { |
| 9969 | case NL80211_CMD_TESTMODE: |
| 9970 | if (WARN_ON(vendor_event_idx != -1)) |
| 9971 | return NULL; |
| 9972 | info = NULL; |
| 9973 | break; |
| 9974 | case NL80211_CMD_VENDOR: |
| 9975 | if (WARN_ON(vendor_event_idx < 0 || |
| 9976 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 9977 | return NULL; |
| 9978 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 9979 | break; |
| 9980 | default: |
| 9981 | WARN_ON(1); |
| 9982 | return NULL; |
| 9983 | } |
| 9984 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9985 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9986 | cmd, attr, info, gfp); |
| 9987 | } |
| 9988 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 9989 | |
| 9990 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 9991 | { |
| 9992 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 9993 | void *hdr = ((void **)skb->cb)[1]; |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 9994 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 9995 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 9996 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 9997 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 9998 | /* clear CB data for netlink core to own from now on */ |
| 9999 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10000 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10001 | nla_nest_end(skb, data); |
| 10002 | genlmsg_end(skb, hdr); |
| 10003 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10004 | if (nlhdr->nlmsg_pid) { |
| 10005 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, |
| 10006 | nlhdr->nlmsg_pid); |
| 10007 | } else { |
| 10008 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 10009 | mcgrp = NL80211_MCGRP_VENDOR; |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10010 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10011 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 10012 | skb, 0, mcgrp, gfp); |
| 10013 | } |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10014 | } |
| 10015 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 10016 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10017 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10018 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 10019 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10020 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10021 | struct wireless_dev *wdev = |
| 10022 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10023 | int err; |
| 10024 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10025 | if (!rdev->ops->testmode_cmd) |
| 10026 | return -EOPNOTSUPP; |
| 10027 | |
| 10028 | if (IS_ERR(wdev)) { |
| 10029 | err = PTR_ERR(wdev); |
| 10030 | if (err != -EINVAL) |
| 10031 | return err; |
| 10032 | wdev = NULL; |
| 10033 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10034 | return -EINVAL; |
| 10035 | } |
| 10036 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10037 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 10038 | return -EINVAL; |
| 10039 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10040 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10041 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10042 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 10043 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10044 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10045 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10046 | return err; |
| 10047 | } |
| 10048 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10049 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 10050 | struct netlink_callback *cb) |
| 10051 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10052 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10053 | struct nlattr **attrbuf = NULL; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10054 | int err; |
| 10055 | long phy_idx; |
| 10056 | void *data = NULL; |
| 10057 | int data_len = 0; |
| 10058 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10059 | rtnl_lock(); |
| 10060 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10061 | if (cb->args[0]) { |
| 10062 | /* |
| 10063 | * 0 is a valid index, but not valid for args[0], |
| 10064 | * so we need to offset by 1. |
| 10065 | */ |
| 10066 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 10067 | |
| 10068 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 10069 | if (!rdev) { |
| 10070 | err = -ENOENT; |
| 10071 | goto out_err; |
| 10072 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10073 | } else { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10074 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 10075 | GFP_KERNEL); |
| 10076 | if (!attrbuf) { |
| 10077 | err = -ENOMEM; |
| 10078 | goto out_err; |
| 10079 | } |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10080 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 10081 | err = nlmsg_parse_deprecated(cb->nlh, |
| 10082 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10083 | attrbuf, nl80211_fam.maxattr, |
| 10084 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10085 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10086 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10087 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10088 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10089 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10090 | err = PTR_ERR(rdev); |
| 10091 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10092 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10093 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10094 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10095 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 10096 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10097 | } |
| 10098 | |
| 10099 | if (cb->args[1]) { |
| 10100 | data = nla_data((void *)cb->args[1]); |
| 10101 | data_len = nla_len((void *)cb->args[1]); |
| 10102 | } |
| 10103 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10104 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10105 | err = -EOPNOTSUPP; |
| 10106 | goto out_err; |
| 10107 | } |
| 10108 | |
| 10109 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10110 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10111 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10112 | NL80211_CMD_TESTMODE); |
| 10113 | struct nlattr *tmdata; |
| 10114 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10115 | if (!hdr) |
| 10116 | break; |
| 10117 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10118 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10119 | genlmsg_cancel(skb, hdr); |
| 10120 | break; |
| 10121 | } |
| 10122 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10123 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10124 | if (!tmdata) { |
| 10125 | genlmsg_cancel(skb, hdr); |
| 10126 | break; |
| 10127 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10128 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10129 | nla_nest_end(skb, tmdata); |
| 10130 | |
| 10131 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10132 | genlmsg_cancel(skb, hdr); |
| 10133 | break; |
| 10134 | } else if (err) { |
| 10135 | genlmsg_cancel(skb, hdr); |
| 10136 | goto out_err; |
| 10137 | } |
| 10138 | |
| 10139 | genlmsg_end(skb, hdr); |
| 10140 | } |
| 10141 | |
| 10142 | err = skb->len; |
| 10143 | /* see above */ |
| 10144 | cb->args[0] = phy_idx + 1; |
| 10145 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10146 | kfree(attrbuf); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10147 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10148 | return err; |
| 10149 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10150 | #endif |
| 10151 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10152 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 10153 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10155 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10156 | struct cfg80211_connect_params connect; |
| 10157 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10158 | struct cfg80211_cached_keys *connkeys = NULL; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10159 | u32 freq = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10160 | int err; |
| 10161 | |
| 10162 | memset(&connect, 0, sizeof(connect)); |
| 10163 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10164 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10165 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10166 | return -EINVAL; |
| 10167 | |
| 10168 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10169 | connect.auth_type = |
| 10170 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10171 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 10172 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10173 | return -EINVAL; |
| 10174 | } else |
| 10175 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 10176 | |
| 10177 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 10178 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 10179 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 10180 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10181 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 10182 | return -EINVAL; |
| 10183 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 10184 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10185 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10186 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10187 | if (err) |
| 10188 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10189 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10190 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10191 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10192 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10193 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10194 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10195 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 10196 | connect.bg_scan_period = -1; |
| 10197 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 10198 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 10199 | connect.bg_scan_period = |
| 10200 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 10201 | } |
| 10202 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10203 | if (info->attrs[NL80211_ATTR_MAC]) |
| 10204 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10205 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 10206 | connect.bssid_hint = |
| 10207 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10208 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10209 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10210 | |
| 10211 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10212 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10213 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10214 | } |
| 10215 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10216 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 10217 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 10218 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 10219 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10220 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 10221 | return -EOPNOTSUPP; |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10222 | } else { |
| 10223 | connect.mfp = NL80211_MFP_NO; |
| 10224 | } |
| 10225 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 10226 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 10227 | connect.prev_bssid = |
| 10228 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 10229 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10230 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10231 | freq = MHZ_TO_KHZ(nla_get_u32( |
| 10232 | info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 10233 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 10234 | freq += |
| 10235 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 10236 | |
| 10237 | if (freq) { |
| 10238 | connect.channel = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10239 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10240 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10241 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10242 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 10243 | freq = MHZ_TO_KHZ(freq); |
| 10244 | connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10245 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10246 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10247 | } |
| 10248 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 10249 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 10250 | connect.edmg.channels = |
| 10251 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 10252 | |
| 10253 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 10254 | connect.edmg.bw_config = |
| 10255 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 10256 | } |
| 10257 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10258 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10259 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10260 | if (IS_ERR(connkeys)) |
| 10261 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10262 | } |
| 10263 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10264 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 10265 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 10266 | |
| 10267 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10268 | memcpy(&connect.ht_capa_mask, |
| 10269 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10270 | sizeof(connect.ht_capa_mask)); |
| 10271 | |
| 10272 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10273 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10274 | kfree_sensitive(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10275 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10276 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10277 | memcpy(&connect.ht_capa, |
| 10278 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10279 | sizeof(connect.ht_capa)); |
| 10280 | } |
| 10281 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10282 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 10283 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 10284 | |
| 10285 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 10286 | memcpy(&connect.vht_capa_mask, |
| 10287 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 10288 | sizeof(connect.vht_capa_mask)); |
| 10289 | |
| 10290 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 10291 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10292 | kfree_sensitive(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10293 | return -EINVAL; |
| 10294 | } |
| 10295 | memcpy(&connect.vht_capa, |
| 10296 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 10297 | sizeof(connect.vht_capa)); |
| 10298 | } |
| 10299 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10300 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 10301 | if (!((rdev->wiphy.features & |
| 10302 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 10303 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 10304 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10305 | NL80211_EXT_FEATURE_RRM)) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10306 | kfree_sensitive(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10307 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 10308 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10309 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 10310 | } |
| 10311 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10312 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10313 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10314 | kfree_sensitive(connkeys); |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10315 | return -EOPNOTSUPP; |
| 10316 | } |
| 10317 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10318 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 10319 | /* bss selection makes no sense if bssid is set */ |
| 10320 | if (connect.bssid) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10321 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10322 | return -EINVAL; |
| 10323 | } |
| 10324 | |
| 10325 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 10326 | wiphy, &connect.bss_select); |
| 10327 | if (err) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10328 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10329 | return err; |
| 10330 | } |
| 10331 | } |
| 10332 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10333 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 10334 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 10335 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10336 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10337 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10338 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10339 | connect.fils_erp_username = |
| 10340 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10341 | connect.fils_erp_username_len = |
| 10342 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10343 | connect.fils_erp_realm = |
| 10344 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10345 | connect.fils_erp_realm_len = |
| 10346 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10347 | connect.fils_erp_next_seq_num = |
| 10348 | nla_get_u16( |
| 10349 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10350 | connect.fils_erp_rrk = |
| 10351 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10352 | connect.fils_erp_rrk_len = |
| 10353 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10354 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10355 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10356 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10357 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10358 | kfree_sensitive(connkeys); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10359 | return -EINVAL; |
| 10360 | } |
| 10361 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10362 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 10363 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10364 | kfree_sensitive(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10365 | GENL_SET_ERR_MSG(info, |
| 10366 | "external auth requires connection ownership"); |
| 10367 | return -EINVAL; |
| 10368 | } |
| 10369 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 10370 | } |
| 10371 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10372 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10373 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 10374 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 10375 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10376 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10377 | kfree_sensitive(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10378 | |
| 10379 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10380 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10381 | if (connect.bssid) |
| 10382 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 10383 | connect.bssid, ETH_ALEN); |
| 10384 | else |
Miaohe Lin | 3b1648f | 2020-08-01 17:15:49 +0800 | [diff] [blame] | 10385 | eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10386 | } |
| 10387 | |
| 10388 | wdev_unlock(dev->ieee80211_ptr); |
| 10389 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10390 | return err; |
| 10391 | } |
| 10392 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10393 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 10394 | struct genl_info *info) |
| 10395 | { |
| 10396 | struct cfg80211_connect_params connect = {}; |
| 10397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10398 | struct net_device *dev = info->user_ptr[1]; |
| 10399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10400 | bool fils_sk_offload; |
| 10401 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10402 | u32 changed = 0; |
| 10403 | int ret; |
| 10404 | |
| 10405 | if (!rdev->ops->update_connect_params) |
| 10406 | return -EOPNOTSUPP; |
| 10407 | |
| 10408 | if (info->attrs[NL80211_ATTR_IE]) { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10409 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10410 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10411 | changed |= UPDATE_ASSOC_IES; |
| 10412 | } |
| 10413 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10414 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 10415 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 10416 | |
| 10417 | /* |
| 10418 | * when driver supports fils-sk offload all attributes must be |
| 10419 | * provided. So the else covers "fils-sk-not-all" and |
| 10420 | * "no-fils-sk-any". |
| 10421 | */ |
| 10422 | if (fils_sk_offload && |
| 10423 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10424 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10425 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10426 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10427 | connect.fils_erp_username = |
| 10428 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10429 | connect.fils_erp_username_len = |
| 10430 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10431 | connect.fils_erp_realm = |
| 10432 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10433 | connect.fils_erp_realm_len = |
| 10434 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10435 | connect.fils_erp_next_seq_num = |
| 10436 | nla_get_u16( |
| 10437 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10438 | connect.fils_erp_rrk = |
| 10439 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10440 | connect.fils_erp_rrk_len = |
| 10441 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10442 | changed |= UPDATE_FILS_ERP_INFO; |
| 10443 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10444 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10445 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10446 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10447 | return -EINVAL; |
| 10448 | } |
| 10449 | |
| 10450 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10451 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 10452 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 10453 | NL80211_CMD_CONNECT)) |
| 10454 | return -EINVAL; |
| 10455 | |
| 10456 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 10457 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 10458 | return -EINVAL; |
| 10459 | |
| 10460 | connect.auth_type = auth_type; |
| 10461 | changed |= UPDATE_AUTH_TYPE; |
| 10462 | } |
| 10463 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10464 | wdev_lock(dev->ieee80211_ptr); |
| 10465 | if (!wdev->current_bss) |
| 10466 | ret = -ENOLINK; |
| 10467 | else |
| 10468 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 10469 | wdev_unlock(dev->ieee80211_ptr); |
| 10470 | |
| 10471 | return ret; |
| 10472 | } |
| 10473 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10474 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 10475 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10476 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10477 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10478 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10479 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10480 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10481 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10482 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10483 | return -EPERM; |
| 10484 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10485 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10486 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 10487 | else |
| 10488 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10489 | |
| 10490 | if (reason == 0) |
| 10491 | return -EINVAL; |
| 10492 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10493 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10494 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10495 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10496 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10497 | wdev_lock(dev->ieee80211_ptr); |
| 10498 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 10499 | wdev_unlock(dev->ieee80211_ptr); |
| 10500 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10501 | } |
| 10502 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10503 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 10504 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10506 | struct net *net; |
| 10507 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10508 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10509 | if (info->attrs[NL80211_ATTR_PID]) { |
| 10510 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 10511 | |
| 10512 | net = get_net_ns_by_pid(pid); |
| 10513 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 10514 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 10515 | |
| 10516 | net = get_net_ns_by_fd(fd); |
| 10517 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10518 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10519 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10520 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10521 | if (IS_ERR(net)) |
| 10522 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10523 | |
| 10524 | err = 0; |
| 10525 | |
| 10526 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10527 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 10528 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10529 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10530 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10531 | return err; |
| 10532 | } |
| 10533 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10534 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10535 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10536 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10537 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 10538 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10539 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10540 | struct cfg80211_pmksa pmksa; |
| 10541 | |
| 10542 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 10543 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10544 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 10545 | return -EINVAL; |
| 10546 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10547 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10548 | |
| 10549 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 10550 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10551 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 10552 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 10553 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 10554 | info->attrs[NL80211_ATTR_PMK])) { |
| 10555 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10556 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10557 | pmksa.cache_id = |
| 10558 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 10559 | } else { |
| 10560 | return -EINVAL; |
| 10561 | } |
| 10562 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 10563 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 10564 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 10565 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10566 | |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 10567 | if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) |
| 10568 | pmksa.pmk_lifetime = |
| 10569 | nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); |
| 10570 | |
| 10571 | if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) |
| 10572 | pmksa.pmk_reauth_threshold = |
| 10573 | nla_get_u8( |
| 10574 | info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); |
| 10575 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10576 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Liangwei Dong | 6c90036 | 2019-01-18 16:54:38 +0530 | [diff] [blame] | 10577 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 10578 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && |
| 10579 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 10580 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10581 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10582 | |
| 10583 | switch (info->genlhdr->cmd) { |
| 10584 | case NL80211_CMD_SET_PMKSA: |
| 10585 | rdev_ops = rdev->ops->set_pmksa; |
| 10586 | break; |
| 10587 | case NL80211_CMD_DEL_PMKSA: |
| 10588 | rdev_ops = rdev->ops->del_pmksa; |
| 10589 | break; |
| 10590 | default: |
| 10591 | WARN_ON(1); |
| 10592 | break; |
| 10593 | } |
| 10594 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10595 | if (!rdev_ops) |
| 10596 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10597 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10598 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10599 | } |
| 10600 | |
| 10601 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10602 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10604 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10605 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10606 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10607 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10608 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10609 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10610 | if (!rdev->ops->flush_pmksa) |
| 10611 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10612 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10613 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10614 | } |
| 10615 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10616 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 10617 | { |
| 10618 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10619 | struct net_device *dev = info->user_ptr[1]; |
| 10620 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10621 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10622 | u16 status_code; |
| 10623 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10624 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10625 | |
| 10626 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10627 | !rdev->ops->tdls_mgmt) |
| 10628 | return -EOPNOTSUPP; |
| 10629 | |
| 10630 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 10631 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 10632 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 10633 | !info->attrs[NL80211_ATTR_IE] || |
| 10634 | !info->attrs[NL80211_ATTR_MAC]) |
| 10635 | return -EINVAL; |
| 10636 | |
| 10637 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10638 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 10639 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 10640 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10641 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10642 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 10643 | peer_capability = |
| 10644 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10645 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10646 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10647 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10648 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10649 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 10650 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10651 | } |
| 10652 | |
| 10653 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 10654 | { |
| 10655 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10656 | struct net_device *dev = info->user_ptr[1]; |
| 10657 | enum nl80211_tdls_operation operation; |
| 10658 | u8 *peer; |
| 10659 | |
| 10660 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10661 | !rdev->ops->tdls_oper) |
| 10662 | return -EOPNOTSUPP; |
| 10663 | |
| 10664 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 10665 | !info->attrs[NL80211_ATTR_MAC]) |
| 10666 | return -EINVAL; |
| 10667 | |
| 10668 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 10669 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10670 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10671 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10672 | } |
| 10673 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10674 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 10675 | struct genl_info *info) |
| 10676 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10678 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10679 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10680 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10681 | struct sk_buff *msg; |
| 10682 | void *hdr; |
| 10683 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10684 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10685 | int err; |
| 10686 | |
| 10687 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 10688 | !info->attrs[NL80211_ATTR_DURATION]) |
| 10689 | return -EINVAL; |
| 10690 | |
| 10691 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 10692 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10693 | if (!rdev->ops->remain_on_channel || |
| 10694 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10695 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10696 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10697 | /* |
| 10698 | * We should be on that channel for at least a minimum amount of |
| 10699 | * time (10ms) but no longer than the driver supports. |
| 10700 | */ |
| 10701 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10702 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 10703 | return -EINVAL; |
| 10704 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10705 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10706 | if (err) |
| 10707 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10708 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10709 | wdev_lock(wdev); |
| 10710 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 10711 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 10712 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 10713 | &chandef); |
| 10714 | if (compat_chandef != &chandef) { |
| 10715 | wdev_unlock(wdev); |
| 10716 | return -EBUSY; |
| 10717 | } |
| 10718 | } |
| 10719 | wdev_unlock(wdev); |
| 10720 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10721 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10722 | if (!msg) |
| 10723 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10724 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10725 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10726 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10727 | if (!hdr) { |
| 10728 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10729 | goto free_msg; |
| 10730 | } |
| 10731 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10732 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 10733 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10734 | |
| 10735 | if (err) |
| 10736 | goto free_msg; |
| 10737 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10738 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10739 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10740 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10741 | |
| 10742 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10743 | |
| 10744 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10745 | |
| 10746 | nla_put_failure: |
| 10747 | err = -ENOBUFS; |
| 10748 | free_msg: |
| 10749 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10750 | return err; |
| 10751 | } |
| 10752 | |
| 10753 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 10754 | struct genl_info *info) |
| 10755 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10757 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10758 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10759 | |
| 10760 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10761 | return -EINVAL; |
| 10762 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10763 | if (!rdev->ops->cancel_remain_on_channel) |
| 10764 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10765 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10766 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10767 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10768 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10769 | } |
| 10770 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10771 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 10772 | struct genl_info *info) |
| 10773 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10774 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10775 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10776 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10777 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10778 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10779 | if (!rdev->ops->set_bitrate_mask) |
| 10780 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10781 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 10782 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 10783 | NL80211_ATTR_TX_RATES, &mask); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 10784 | if (err) |
| 10785 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 10786 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10787 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 10788 | } |
| 10789 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10790 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10791 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10793 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10794 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10795 | |
| 10796 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 10797 | return -EINVAL; |
| 10798 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10799 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 10800 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10801 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10802 | switch (wdev->iftype) { |
| 10803 | case NL80211_IFTYPE_STATION: |
| 10804 | case NL80211_IFTYPE_ADHOC: |
| 10805 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10806 | case NL80211_IFTYPE_AP: |
| 10807 | case NL80211_IFTYPE_AP_VLAN: |
| 10808 | case NL80211_IFTYPE_MESH_POINT: |
| 10809 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10810 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10811 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10812 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10813 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10814 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10815 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10816 | |
| 10817 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10818 | if (!rdev->ops->mgmt_tx) |
| 10819 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10820 | |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 10821 | if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && |
| 10822 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10823 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { |
| 10824 | GENL_SET_ERR_MSG(info, |
| 10825 | "multicast RX registrations are not supported"); |
| 10826 | return -EOPNOTSUPP; |
| 10827 | } |
| 10828 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10829 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 10830 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 10831 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 10832 | info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 10833 | info->extack); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10834 | } |
| 10835 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 10836 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10837 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10839 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10840 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10841 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 10842 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10843 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10844 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10845 | struct cfg80211_mgmt_tx_params params = { |
| 10846 | .dont_wait_for_ack = |
| 10847 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 10848 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10849 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10850 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10851 | return -EINVAL; |
| 10852 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10853 | if (!rdev->ops->mgmt_tx) |
| 10854 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10855 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10856 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10857 | case NL80211_IFTYPE_P2P_DEVICE: |
| 10858 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10859 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10860 | case NL80211_IFTYPE_STATION: |
| 10861 | case NL80211_IFTYPE_ADHOC: |
| 10862 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10863 | case NL80211_IFTYPE_AP: |
| 10864 | case NL80211_IFTYPE_AP_VLAN: |
| 10865 | case NL80211_IFTYPE_MESH_POINT: |
| 10866 | case NL80211_IFTYPE_P2P_GO: |
| 10867 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10868 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10869 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10870 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10871 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10872 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10873 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10874 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10875 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10876 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10877 | |
| 10878 | /* |
| 10879 | * We should wait on the channel for at least a minimum amount |
| 10880 | * of time (10ms) but no longer than the driver supports. |
| 10881 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10882 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 10883 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 10884 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10885 | } |
| 10886 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10887 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10888 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10889 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10890 | return -EINVAL; |
| 10891 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10892 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 10893 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10894 | /* get the channel if any has been specified, otherwise pass NULL to |
| 10895 | * the driver. The latter will use the current one |
| 10896 | */ |
| 10897 | chandef.chan = NULL; |
| 10898 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 10899 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 10900 | if (err) |
| 10901 | return err; |
| 10902 | } |
| 10903 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10904 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 10905 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10906 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10907 | wdev_lock(wdev); |
| 10908 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 10909 | wdev_unlock(wdev); |
| 10910 | return -EBUSY; |
| 10911 | } |
| 10912 | wdev_unlock(wdev); |
| 10913 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 10914 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 10915 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 10916 | |
| 10917 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 10918 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10919 | int i; |
| 10920 | |
| 10921 | if (len % sizeof(u16)) |
| 10922 | return -EINVAL; |
| 10923 | |
| 10924 | params.n_csa_offsets = len / sizeof(u16); |
| 10925 | params.csa_offsets = |
| 10926 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 10927 | |
| 10928 | /* check that all the offsets fit the frame */ |
| 10929 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 10930 | if (params.csa_offsets[i] >= params.len) |
| 10931 | return -EINVAL; |
| 10932 | } |
| 10933 | } |
| 10934 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10935 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10936 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 10937 | if (!msg) |
| 10938 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10939 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10940 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10941 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10942 | if (!hdr) { |
| 10943 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10944 | goto free_msg; |
| 10945 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10946 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10947 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 10948 | params.chan = chandef.chan; |
| 10949 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10950 | if (err) |
| 10951 | goto free_msg; |
| 10952 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10953 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10954 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 10955 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10956 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10957 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 10958 | genlmsg_end(msg, hdr); |
| 10959 | return genlmsg_reply(msg, info); |
| 10960 | } |
| 10961 | |
| 10962 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10963 | |
| 10964 | nla_put_failure: |
| 10965 | err = -ENOBUFS; |
| 10966 | free_msg: |
| 10967 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 10968 | return err; |
| 10969 | } |
| 10970 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10971 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 10972 | { |
| 10973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10974 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10975 | u64 cookie; |
| 10976 | |
| 10977 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 10978 | return -EINVAL; |
| 10979 | |
| 10980 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 10981 | return -EOPNOTSUPP; |
| 10982 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10983 | switch (wdev->iftype) { |
| 10984 | case NL80211_IFTYPE_STATION: |
| 10985 | case NL80211_IFTYPE_ADHOC: |
| 10986 | case NL80211_IFTYPE_P2P_CLIENT: |
| 10987 | case NL80211_IFTYPE_AP: |
| 10988 | case NL80211_IFTYPE_AP_VLAN: |
| 10989 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 10990 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10991 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 10992 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10993 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10994 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10995 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 10996 | |
| 10997 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 10998 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10999 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11000 | } |
| 11001 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11002 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11003 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11004 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11005 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11006 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11007 | u8 ps_state; |
| 11008 | bool state; |
| 11009 | int err; |
| 11010 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11011 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 11012 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11013 | |
| 11014 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 11015 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11016 | wdev = dev->ieee80211_ptr; |
| 11017 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11018 | if (!rdev->ops->set_power_mgmt) |
| 11019 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11020 | |
| 11021 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 11022 | |
| 11023 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11024 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11025 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11026 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11027 | if (!err) |
| 11028 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11029 | return err; |
| 11030 | } |
| 11031 | |
| 11032 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11033 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11034 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11035 | enum nl80211_ps_state ps_state; |
| 11036 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11037 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11038 | struct sk_buff *msg; |
| 11039 | void *hdr; |
| 11040 | int err; |
| 11041 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11042 | wdev = dev->ieee80211_ptr; |
| 11043 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11044 | if (!rdev->ops->set_power_mgmt) |
| 11045 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11046 | |
| 11047 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11048 | if (!msg) |
| 11049 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11050 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11051 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11052 | NL80211_CMD_GET_POWER_SAVE); |
| 11053 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11054 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11055 | goto free_msg; |
| 11056 | } |
| 11057 | |
| 11058 | if (wdev->ps) |
| 11059 | ps_state = NL80211_PS_ENABLED; |
| 11060 | else |
| 11061 | ps_state = NL80211_PS_DISABLED; |
| 11062 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11063 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 11064 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11065 | |
| 11066 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11067 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11068 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11069 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11070 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11071 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11072 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11073 | return err; |
| 11074 | } |
| 11075 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 11076 | static const struct nla_policy |
| 11077 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11078 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11079 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 11080 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11081 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 11082 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 11083 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 11084 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11085 | }; |
| 11086 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11087 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11088 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11089 | { |
| 11090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11091 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11092 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11093 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11094 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11095 | return -EINVAL; |
| 11096 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11097 | if (!rdev->ops->set_cqm_txe_config) |
| 11098 | return -EOPNOTSUPP; |
| 11099 | |
| 11100 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 11101 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11102 | return -EOPNOTSUPP; |
| 11103 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11104 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11105 | } |
| 11106 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11107 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 11108 | struct net_device *dev) |
| 11109 | { |
| 11110 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11111 | s32 last, low, high; |
| 11112 | u32 hyst; |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11113 | int i, n, low_index; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11114 | int err; |
| 11115 | |
| 11116 | /* RSSI reporting disabled? */ |
| 11117 | if (!wdev->cqm_config) |
| 11118 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 11119 | |
| 11120 | /* |
| 11121 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 11122 | * event has been received yet, we should receive an event after a |
| 11123 | * connection is established and enough beacons received to calculate |
| 11124 | * the average. |
| 11125 | */ |
| 11126 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 11127 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11128 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11129 | u8 *mac_addr; |
| 11130 | |
| 11131 | mac_addr = wdev->current_bss->pub.bssid; |
| 11132 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11133 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 11134 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11135 | return err; |
| 11136 | |
Felix Fietkau | df16737 | 2020-01-08 18:06:30 +0100 | [diff] [blame] | 11137 | cfg80211_sinfo_release_content(&sinfo); |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 11138 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11139 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11140 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11141 | } |
| 11142 | |
| 11143 | last = wdev->cqm_config->last_rssi_event_value; |
| 11144 | hyst = wdev->cqm_config->rssi_hyst; |
| 11145 | n = wdev->cqm_config->n_rssi_thresholds; |
| 11146 | |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11147 | for (i = 0; i < n; i++) { |
| 11148 | i = array_index_nospec(i, n); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11149 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 11150 | break; |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11151 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11152 | |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11153 | low_index = i - 1; |
| 11154 | if (low_index >= 0) { |
| 11155 | low_index = array_index_nospec(low_index, n); |
| 11156 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 11157 | } else { |
| 11158 | low = S32_MIN; |
| 11159 | } |
| 11160 | if (i < n) { |
| 11161 | i = array_index_nospec(i, n); |
| 11162 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 11163 | } else { |
| 11164 | high = S32_MAX; |
| 11165 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11166 | |
| 11167 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 11168 | } |
| 11169 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11170 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11171 | const s32 *thresholds, int n_thresholds, |
| 11172 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11173 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11174 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11175 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11176 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11177 | int i, err; |
| 11178 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11179 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11180 | /* Check all values negative and sorted */ |
| 11181 | for (i = 0; i < n_thresholds; i++) { |
| 11182 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 11183 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11184 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11185 | prev = thresholds[i]; |
| 11186 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11187 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11188 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11189 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11190 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11191 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11192 | wdev_lock(wdev); |
| 11193 | cfg80211_cqm_config_free(wdev); |
| 11194 | wdev_unlock(wdev); |
| 11195 | |
| 11196 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 11197 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 11198 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 11199 | |
| 11200 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 11201 | thresholds[0], hysteresis); |
| 11202 | } |
| 11203 | |
| 11204 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 11205 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 11206 | return -EOPNOTSUPP; |
| 11207 | |
| 11208 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 11209 | n_thresholds = 0; |
| 11210 | |
| 11211 | wdev_lock(wdev); |
| 11212 | if (n_thresholds) { |
| 11213 | struct cfg80211_cqm_config *cqm_config; |
| 11214 | |
| 11215 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 11216 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 11217 | if (!cqm_config) { |
| 11218 | err = -ENOMEM; |
| 11219 | goto unlock; |
| 11220 | } |
| 11221 | |
| 11222 | cqm_config->rssi_hyst = hysteresis; |
| 11223 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 11224 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 11225 | n_thresholds * sizeof(s32)); |
| 11226 | |
| 11227 | wdev->cqm_config = cqm_config; |
| 11228 | } |
| 11229 | |
| 11230 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 11231 | |
| 11232 | unlock: |
| 11233 | wdev_unlock(wdev); |
| 11234 | |
| 11235 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11236 | } |
| 11237 | |
| 11238 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 11239 | { |
| 11240 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 11241 | struct nlattr *cqm; |
| 11242 | int err; |
| 11243 | |
| 11244 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11245 | if (!cqm) |
| 11246 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11247 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11248 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 11249 | nl80211_attr_cqm_policy, |
| 11250 | info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11251 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11252 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11253 | |
| 11254 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 11255 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11256 | const s32 *thresholds = |
| 11257 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 11258 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11259 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11260 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11261 | if (len % 4) |
| 11262 | return -EINVAL; |
| 11263 | |
| 11264 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 11265 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11266 | } |
| 11267 | |
| 11268 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 11269 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 11270 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 11271 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 11272 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 11273 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 11274 | |
| 11275 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 11276 | } |
| 11277 | |
| 11278 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11279 | } |
| 11280 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11281 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11282 | { |
| 11283 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11284 | struct net_device *dev = info->user_ptr[1]; |
| 11285 | struct ocb_setup setup = {}; |
| 11286 | int err; |
| 11287 | |
| 11288 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11289 | if (err) |
| 11290 | return err; |
| 11291 | |
| 11292 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 11293 | } |
| 11294 | |
| 11295 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11296 | { |
| 11297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11298 | struct net_device *dev = info->user_ptr[1]; |
| 11299 | |
| 11300 | return cfg80211_leave_ocb(rdev, dev); |
| 11301 | } |
| 11302 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11303 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11304 | { |
| 11305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11306 | struct net_device *dev = info->user_ptr[1]; |
| 11307 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11308 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11309 | int err; |
| 11310 | |
| 11311 | /* start with default */ |
| 11312 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11313 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11314 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11315 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11316 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11317 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11318 | if (err) |
| 11319 | return err; |
| 11320 | } |
| 11321 | |
| 11322 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 11323 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 11324 | return -EINVAL; |
| 11325 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11326 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11327 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11328 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 11329 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 11330 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 11331 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 11332 | return -EINVAL; |
| 11333 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11334 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 11335 | setup.beacon_interval = |
| 11336 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11337 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 11338 | err = cfg80211_validate_beacon_int(rdev, |
| 11339 | NL80211_IFTYPE_MESH_POINT, |
| 11340 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11341 | if (err) |
| 11342 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11343 | } |
| 11344 | |
| 11345 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 11346 | setup.dtim_period = |
| 11347 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 11348 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 11349 | return -EINVAL; |
| 11350 | } |
| 11351 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11352 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 11353 | /* parse additional setup parameters if given */ |
| 11354 | err = nl80211_parse_mesh_setup(info, &setup); |
| 11355 | if (err) |
| 11356 | return err; |
| 11357 | } |
| 11358 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 11359 | if (setup.user_mpm) |
| 11360 | cfg.auto_open_plinks = false; |
| 11361 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11362 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11363 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11364 | if (err) |
| 11365 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11366 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11367 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11368 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11369 | } |
| 11370 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 11371 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 11372 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11373 | int n_rates = |
| 11374 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11375 | struct ieee80211_supported_band *sband; |
| 11376 | |
| 11377 | if (!setup.chandef.chan) |
| 11378 | return -EINVAL; |
| 11379 | |
| 11380 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 11381 | |
| 11382 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 11383 | &setup.basic_rates); |
| 11384 | if (err) |
| 11385 | return err; |
| 11386 | } |
| 11387 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11388 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 11389 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 11390 | NL80211_ATTR_TX_RATES, |
| 11391 | &setup.beacon_rate); |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11392 | if (err) |
| 11393 | return err; |
| 11394 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 11395 | if (!setup.chandef.chan) |
| 11396 | return -EINVAL; |
| 11397 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11398 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 11399 | &setup.beacon_rate); |
| 11400 | if (err) |
| 11401 | return err; |
| 11402 | } |
| 11403 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 11404 | setup.userspace_handles_dfs = |
| 11405 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 11406 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 11407 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 11408 | int r = validate_pae_over_nl80211(rdev, info); |
| 11409 | |
| 11410 | if (r < 0) |
| 11411 | return r; |
| 11412 | |
| 11413 | setup.control_port_over_nl80211 = true; |
| 11414 | } |
| 11415 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11416 | wdev_lock(dev->ieee80211_ptr); |
| 11417 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 11418 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 11419 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 11420 | wdev_unlock(dev->ieee80211_ptr); |
| 11421 | |
| 11422 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11423 | } |
| 11424 | |
| 11425 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11426 | { |
| 11427 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11428 | struct net_device *dev = info->user_ptr[1]; |
| 11429 | |
| 11430 | return cfg80211_leave_mesh(rdev, dev); |
| 11431 | } |
| 11432 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11433 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11434 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 11435 | struct cfg80211_registered_device *rdev) |
| 11436 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11437 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11438 | struct nlattr *nl_pats, *nl_pat; |
| 11439 | int i, pat_len; |
| 11440 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11441 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11442 | return 0; |
| 11443 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11444 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11445 | if (!nl_pats) |
| 11446 | return -ENOBUFS; |
| 11447 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11448 | for (i = 0; i < wowlan->n_patterns; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11449 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11450 | if (!nl_pat) |
| 11451 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11452 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11453 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11454 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11455 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11456 | wowlan->patterns[i].pattern) || |
| 11457 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11458 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11459 | return -ENOBUFS; |
| 11460 | nla_nest_end(msg, nl_pat); |
| 11461 | } |
| 11462 | nla_nest_end(msg, nl_pats); |
| 11463 | |
| 11464 | return 0; |
| 11465 | } |
| 11466 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11467 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 11468 | struct cfg80211_wowlan_tcp *tcp) |
| 11469 | { |
| 11470 | struct nlattr *nl_tcp; |
| 11471 | |
| 11472 | if (!tcp) |
| 11473 | return 0; |
| 11474 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11475 | nl_tcp = nla_nest_start_noflag(msg, |
| 11476 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11477 | if (!nl_tcp) |
| 11478 | return -ENOBUFS; |
| 11479 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 11480 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 11481 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11482 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 11483 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 11484 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 11485 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 11486 | tcp->payload_len, tcp->payload) || |
| 11487 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 11488 | tcp->data_interval) || |
| 11489 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 11490 | tcp->wake_len, tcp->wake_data) || |
| 11491 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 11492 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 11493 | return -ENOBUFS; |
| 11494 | |
| 11495 | if (tcp->payload_seq.len && |
| 11496 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 11497 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 11498 | return -ENOBUFS; |
| 11499 | |
| 11500 | if (tcp->payload_tok.len && |
| 11501 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 11502 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 11503 | &tcp->payload_tok)) |
| 11504 | return -ENOBUFS; |
| 11505 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 11506 | nla_nest_end(msg, nl_tcp); |
| 11507 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11508 | return 0; |
| 11509 | } |
| 11510 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11511 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 11512 | struct cfg80211_sched_scan_request *req) |
| 11513 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11514 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11515 | int i; |
| 11516 | |
| 11517 | if (!req) |
| 11518 | return 0; |
| 11519 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11520 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11521 | if (!nd) |
| 11522 | return -ENOBUFS; |
| 11523 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11524 | if (req->n_scan_plans == 1 && |
| 11525 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 11526 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11527 | return -ENOBUFS; |
| 11528 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 11529 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 11530 | return -ENOBUFS; |
| 11531 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 11532 | if (req->relative_rssi_set) { |
| 11533 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 11534 | |
| 11535 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 11536 | req->relative_rssi)) |
| 11537 | return -ENOBUFS; |
| 11538 | |
| 11539 | rssi_adjust.band = req->rssi_adjust.band; |
| 11540 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 11541 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 11542 | sizeof(rssi_adjust), &rssi_adjust)) |
| 11543 | return -ENOBUFS; |
| 11544 | } |
| 11545 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11546 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11547 | if (!freqs) |
| 11548 | return -ENOBUFS; |
| 11549 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11550 | for (i = 0; i < req->n_channels; i++) { |
| 11551 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11552 | return -ENOBUFS; |
| 11553 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11554 | |
| 11555 | nla_nest_end(msg, freqs); |
| 11556 | |
| 11557 | if (req->n_match_sets) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11558 | matches = nla_nest_start_noflag(msg, |
| 11559 | NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11560 | if (!matches) |
| 11561 | return -ENOBUFS; |
| 11562 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11563 | for (i = 0; i < req->n_match_sets; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11564 | match = nla_nest_start_noflag(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11565 | if (!match) |
| 11566 | return -ENOBUFS; |
| 11567 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11568 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 11569 | req->match_sets[i].ssid.ssid_len, |
| 11570 | req->match_sets[i].ssid.ssid)) |
| 11571 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11572 | nla_nest_end(msg, match); |
| 11573 | } |
| 11574 | nla_nest_end(msg, matches); |
| 11575 | } |
| 11576 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11577 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11578 | if (!scan_plans) |
| 11579 | return -ENOBUFS; |
| 11580 | |
| 11581 | for (i = 0; i < req->n_scan_plans; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11582 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11583 | if (!scan_plan) |
| 11584 | return -ENOBUFS; |
| 11585 | |
Colin Ian King | 6762696 | 2018-09-06 10:58:44 +0100 | [diff] [blame] | 11586 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11587 | req->scan_plans[i].interval) || |
| 11588 | (req->scan_plans[i].iterations && |
| 11589 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 11590 | req->scan_plans[i].iterations))) |
| 11591 | return -ENOBUFS; |
| 11592 | nla_nest_end(msg, scan_plan); |
| 11593 | } |
| 11594 | nla_nest_end(msg, scan_plans); |
| 11595 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11596 | nla_nest_end(msg, nd); |
| 11597 | |
| 11598 | return 0; |
| 11599 | } |
| 11600 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11601 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11602 | { |
| 11603 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11604 | struct sk_buff *msg; |
| 11605 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11606 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11607 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11608 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11609 | return -EOPNOTSUPP; |
| 11610 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11611 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11612 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11613 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 11614 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 11615 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 11616 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11617 | } |
| 11618 | |
| 11619 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11620 | if (!msg) |
| 11621 | return -ENOMEM; |
| 11622 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11623 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11624 | NL80211_CMD_GET_WOWLAN); |
| 11625 | if (!hdr) |
| 11626 | goto nla_put_failure; |
| 11627 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11628 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11629 | struct nlattr *nl_wowlan; |
| 11630 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11631 | nl_wowlan = nla_nest_start_noflag(msg, |
| 11632 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11633 | if (!nl_wowlan) |
| 11634 | goto nla_put_failure; |
| 11635 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11636 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11637 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11638 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11639 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11640 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11641 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11642 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11643 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11644 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11645 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11646 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11647 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11648 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11649 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 11650 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11651 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11652 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 11653 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11654 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11655 | if (nl80211_send_wowlan_tcp(msg, |
| 11656 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11657 | goto nla_put_failure; |
| 11658 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11659 | if (nl80211_send_wowlan_nd( |
| 11660 | msg, |
| 11661 | rdev->wiphy.wowlan_config->nd_config)) |
| 11662 | goto nla_put_failure; |
| 11663 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11664 | nla_nest_end(msg, nl_wowlan); |
| 11665 | } |
| 11666 | |
| 11667 | genlmsg_end(msg, hdr); |
| 11668 | return genlmsg_reply(msg, info); |
| 11669 | |
| 11670 | nla_put_failure: |
| 11671 | nlmsg_free(msg); |
| 11672 | return -ENOBUFS; |
| 11673 | } |
| 11674 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11675 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 11676 | struct nlattr *attr, |
| 11677 | struct cfg80211_wowlan *trig) |
| 11678 | { |
| 11679 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 11680 | struct cfg80211_wowlan_tcp *cfg; |
| 11681 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 11682 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 11683 | u32 size; |
| 11684 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 11685 | int err, port; |
| 11686 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11687 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11688 | return -EINVAL; |
| 11689 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11690 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 11691 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11692 | if (err) |
| 11693 | return err; |
| 11694 | |
| 11695 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 11696 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 11697 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 11698 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 11699 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 11700 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 11701 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 11702 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 11703 | return -EINVAL; |
| 11704 | |
| 11705 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11706 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11707 | return -EINVAL; |
| 11708 | |
| 11709 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11710 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 11711 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11712 | return -EINVAL; |
| 11713 | |
| 11714 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11715 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11716 | return -EINVAL; |
| 11717 | |
| 11718 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 11719 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 11720 | return -EINVAL; |
| 11721 | |
| 11722 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 11723 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11724 | |
| 11725 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 11726 | tokens_size = tokln - sizeof(*tok); |
| 11727 | |
| 11728 | if (!tok->len || tokens_size % tok->len) |
| 11729 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11730 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11731 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11732 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11733 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11734 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11735 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11736 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11737 | return -EINVAL; |
| 11738 | if (tok->offset + tok->len > data_size) |
| 11739 | return -EINVAL; |
| 11740 | } |
| 11741 | |
| 11742 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 11743 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11744 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11745 | return -EINVAL; |
| 11746 | if (seq->len == 0 || seq->len > 4) |
| 11747 | return -EINVAL; |
| 11748 | if (seq->len + seq->offset > data_size) |
| 11749 | return -EINVAL; |
| 11750 | } |
| 11751 | |
| 11752 | size = sizeof(*cfg); |
| 11753 | size += data_size; |
| 11754 | size += wake_size + wake_mask_size; |
| 11755 | size += tokens_size; |
| 11756 | |
| 11757 | cfg = kzalloc(size, GFP_KERNEL); |
| 11758 | if (!cfg) |
| 11759 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 11760 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 11761 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11762 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 11763 | ETH_ALEN); |
| 11764 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 11765 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 11766 | else |
| 11767 | port = 0; |
| 11768 | #ifdef CONFIG_INET |
| 11769 | /* allocate a socket and port for it and use it */ |
| 11770 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 11771 | IPPROTO_TCP, &cfg->sock, 1); |
| 11772 | if (err) { |
| 11773 | kfree(cfg); |
| 11774 | return err; |
| 11775 | } |
| 11776 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 11777 | sock_release(cfg->sock); |
| 11778 | kfree(cfg); |
| 11779 | return -EADDRINUSE; |
| 11780 | } |
| 11781 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 11782 | #else |
| 11783 | if (!port) { |
| 11784 | kfree(cfg); |
| 11785 | return -EINVAL; |
| 11786 | } |
| 11787 | cfg->src_port = port; |
| 11788 | #endif |
| 11789 | |
| 11790 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 11791 | cfg->payload_len = data_size; |
| 11792 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 11793 | memcpy((void *)cfg->payload, |
| 11794 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 11795 | data_size); |
| 11796 | if (seq) |
| 11797 | cfg->payload_seq = *seq; |
| 11798 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 11799 | cfg->wake_len = wake_size; |
| 11800 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 11801 | memcpy((void *)cfg->wake_data, |
| 11802 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 11803 | wake_size); |
| 11804 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 11805 | data_size + wake_size; |
| 11806 | memcpy((void *)cfg->wake_mask, |
| 11807 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 11808 | wake_mask_size); |
| 11809 | if (tok) { |
| 11810 | cfg->tokens_size = tokens_size; |
| 11811 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 11812 | } |
| 11813 | |
| 11814 | trig->tcp = cfg; |
| 11815 | |
| 11816 | return 0; |
| 11817 | } |
| 11818 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11819 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 11820 | const struct wiphy_wowlan_support *wowlan, |
| 11821 | struct nlattr *attr, |
| 11822 | struct cfg80211_wowlan *trig) |
| 11823 | { |
| 11824 | struct nlattr **tb; |
| 11825 | int err; |
| 11826 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 11827 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11828 | if (!tb) |
| 11829 | return -ENOMEM; |
| 11830 | |
| 11831 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 11832 | err = -EOPNOTSUPP; |
| 11833 | goto out; |
| 11834 | } |
| 11835 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11836 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
| 11837 | nl80211_policy, NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11838 | if (err) |
| 11839 | goto out; |
| 11840 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 11841 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 11842 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 11843 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 11844 | if (err) |
| 11845 | trig->nd_config = NULL; |
| 11846 | |
| 11847 | out: |
| 11848 | kfree(tb); |
| 11849 | return err; |
| 11850 | } |
| 11851 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11852 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11853 | { |
| 11854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11855 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11856 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11857 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11858 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11859 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11860 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11861 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11862 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11863 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11864 | return -EOPNOTSUPP; |
| 11865 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11866 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 11867 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11868 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 11869 | goto set_wakeup; |
| 11870 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11871 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11872 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
| 11873 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 11874 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11875 | if (err) |
| 11876 | return err; |
| 11877 | |
| 11878 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 11879 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 11880 | return -EINVAL; |
| 11881 | new_triggers.any = true; |
| 11882 | } |
| 11883 | |
| 11884 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 11885 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 11886 | return -EINVAL; |
| 11887 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11888 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11889 | } |
| 11890 | |
| 11891 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 11892 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 11893 | return -EINVAL; |
| 11894 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11895 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11896 | } |
| 11897 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11898 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 11899 | return -EINVAL; |
| 11900 | |
| 11901 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 11902 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 11903 | return -EINVAL; |
| 11904 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11905 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11906 | } |
| 11907 | |
| 11908 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 11909 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 11910 | return -EINVAL; |
| 11911 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11912 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11913 | } |
| 11914 | |
| 11915 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 11916 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 11917 | return -EINVAL; |
| 11918 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11919 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11920 | } |
| 11921 | |
| 11922 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 11923 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 11924 | return -EINVAL; |
| 11925 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11926 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 11927 | } |
| 11928 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11929 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 11930 | struct nlattr *pat; |
| 11931 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11932 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11933 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11934 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 11935 | regular = true; |
| 11936 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11937 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11938 | rem) |
| 11939 | n_patterns++; |
| 11940 | if (n_patterns > wowlan->n_patterns) |
| 11941 | return -EINVAL; |
| 11942 | |
| 11943 | new_triggers.patterns = kcalloc(n_patterns, |
| 11944 | sizeof(new_triggers.patterns[0]), |
| 11945 | GFP_KERNEL); |
| 11946 | if (!new_triggers.patterns) |
| 11947 | return -ENOMEM; |
| 11948 | |
| 11949 | new_triggers.n_patterns = n_patterns; |
| 11950 | i = 0; |
| 11951 | |
| 11952 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 11953 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11954 | u8 *mask_pat; |
| 11955 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11956 | err = nla_parse_nested_deprecated(pat_tb, |
| 11957 | MAX_NL80211_PKTPAT, |
| 11958 | pat, |
| 11959 | nl80211_packet_pattern_policy, |
| 11960 | info->extack); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 11961 | if (err) |
| 11962 | goto error; |
| 11963 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11964 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11965 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 11966 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11967 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11968 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11969 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11970 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11971 | goto error; |
| 11972 | if (pat_len > wowlan->pattern_max_len || |
| 11973 | pat_len < wowlan->pattern_min_len) |
| 11974 | goto error; |
| 11975 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11976 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11977 | pkt_offset = 0; |
| 11978 | else |
| 11979 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11980 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11981 | if (pkt_offset > wowlan->max_pkt_offset) |
| 11982 | goto error; |
| 11983 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 11984 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11985 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 11986 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11987 | err = -ENOMEM; |
| 11988 | goto error; |
| 11989 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11990 | new_triggers.patterns[i].mask = mask_pat; |
| 11991 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11992 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11993 | mask_pat += mask_len; |
| 11994 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11995 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 11996 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11997 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11998 | pat_len); |
| 11999 | i++; |
| 12000 | } |
| 12001 | } |
| 12002 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12003 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12004 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12005 | err = nl80211_parse_wowlan_tcp( |
| 12006 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 12007 | &new_triggers); |
| 12008 | if (err) |
| 12009 | goto error; |
| 12010 | } |
| 12011 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12012 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12013 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12014 | err = nl80211_parse_wowlan_nd( |
| 12015 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 12016 | &new_triggers); |
| 12017 | if (err) |
| 12018 | goto error; |
| 12019 | } |
| 12020 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12021 | /* The 'any' trigger means the device continues operating more or less |
| 12022 | * as in its normal operation mode and wakes up the host on most of the |
| 12023 | * normal interrupts (like packet RX, ...) |
| 12024 | * It therefore makes little sense to combine with the more constrained |
| 12025 | * wakeup trigger modes. |
| 12026 | */ |
| 12027 | if (new_triggers.any && regular) { |
| 12028 | err = -EINVAL; |
| 12029 | goto error; |
| 12030 | } |
| 12031 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12032 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 12033 | if (!ntrig) { |
| 12034 | err = -ENOMEM; |
| 12035 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12036 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12037 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12038 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12039 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12040 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12041 | if (rdev->ops->set_wakeup && |
| 12042 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 12043 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 12044 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12045 | return 0; |
| 12046 | error: |
| 12047 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 12048 | kfree(new_triggers.patterns[i].mask); |
| 12049 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12050 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 12051 | sock_release(new_triggers.tcp->sock); |
| 12052 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 12053 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12054 | return err; |
| 12055 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12056 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12057 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12058 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 12059 | struct cfg80211_registered_device *rdev) |
| 12060 | { |
| 12061 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 12062 | int i, j, pat_len; |
| 12063 | struct cfg80211_coalesce_rules *rule; |
| 12064 | |
| 12065 | if (!rdev->coalesce->n_rules) |
| 12066 | return 0; |
| 12067 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12068 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12069 | if (!nl_rules) |
| 12070 | return -ENOBUFS; |
| 12071 | |
| 12072 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12073 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12074 | if (!nl_rule) |
| 12075 | return -ENOBUFS; |
| 12076 | |
| 12077 | rule = &rdev->coalesce->rules[i]; |
| 12078 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 12079 | rule->delay)) |
| 12080 | return -ENOBUFS; |
| 12081 | |
| 12082 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 12083 | rule->condition)) |
| 12084 | return -ENOBUFS; |
| 12085 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12086 | nl_pats = nla_nest_start_noflag(msg, |
| 12087 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12088 | if (!nl_pats) |
| 12089 | return -ENOBUFS; |
| 12090 | |
| 12091 | for (j = 0; j < rule->n_patterns; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12092 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12093 | if (!nl_pat) |
| 12094 | return -ENOBUFS; |
| 12095 | pat_len = rule->patterns[j].pattern_len; |
| 12096 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 12097 | DIV_ROUND_UP(pat_len, 8), |
| 12098 | rule->patterns[j].mask) || |
| 12099 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 12100 | rule->patterns[j].pattern) || |
| 12101 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 12102 | rule->patterns[j].pkt_offset)) |
| 12103 | return -ENOBUFS; |
| 12104 | nla_nest_end(msg, nl_pat); |
| 12105 | } |
| 12106 | nla_nest_end(msg, nl_pats); |
| 12107 | nla_nest_end(msg, nl_rule); |
| 12108 | } |
| 12109 | nla_nest_end(msg, nl_rules); |
| 12110 | |
| 12111 | return 0; |
| 12112 | } |
| 12113 | |
| 12114 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12115 | { |
| 12116 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12117 | struct sk_buff *msg; |
| 12118 | void *hdr; |
| 12119 | |
| 12120 | if (!rdev->wiphy.coalesce) |
| 12121 | return -EOPNOTSUPP; |
| 12122 | |
| 12123 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12124 | if (!msg) |
| 12125 | return -ENOMEM; |
| 12126 | |
| 12127 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12128 | NL80211_CMD_GET_COALESCE); |
| 12129 | if (!hdr) |
| 12130 | goto nla_put_failure; |
| 12131 | |
| 12132 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 12133 | goto nla_put_failure; |
| 12134 | |
| 12135 | genlmsg_end(msg, hdr); |
| 12136 | return genlmsg_reply(msg, info); |
| 12137 | |
| 12138 | nla_put_failure: |
| 12139 | nlmsg_free(msg); |
| 12140 | return -ENOBUFS; |
| 12141 | } |
| 12142 | |
| 12143 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 12144 | { |
| 12145 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 12146 | int i, j; |
| 12147 | struct cfg80211_coalesce_rules *rule; |
| 12148 | |
| 12149 | if (!coalesce) |
| 12150 | return; |
| 12151 | |
| 12152 | for (i = 0; i < coalesce->n_rules; i++) { |
| 12153 | rule = &coalesce->rules[i]; |
| 12154 | for (j = 0; j < rule->n_patterns; j++) |
| 12155 | kfree(rule->patterns[j].mask); |
| 12156 | kfree(rule->patterns); |
| 12157 | } |
| 12158 | kfree(coalesce->rules); |
| 12159 | kfree(coalesce); |
| 12160 | rdev->coalesce = NULL; |
| 12161 | } |
| 12162 | |
| 12163 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 12164 | struct nlattr *rule, |
| 12165 | struct cfg80211_coalesce_rules *new_rule) |
| 12166 | { |
| 12167 | int err, i; |
| 12168 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12169 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 12170 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 12171 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12172 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12173 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
| 12174 | rule, nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12175 | if (err) |
| 12176 | return err; |
| 12177 | |
| 12178 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 12179 | new_rule->delay = |
| 12180 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 12181 | if (new_rule->delay > coalesce->max_delay) |
| 12182 | return -EINVAL; |
| 12183 | |
| 12184 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 12185 | new_rule->condition = |
| 12186 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12187 | |
| 12188 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 12189 | return -EINVAL; |
| 12190 | |
| 12191 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12192 | rem) |
| 12193 | n_patterns++; |
| 12194 | if (n_patterns > coalesce->n_patterns) |
| 12195 | return -EINVAL; |
| 12196 | |
| 12197 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 12198 | GFP_KERNEL); |
| 12199 | if (!new_rule->patterns) |
| 12200 | return -ENOMEM; |
| 12201 | |
| 12202 | new_rule->n_patterns = n_patterns; |
| 12203 | i = 0; |
| 12204 | |
| 12205 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12206 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12207 | u8 *mask_pat; |
| 12208 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12209 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
| 12210 | pat, |
| 12211 | nl80211_packet_pattern_policy, |
| 12212 | NULL); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12213 | if (err) |
| 12214 | return err; |
| 12215 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12216 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12217 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12218 | return -EINVAL; |
| 12219 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12220 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12221 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12222 | return -EINVAL; |
| 12223 | if (pat_len > coalesce->pattern_max_len || |
| 12224 | pat_len < coalesce->pattern_min_len) |
| 12225 | return -EINVAL; |
| 12226 | |
| 12227 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12228 | pkt_offset = 0; |
| 12229 | else |
| 12230 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12231 | if (pkt_offset > coalesce->max_pkt_offset) |
| 12232 | return -EINVAL; |
| 12233 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 12234 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12235 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12236 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12237 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12238 | |
| 12239 | new_rule->patterns[i].mask = mask_pat; |
| 12240 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12241 | mask_len); |
| 12242 | |
| 12243 | mask_pat += mask_len; |
| 12244 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12245 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12246 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 12247 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12248 | i++; |
| 12249 | } |
| 12250 | |
| 12251 | return 0; |
| 12252 | } |
| 12253 | |
| 12254 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12255 | { |
| 12256 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12257 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12258 | struct cfg80211_coalesce new_coalesce = {}; |
| 12259 | struct cfg80211_coalesce *n_coalesce; |
| 12260 | int err, rem_rule, n_rules = 0, i, j; |
| 12261 | struct nlattr *rule; |
| 12262 | struct cfg80211_coalesce_rules *tmp_rule; |
| 12263 | |
| 12264 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 12265 | return -EOPNOTSUPP; |
| 12266 | |
| 12267 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 12268 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12269 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12270 | return 0; |
| 12271 | } |
| 12272 | |
| 12273 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12274 | rem_rule) |
| 12275 | n_rules++; |
| 12276 | if (n_rules > coalesce->n_rules) |
| 12277 | return -EINVAL; |
| 12278 | |
| 12279 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 12280 | GFP_KERNEL); |
| 12281 | if (!new_coalesce.rules) |
| 12282 | return -ENOMEM; |
| 12283 | |
| 12284 | new_coalesce.n_rules = n_rules; |
| 12285 | i = 0; |
| 12286 | |
| 12287 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12288 | rem_rule) { |
| 12289 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 12290 | &new_coalesce.rules[i]); |
| 12291 | if (err) |
| 12292 | goto error; |
| 12293 | |
| 12294 | i++; |
| 12295 | } |
| 12296 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12297 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12298 | if (err) |
| 12299 | goto error; |
| 12300 | |
| 12301 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 12302 | if (!n_coalesce) { |
| 12303 | err = -ENOMEM; |
| 12304 | goto error; |
| 12305 | } |
| 12306 | cfg80211_rdev_free_coalesce(rdev); |
| 12307 | rdev->coalesce = n_coalesce; |
| 12308 | |
| 12309 | return 0; |
| 12310 | error: |
| 12311 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 12312 | tmp_rule = &new_coalesce.rules[i]; |
| 12313 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 12314 | kfree(tmp_rule->patterns[j].mask); |
| 12315 | kfree(tmp_rule->patterns); |
| 12316 | } |
| 12317 | kfree(new_coalesce.rules); |
| 12318 | |
| 12319 | return err; |
| 12320 | } |
| 12321 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12322 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 12323 | { |
| 12324 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12325 | struct net_device *dev = info->user_ptr[1]; |
| 12326 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12327 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 12328 | struct cfg80211_gtk_rekey_data rekey_data; |
| 12329 | int err; |
| 12330 | |
| 12331 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 12332 | return -EINVAL; |
| 12333 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12334 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
| 12335 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 12336 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12337 | if (err) |
| 12338 | return err; |
| 12339 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 12340 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 12341 | !tb[NL80211_REKEY_DATA_KCK]) |
| 12342 | return -EINVAL; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12343 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && |
| 12344 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12345 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12346 | return -ERANGE; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12347 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && |
| 12348 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12349 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12350 | return -ERANGE; |
| 12351 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 12352 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 12353 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 12354 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12355 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
| 12356 | rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); |
| 12357 | if (tb[NL80211_REKEY_DATA_AKM]) |
| 12358 | rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12359 | |
| 12360 | wdev_lock(wdev); |
| 12361 | if (!wdev->current_bss) { |
| 12362 | err = -ENOTCONN; |
| 12363 | goto out; |
| 12364 | } |
| 12365 | |
| 12366 | if (!rdev->ops->set_rekey_data) { |
| 12367 | err = -EOPNOTSUPP; |
| 12368 | goto out; |
| 12369 | } |
| 12370 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12371 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12372 | out: |
| 12373 | wdev_unlock(wdev); |
| 12374 | return err; |
| 12375 | } |
| 12376 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12377 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 12378 | struct genl_info *info) |
| 12379 | { |
| 12380 | struct net_device *dev = info->user_ptr[1]; |
| 12381 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12382 | |
| 12383 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12384 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12385 | return -EINVAL; |
| 12386 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12387 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12388 | return -EBUSY; |
| 12389 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12390 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12391 | return 0; |
| 12392 | } |
| 12393 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12394 | static int nl80211_probe_client(struct sk_buff *skb, |
| 12395 | struct genl_info *info) |
| 12396 | { |
| 12397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12398 | struct net_device *dev = info->user_ptr[1]; |
| 12399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12400 | struct sk_buff *msg; |
| 12401 | void *hdr; |
| 12402 | const u8 *addr; |
| 12403 | u64 cookie; |
| 12404 | int err; |
| 12405 | |
| 12406 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12407 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12408 | return -EOPNOTSUPP; |
| 12409 | |
| 12410 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12411 | return -EINVAL; |
| 12412 | |
| 12413 | if (!rdev->ops->probe_client) |
| 12414 | return -EOPNOTSUPP; |
| 12415 | |
| 12416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12417 | if (!msg) |
| 12418 | return -ENOMEM; |
| 12419 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12420 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12421 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 12422 | if (!hdr) { |
| 12423 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12424 | goto free_msg; |
| 12425 | } |
| 12426 | |
| 12427 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12428 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12429 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12430 | if (err) |
| 12431 | goto free_msg; |
| 12432 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12433 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12434 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12435 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12436 | |
| 12437 | genlmsg_end(msg, hdr); |
| 12438 | |
| 12439 | return genlmsg_reply(msg, info); |
| 12440 | |
| 12441 | nla_put_failure: |
| 12442 | err = -ENOBUFS; |
| 12443 | free_msg: |
| 12444 | nlmsg_free(msg); |
| 12445 | return err; |
| 12446 | } |
| 12447 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12448 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 12449 | { |
| 12450 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12451 | struct cfg80211_beacon_registration *reg, *nreg; |
| 12452 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12453 | |
| 12454 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 12455 | return -EOPNOTSUPP; |
| 12456 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12457 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 12458 | if (!nreg) |
| 12459 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12460 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12461 | /* First, check if already registered. */ |
| 12462 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12463 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12464 | if (reg->nlportid == info->snd_portid) { |
| 12465 | rv = -EALREADY; |
| 12466 | goto out_err; |
| 12467 | } |
| 12468 | } |
| 12469 | /* Add it to the list */ |
| 12470 | nreg->nlportid = info->snd_portid; |
| 12471 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 12472 | |
| 12473 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12474 | |
| 12475 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12476 | out_err: |
| 12477 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12478 | kfree(nreg); |
| 12479 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12480 | } |
| 12481 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12482 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12483 | { |
| 12484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12485 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12486 | int err; |
| 12487 | |
| 12488 | if (!rdev->ops->start_p2p_device) |
| 12489 | return -EOPNOTSUPP; |
| 12490 | |
| 12491 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12492 | return -EOPNOTSUPP; |
| 12493 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12494 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12495 | return 0; |
| 12496 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 12497 | if (rfkill_blocked(rdev->rfkill)) |
| 12498 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12499 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 12500 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12501 | if (err) |
| 12502 | return err; |
| 12503 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12504 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12505 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12506 | |
| 12507 | return 0; |
| 12508 | } |
| 12509 | |
| 12510 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12511 | { |
| 12512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12513 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12514 | |
| 12515 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12516 | return -EOPNOTSUPP; |
| 12517 | |
| 12518 | if (!rdev->ops->stop_p2p_device) |
| 12519 | return -EOPNOTSUPP; |
| 12520 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 12521 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12522 | |
| 12523 | return 0; |
| 12524 | } |
| 12525 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12526 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 12527 | { |
| 12528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12529 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12530 | struct cfg80211_nan_conf conf = {}; |
| 12531 | int err; |
| 12532 | |
| 12533 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12534 | return -EOPNOTSUPP; |
| 12535 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 12536 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12537 | return -EEXIST; |
| 12538 | |
| 12539 | if (rfkill_blocked(rdev->rfkill)) |
| 12540 | return -ERFKILL; |
| 12541 | |
| 12542 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 12543 | return -EINVAL; |
| 12544 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12545 | conf.master_pref = |
| 12546 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12547 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12548 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12549 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12550 | |
| 12551 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12552 | return -EOPNOTSUPP; |
| 12553 | |
| 12554 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12555 | return -EINVAL; |
| 12556 | |
| 12557 | conf.bands = bands; |
| 12558 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12559 | |
| 12560 | err = rdev_start_nan(rdev, wdev, &conf); |
| 12561 | if (err) |
| 12562 | return err; |
| 12563 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12564 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12565 | rdev->opencount++; |
| 12566 | |
| 12567 | return 0; |
| 12568 | } |
| 12569 | |
| 12570 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 12571 | { |
| 12572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12573 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12574 | |
| 12575 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12576 | return -EOPNOTSUPP; |
| 12577 | |
| 12578 | cfg80211_stop_nan(rdev, wdev); |
| 12579 | |
| 12580 | return 0; |
| 12581 | } |
| 12582 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12583 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 12584 | { |
| 12585 | struct nlattr *attr; |
| 12586 | int len = 0, n_entries = 0, rem; |
| 12587 | |
| 12588 | nla_for_each_nested(attr, filter_attr, rem) { |
| 12589 | len += nla_len(attr); |
| 12590 | n_entries++; |
| 12591 | } |
| 12592 | |
| 12593 | if (len >= U8_MAX) |
| 12594 | return -EINVAL; |
| 12595 | |
| 12596 | return n_entries; |
| 12597 | } |
| 12598 | |
| 12599 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 12600 | struct cfg80211_nan_func *func, |
| 12601 | bool tx) |
| 12602 | { |
| 12603 | struct nlattr *attr; |
| 12604 | int n_entries, rem, i; |
| 12605 | struct cfg80211_nan_func_filter *filter; |
| 12606 | |
| 12607 | n_entries = validate_nan_filter(attr_filter); |
| 12608 | if (n_entries < 0) |
| 12609 | return n_entries; |
| 12610 | |
| 12611 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 12612 | |
| 12613 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 12614 | if (!filter) |
| 12615 | return -ENOMEM; |
| 12616 | |
| 12617 | i = 0; |
| 12618 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 12619 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12620 | filter[i].len = nla_len(attr); |
| 12621 | i++; |
| 12622 | } |
| 12623 | if (tx) { |
| 12624 | func->num_tx_filters = n_entries; |
| 12625 | func->tx_filters = filter; |
| 12626 | } else { |
| 12627 | func->num_rx_filters = n_entries; |
| 12628 | func->rx_filters = filter; |
| 12629 | } |
| 12630 | |
| 12631 | return 0; |
| 12632 | } |
| 12633 | |
| 12634 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 12635 | struct genl_info *info) |
| 12636 | { |
| 12637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12638 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12639 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 12640 | struct cfg80211_nan_func *func; |
| 12641 | struct sk_buff *msg = NULL; |
| 12642 | void *hdr = NULL; |
| 12643 | int err = 0; |
| 12644 | |
| 12645 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12646 | return -EOPNOTSUPP; |
| 12647 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12648 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12649 | return -ENOTCONN; |
| 12650 | |
| 12651 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 12652 | return -EINVAL; |
| 12653 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12654 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 12655 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 12656 | nl80211_nan_func_policy, |
| 12657 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12658 | if (err) |
| 12659 | return err; |
| 12660 | |
| 12661 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 12662 | if (!func) |
| 12663 | return -ENOMEM; |
| 12664 | |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 12665 | func->cookie = cfg80211_assign_cookie(rdev); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12666 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 12667 | if (!tb[NL80211_NAN_FUNC_TYPE]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12668 | err = -EINVAL; |
| 12669 | goto out; |
| 12670 | } |
| 12671 | |
| 12672 | |
| 12673 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 12674 | |
| 12675 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 12676 | err = -EINVAL; |
| 12677 | goto out; |
| 12678 | } |
| 12679 | |
| 12680 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 12681 | sizeof(func->service_id)); |
| 12682 | |
| 12683 | func->close_range = |
| 12684 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 12685 | |
| 12686 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 12687 | func->serv_spec_info_len = |
| 12688 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 12689 | func->serv_spec_info = |
| 12690 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 12691 | func->serv_spec_info_len, |
| 12692 | GFP_KERNEL); |
| 12693 | if (!func->serv_spec_info) { |
| 12694 | err = -ENOMEM; |
| 12695 | goto out; |
| 12696 | } |
| 12697 | } |
| 12698 | |
| 12699 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 12700 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 12701 | |
| 12702 | switch (func->type) { |
| 12703 | case NL80211_NAN_FUNC_PUBLISH: |
| 12704 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 12705 | err = -EINVAL; |
| 12706 | goto out; |
| 12707 | } |
| 12708 | |
| 12709 | func->publish_type = |
| 12710 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 12711 | func->publish_bcast = |
| 12712 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 12713 | |
| 12714 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 12715 | func->publish_bcast) { |
| 12716 | err = -EINVAL; |
| 12717 | goto out; |
| 12718 | } |
| 12719 | break; |
| 12720 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 12721 | func->subscribe_active = |
| 12722 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 12723 | break; |
| 12724 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 12725 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 12726 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 12727 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12728 | err = -EINVAL; |
| 12729 | goto out; |
| 12730 | } |
| 12731 | |
| 12732 | func->followup_id = |
| 12733 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 12734 | func->followup_reqid = |
| 12735 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 12736 | memcpy(func->followup_dest.addr, |
| 12737 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 12738 | sizeof(func->followup_dest.addr)); |
| 12739 | if (func->ttl) { |
| 12740 | err = -EINVAL; |
| 12741 | goto out; |
| 12742 | } |
| 12743 | break; |
| 12744 | default: |
| 12745 | err = -EINVAL; |
| 12746 | goto out; |
| 12747 | } |
| 12748 | |
| 12749 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 12750 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 12751 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12752 | err = nla_parse_nested_deprecated(srf_tb, |
| 12753 | NL80211_NAN_SRF_ATTR_MAX, |
| 12754 | tb[NL80211_NAN_FUNC_SRF], |
| 12755 | nl80211_nan_srf_policy, |
| 12756 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12757 | if (err) |
| 12758 | goto out; |
| 12759 | |
| 12760 | func->srf_include = |
| 12761 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 12762 | |
| 12763 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 12764 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 12765 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 12766 | err = -EINVAL; |
| 12767 | goto out; |
| 12768 | } |
| 12769 | |
| 12770 | func->srf_bf_len = |
| 12771 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 12772 | func->srf_bf = |
| 12773 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 12774 | func->srf_bf_len, GFP_KERNEL); |
| 12775 | if (!func->srf_bf) { |
| 12776 | err = -ENOMEM; |
| 12777 | goto out; |
| 12778 | } |
| 12779 | |
| 12780 | func->srf_bf_idx = |
| 12781 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 12782 | } else { |
| 12783 | struct nlattr *attr, *mac_attr = |
| 12784 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 12785 | int n_entries, rem, i = 0; |
| 12786 | |
| 12787 | if (!mac_attr) { |
| 12788 | err = -EINVAL; |
| 12789 | goto out; |
| 12790 | } |
| 12791 | |
| 12792 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 12793 | if (n_entries <= 0) { |
| 12794 | err = -EINVAL; |
| 12795 | goto out; |
| 12796 | } |
| 12797 | |
| 12798 | func->srf_num_macs = n_entries; |
| 12799 | func->srf_macs = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12800 | kcalloc(n_entries, sizeof(*func->srf_macs), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12801 | GFP_KERNEL); |
| 12802 | if (!func->srf_macs) { |
| 12803 | err = -ENOMEM; |
| 12804 | goto out; |
| 12805 | } |
| 12806 | |
| 12807 | nla_for_each_nested(attr, mac_attr, rem) |
| 12808 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 12809 | sizeof(*func->srf_macs)); |
| 12810 | } |
| 12811 | } |
| 12812 | |
| 12813 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 12814 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 12815 | func, true); |
| 12816 | if (err) |
| 12817 | goto out; |
| 12818 | } |
| 12819 | |
| 12820 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 12821 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 12822 | func, false); |
| 12823 | if (err) |
| 12824 | goto out; |
| 12825 | } |
| 12826 | |
| 12827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12828 | if (!msg) { |
| 12829 | err = -ENOMEM; |
| 12830 | goto out; |
| 12831 | } |
| 12832 | |
| 12833 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12834 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 12835 | /* This can't really happen - we just allocated 4KB */ |
| 12836 | if (WARN_ON(!hdr)) { |
| 12837 | err = -ENOMEM; |
| 12838 | goto out; |
| 12839 | } |
| 12840 | |
| 12841 | err = rdev_add_nan_func(rdev, wdev, func); |
| 12842 | out: |
| 12843 | if (err < 0) { |
| 12844 | cfg80211_free_nan_func(func); |
| 12845 | nlmsg_free(msg); |
| 12846 | return err; |
| 12847 | } |
| 12848 | |
| 12849 | /* propagate the instance id and cookie to userspace */ |
| 12850 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 12851 | NL80211_ATTR_PAD)) |
| 12852 | goto nla_put_failure; |
| 12853 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12854 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12855 | if (!func_attr) |
| 12856 | goto nla_put_failure; |
| 12857 | |
| 12858 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 12859 | func->instance_id)) |
| 12860 | goto nla_put_failure; |
| 12861 | |
| 12862 | nla_nest_end(msg, func_attr); |
| 12863 | |
| 12864 | genlmsg_end(msg, hdr); |
| 12865 | return genlmsg_reply(msg, info); |
| 12866 | |
| 12867 | nla_put_failure: |
| 12868 | nlmsg_free(msg); |
| 12869 | return -ENOBUFS; |
| 12870 | } |
| 12871 | |
| 12872 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 12873 | struct genl_info *info) |
| 12874 | { |
| 12875 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12876 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12877 | u64 cookie; |
| 12878 | |
| 12879 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12880 | return -EOPNOTSUPP; |
| 12881 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12882 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12883 | return -ENOTCONN; |
| 12884 | |
| 12885 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 12886 | return -EINVAL; |
| 12887 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12888 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 12889 | |
| 12890 | rdev_del_nan_func(rdev, wdev, cookie); |
| 12891 | |
| 12892 | return 0; |
| 12893 | } |
| 12894 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12895 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 12896 | struct genl_info *info) |
| 12897 | { |
| 12898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12899 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12900 | struct cfg80211_nan_conf conf = {}; |
| 12901 | u32 changed = 0; |
| 12902 | |
| 12903 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12904 | return -EOPNOTSUPP; |
| 12905 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12906 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12907 | return -ENOTCONN; |
| 12908 | |
| 12909 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 12910 | conf.master_pref = |
| 12911 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 12912 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 12913 | return -EINVAL; |
| 12914 | |
| 12915 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 12916 | } |
| 12917 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12918 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12919 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12920 | |
| 12921 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12922 | return -EOPNOTSUPP; |
| 12923 | |
| 12924 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12925 | return -EINVAL; |
| 12926 | |
| 12927 | conf.bands = bands; |
| 12928 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 12929 | } |
| 12930 | |
| 12931 | if (!changed) |
| 12932 | return -EINVAL; |
| 12933 | |
| 12934 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 12935 | } |
| 12936 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12937 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 12938 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 12939 | { |
| 12940 | struct wiphy *wiphy = wdev->wiphy; |
| 12941 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 12942 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 12943 | struct sk_buff *msg; |
| 12944 | void *hdr; |
| 12945 | |
| 12946 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 12947 | return; |
| 12948 | |
| 12949 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 12950 | if (!msg) |
| 12951 | return; |
| 12952 | |
| 12953 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 12954 | if (!hdr) { |
| 12955 | nlmsg_free(msg); |
| 12956 | return; |
| 12957 | } |
| 12958 | |
| 12959 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 12960 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 12961 | wdev->netdev->ifindex)) || |
| 12962 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 12963 | NL80211_ATTR_PAD)) |
| 12964 | goto nla_put_failure; |
| 12965 | |
| 12966 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 12967 | NL80211_ATTR_PAD) || |
| 12968 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 12969 | goto nla_put_failure; |
| 12970 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12971 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12972 | if (!match_attr) |
| 12973 | goto nla_put_failure; |
| 12974 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12975 | local_func_attr = nla_nest_start_noflag(msg, |
| 12976 | NL80211_NAN_MATCH_FUNC_LOCAL); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12977 | if (!local_func_attr) |
| 12978 | goto nla_put_failure; |
| 12979 | |
| 12980 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 12981 | goto nla_put_failure; |
| 12982 | |
| 12983 | nla_nest_end(msg, local_func_attr); |
| 12984 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12985 | peer_func_attr = nla_nest_start_noflag(msg, |
| 12986 | NL80211_NAN_MATCH_FUNC_PEER); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 12987 | if (!peer_func_attr) |
| 12988 | goto nla_put_failure; |
| 12989 | |
| 12990 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 12991 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 12992 | goto nla_put_failure; |
| 12993 | |
| 12994 | if (match->info && match->info_len && |
| 12995 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 12996 | match->info)) |
| 12997 | goto nla_put_failure; |
| 12998 | |
| 12999 | nla_nest_end(msg, peer_func_attr); |
| 13000 | nla_nest_end(msg, match_attr); |
| 13001 | genlmsg_end(msg, hdr); |
| 13002 | |
| 13003 | if (!wdev->owner_nlportid) |
| 13004 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13005 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13006 | else |
| 13007 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13008 | wdev->owner_nlportid); |
| 13009 | |
| 13010 | return; |
| 13011 | |
| 13012 | nla_put_failure: |
| 13013 | nlmsg_free(msg); |
| 13014 | } |
| 13015 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 13016 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13017 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 13018 | u8 inst_id, |
| 13019 | enum nl80211_nan_func_term_reason reason, |
| 13020 | u64 cookie, gfp_t gfp) |
| 13021 | { |
| 13022 | struct wiphy *wiphy = wdev->wiphy; |
| 13023 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13024 | struct sk_buff *msg; |
| 13025 | struct nlattr *func_attr; |
| 13026 | void *hdr; |
| 13027 | |
| 13028 | if (WARN_ON(!inst_id)) |
| 13029 | return; |
| 13030 | |
| 13031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13032 | if (!msg) |
| 13033 | return; |
| 13034 | |
| 13035 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 13036 | if (!hdr) { |
| 13037 | nlmsg_free(msg); |
| 13038 | return; |
| 13039 | } |
| 13040 | |
| 13041 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13042 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13043 | wdev->netdev->ifindex)) || |
| 13044 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13045 | NL80211_ATTR_PAD)) |
| 13046 | goto nla_put_failure; |
| 13047 | |
| 13048 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13049 | NL80211_ATTR_PAD)) |
| 13050 | goto nla_put_failure; |
| 13051 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13052 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13053 | if (!func_attr) |
| 13054 | goto nla_put_failure; |
| 13055 | |
| 13056 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 13057 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 13058 | goto nla_put_failure; |
| 13059 | |
| 13060 | nla_nest_end(msg, func_attr); |
| 13061 | genlmsg_end(msg, hdr); |
| 13062 | |
| 13063 | if (!wdev->owner_nlportid) |
| 13064 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13065 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13066 | else |
| 13067 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13068 | wdev->owner_nlportid); |
| 13069 | |
| 13070 | return; |
| 13071 | |
| 13072 | nla_put_failure: |
| 13073 | nlmsg_free(msg); |
| 13074 | } |
| 13075 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 13076 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13077 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 13078 | struct genl_info *info) |
| 13079 | { |
| 13080 | void *hdr; |
| 13081 | struct sk_buff *msg; |
| 13082 | |
| 13083 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13084 | if (!msg) |
| 13085 | return -ENOMEM; |
| 13086 | |
| 13087 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13088 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 13089 | if (!hdr) |
| 13090 | goto nla_put_failure; |
| 13091 | |
| 13092 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 13093 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 13094 | goto nla_put_failure; |
| 13095 | |
| 13096 | genlmsg_end(msg, hdr); |
| 13097 | return genlmsg_reply(msg, info); |
| 13098 | |
| 13099 | nla_put_failure: |
| 13100 | kfree_skb(msg); |
| 13101 | return -ENOBUFS; |
| 13102 | } |
| 13103 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13104 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 13105 | { |
| 13106 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13107 | struct cfg80211_update_ft_ies_params ft_params; |
| 13108 | struct net_device *dev = info->user_ptr[1]; |
| 13109 | |
| 13110 | if (!rdev->ops->update_ft_ies) |
| 13111 | return -EOPNOTSUPP; |
| 13112 | |
| 13113 | if (!info->attrs[NL80211_ATTR_MDID] || |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 13114 | !info->attrs[NL80211_ATTR_IE]) |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13115 | return -EINVAL; |
| 13116 | |
| 13117 | memset(&ft_params, 0, sizeof(ft_params)); |
| 13118 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 13119 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13120 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13121 | |
| 13122 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 13123 | } |
| 13124 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13125 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 13126 | struct genl_info *info) |
| 13127 | { |
| 13128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13129 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13130 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 13131 | u16 duration; |
| 13132 | int ret; |
| 13133 | |
| 13134 | if (!rdev->ops->crit_proto_start) |
| 13135 | return -EOPNOTSUPP; |
| 13136 | |
| 13137 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 13138 | return -EINVAL; |
| 13139 | |
| 13140 | if (rdev->crit_proto_nlportid) |
| 13141 | return -EBUSY; |
| 13142 | |
| 13143 | /* determine protocol if provided */ |
| 13144 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 13145 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 13146 | |
| 13147 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 13148 | return -EINVAL; |
| 13149 | |
| 13150 | /* timeout must be provided */ |
| 13151 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 13152 | return -EINVAL; |
| 13153 | |
| 13154 | duration = |
| 13155 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 13156 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13157 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 13158 | if (!ret) |
| 13159 | rdev->crit_proto_nlportid = info->snd_portid; |
| 13160 | |
| 13161 | return ret; |
| 13162 | } |
| 13163 | |
| 13164 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 13165 | struct genl_info *info) |
| 13166 | { |
| 13167 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13168 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13169 | |
| 13170 | if (!rdev->ops->crit_proto_stop) |
| 13171 | return -EOPNOTSUPP; |
| 13172 | |
| 13173 | if (rdev->crit_proto_nlportid) { |
| 13174 | rdev->crit_proto_nlportid = 0; |
| 13175 | rdev_crit_proto_stop(rdev, wdev); |
| 13176 | } |
| 13177 | return 0; |
| 13178 | } |
| 13179 | |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13180 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
| 13181 | struct nlattr *attr, |
| 13182 | struct netlink_ext_ack *extack) |
| 13183 | { |
| 13184 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { |
| 13185 | if (attr->nla_type & NLA_F_NESTED) { |
| 13186 | NL_SET_ERR_MSG_ATTR(extack, attr, |
| 13187 | "unexpected nested data"); |
| 13188 | return -EINVAL; |
| 13189 | } |
| 13190 | |
| 13191 | return 0; |
| 13192 | } |
| 13193 | |
| 13194 | if (!(attr->nla_type & NLA_F_NESTED)) { |
| 13195 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); |
| 13196 | return -EINVAL; |
| 13197 | } |
| 13198 | |
Michal Kubecek | 32d5109 | 2019-12-11 10:58:19 +0100 | [diff] [blame] | 13199 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13200 | } |
| 13201 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13202 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 13203 | { |
| 13204 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13205 | struct wireless_dev *wdev = |
| 13206 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 13207 | int i, err; |
| 13208 | u32 vid, subcmd; |
| 13209 | |
| 13210 | if (!rdev->wiphy.vendor_commands) |
| 13211 | return -EOPNOTSUPP; |
| 13212 | |
| 13213 | if (IS_ERR(wdev)) { |
| 13214 | err = PTR_ERR(wdev); |
| 13215 | if (err != -EINVAL) |
| 13216 | return err; |
| 13217 | wdev = NULL; |
| 13218 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 13219 | return -EINVAL; |
| 13220 | } |
| 13221 | |
| 13222 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 13223 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 13224 | return -EINVAL; |
| 13225 | |
| 13226 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 13227 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13228 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 13229 | const struct wiphy_vendor_command *vcmd; |
| 13230 | void *data = NULL; |
| 13231 | int len = 0; |
| 13232 | |
| 13233 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 13234 | |
| 13235 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13236 | continue; |
| 13237 | |
| 13238 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13239 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13240 | if (!wdev) |
| 13241 | return -EINVAL; |
| 13242 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 13243 | !wdev->netdev) |
| 13244 | return -EINVAL; |
| 13245 | |
| 13246 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13247 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13248 | return -ENETDOWN; |
| 13249 | } |
| 13250 | } else { |
| 13251 | wdev = NULL; |
| 13252 | } |
| 13253 | |
Julian Squires | 4052d3d | 2020-07-06 17:13:53 -0400 | [diff] [blame] | 13254 | if (!vcmd->doit) |
| 13255 | return -EOPNOTSUPP; |
| 13256 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13257 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 13258 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 13259 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13260 | |
| 13261 | err = nl80211_vendor_check_policy(vcmd, |
| 13262 | info->attrs[NL80211_ATTR_VENDOR_DATA], |
| 13263 | info->extack); |
| 13264 | if (err) |
| 13265 | return err; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13266 | } |
| 13267 | |
| 13268 | rdev->cur_cmd_info = info; |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13269 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13270 | rdev->cur_cmd_info = NULL; |
| 13271 | return err; |
| 13272 | } |
| 13273 | |
| 13274 | return -EOPNOTSUPP; |
| 13275 | } |
| 13276 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13277 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 13278 | struct netlink_callback *cb, |
| 13279 | struct cfg80211_registered_device **rdev, |
| 13280 | struct wireless_dev **wdev) |
| 13281 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13282 | struct nlattr **attrbuf; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13283 | u32 vid, subcmd; |
| 13284 | unsigned int i; |
| 13285 | int vcmd_idx = -1; |
| 13286 | int err; |
| 13287 | void *data = NULL; |
| 13288 | unsigned int data_len = 0; |
| 13289 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13290 | if (cb->args[0]) { |
| 13291 | /* subtract the 1 again here */ |
| 13292 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 13293 | struct wireless_dev *tmp; |
| 13294 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13295 | if (!wiphy) |
| 13296 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13297 | *rdev = wiphy_to_rdev(wiphy); |
| 13298 | *wdev = NULL; |
| 13299 | |
| 13300 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13301 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13302 | if (tmp->identifier == cb->args[1] - 1) { |
| 13303 | *wdev = tmp; |
| 13304 | break; |
| 13305 | } |
| 13306 | } |
| 13307 | } |
| 13308 | |
| 13309 | /* keep rtnl locked in successful case */ |
| 13310 | return 0; |
| 13311 | } |
| 13312 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13313 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 13314 | if (!attrbuf) |
| 13315 | return -ENOMEM; |
| 13316 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13317 | err = nlmsg_parse_deprecated(cb->nlh, |
| 13318 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 13319 | attrbuf, nl80211_fam.maxattr, |
| 13320 | nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13321 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13322 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13323 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13324 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13325 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 13326 | err = -EINVAL; |
| 13327 | goto out; |
| 13328 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13329 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13330 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13331 | if (IS_ERR(*wdev)) |
| 13332 | *wdev = NULL; |
| 13333 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13334 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13335 | if (IS_ERR(*rdev)) { |
| 13336 | err = PTR_ERR(*rdev); |
| 13337 | goto out; |
| 13338 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13339 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13340 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 13341 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13342 | |
| 13343 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 13344 | const struct wiphy_vendor_command *vcmd; |
| 13345 | |
| 13346 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 13347 | |
| 13348 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13349 | continue; |
| 13350 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13351 | if (!vcmd->dumpit) { |
| 13352 | err = -EOPNOTSUPP; |
| 13353 | goto out; |
| 13354 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13355 | |
| 13356 | vcmd_idx = i; |
| 13357 | break; |
| 13358 | } |
| 13359 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13360 | if (vcmd_idx < 0) { |
| 13361 | err = -EOPNOTSUPP; |
| 13362 | goto out; |
| 13363 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13364 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13365 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 13366 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 13367 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13368 | |
| 13369 | err = nl80211_vendor_check_policy( |
| 13370 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], |
| 13371 | attrbuf[NL80211_ATTR_VENDOR_DATA], |
| 13372 | cb->extack); |
| 13373 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13374 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13375 | } |
| 13376 | |
| 13377 | /* 0 is the first index - add 1 to parse only once */ |
| 13378 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 13379 | /* add 1 to know if it was NULL */ |
| 13380 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 13381 | cb->args[2] = vcmd_idx; |
| 13382 | cb->args[3] = (unsigned long)data; |
| 13383 | cb->args[4] = data_len; |
| 13384 | |
| 13385 | /* keep rtnl locked in successful case */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13386 | err = 0; |
| 13387 | out: |
| 13388 | kfree(attrbuf); |
| 13389 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13390 | } |
| 13391 | |
| 13392 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 13393 | struct netlink_callback *cb) |
| 13394 | { |
| 13395 | struct cfg80211_registered_device *rdev; |
| 13396 | struct wireless_dev *wdev; |
| 13397 | unsigned int vcmd_idx; |
| 13398 | const struct wiphy_vendor_command *vcmd; |
| 13399 | void *data; |
| 13400 | int data_len; |
| 13401 | int err; |
| 13402 | struct nlattr *vendor_data; |
| 13403 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13404 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13405 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 13406 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13407 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13408 | |
| 13409 | vcmd_idx = cb->args[2]; |
| 13410 | data = (void *)cb->args[3]; |
| 13411 | data_len = cb->args[4]; |
| 13412 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 13413 | |
| 13414 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13415 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13416 | if (!wdev) { |
| 13417 | err = -EINVAL; |
| 13418 | goto out; |
| 13419 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13420 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13421 | !wdev->netdev) { |
| 13422 | err = -EINVAL; |
| 13423 | goto out; |
| 13424 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13425 | |
| 13426 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13427 | if (!wdev_running(wdev)) { |
| 13428 | err = -ENETDOWN; |
| 13429 | goto out; |
| 13430 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13431 | } |
| 13432 | } |
| 13433 | |
| 13434 | while (1) { |
| 13435 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 13436 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 13437 | NL80211_CMD_VENDOR); |
| 13438 | if (!hdr) |
| 13439 | break; |
| 13440 | |
| 13441 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13442 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 13443 | wdev_id(wdev), |
| 13444 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13445 | genlmsg_cancel(skb, hdr); |
| 13446 | break; |
| 13447 | } |
| 13448 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13449 | vendor_data = nla_nest_start_noflag(skb, |
| 13450 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13451 | if (!vendor_data) { |
| 13452 | genlmsg_cancel(skb, hdr); |
| 13453 | break; |
| 13454 | } |
| 13455 | |
| 13456 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 13457 | (unsigned long *)&cb->args[5]); |
| 13458 | nla_nest_end(skb, vendor_data); |
| 13459 | |
| 13460 | if (err == -ENOBUFS || err == -ENOENT) { |
| 13461 | genlmsg_cancel(skb, hdr); |
| 13462 | break; |
Julian Squires | 9c167b2 | 2020-07-20 12:20:35 -0230 | [diff] [blame] | 13463 | } else if (err <= 0) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13464 | genlmsg_cancel(skb, hdr); |
| 13465 | goto out; |
| 13466 | } |
| 13467 | |
| 13468 | genlmsg_end(skb, hdr); |
| 13469 | } |
| 13470 | |
| 13471 | err = skb->len; |
| 13472 | out: |
| 13473 | rtnl_unlock(); |
| 13474 | return err; |
| 13475 | } |
| 13476 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13477 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 13478 | enum nl80211_commands cmd, |
| 13479 | enum nl80211_attrs attr, |
| 13480 | int approxlen) |
| 13481 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13482 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13483 | |
| 13484 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13485 | return NULL; |
| 13486 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 13487 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13488 | rdev->cur_cmd_info->snd_portid, |
| 13489 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 13490 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13491 | } |
| 13492 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 13493 | |
| 13494 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 13495 | { |
| 13496 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 13497 | void *hdr = ((void **)skb->cb)[1]; |
| 13498 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 13499 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 13500 | /* clear CB data for netlink core to own from now on */ |
| 13501 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 13502 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13503 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 13504 | kfree_skb(skb); |
| 13505 | return -EINVAL; |
| 13506 | } |
| 13507 | |
| 13508 | nla_nest_end(skb, data); |
| 13509 | genlmsg_end(skb, hdr); |
| 13510 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 13511 | } |
| 13512 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 13513 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 13514 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
| 13515 | { |
| 13516 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13517 | |
| 13518 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13519 | return 0; |
| 13520 | |
| 13521 | return rdev->cur_cmd_info->snd_portid; |
| 13522 | } |
| 13523 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); |
| 13524 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13525 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 13526 | struct genl_info *info) |
| 13527 | { |
| 13528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13529 | struct cfg80211_qos_map *qos_map = NULL; |
| 13530 | struct net_device *dev = info->user_ptr[1]; |
| 13531 | u8 *pos, len, num_des, des_len, des; |
| 13532 | int ret; |
| 13533 | |
| 13534 | if (!rdev->ops->set_qos_map) |
| 13535 | return -EOPNOTSUPP; |
| 13536 | |
| 13537 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 13538 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13539 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13540 | |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame^] | 13541 | if (len % 2) |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13542 | return -EINVAL; |
| 13543 | |
| 13544 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 13545 | if (!qos_map) |
| 13546 | return -ENOMEM; |
| 13547 | |
| 13548 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 13549 | if (num_des) { |
| 13550 | des_len = num_des * |
| 13551 | sizeof(struct cfg80211_dscp_exception); |
| 13552 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 13553 | qos_map->num_des = num_des; |
| 13554 | for (des = 0; des < num_des; des++) { |
| 13555 | if (qos_map->dscp_exception[des].up > 7) { |
| 13556 | kfree(qos_map); |
| 13557 | return -EINVAL; |
| 13558 | } |
| 13559 | } |
| 13560 | pos += des_len; |
| 13561 | } |
| 13562 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 13563 | } |
| 13564 | |
| 13565 | wdev_lock(dev->ieee80211_ptr); |
| 13566 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 13567 | if (!ret) |
| 13568 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 13569 | wdev_unlock(dev->ieee80211_ptr); |
| 13570 | |
| 13571 | kfree(qos_map); |
| 13572 | return ret; |
| 13573 | } |
| 13574 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13575 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13576 | { |
| 13577 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13578 | struct net_device *dev = info->user_ptr[1]; |
| 13579 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13580 | const u8 *peer; |
| 13581 | u8 tsid, up; |
| 13582 | u16 admitted_time = 0; |
| 13583 | int err; |
| 13584 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13585 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13586 | return -EOPNOTSUPP; |
| 13587 | |
| 13588 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 13589 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 13590 | return -EINVAL; |
| 13591 | |
| 13592 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13593 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13594 | |
| 13595 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13596 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13597 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13598 | * need more attributes for that (e.g. BA session requirement); |
| 13599 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13600 | */ |
| 13601 | return -EINVAL; |
| 13602 | } |
| 13603 | |
| 13604 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13605 | |
| 13606 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 13607 | admitted_time = |
| 13608 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 13609 | if (!admitted_time) |
| 13610 | return -EINVAL; |
| 13611 | } |
| 13612 | |
| 13613 | wdev_lock(wdev); |
| 13614 | switch (wdev->iftype) { |
| 13615 | case NL80211_IFTYPE_STATION: |
| 13616 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13617 | if (wdev->current_bss) |
| 13618 | break; |
| 13619 | err = -ENOTCONN; |
| 13620 | goto out; |
| 13621 | default: |
| 13622 | err = -EOPNOTSUPP; |
| 13623 | goto out; |
| 13624 | } |
| 13625 | |
| 13626 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 13627 | |
| 13628 | out: |
| 13629 | wdev_unlock(wdev); |
| 13630 | return err; |
| 13631 | } |
| 13632 | |
| 13633 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13634 | { |
| 13635 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13636 | struct net_device *dev = info->user_ptr[1]; |
| 13637 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13638 | const u8 *peer; |
| 13639 | u8 tsid; |
| 13640 | int err; |
| 13641 | |
| 13642 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 13643 | return -EINVAL; |
| 13644 | |
| 13645 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 13646 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13647 | |
| 13648 | wdev_lock(wdev); |
| 13649 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 13650 | wdev_unlock(wdev); |
| 13651 | |
| 13652 | return err; |
| 13653 | } |
| 13654 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13655 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 13656 | struct genl_info *info) |
| 13657 | { |
| 13658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13659 | struct net_device *dev = info->user_ptr[1]; |
| 13660 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13661 | struct cfg80211_chan_def chandef = {}; |
| 13662 | const u8 *addr; |
| 13663 | u8 oper_class; |
| 13664 | int err; |
| 13665 | |
| 13666 | if (!rdev->ops->tdls_channel_switch || |
| 13667 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13668 | return -EOPNOTSUPP; |
| 13669 | |
| 13670 | switch (dev->ieee80211_ptr->iftype) { |
| 13671 | case NL80211_IFTYPE_STATION: |
| 13672 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13673 | break; |
| 13674 | default: |
| 13675 | return -EOPNOTSUPP; |
| 13676 | } |
| 13677 | |
| 13678 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 13679 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 13680 | return -EINVAL; |
| 13681 | |
| 13682 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 13683 | if (err) |
| 13684 | return err; |
| 13685 | |
| 13686 | /* |
| 13687 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 13688 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 13689 | * specification is not defined for them. |
| 13690 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 13691 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13692 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 13693 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 13694 | return -EINVAL; |
| 13695 | |
| 13696 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 13697 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 13698 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13699 | return -EINVAL; |
| 13700 | |
| 13701 | /* don't allow switching to DFS channels */ |
| 13702 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 13703 | return -EINVAL; |
| 13704 | |
| 13705 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13706 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 13707 | |
| 13708 | wdev_lock(wdev); |
| 13709 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 13710 | wdev_unlock(wdev); |
| 13711 | |
| 13712 | return err; |
| 13713 | } |
| 13714 | |
| 13715 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 13716 | struct genl_info *info) |
| 13717 | { |
| 13718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13719 | struct net_device *dev = info->user_ptr[1]; |
| 13720 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13721 | const u8 *addr; |
| 13722 | |
| 13723 | if (!rdev->ops->tdls_channel_switch || |
| 13724 | !rdev->ops->tdls_cancel_channel_switch || |
| 13725 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13726 | return -EOPNOTSUPP; |
| 13727 | |
| 13728 | switch (dev->ieee80211_ptr->iftype) { |
| 13729 | case NL80211_IFTYPE_STATION: |
| 13730 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13731 | break; |
| 13732 | default: |
| 13733 | return -EOPNOTSUPP; |
| 13734 | } |
| 13735 | |
| 13736 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13737 | return -EINVAL; |
| 13738 | |
| 13739 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13740 | |
| 13741 | wdev_lock(wdev); |
| 13742 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 13743 | wdev_unlock(wdev); |
| 13744 | |
| 13745 | return 0; |
| 13746 | } |
| 13747 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13748 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 13749 | struct genl_info *info) |
| 13750 | { |
| 13751 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13752 | struct net_device *dev = info->user_ptr[1]; |
| 13753 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13754 | const struct nlattr *nla; |
| 13755 | bool enabled; |
| 13756 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 13757 | if (!rdev->ops->set_multicast_to_unicast) |
| 13758 | return -EOPNOTSUPP; |
| 13759 | |
| 13760 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 13761 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 13762 | return -EOPNOTSUPP; |
| 13763 | |
| 13764 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 13765 | enabled = nla_get_flag(nla); |
| 13766 | |
| 13767 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 13768 | } |
| 13769 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13770 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13771 | { |
| 13772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13773 | struct net_device *dev = info->user_ptr[1]; |
| 13774 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13775 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 13776 | int ret; |
| 13777 | |
| 13778 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13779 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13780 | return -EOPNOTSUPP; |
| 13781 | |
| 13782 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13783 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13784 | return -EOPNOTSUPP; |
| 13785 | |
| 13786 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 13787 | return -EINVAL; |
| 13788 | |
| 13789 | wdev_lock(wdev); |
| 13790 | if (!wdev->current_bss) { |
| 13791 | ret = -ENOTCONN; |
| 13792 | goto out; |
| 13793 | } |
| 13794 | |
| 13795 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13796 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 13797 | ret = -EINVAL; |
| 13798 | goto out; |
| 13799 | } |
| 13800 | |
| 13801 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 13802 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 13803 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 13804 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 13805 | ret = -EINVAL; |
| 13806 | goto out; |
| 13807 | } |
| 13808 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 13809 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13810 | pmk_conf.pmk_r0_name = |
| 13811 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 13812 | |
| 13813 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 13814 | out: |
| 13815 | wdev_unlock(wdev); |
| 13816 | return ret; |
| 13817 | } |
| 13818 | |
| 13819 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 13820 | { |
| 13821 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13822 | struct net_device *dev = info->user_ptr[1]; |
| 13823 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13824 | const u8 *aa; |
| 13825 | int ret; |
| 13826 | |
| 13827 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 13828 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 13829 | return -EOPNOTSUPP; |
| 13830 | |
| 13831 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13832 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 13833 | return -EOPNOTSUPP; |
| 13834 | |
| 13835 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13836 | return -EINVAL; |
| 13837 | |
| 13838 | wdev_lock(wdev); |
| 13839 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13840 | ret = rdev_del_pmk(rdev, dev, aa); |
| 13841 | wdev_unlock(wdev); |
| 13842 | |
| 13843 | return ret; |
| 13844 | } |
| 13845 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13846 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 13847 | { |
| 13848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13849 | struct net_device *dev = info->user_ptr[1]; |
| 13850 | struct cfg80211_external_auth_params params; |
| 13851 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 13852 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13853 | return -EOPNOTSUPP; |
| 13854 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13855 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 13856 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 13857 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13858 | return -EINVAL; |
| 13859 | |
| 13860 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 13861 | return -EINVAL; |
| 13862 | |
| 13863 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 13864 | return -EINVAL; |
| 13865 | |
| 13866 | memset(¶ms, 0, sizeof(params)); |
| 13867 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13868 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 13869 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 13870 | if (params.ssid.ssid_len == 0) |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13871 | return -EINVAL; |
| 13872 | memcpy(params.ssid.ssid, |
| 13873 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 13874 | params.ssid.ssid_len); |
| 13875 | } |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13876 | |
| 13877 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 13878 | ETH_ALEN); |
| 13879 | |
| 13880 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 13881 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 13882 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 13883 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 13884 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 13885 | return rdev_external_auth(rdev, dev, ¶ms); |
| 13886 | } |
| 13887 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13888 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 13889 | { |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 13890 | bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13891 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13892 | struct net_device *dev = info->user_ptr[1]; |
| 13893 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13894 | const u8 *buf; |
| 13895 | size_t len; |
| 13896 | u8 *dest; |
| 13897 | u16 proto; |
| 13898 | bool noencrypt; |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 13899 | u64 cookie = 0; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13900 | int err; |
| 13901 | |
| 13902 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 13903 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 13904 | return -EOPNOTSUPP; |
| 13905 | |
| 13906 | if (!rdev->ops->tx_control_port) |
| 13907 | return -EOPNOTSUPP; |
| 13908 | |
| 13909 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 13910 | !info->attrs[NL80211_ATTR_MAC] || |
| 13911 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 13912 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 13913 | return -EINVAL; |
| 13914 | } |
| 13915 | |
| 13916 | wdev_lock(wdev); |
| 13917 | |
| 13918 | switch (wdev->iftype) { |
| 13919 | case NL80211_IFTYPE_AP: |
| 13920 | case NL80211_IFTYPE_P2P_GO: |
| 13921 | case NL80211_IFTYPE_MESH_POINT: |
| 13922 | break; |
| 13923 | case NL80211_IFTYPE_ADHOC: |
| 13924 | case NL80211_IFTYPE_STATION: |
| 13925 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13926 | if (wdev->current_bss) |
| 13927 | break; |
| 13928 | err = -ENOTCONN; |
| 13929 | goto out; |
| 13930 | default: |
| 13931 | err = -EOPNOTSUPP; |
| 13932 | goto out; |
| 13933 | } |
| 13934 | |
| 13935 | wdev_unlock(wdev); |
| 13936 | |
| 13937 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 13938 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 13939 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13940 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 13941 | noencrypt = |
| 13942 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 13943 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 13944 | err = rdev_tx_control_port(rdev, dev, buf, len, |
| 13945 | dest, cpu_to_be16(proto), noencrypt, |
| 13946 | dont_wait_for_ack ? NULL : &cookie); |
| 13947 | if (!err && !dont_wait_for_ack) |
| 13948 | nl_set_extack_cookie_u64(info->extack, cookie); |
| 13949 | return err; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 13950 | out: |
| 13951 | wdev_unlock(wdev); |
| 13952 | return err; |
| 13953 | } |
| 13954 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13955 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 13956 | struct genl_info *info) |
| 13957 | { |
| 13958 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13959 | struct net_device *dev = info->user_ptr[1]; |
| 13960 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13961 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 13962 | struct sk_buff *msg; |
| 13963 | void *hdr; |
| 13964 | struct nlattr *ftm_stats_attr; |
| 13965 | int err; |
| 13966 | |
| 13967 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 13968 | return -EOPNOTSUPP; |
| 13969 | |
| 13970 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 13971 | if (err) |
| 13972 | return err; |
| 13973 | |
| 13974 | if (!ftm_stats.filled) |
| 13975 | return -ENODATA; |
| 13976 | |
| 13977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13978 | if (!msg) |
| 13979 | return -ENOMEM; |
| 13980 | |
| 13981 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13982 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 13983 | if (!hdr) |
Navid Emamdoost | 1399c59 | 2019-10-04 14:42:19 -0500 | [diff] [blame] | 13984 | goto nla_put_failure; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13985 | |
| 13986 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 13987 | goto nla_put_failure; |
| 13988 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13989 | ftm_stats_attr = nla_nest_start_noflag(msg, |
| 13990 | NL80211_ATTR_FTM_RESPONDER_STATS); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 13991 | if (!ftm_stats_attr) |
| 13992 | goto nla_put_failure; |
| 13993 | |
| 13994 | #define SET_FTM(field, name, type) \ |
| 13995 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 13996 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 13997 | ftm_stats.field)) \ |
| 13998 | goto nla_put_failure; } while (0) |
| 13999 | #define SET_FTM_U64(field, name) \ |
| 14000 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14001 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 14002 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 14003 | goto nla_put_failure; } while (0) |
| 14004 | |
| 14005 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 14006 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 14007 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 14008 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 14009 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 14010 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 14011 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 14012 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 14013 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 14014 | #undef SET_FTM |
| 14015 | |
| 14016 | nla_nest_end(msg, ftm_stats_attr); |
| 14017 | |
| 14018 | genlmsg_end(msg, hdr); |
| 14019 | return genlmsg_reply(msg, info); |
| 14020 | |
| 14021 | nla_put_failure: |
| 14022 | nlmsg_free(msg); |
| 14023 | return -ENOBUFS; |
| 14024 | } |
| 14025 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 14026 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
| 14027 | { |
| 14028 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14029 | struct cfg80211_update_owe_info owe_info; |
| 14030 | struct net_device *dev = info->user_ptr[1]; |
| 14031 | |
| 14032 | if (!rdev->ops->update_owe_info) |
| 14033 | return -EOPNOTSUPP; |
| 14034 | |
| 14035 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 14036 | !info->attrs[NL80211_ATTR_MAC]) |
| 14037 | return -EINVAL; |
| 14038 | |
| 14039 | memset(&owe_info, 0, sizeof(owe_info)); |
| 14040 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14041 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); |
| 14042 | |
| 14043 | if (info->attrs[NL80211_ATTR_IE]) { |
| 14044 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 14045 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 14046 | } |
| 14047 | |
| 14048 | return rdev_update_owe_info(rdev, dev, &owe_info); |
| 14049 | } |
| 14050 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14051 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
| 14052 | { |
| 14053 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14054 | struct net_device *dev = info->user_ptr[1]; |
| 14055 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14056 | struct station_info sinfo = {}; |
| 14057 | const u8 *buf; |
| 14058 | size_t len; |
| 14059 | u8 *dest; |
| 14060 | int err; |
| 14061 | |
| 14062 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) |
| 14063 | return -EOPNOTSUPP; |
| 14064 | |
| 14065 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14066 | !info->attrs[NL80211_ATTR_FRAME]) { |
| 14067 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); |
| 14068 | return -EINVAL; |
| 14069 | } |
| 14070 | |
| 14071 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 14072 | return -EOPNOTSUPP; |
| 14073 | |
| 14074 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14075 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14076 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14077 | |
| 14078 | if (len < sizeof(struct ethhdr)) |
| 14079 | return -EINVAL; |
| 14080 | |
| 14081 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || |
| 14082 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) |
| 14083 | return -EINVAL; |
| 14084 | |
| 14085 | err = rdev_get_station(rdev, dev, dest, &sinfo); |
| 14086 | if (err) |
| 14087 | return err; |
| 14088 | |
Felix Fietkau | 2a279b34 | 2020-01-08 18:06:29 +0100 | [diff] [blame] | 14089 | cfg80211_sinfo_release_content(&sinfo); |
| 14090 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14091 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
| 14092 | } |
| 14093 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14094 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
| 14095 | struct nlattr *attrs[], struct net_device *dev, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14096 | struct cfg80211_tid_cfg *tid_conf, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14097 | struct genl_info *info, const u8 *peer) |
| 14098 | { |
| 14099 | struct netlink_ext_ack *extack = info->extack; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14100 | u64 mask; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14101 | int err; |
| 14102 | |
| 14103 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) |
| 14104 | return -EINVAL; |
| 14105 | |
| 14106 | tid_conf->config_override = |
| 14107 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14108 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14109 | |
| 14110 | if (tid_conf->config_override) { |
| 14111 | if (rdev->ops->reset_tid_config) { |
| 14112 | err = rdev_reset_tid_config(rdev, dev, peer, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14113 | tid_conf->tids); |
Sergey Matyukevich | c033695 | 2020-04-24 14:29:04 +0300 | [diff] [blame] | 14114 | if (err) |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14115 | return err; |
| 14116 | } else { |
| 14117 | return -EINVAL; |
| 14118 | } |
| 14119 | } |
| 14120 | |
| 14121 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14122 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14123 | tid_conf->noack = |
| 14124 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); |
| 14125 | } |
| 14126 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 14127 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { |
| 14128 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); |
| 14129 | tid_conf->retry_short = |
| 14130 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); |
| 14131 | |
| 14132 | if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) |
| 14133 | return -EINVAL; |
| 14134 | } |
| 14135 | |
| 14136 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { |
| 14137 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); |
| 14138 | tid_conf->retry_long = |
| 14139 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); |
| 14140 | |
| 14141 | if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) |
| 14142 | return -EINVAL; |
| 14143 | } |
| 14144 | |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 14145 | if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { |
| 14146 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); |
| 14147 | tid_conf->ampdu = |
| 14148 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); |
| 14149 | } |
| 14150 | |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 14151 | if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { |
| 14152 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); |
| 14153 | tid_conf->rtscts = |
| 14154 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); |
| 14155 | } |
| 14156 | |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 14157 | if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { |
| 14158 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); |
| 14159 | tid_conf->amsdu = |
| 14160 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); |
| 14161 | } |
| 14162 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14163 | if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { |
| 14164 | u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; |
| 14165 | |
| 14166 | tid_conf->txrate_type = nla_get_u8(attrs[idx]); |
| 14167 | |
| 14168 | if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { |
| 14169 | attr = NL80211_TID_CONFIG_ATTR_TX_RATE; |
| 14170 | err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, |
| 14171 | &tid_conf->txrate_mask); |
| 14172 | if (err) |
| 14173 | return err; |
| 14174 | |
| 14175 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); |
| 14176 | } |
| 14177 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); |
| 14178 | } |
| 14179 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14180 | if (peer) |
| 14181 | mask = rdev->wiphy.tid_config_support.peer; |
| 14182 | else |
| 14183 | mask = rdev->wiphy.tid_config_support.vif; |
| 14184 | |
| 14185 | if (tid_conf->mask & ~mask) { |
| 14186 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); |
| 14187 | return -ENOTSUPP; |
| 14188 | } |
| 14189 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14190 | return 0; |
| 14191 | } |
| 14192 | |
| 14193 | static int nl80211_set_tid_config(struct sk_buff *skb, |
| 14194 | struct genl_info *info) |
| 14195 | { |
| 14196 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14197 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; |
| 14198 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14199 | struct cfg80211_tid_config *tid_config; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14200 | struct nlattr *tid; |
| 14201 | int conf_idx = 0, rem_conf; |
| 14202 | int ret = -EINVAL; |
| 14203 | u32 num_conf = 0; |
| 14204 | |
| 14205 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) |
| 14206 | return -EINVAL; |
| 14207 | |
| 14208 | if (!rdev->ops->set_tid_config) |
| 14209 | return -EOPNOTSUPP; |
| 14210 | |
| 14211 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14212 | rem_conf) |
| 14213 | num_conf++; |
| 14214 | |
| 14215 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), |
| 14216 | GFP_KERNEL); |
| 14217 | if (!tid_config) |
| 14218 | return -ENOMEM; |
| 14219 | |
| 14220 | tid_config->n_tid_conf = num_conf; |
| 14221 | |
| 14222 | if (info->attrs[NL80211_ATTR_MAC]) |
| 14223 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14224 | |
| 14225 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14226 | rem_conf) { |
| 14227 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, |
| 14228 | tid, NULL, NULL); |
| 14229 | |
| 14230 | if (ret) |
| 14231 | goto bad_tid_conf; |
| 14232 | |
| 14233 | ret = parse_tid_conf(rdev, attrs, dev, |
| 14234 | &tid_config->tid_conf[conf_idx], |
| 14235 | info, tid_config->peer); |
| 14236 | if (ret) |
| 14237 | goto bad_tid_conf; |
| 14238 | |
| 14239 | conf_idx++; |
| 14240 | } |
| 14241 | |
| 14242 | ret = rdev_set_tid_config(rdev, dev, tid_config); |
| 14243 | |
| 14244 | bad_tid_conf: |
| 14245 | kfree(tid_config); |
| 14246 | return ret; |
| 14247 | } |
| 14248 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14249 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 14250 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 14251 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14252 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 14253 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 14254 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14255 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14256 | /* If a netdev is associated, it must be UP, P2P must be started */ |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14257 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 14258 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14259 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14260 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14261 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14262 | struct genl_info *info) |
| 14263 | { |
| 14264 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14265 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14266 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14267 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 14268 | |
| 14269 | if (rtnl) |
| 14270 | rtnl_lock(); |
| 14271 | |
| 14272 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 14273 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14274 | if (IS_ERR(rdev)) { |
| 14275 | if (rtnl) |
| 14276 | rtnl_unlock(); |
| 14277 | return PTR_ERR(rdev); |
| 14278 | } |
| 14279 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14280 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 14281 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14282 | ASSERT_RTNL(); |
| 14283 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14284 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 14285 | info->attrs); |
| 14286 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14287 | if (rtnl) |
| 14288 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14289 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14290 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14291 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14292 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14293 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14294 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14295 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 14296 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14297 | if (rtnl) |
| 14298 | rtnl_unlock(); |
| 14299 | return -EINVAL; |
| 14300 | } |
| 14301 | |
| 14302 | info->user_ptr[1] = dev; |
| 14303 | } else { |
| 14304 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14305 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14306 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14307 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 14308 | !wdev_running(wdev)) { |
| 14309 | if (rtnl) |
| 14310 | rtnl_unlock(); |
| 14311 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14312 | } |
| 14313 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14314 | if (dev) |
| 14315 | dev_hold(dev); |
| 14316 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14317 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14318 | } |
| 14319 | |
| 14320 | return 0; |
| 14321 | } |
| 14322 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14323 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14324 | struct genl_info *info) |
| 14325 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14326 | if (info->user_ptr[1]) { |
| 14327 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 14328 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 14329 | |
| 14330 | if (wdev->netdev) |
| 14331 | dev_put(wdev->netdev); |
| 14332 | } else { |
| 14333 | dev_put(info->user_ptr[1]); |
| 14334 | } |
| 14335 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14336 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14337 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 14338 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14339 | |
| 14340 | /* If needed, clear the netlink message payload from the SKB |
| 14341 | * as it might contain key data that shouldn't stick around on |
| 14342 | * the heap after the SKB is freed. The netlink message header |
| 14343 | * is still needed for further processing, so leave it intact. |
| 14344 | */ |
| 14345 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 14346 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 14347 | |
| 14348 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 14349 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14350 | } |
| 14351 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 14352 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14353 | { |
| 14354 | .cmd = NL80211_CMD_GET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14355 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14356 | .doit = nl80211_get_wiphy, |
| 14357 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 14358 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14359 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14360 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14361 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14362 | }, |
| 14363 | { |
| 14364 | .cmd = NL80211_CMD_SET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14365 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14366 | .doit = nl80211_set_wiphy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14367 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14368 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14369 | }, |
| 14370 | { |
| 14371 | .cmd = NL80211_CMD_GET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14372 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14373 | .doit = nl80211_get_interface, |
| 14374 | .dumpit = nl80211_dump_interface, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14375 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14376 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14377 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14378 | }, |
| 14379 | { |
| 14380 | .cmd = NL80211_CMD_SET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14381 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14382 | .doit = nl80211_set_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14383 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14384 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14385 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14386 | }, |
| 14387 | { |
| 14388 | .cmd = NL80211_CMD_NEW_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14389 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14390 | .doit = nl80211_new_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14391 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14392 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14393 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14394 | }, |
| 14395 | { |
| 14396 | .cmd = NL80211_CMD_DEL_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14397 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14398 | .doit = nl80211_del_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14399 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 14400 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14401 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14402 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14403 | { |
| 14404 | .cmd = NL80211_CMD_GET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14405 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14406 | .doit = nl80211_get_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14407 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14408 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14409 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14410 | }, |
| 14411 | { |
| 14412 | .cmd = NL80211_CMD_SET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14413 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14414 | .doit = nl80211_set_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14415 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14416 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14417 | NL80211_FLAG_NEED_RTNL | |
| 14418 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14419 | }, |
| 14420 | { |
| 14421 | .cmd = NL80211_CMD_NEW_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14422 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14423 | .doit = nl80211_new_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14424 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14425 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14426 | NL80211_FLAG_NEED_RTNL | |
| 14427 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14428 | }, |
| 14429 | { |
| 14430 | .cmd = NL80211_CMD_DEL_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14431 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14432 | .doit = nl80211_del_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14433 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14435 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14436 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14437 | { |
| 14438 | .cmd = NL80211_CMD_SET_BEACON, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14439 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14440 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14441 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14443 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14444 | }, |
| 14445 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14446 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14447 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14448 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14449 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14451 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14452 | }, |
| 14453 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14454 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14455 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14456 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14457 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14459 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14460 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14461 | { |
| 14462 | .cmd = NL80211_CMD_GET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14463 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14464 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14465 | .dumpit = nl80211_dump_station, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14466 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14467 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14468 | }, |
| 14469 | { |
| 14470 | .cmd = NL80211_CMD_SET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14471 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14472 | .doit = nl80211_set_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14473 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14474 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14475 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14476 | }, |
| 14477 | { |
| 14478 | .cmd = NL80211_CMD_NEW_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14479 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14480 | .doit = nl80211_new_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14481 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14482 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14483 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14484 | }, |
| 14485 | { |
| 14486 | .cmd = NL80211_CMD_DEL_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14487 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14488 | .doit = nl80211_del_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14489 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14490 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14491 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14492 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14493 | { |
| 14494 | .cmd = NL80211_CMD_GET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14495 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14496 | .doit = nl80211_get_mpath, |
| 14497 | .dumpit = nl80211_dump_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14498 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14500 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14501 | }, |
| 14502 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14503 | .cmd = NL80211_CMD_GET_MPP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14504 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14505 | .doit = nl80211_get_mpp, |
| 14506 | .dumpit = nl80211_dump_mpp, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14507 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14508 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14509 | NL80211_FLAG_NEED_RTNL, |
| 14510 | }, |
| 14511 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14512 | .cmd = NL80211_CMD_SET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14513 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14514 | .doit = nl80211_set_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14515 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14516 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14517 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14518 | }, |
| 14519 | { |
| 14520 | .cmd = NL80211_CMD_NEW_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14521 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14522 | .doit = nl80211_new_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14523 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14524 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14525 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14526 | }, |
| 14527 | { |
| 14528 | .cmd = NL80211_CMD_DEL_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14529 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14530 | .doit = nl80211_del_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14531 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14532 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14533 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14534 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14535 | { |
| 14536 | .cmd = NL80211_CMD_SET_BSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14537 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14538 | .doit = nl80211_set_bss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14539 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14540 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14541 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14542 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14543 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14544 | .cmd = NL80211_CMD_GET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14545 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14546 | .doit = nl80211_get_reg_do, |
| 14547 | .dumpit = nl80211_get_reg_dump, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14548 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14549 | /* can be retrieved by unprivileged users */ |
| 14550 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14551 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14552 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14553 | .cmd = NL80211_CMD_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14554 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14555 | .doit = nl80211_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14556 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14557 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14558 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14559 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14560 | { |
| 14561 | .cmd = NL80211_CMD_REQ_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14562 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14563 | .doit = nl80211_req_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14564 | .flags = GENL_ADMIN_PERM, |
| 14565 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14566 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14567 | .cmd = NL80211_CMD_RELOAD_REGDB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14568 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14569 | .doit = nl80211_reload_regdb, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14570 | .flags = GENL_ADMIN_PERM, |
| 14571 | }, |
| 14572 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14573 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14574 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14575 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14576 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14577 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14578 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14579 | }, |
| 14580 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14581 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14582 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14583 | .doit = nl80211_update_mesh_config, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14584 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14585 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14586 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14587 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 14588 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14589 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14590 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14591 | .doit = nl80211_trigger_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14592 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14593 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14594 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14595 | }, |
| 14596 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14597 | .cmd = NL80211_CMD_ABORT_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14598 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14599 | .doit = nl80211_abort_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14600 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14601 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14602 | NL80211_FLAG_NEED_RTNL, |
| 14603 | }, |
| 14604 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14605 | .cmd = NL80211_CMD_GET_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14606 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14607 | .dumpit = nl80211_dump_scan, |
| 14608 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14609 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14610 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14611 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14612 | .doit = nl80211_start_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14613 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14614 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14615 | NL80211_FLAG_NEED_RTNL, |
| 14616 | }, |
| 14617 | { |
| 14618 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14619 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14620 | .doit = nl80211_stop_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14621 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14622 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14623 | NL80211_FLAG_NEED_RTNL, |
| 14624 | }, |
| 14625 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14626 | .cmd = NL80211_CMD_AUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14627 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14628 | .doit = nl80211_authenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14629 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14630 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14631 | NL80211_FLAG_NEED_RTNL | |
| 14632 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14633 | }, |
| 14634 | { |
| 14635 | .cmd = NL80211_CMD_ASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14636 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14637 | .doit = nl80211_associate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14638 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14639 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14640 | NL80211_FLAG_NEED_RTNL | |
| 14641 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14642 | }, |
| 14643 | { |
| 14644 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14645 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14646 | .doit = nl80211_deauthenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14647 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14648 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14649 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14650 | }, |
| 14651 | { |
| 14652 | .cmd = NL80211_CMD_DISASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14653 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14654 | .doit = nl80211_disassociate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14655 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14656 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14657 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14658 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14659 | { |
| 14660 | .cmd = NL80211_CMD_JOIN_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14661 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14662 | .doit = nl80211_join_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14663 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14664 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14665 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14666 | }, |
| 14667 | { |
| 14668 | .cmd = NL80211_CMD_LEAVE_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14669 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14670 | .doit = nl80211_leave_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14671 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14672 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14673 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14674 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14675 | #ifdef CONFIG_NL80211_TESTMODE |
| 14676 | { |
| 14677 | .cmd = NL80211_CMD_TESTMODE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14678 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14679 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 14680 | .dumpit = nl80211_testmode_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14681 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14682 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14683 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14684 | }, |
| 14685 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14686 | { |
| 14687 | .cmd = NL80211_CMD_CONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14688 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14689 | .doit = nl80211_connect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14690 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14692 | NL80211_FLAG_NEED_RTNL | |
| 14693 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14694 | }, |
| 14695 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14696 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14697 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14698 | .doit = nl80211_update_connect_params, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14699 | .flags = GENL_ADMIN_PERM, |
| 14700 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14701 | NL80211_FLAG_NEED_RTNL | |
| 14702 | NL80211_FLAG_CLEAR_SKB, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 14703 | }, |
| 14704 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14705 | .cmd = NL80211_CMD_DISCONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14706 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14707 | .doit = nl80211_disconnect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14708 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14709 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14710 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14711 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14712 | { |
| 14713 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14714 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14715 | .doit = nl80211_wiphy_netns, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14716 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14717 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14718 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 14719 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 14720 | { |
| 14721 | .cmd = NL80211_CMD_GET_SURVEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14722 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 14723 | .dumpit = nl80211_dump_survey, |
| 14724 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14725 | { |
| 14726 | .cmd = NL80211_CMD_SET_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14727 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14728 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14729 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14730 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14731 | NL80211_FLAG_NEED_RTNL | |
| 14732 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14733 | }, |
| 14734 | { |
| 14735 | .cmd = NL80211_CMD_DEL_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14736 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14737 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14738 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14739 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14740 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14741 | }, |
| 14742 | { |
| 14743 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14744 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14745 | .doit = nl80211_flush_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14746 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14747 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14748 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 14749 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14750 | { |
| 14751 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14752 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14753 | .doit = nl80211_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14754 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14755 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14756 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14757 | }, |
| 14758 | { |
| 14759 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14760 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14761 | .doit = nl80211_cancel_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14762 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14763 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14764 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 14765 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14766 | { |
| 14767 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14768 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14769 | .doit = nl80211_set_tx_bitrate_mask, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14770 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14771 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14772 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 14773 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14774 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14775 | .cmd = NL80211_CMD_REGISTER_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14776 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14777 | .doit = nl80211_register_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14778 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14779 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14780 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14781 | }, |
| 14782 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14783 | .cmd = NL80211_CMD_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14784 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 14785 | .doit = nl80211_tx_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14786 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14787 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14788 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 14789 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14790 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14791 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14792 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14793 | .doit = nl80211_tx_mgmt_cancel_wait, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14794 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 14795 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 14796 | NL80211_FLAG_NEED_RTNL, |
| 14797 | }, |
| 14798 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14799 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14800 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14801 | .doit = nl80211_set_power_save, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14802 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14803 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14804 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14805 | }, |
| 14806 | { |
| 14807 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14808 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14809 | .doit = nl80211_get_power_save, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14810 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14811 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14812 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 14813 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14814 | { |
| 14815 | .cmd = NL80211_CMD_SET_CQM, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14816 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14817 | .doit = nl80211_set_cqm, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14818 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14819 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14820 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 14821 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 14822 | { |
| 14823 | .cmd = NL80211_CMD_SET_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14824 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 14825 | .doit = nl80211_set_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14826 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14827 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14828 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 14829 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 14830 | { |
| 14831 | .cmd = NL80211_CMD_SET_WDS_PEER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14832 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 14833 | .doit = nl80211_set_wds_peer, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14834 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 14835 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14836 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 14837 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14838 | { |
| 14839 | .cmd = NL80211_CMD_JOIN_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14840 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14841 | .doit = nl80211_join_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14842 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14843 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14844 | NL80211_FLAG_NEED_RTNL, |
| 14845 | }, |
| 14846 | { |
| 14847 | .cmd = NL80211_CMD_LEAVE_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14848 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14849 | .doit = nl80211_leave_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14850 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14852 | NL80211_FLAG_NEED_RTNL, |
| 14853 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14854 | { |
| 14855 | .cmd = NL80211_CMD_JOIN_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14856 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14857 | .doit = nl80211_join_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14858 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14859 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14860 | NL80211_FLAG_NEED_RTNL, |
| 14861 | }, |
| 14862 | { |
| 14863 | .cmd = NL80211_CMD_LEAVE_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14864 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14865 | .doit = nl80211_leave_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14866 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 14867 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14868 | NL80211_FLAG_NEED_RTNL, |
| 14869 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 14870 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14871 | { |
| 14872 | .cmd = NL80211_CMD_GET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14873 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14874 | .doit = nl80211_get_wowlan, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14875 | /* can be retrieved by unprivileged users */ |
| 14876 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14877 | NL80211_FLAG_NEED_RTNL, |
| 14878 | }, |
| 14879 | { |
| 14880 | .cmd = NL80211_CMD_SET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14881 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14882 | .doit = nl80211_set_wowlan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14883 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 14884 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14885 | NL80211_FLAG_NEED_RTNL, |
| 14886 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 14887 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14888 | { |
| 14889 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14890 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14891 | .doit = nl80211_set_rekey_data, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14892 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14893 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14894 | NL80211_FLAG_NEED_RTNL | |
| 14895 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 14896 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14897 | { |
| 14898 | .cmd = NL80211_CMD_TDLS_MGMT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14899 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14900 | .doit = nl80211_tdls_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14901 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14902 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14903 | NL80211_FLAG_NEED_RTNL, |
| 14904 | }, |
| 14905 | { |
| 14906 | .cmd = NL80211_CMD_TDLS_OPER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14907 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14908 | .doit = nl80211_tdls_oper, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14909 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 14910 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14911 | NL80211_FLAG_NEED_RTNL, |
| 14912 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14913 | { |
| 14914 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14915 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14916 | .doit = nl80211_register_unexpected_frame, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14917 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 14918 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14919 | NL80211_FLAG_NEED_RTNL, |
| 14920 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14921 | { |
| 14922 | .cmd = NL80211_CMD_PROBE_CLIENT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14923 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14924 | .doit = nl80211_probe_client, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14925 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 14927 | NL80211_FLAG_NEED_RTNL, |
| 14928 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14929 | { |
| 14930 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14931 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14932 | .doit = nl80211_register_beacons, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14933 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 14934 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14935 | NL80211_FLAG_NEED_RTNL, |
| 14936 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 14937 | { |
| 14938 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14939 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 14940 | .doit = nl80211_set_noack_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14941 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 14942 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14943 | NL80211_FLAG_NEED_RTNL, |
| 14944 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14945 | { |
| 14946 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14947 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14948 | .doit = nl80211_start_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14949 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14950 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14951 | NL80211_FLAG_NEED_RTNL, |
| 14952 | }, |
| 14953 | { |
| 14954 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14955 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14956 | .doit = nl80211_stop_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14957 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14958 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14959 | NL80211_FLAG_NEED_RTNL, |
| 14960 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 14961 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14962 | .cmd = NL80211_CMD_START_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14963 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14964 | .doit = nl80211_start_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14965 | .flags = GENL_ADMIN_PERM, |
| 14966 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14967 | NL80211_FLAG_NEED_RTNL, |
| 14968 | }, |
| 14969 | { |
| 14970 | .cmd = NL80211_CMD_STOP_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14971 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14972 | .doit = nl80211_stop_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 14973 | .flags = GENL_ADMIN_PERM, |
| 14974 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14975 | NL80211_FLAG_NEED_RTNL, |
| 14976 | }, |
| 14977 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14978 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14979 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14980 | .doit = nl80211_nan_add_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14981 | .flags = GENL_ADMIN_PERM, |
| 14982 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14983 | NL80211_FLAG_NEED_RTNL, |
| 14984 | }, |
| 14985 | { |
| 14986 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14987 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14988 | .doit = nl80211_nan_del_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 14989 | .flags = GENL_ADMIN_PERM, |
| 14990 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14991 | NL80211_FLAG_NEED_RTNL, |
| 14992 | }, |
| 14993 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 14994 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14995 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 14996 | .doit = nl80211_nan_change_config, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 14997 | .flags = GENL_ADMIN_PERM, |
| 14998 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14999 | NL80211_FLAG_NEED_RTNL, |
| 15000 | }, |
| 15001 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15002 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15003 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15004 | .doit = nl80211_set_mcast_rate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15005 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15006 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15007 | NL80211_FLAG_NEED_RTNL, |
| 15008 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15009 | { |
| 15010 | .cmd = NL80211_CMD_SET_MAC_ACL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15011 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15012 | .doit = nl80211_set_mac_acl, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15013 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15014 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15015 | NL80211_FLAG_NEED_RTNL, |
| 15016 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15017 | { |
| 15018 | .cmd = NL80211_CMD_RADAR_DETECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15019 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15020 | .doit = nl80211_start_radar_detection, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15021 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15023 | NL80211_FLAG_NEED_RTNL, |
| 15024 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15025 | { |
| 15026 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15027 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15028 | .doit = nl80211_get_protocol_features, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15029 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15030 | { |
| 15031 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15032 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15033 | .doit = nl80211_update_ft_ies, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15034 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15035 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15036 | NL80211_FLAG_NEED_RTNL, |
| 15037 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15038 | { |
| 15039 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15040 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15041 | .doit = nl80211_crit_protocol_start, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15042 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15043 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15044 | NL80211_FLAG_NEED_RTNL, |
| 15045 | }, |
| 15046 | { |
| 15047 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15048 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15049 | .doit = nl80211_crit_protocol_stop, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15050 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15051 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15052 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15053 | }, |
| 15054 | { |
| 15055 | .cmd = NL80211_CMD_GET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15056 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15057 | .doit = nl80211_get_coalesce, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15058 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15059 | NL80211_FLAG_NEED_RTNL, |
| 15060 | }, |
| 15061 | { |
| 15062 | .cmd = NL80211_CMD_SET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15063 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15064 | .doit = nl80211_set_coalesce, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15065 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15066 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15067 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15068 | }, |
| 15069 | { |
| 15070 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15071 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15072 | .doit = nl80211_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15073 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15074 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15075 | NL80211_FLAG_NEED_RTNL, |
| 15076 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15077 | { |
| 15078 | .cmd = NL80211_CMD_VENDOR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15079 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15080 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 15081 | .dumpit = nl80211_vendor_cmd_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15082 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15083 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15084 | NL80211_FLAG_NEED_RTNL | |
| 15085 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15086 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15087 | { |
| 15088 | .cmd = NL80211_CMD_SET_QOS_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15089 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15090 | .doit = nl80211_set_qos_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15091 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15092 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15093 | NL80211_FLAG_NEED_RTNL, |
| 15094 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15095 | { |
| 15096 | .cmd = NL80211_CMD_ADD_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15097 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15098 | .doit = nl80211_add_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15099 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15100 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15101 | NL80211_FLAG_NEED_RTNL, |
| 15102 | }, |
| 15103 | { |
| 15104 | .cmd = NL80211_CMD_DEL_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15105 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15106 | .doit = nl80211_del_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15107 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15108 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15109 | NL80211_FLAG_NEED_RTNL, |
| 15110 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15111 | { |
| 15112 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15113 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15114 | .doit = nl80211_tdls_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15115 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15116 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15117 | NL80211_FLAG_NEED_RTNL, |
| 15118 | }, |
| 15119 | { |
| 15120 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15121 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15122 | .doit = nl80211_tdls_cancel_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15123 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15124 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15125 | NL80211_FLAG_NEED_RTNL, |
| 15126 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15127 | { |
| 15128 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15129 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15130 | .doit = nl80211_set_multicast_to_unicast, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15131 | .flags = GENL_UNS_ADMIN_PERM, |
| 15132 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15133 | NL80211_FLAG_NEED_RTNL, |
| 15134 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15135 | { |
| 15136 | .cmd = NL80211_CMD_SET_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15137 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15138 | .doit = nl80211_set_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15139 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15140 | NL80211_FLAG_NEED_RTNL | |
| 15141 | NL80211_FLAG_CLEAR_SKB, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15142 | }, |
| 15143 | { |
| 15144 | .cmd = NL80211_CMD_DEL_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15145 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15146 | .doit = nl80211_del_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15147 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15148 | NL80211_FLAG_NEED_RTNL, |
| 15149 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15150 | { |
| 15151 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15152 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15153 | .doit = nl80211_external_auth, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15154 | .flags = GENL_ADMIN_PERM, |
| 15155 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15156 | NL80211_FLAG_NEED_RTNL, |
| 15157 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15158 | { |
| 15159 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15160 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15161 | .doit = nl80211_tx_control_port, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15162 | .flags = GENL_UNS_ADMIN_PERM, |
| 15163 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15164 | NL80211_FLAG_NEED_RTNL, |
| 15165 | }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15166 | { |
| 15167 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15168 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15169 | .doit = nl80211_get_ftm_responder_stats, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15170 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15171 | NL80211_FLAG_NEED_RTNL, |
| 15172 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15173 | { |
| 15174 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15175 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15176 | .doit = nl80211_pmsr_start, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15177 | .flags = GENL_UNS_ADMIN_PERM, |
| 15178 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15179 | NL80211_FLAG_NEED_RTNL, |
| 15180 | }, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15181 | { |
| 15182 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15183 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15184 | .doit = nl80211_notify_radar_detection, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15185 | .flags = GENL_UNS_ADMIN_PERM, |
| 15186 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15187 | NL80211_FLAG_NEED_RTNL, |
| 15188 | }, |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 15189 | { |
| 15190 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, |
| 15191 | .doit = nl80211_update_owe_info, |
| 15192 | .flags = GENL_ADMIN_PERM, |
| 15193 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15194 | NL80211_FLAG_NEED_RTNL, |
| 15195 | }, |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 15196 | { |
| 15197 | .cmd = NL80211_CMD_PROBE_MESH_LINK, |
| 15198 | .doit = nl80211_probe_mesh_link, |
| 15199 | .flags = GENL_UNS_ADMIN_PERM, |
| 15200 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15201 | NL80211_FLAG_NEED_RTNL, |
| 15202 | }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 15203 | { |
| 15204 | .cmd = NL80211_CMD_SET_TID_CONFIG, |
| 15205 | .doit = nl80211_set_tid_config, |
| 15206 | .flags = GENL_UNS_ADMIN_PERM, |
| 15207 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15208 | NL80211_FLAG_NEED_RTNL, |
| 15209 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15210 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15211 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15212 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15213 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 15214 | .hdrsize = 0, /* no private header */ |
| 15215 | .version = 1, /* no particular meaning now */ |
| 15216 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 3b0f31f | 2019-03-21 22:51:02 +0100 | [diff] [blame] | 15217 | .policy = nl80211_policy, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15218 | .netnsok = true, |
| 15219 | .pre_doit = nl80211_pre_doit, |
| 15220 | .post_doit = nl80211_post_doit, |
| 15221 | .module = THIS_MODULE, |
| 15222 | .ops = nl80211_ops, |
| 15223 | .n_ops = ARRAY_SIZE(nl80211_ops), |
| 15224 | .mcgrps = nl80211_mcgrps, |
| 15225 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 15226 | .parallel_ops = true, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15227 | }; |
| 15228 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15229 | /* notification functions */ |
| 15230 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15231 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 15232 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15233 | { |
| 15234 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 15235 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15236 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15237 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 15238 | cmd != NL80211_CMD_DEL_WIPHY); |
| 15239 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15240 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15241 | if (!msg) |
| 15242 | return; |
| 15243 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15244 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15245 | nlmsg_free(msg); |
| 15246 | return; |
| 15247 | } |
| 15248 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15249 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15250 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15251 | } |
| 15252 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15253 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 15254 | struct wireless_dev *wdev, |
| 15255 | enum nl80211_commands cmd) |
| 15256 | { |
| 15257 | struct sk_buff *msg; |
| 15258 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15259 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15260 | if (!msg) |
| 15261 | return; |
| 15262 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 15263 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15264 | nlmsg_free(msg); |
| 15265 | return; |
| 15266 | } |
| 15267 | |
| 15268 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15269 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 15270 | } |
| 15271 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15272 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 15273 | struct cfg80211_registered_device *rdev) |
| 15274 | { |
| 15275 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 15276 | struct nlattr *nest; |
| 15277 | int i; |
| 15278 | |
| 15279 | if (WARN_ON(!req)) |
| 15280 | return 0; |
| 15281 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15282 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15283 | if (!nest) |
| 15284 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15285 | for (i = 0; i < req->n_ssids; i++) { |
| 15286 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 15287 | goto nla_put_failure; |
| 15288 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15289 | nla_nest_end(msg, nest); |
| 15290 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 15291 | if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { |
| 15292 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); |
| 15293 | if (!nest) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15294 | goto nla_put_failure; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 15295 | for (i = 0; i < req->n_channels; i++) { |
| 15296 | if (nla_put_u32(msg, i, |
| 15297 | ieee80211_channel_to_khz(req->channels[i]))) |
| 15298 | goto nla_put_failure; |
| 15299 | } |
| 15300 | nla_nest_end(msg, nest); |
| 15301 | } else { |
| 15302 | nest = nla_nest_start_noflag(msg, |
| 15303 | NL80211_ATTR_SCAN_FREQUENCIES); |
| 15304 | if (!nest) |
| 15305 | goto nla_put_failure; |
| 15306 | for (i = 0; i < req->n_channels; i++) { |
| 15307 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 15308 | goto nla_put_failure; |
| 15309 | } |
| 15310 | nla_nest_end(msg, nest); |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15311 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15312 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15313 | if (req->ie && |
| 15314 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 15315 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15316 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15317 | if (req->flags && |
| 15318 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 15319 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 15320 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 15321 | if (req->info.scan_start_tsf && |
| 15322 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
| 15323 | req->info.scan_start_tsf, NL80211_BSS_PAD) || |
| 15324 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
| 15325 | req->info.tsf_bssid))) |
| 15326 | goto nla_put_failure; |
| 15327 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15328 | return 0; |
| 15329 | nla_put_failure: |
| 15330 | return -ENOBUFS; |
| 15331 | } |
| 15332 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15333 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15334 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15335 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15336 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15337 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15338 | { |
| 15339 | void *hdr; |
| 15340 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15341 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15342 | if (!hdr) |
| 15343 | return -1; |
| 15344 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15345 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15346 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15347 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15348 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15349 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15350 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15351 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15352 | /* ignore errors and send incomplete event anyway */ |
| 15353 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15354 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15355 | genlmsg_end(msg, hdr); |
| 15356 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15357 | |
| 15358 | nla_put_failure: |
| 15359 | genlmsg_cancel(msg, hdr); |
| 15360 | return -EMSGSIZE; |
| 15361 | } |
| 15362 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15363 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15364 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15365 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15366 | { |
| 15367 | void *hdr; |
| 15368 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15369 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15370 | if (!hdr) |
| 15371 | return -1; |
| 15372 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15373 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 15374 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 15375 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 15376 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 15377 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15378 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15379 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15380 | genlmsg_end(msg, hdr); |
| 15381 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15382 | |
| 15383 | nla_put_failure: |
| 15384 | genlmsg_cancel(msg, hdr); |
| 15385 | return -EMSGSIZE; |
| 15386 | } |
| 15387 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15388 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15389 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15390 | { |
| 15391 | struct sk_buff *msg; |
| 15392 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15393 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15394 | if (!msg) |
| 15395 | return; |
| 15396 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15397 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15398 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 15399 | nlmsg_free(msg); |
| 15400 | return; |
| 15401 | } |
| 15402 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15403 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15404 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15405 | } |
| 15406 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15407 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 15408 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15409 | { |
| 15410 | struct sk_buff *msg; |
| 15411 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15412 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15413 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15414 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15415 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15416 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15417 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 15418 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15419 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15420 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15421 | } |
| 15422 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15423 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15424 | } |
| 15425 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15426 | /* send message created by nl80211_build_scan_msg() */ |
| 15427 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 15428 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15429 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15430 | if (!msg) |
| 15431 | return; |
| 15432 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15433 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15434 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15435 | } |
| 15436 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15437 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15438 | { |
| 15439 | struct sk_buff *msg; |
| 15440 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15441 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15442 | if (!msg) |
| 15443 | return; |
| 15444 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15445 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15446 | nlmsg_free(msg); |
| 15447 | return; |
| 15448 | } |
| 15449 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15450 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15451 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15452 | } |
| 15453 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15454 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 15455 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15456 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15457 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15458 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 15459 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15460 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15461 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 15462 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15463 | NL80211_REGDOM_TYPE_WORLD)) |
| 15464 | goto nla_put_failure; |
| 15465 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 15466 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15467 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 15468 | goto nla_put_failure; |
| 15469 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 15470 | request->intersect) { |
| 15471 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15472 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 15473 | goto nla_put_failure; |
| 15474 | } else { |
| 15475 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15476 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 15477 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 15478 | request->alpha2)) |
| 15479 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15480 | } |
| 15481 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15482 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 15483 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 15484 | |
| 15485 | if (wiphy && |
| 15486 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 15487 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 15488 | |
| 15489 | if (wiphy && |
| 15490 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 15491 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 15492 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15493 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15494 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15495 | return true; |
| 15496 | |
| 15497 | nla_put_failure: |
| 15498 | return false; |
| 15499 | } |
| 15500 | |
| 15501 | /* |
| 15502 | * This can happen on global regulatory changes or device specific settings |
| 15503 | * based on custom regulatory domains. |
| 15504 | */ |
| 15505 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 15506 | struct regulatory_request *request) |
| 15507 | { |
| 15508 | struct sk_buff *msg; |
| 15509 | void *hdr; |
| 15510 | |
| 15511 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15512 | if (!msg) |
| 15513 | return; |
| 15514 | |
| 15515 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15516 | if (!hdr) |
| 15517 | goto nla_put_failure; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15518 | |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15519 | if (!nl80211_reg_change_event_fill(msg, request)) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15520 | goto nla_put_failure; |
| 15521 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15522 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15523 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15524 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15525 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15526 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15527 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15528 | |
| 15529 | return; |
| 15530 | |
| 15531 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15532 | nlmsg_free(msg); |
| 15533 | } |
| 15534 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15535 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 15536 | struct net_device *netdev, |
| 15537 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15538 | enum nl80211_commands cmd, gfp_t gfp, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15539 | int uapsd_queues, const u8 *req_ies, |
| 15540 | size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15541 | { |
| 15542 | struct sk_buff *msg; |
| 15543 | void *hdr; |
| 15544 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15545 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15546 | if (!msg) |
| 15547 | return; |
| 15548 | |
| 15549 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15550 | if (!hdr) { |
| 15551 | nlmsg_free(msg); |
| 15552 | return; |
| 15553 | } |
| 15554 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15555 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15556 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15557 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15558 | (req_ies && |
| 15559 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15560 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15561 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15562 | if (uapsd_queues >= 0) { |
| 15563 | struct nlattr *nla_wmm = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15564 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15565 | if (!nla_wmm) |
| 15566 | goto nla_put_failure; |
| 15567 | |
| 15568 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 15569 | uapsd_queues)) |
| 15570 | goto nla_put_failure; |
| 15571 | |
| 15572 | nla_nest_end(msg, nla_wmm); |
| 15573 | } |
| 15574 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15575 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15576 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15577 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15578 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15579 | return; |
| 15580 | |
| 15581 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15582 | nlmsg_free(msg); |
| 15583 | } |
| 15584 | |
| 15585 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15586 | struct net_device *netdev, const u8 *buf, |
| 15587 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15588 | { |
| 15589 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15590 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15591 | } |
| 15592 | |
| 15593 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 15594 | struct net_device *netdev, const u8 *buf, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15595 | size_t len, gfp_t gfp, int uapsd_queues, |
| 15596 | const u8 *req_ies, size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15597 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15598 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15599 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
| 15600 | req_ies, req_ies_len); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15601 | } |
| 15602 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15603 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15604 | struct net_device *netdev, const u8 *buf, |
| 15605 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15606 | { |
| 15607 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15608 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15609 | } |
| 15610 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15611 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 15612 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15613 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15614 | { |
| 15615 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15616 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15617 | } |
| 15618 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15619 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 15620 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15621 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15622 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15623 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15624 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15625 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 15626 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15627 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15628 | if (WARN_ON(len < 2)) |
| 15629 | return; |
| 15630 | |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15631 | if (ieee80211_is_deauth(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15632 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15633 | } else if (ieee80211_is_disassoc(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15634 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15635 | } else if (ieee80211_is_beacon(mgmt->frame_control)) { |
| 15636 | if (wdev->unprot_beacon_reported && |
| 15637 | elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) |
| 15638 | return; |
| 15639 | cmd = NL80211_CMD_UNPROT_BEACON; |
| 15640 | wdev->unprot_beacon_reported = jiffies; |
| 15641 | } else { |
| 15642 | return; |
| 15643 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15644 | |
| 15645 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15646 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
| 15647 | NULL, 0); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15648 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15649 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15650 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 15651 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 15652 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15653 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15654 | { |
| 15655 | struct sk_buff *msg; |
| 15656 | void *hdr; |
| 15657 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15659 | if (!msg) |
| 15660 | return; |
| 15661 | |
| 15662 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15663 | if (!hdr) { |
| 15664 | nlmsg_free(msg); |
| 15665 | return; |
| 15666 | } |
| 15667 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15668 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15669 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15670 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 15671 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 15672 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15673 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15674 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15675 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15676 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15677 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15678 | return; |
| 15679 | |
| 15680 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15681 | nlmsg_free(msg); |
| 15682 | } |
| 15683 | |
| 15684 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15685 | struct net_device *netdev, const u8 *addr, |
| 15686 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15687 | { |
| 15688 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15689 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15690 | } |
| 15691 | |
| 15692 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15693 | struct net_device *netdev, const u8 *addr, |
| 15694 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15695 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15696 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 15697 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15698 | } |
| 15699 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15700 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15701 | struct net_device *netdev, |
| 15702 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 15703 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15704 | { |
| 15705 | struct sk_buff *msg; |
| 15706 | void *hdr; |
| 15707 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15708 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15709 | cr->fils.kek_len + cr->fils.pmk_len + |
| 15710 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15711 | if (!msg) |
| 15712 | return; |
| 15713 | |
| 15714 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 15715 | if (!hdr) { |
| 15716 | nlmsg_free(msg); |
| 15717 | return; |
| 15718 | } |
| 15719 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15720 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15721 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15722 | (cr->bssid && |
| 15723 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 15724 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15725 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 15726 | cr->status) || |
| 15727 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 15728 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 15729 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 15730 | cr->timeout_reason))) || |
| 15731 | (cr->req_ie && |
| 15732 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 15733 | (cr->resp_ie && |
| 15734 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15735 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15736 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15737 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15738 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 15739 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 15740 | ((cr->fils.kek && |
| 15741 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 15742 | cr->fils.kek)) || |
| 15743 | (cr->fils.pmk && |
| 15744 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 15745 | (cr->fils.pmkid && |
| 15746 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid))))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15747 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15748 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15749 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15750 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15751 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15752 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15753 | return; |
| 15754 | |
| 15755 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15756 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15757 | } |
| 15758 | |
| 15759 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15760 | struct net_device *netdev, |
| 15761 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15762 | { |
| 15763 | struct sk_buff *msg; |
| 15764 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15765 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15766 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 15767 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 15768 | info->fils.kek_len + info->fils.pmk_len + |
| 15769 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15770 | if (!msg) |
| 15771 | return; |
| 15772 | |
| 15773 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 15774 | if (!hdr) { |
| 15775 | nlmsg_free(msg); |
| 15776 | return; |
| 15777 | } |
| 15778 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15779 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15780 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15781 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 15782 | (info->req_ie && |
| 15783 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 15784 | info->req_ie)) || |
| 15785 | (info->resp_ie && |
| 15786 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 15787 | info->resp_ie)) || |
| 15788 | (info->fils.update_erp_next_seq_num && |
| 15789 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 15790 | info->fils.erp_next_seq_num)) || |
| 15791 | (info->fils.kek && |
| 15792 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 15793 | info->fils.kek)) || |
| 15794 | (info->fils.pmk && |
| 15795 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 15796 | (info->fils.pmkid && |
| 15797 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15798 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15799 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15800 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15801 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15802 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15803 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15804 | return; |
| 15805 | |
| 15806 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15807 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15808 | } |
| 15809 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 15810 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 15811 | struct net_device *netdev, const u8 *bssid) |
| 15812 | { |
| 15813 | struct sk_buff *msg; |
| 15814 | void *hdr; |
| 15815 | |
| 15816 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15817 | if (!msg) |
| 15818 | return; |
| 15819 | |
| 15820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 15821 | if (!hdr) { |
| 15822 | nlmsg_free(msg); |
| 15823 | return; |
| 15824 | } |
| 15825 | |
Chung-Hsien Hsu | f4d7599 | 2019-05-09 09:48:25 +0000 | [diff] [blame] | 15826 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15827 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15828 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 15829 | goto nla_put_failure; |
| 15830 | |
| 15831 | genlmsg_end(msg, hdr); |
| 15832 | |
| 15833 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15834 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 15835 | return; |
| 15836 | |
| 15837 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 15838 | nlmsg_free(msg); |
| 15839 | } |
| 15840 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15841 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 15842 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 15843 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15844 | { |
| 15845 | struct sk_buff *msg; |
| 15846 | void *hdr; |
| 15847 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15848 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15849 | if (!msg) |
| 15850 | return; |
| 15851 | |
| 15852 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 15853 | if (!hdr) { |
| 15854 | nlmsg_free(msg); |
| 15855 | return; |
| 15856 | } |
| 15857 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15858 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15859 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 15860 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15861 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 15862 | (from_ap && |
| 15863 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 15864 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 15865 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15866 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15867 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15868 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15869 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15870 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15871 | return; |
| 15872 | |
| 15873 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15874 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15875 | } |
| 15876 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15877 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 15878 | struct net_device *netdev, const u8 *bssid, |
| 15879 | gfp_t gfp) |
| 15880 | { |
| 15881 | struct sk_buff *msg; |
| 15882 | void *hdr; |
| 15883 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15884 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15885 | if (!msg) |
| 15886 | return; |
| 15887 | |
| 15888 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 15889 | if (!hdr) { |
| 15890 | nlmsg_free(msg); |
| 15891 | return; |
| 15892 | } |
| 15893 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15894 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15895 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15896 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 15897 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15898 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15899 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15900 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15901 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15902 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15903 | return; |
| 15904 | |
| 15905 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15906 | nlmsg_free(msg); |
| 15907 | } |
| 15908 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15909 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 15910 | const u8 *ie, u8 ie_len, |
| 15911 | int sig_dbm, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15912 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15913 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15914 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15915 | struct sk_buff *msg; |
| 15916 | void *hdr; |
| 15917 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15918 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 15919 | return; |
| 15920 | |
| 15921 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 15922 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 15923 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15924 | if (!msg) |
| 15925 | return; |
| 15926 | |
| 15927 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 15928 | if (!hdr) { |
| 15929 | nlmsg_free(msg); |
| 15930 | return; |
| 15931 | } |
| 15932 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15933 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15934 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 15935 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15936 | (ie_len && ie && |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 15937 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 15938 | (sig_dbm && |
| 15939 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15940 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15941 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15942 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15943 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15944 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15945 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15946 | return; |
| 15947 | |
| 15948 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15949 | nlmsg_free(msg); |
| 15950 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15951 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 15952 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15953 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 15954 | struct net_device *netdev, const u8 *addr, |
| 15955 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15956 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15957 | { |
| 15958 | struct sk_buff *msg; |
| 15959 | void *hdr; |
| 15960 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15961 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15962 | if (!msg) |
| 15963 | return; |
| 15964 | |
| 15965 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 15966 | if (!hdr) { |
| 15967 | nlmsg_free(msg); |
| 15968 | return; |
| 15969 | } |
| 15970 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15971 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15972 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15973 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 15974 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 15975 | (key_id != -1 && |
| 15976 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 15977 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 15978 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15979 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15980 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15981 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15982 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15983 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15984 | return; |
| 15985 | |
| 15986 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 15987 | nlmsg_free(msg); |
| 15988 | } |
| 15989 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15990 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 15991 | struct ieee80211_channel *channel_before, |
| 15992 | struct ieee80211_channel *channel_after) |
| 15993 | { |
| 15994 | struct sk_buff *msg; |
| 15995 | void *hdr; |
| 15996 | struct nlattr *nl_freq; |
| 15997 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 15999 | if (!msg) |
| 16000 | return; |
| 16001 | |
| 16002 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 16003 | if (!hdr) { |
| 16004 | nlmsg_free(msg); |
| 16005 | return; |
| 16006 | } |
| 16007 | |
| 16008 | /* |
| 16009 | * Since we are applying the beacon hint to a wiphy we know its |
| 16010 | * wiphy_idx is valid |
| 16011 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16012 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 16013 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16014 | |
| 16015 | /* Before */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16016 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16017 | if (!nl_freq) |
| 16018 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16019 | |
| 16020 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16021 | goto nla_put_failure; |
| 16022 | nla_nest_end(msg, nl_freq); |
| 16023 | |
| 16024 | /* After */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16025 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16026 | if (!nl_freq) |
| 16027 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16028 | |
| 16029 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16030 | goto nla_put_failure; |
| 16031 | nla_nest_end(msg, nl_freq); |
| 16032 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16033 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16034 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16035 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16036 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16037 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16038 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16039 | |
| 16040 | return; |
| 16041 | |
| 16042 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16043 | nlmsg_free(msg); |
| 16044 | } |
| 16045 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16046 | static void nl80211_send_remain_on_chan_event( |
| 16047 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16048 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16049 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16050 | unsigned int duration, gfp_t gfp) |
| 16051 | { |
| 16052 | struct sk_buff *msg; |
| 16053 | void *hdr; |
| 16054 | |
| 16055 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16056 | if (!msg) |
| 16057 | return; |
| 16058 | |
| 16059 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16060 | if (!hdr) { |
| 16061 | nlmsg_free(msg); |
| 16062 | return; |
| 16063 | } |
| 16064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16065 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16066 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16067 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16068 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16069 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16070 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16071 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 16072 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16073 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16074 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16075 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16076 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16077 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 16078 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 16079 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16080 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16081 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16082 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16083 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16084 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16085 | return; |
| 16086 | |
| 16087 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16088 | nlmsg_free(msg); |
| 16089 | } |
| 16090 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16091 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 16092 | struct ieee80211_channel *chan, |
| 16093 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16094 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16095 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16096 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16097 | |
| 16098 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16099 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16100 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16101 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16102 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16103 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16104 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16105 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 16106 | struct ieee80211_channel *chan, |
| 16107 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16108 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16109 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16110 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16111 | |
| 16112 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16113 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16114 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16115 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16116 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16117 | |
James Prestwood | 1c38c7f | 2019-06-12 12:35:09 -0700 | [diff] [blame] | 16118 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
| 16119 | struct ieee80211_channel *chan, |
| 16120 | gfp_t gfp) |
| 16121 | { |
| 16122 | struct wiphy *wiphy = wdev->wiphy; |
| 16123 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16124 | |
| 16125 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); |
| 16126 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, |
| 16127 | rdev, wdev, cookie, chan, 0, gfp); |
| 16128 | } |
| 16129 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); |
| 16130 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16131 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 16132 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16133 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16134 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16135 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16136 | struct sk_buff *msg; |
| 16137 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16138 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 16139 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16140 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16141 | if (!msg) |
| 16142 | return; |
| 16143 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16144 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 16145 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16146 | nlmsg_free(msg); |
| 16147 | return; |
| 16148 | } |
| 16149 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16150 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16151 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16152 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16153 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16154 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16155 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 16156 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16157 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16158 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16159 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16160 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16161 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16162 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16163 | if (!sinfo) |
| 16164 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16165 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16166 | trace_cfg80211_del_sta(dev, mac_addr); |
| 16167 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16168 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 16169 | if (!msg) { |
| 16170 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16171 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 16172 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16173 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16174 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 16175 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16176 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16177 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16178 | } |
| 16179 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16180 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16181 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16182 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16183 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16184 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16185 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 16186 | enum nl80211_connect_failed_reason reason, |
| 16187 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16188 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16189 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16190 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16191 | struct sk_buff *msg; |
| 16192 | void *hdr; |
| 16193 | |
| 16194 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 16195 | if (!msg) |
| 16196 | return; |
| 16197 | |
| 16198 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 16199 | if (!hdr) { |
| 16200 | nlmsg_free(msg); |
| 16201 | return; |
| 16202 | } |
| 16203 | |
| 16204 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16205 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 16206 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 16207 | goto nla_put_failure; |
| 16208 | |
| 16209 | genlmsg_end(msg, hdr); |
| 16210 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16211 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16212 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16213 | return; |
| 16214 | |
| 16215 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16216 | nlmsg_free(msg); |
| 16217 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16218 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16219 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16220 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 16221 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16222 | { |
| 16223 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16224 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16225 | struct sk_buff *msg; |
| 16226 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 16227 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16228 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16229 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16230 | return false; |
| 16231 | |
| 16232 | msg = nlmsg_new(100, gfp); |
| 16233 | if (!msg) |
| 16234 | return true; |
| 16235 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16236 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16237 | if (!hdr) { |
| 16238 | nlmsg_free(msg); |
| 16239 | return true; |
| 16240 | } |
| 16241 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16242 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16243 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16244 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16245 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16246 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16247 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16248 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16249 | return true; |
| 16250 | |
| 16251 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16252 | nlmsg_free(msg); |
| 16253 | return true; |
| 16254 | } |
| 16255 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16256 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 16257 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16258 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16259 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16260 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16261 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16262 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 16263 | |
| 16264 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16265 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 16266 | trace_cfg80211_return_bool(false); |
| 16267 | return false; |
| 16268 | } |
| 16269 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 16270 | addr, gfp); |
| 16271 | trace_cfg80211_return_bool(ret); |
| 16272 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16273 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16274 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 16275 | |
| 16276 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 16277 | const u8 *addr, gfp_t gfp) |
| 16278 | { |
| 16279 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16280 | bool ret; |
| 16281 | |
| 16282 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 16283 | |
| 16284 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16285 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 16286 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 16287 | trace_cfg80211_return_bool(false); |
| 16288 | return false; |
| 16289 | } |
| 16290 | ret = __nl80211_unexpected_frame(dev, |
| 16291 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 16292 | addr, gfp); |
| 16293 | trace_cfg80211_return_bool(ret); |
| 16294 | return ret; |
| 16295 | } |
| 16296 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16297 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16298 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16299 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 16300 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16301 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16302 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16303 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16304 | struct sk_buff *msg; |
| 16305 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16306 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16307 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16308 | if (!msg) |
| 16309 | return -ENOMEM; |
| 16310 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16311 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16312 | if (!hdr) { |
| 16313 | nlmsg_free(msg); |
| 16314 | return -ENOMEM; |
| 16315 | } |
| 16316 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16317 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16318 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16319 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16320 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16321 | NL80211_ATTR_PAD) || |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 16322 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 16323 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16324 | (sig_dbm && |
| 16325 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16326 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16327 | (flags && |
| 16328 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16329 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16330 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16331 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16332 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16333 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16334 | |
| 16335 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16336 | nlmsg_free(msg); |
| 16337 | return -ENOBUFS; |
| 16338 | } |
| 16339 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16340 | static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16341 | const u8 *buf, size_t len, bool ack, |
| 16342 | gfp_t gfp, enum nl80211_commands command) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16343 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16344 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16345 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16346 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16347 | struct sk_buff *msg; |
| 16348 | void *hdr; |
| 16349 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16350 | if (command == NL80211_CMD_FRAME_TX_STATUS) |
| 16351 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 16352 | else |
| 16353 | trace_cfg80211_control_port_tx_status(wdev, cookie, ack); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16354 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16355 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16356 | if (!msg) |
| 16357 | return; |
| 16358 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16359 | hdr = nl80211hdr_put(msg, 0, 0, 0, command); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16360 | if (!hdr) { |
| 16361 | nlmsg_free(msg); |
| 16362 | return; |
| 16363 | } |
| 16364 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16365 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16366 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16367 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16368 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16369 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16370 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16371 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16372 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16373 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 16374 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16375 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16376 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16377 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16378 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16379 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16380 | return; |
| 16381 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16382 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16383 | nlmsg_free(msg); |
| 16384 | } |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16385 | |
| 16386 | void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16387 | const u8 *buf, size_t len, bool ack, |
| 16388 | gfp_t gfp) |
| 16389 | { |
| 16390 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16391 | NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); |
| 16392 | } |
| 16393 | EXPORT_SYMBOL(cfg80211_control_port_tx_status); |
| 16394 | |
| 16395 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16396 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
| 16397 | { |
| 16398 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16399 | NL80211_CMD_FRAME_TX_STATUS); |
| 16400 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16401 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16402 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16403 | static int __nl80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16404 | struct sk_buff *skb, |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16405 | bool unencrypted, gfp_t gfp) |
| 16406 | { |
| 16407 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16408 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16409 | struct ethhdr *ehdr = eth_hdr(skb); |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16410 | const u8 *addr = ehdr->h_source; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16411 | u16 proto = be16_to_cpu(skb->protocol); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16412 | struct sk_buff *msg; |
| 16413 | void *hdr; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16414 | struct nlattr *frame; |
| 16415 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16416 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 16417 | |
| 16418 | if (!nlportid) |
| 16419 | return -ENOENT; |
| 16420 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16421 | msg = nlmsg_new(100 + skb->len, gfp); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16422 | if (!msg) |
| 16423 | return -ENOMEM; |
| 16424 | |
| 16425 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 16426 | if (!hdr) { |
| 16427 | nlmsg_free(msg); |
| 16428 | return -ENOBUFS; |
| 16429 | } |
| 16430 | |
| 16431 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16432 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16433 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16434 | NL80211_ATTR_PAD) || |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16435 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16436 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 16437 | (unencrypted && nla_put_flag(msg, |
| 16438 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 16439 | goto nla_put_failure; |
| 16440 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16441 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 16442 | if (!frame) |
| 16443 | goto nla_put_failure; |
| 16444 | |
| 16445 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16446 | genlmsg_end(msg, hdr); |
| 16447 | |
| 16448 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16449 | |
| 16450 | nla_put_failure: |
| 16451 | nlmsg_free(msg); |
| 16452 | return -ENOBUFS; |
| 16453 | } |
| 16454 | |
| 16455 | bool cfg80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16456 | struct sk_buff *skb, bool unencrypted) |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16457 | { |
| 16458 | int ret; |
| 16459 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16460 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 16461 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16462 | trace_cfg80211_return_bool(ret == 0); |
| 16463 | return ret == 0; |
| 16464 | } |
| 16465 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 16466 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16467 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 16468 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16469 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16470 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16471 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16472 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16473 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16474 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16475 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16476 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16477 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16478 | cb = (void **)msg->cb; |
| 16479 | |
| 16480 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 16481 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16482 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16483 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16484 | } |
| 16485 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16486 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16487 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16488 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16489 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16490 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16491 | goto nla_put_failure; |
| 16492 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16493 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16494 | if (!cb[1]) |
| 16495 | goto nla_put_failure; |
| 16496 | |
| 16497 | cb[2] = rdev; |
| 16498 | |
| 16499 | return msg; |
| 16500 | nla_put_failure: |
| 16501 | nlmsg_free(msg); |
| 16502 | return NULL; |
| 16503 | } |
| 16504 | |
| 16505 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 16506 | { |
| 16507 | void **cb = (void **)msg->cb; |
| 16508 | struct cfg80211_registered_device *rdev = cb[2]; |
| 16509 | |
| 16510 | nla_nest_end(msg, cb[1]); |
| 16511 | genlmsg_end(msg, cb[0]); |
| 16512 | |
| 16513 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 16514 | |
| 16515 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16516 | NL80211_MCGRP_MLME, gfp); |
| 16517 | } |
| 16518 | |
| 16519 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 16520 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16521 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16522 | { |
| 16523 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16524 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16525 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16526 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16527 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16528 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16529 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 16530 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 16531 | return; |
| 16532 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16533 | if (wdev->cqm_config) { |
| 16534 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 16535 | |
| 16536 | cfg80211_cqm_rssi_update(rdev, dev); |
| 16537 | |
| 16538 | if (rssi_level == 0) |
| 16539 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 16540 | } |
| 16541 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16542 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16543 | if (!msg) |
| 16544 | return; |
| 16545 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16546 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 16547 | rssi_event)) |
| 16548 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16549 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16550 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 16551 | rssi_level)) |
| 16552 | goto nla_put_failure; |
| 16553 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16554 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16555 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16556 | return; |
| 16557 | |
| 16558 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16559 | nlmsg_free(msg); |
| 16560 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16561 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16562 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16563 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 16564 | const u8 *peer, u32 num_packets, |
| 16565 | u32 rate, u32 intvl, gfp_t gfp) |
| 16566 | { |
| 16567 | struct sk_buff *msg; |
| 16568 | |
| 16569 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16570 | if (!msg) |
| 16571 | return; |
| 16572 | |
| 16573 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 16574 | goto nla_put_failure; |
| 16575 | |
| 16576 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 16577 | goto nla_put_failure; |
| 16578 | |
| 16579 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 16580 | goto nla_put_failure; |
| 16581 | |
| 16582 | cfg80211_send_cqm(msg, gfp); |
| 16583 | return; |
| 16584 | |
| 16585 | nla_put_failure: |
| 16586 | nlmsg_free(msg); |
| 16587 | } |
| 16588 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 16589 | |
| 16590 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 16591 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 16592 | { |
| 16593 | struct sk_buff *msg; |
| 16594 | |
| 16595 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 16596 | |
| 16597 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16598 | if (!msg) |
| 16599 | return; |
| 16600 | |
| 16601 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 16602 | goto nla_put_failure; |
| 16603 | |
| 16604 | cfg80211_send_cqm(msg, gfp); |
| 16605 | return; |
| 16606 | |
| 16607 | nla_put_failure: |
| 16608 | nlmsg_free(msg); |
| 16609 | } |
| 16610 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 16611 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16612 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 16613 | { |
| 16614 | struct sk_buff *msg; |
| 16615 | |
| 16616 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16617 | if (!msg) |
| 16618 | return; |
| 16619 | |
| 16620 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 16621 | goto nla_put_failure; |
| 16622 | |
| 16623 | cfg80211_send_cqm(msg, gfp); |
| 16624 | return; |
| 16625 | |
| 16626 | nla_put_failure: |
| 16627 | nlmsg_free(msg); |
| 16628 | } |
| 16629 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 16630 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16631 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 16632 | struct net_device *netdev, const u8 *bssid, |
| 16633 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16634 | { |
| 16635 | struct sk_buff *msg; |
| 16636 | struct nlattr *rekey_attr; |
| 16637 | void *hdr; |
| 16638 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16639 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16640 | if (!msg) |
| 16641 | return; |
| 16642 | |
| 16643 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 16644 | if (!hdr) { |
| 16645 | nlmsg_free(msg); |
| 16646 | return; |
| 16647 | } |
| 16648 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16649 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16650 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16651 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16652 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16653 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16654 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16655 | if (!rekey_attr) |
| 16656 | goto nla_put_failure; |
| 16657 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16658 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 16659 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 16660 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16661 | |
| 16662 | nla_nest_end(msg, rekey_attr); |
| 16663 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16664 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16665 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16666 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16667 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16668 | return; |
| 16669 | |
| 16670 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16671 | nlmsg_free(msg); |
| 16672 | } |
| 16673 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16674 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 16675 | const u8 *replay_ctr, gfp_t gfp) |
| 16676 | { |
| 16677 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16678 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16679 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16680 | |
| 16681 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 16682 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 16683 | } |
| 16684 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 16685 | |
| 16686 | static void |
| 16687 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 16688 | struct net_device *netdev, int index, |
| 16689 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16690 | { |
| 16691 | struct sk_buff *msg; |
| 16692 | struct nlattr *attr; |
| 16693 | void *hdr; |
| 16694 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16695 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16696 | if (!msg) |
| 16697 | return; |
| 16698 | |
| 16699 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 16700 | if (!hdr) { |
| 16701 | nlmsg_free(msg); |
| 16702 | return; |
| 16703 | } |
| 16704 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 16707 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16708 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16709 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16710 | if (!attr) |
| 16711 | goto nla_put_failure; |
| 16712 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16713 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 16714 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 16715 | (preauth && |
| 16716 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 16717 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16718 | |
| 16719 | nla_nest_end(msg, attr); |
| 16720 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16721 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16722 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16723 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16724 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16725 | return; |
| 16726 | |
| 16727 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 16728 | nlmsg_free(msg); |
| 16729 | } |
| 16730 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16731 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 16732 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 16733 | { |
| 16734 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16735 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16736 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16737 | |
| 16738 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 16739 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 16740 | } |
| 16741 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 16742 | |
| 16743 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 16744 | struct net_device *netdev, |
| 16745 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16746 | gfp_t gfp, |
| 16747 | enum nl80211_commands notif, |
| 16748 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16749 | { |
| 16750 | struct sk_buff *msg; |
| 16751 | void *hdr; |
| 16752 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16753 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16754 | if (!msg) |
| 16755 | return; |
| 16756 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16757 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16758 | if (!hdr) { |
| 16759 | nlmsg_free(msg); |
| 16760 | return; |
| 16761 | } |
| 16762 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 16763 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 16764 | goto nla_put_failure; |
| 16765 | |
| 16766 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 16767 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16768 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16769 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 16770 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 16771 | goto nla_put_failure; |
| 16772 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16773 | genlmsg_end(msg, hdr); |
| 16774 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16775 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16776 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16777 | return; |
| 16778 | |
| 16779 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 16780 | nlmsg_free(msg); |
| 16781 | } |
| 16782 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16783 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 16784 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 16785 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16786 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16787 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16788 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16789 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 16790 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16791 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 16792 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16793 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 16794 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 16795 | wdev->preset_chandef = *chandef; |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 16796 | |
| 16797 | if (wdev->iftype == NL80211_IFTYPE_STATION && |
| 16798 | !WARN_ON(!wdev->current_bss)) |
Sergey Matyukevich | 0afd425 | 2019-07-26 16:39:34 +0000 | [diff] [blame] | 16799 | cfg80211_update_assoc_bss_entry(wdev, chandef->chan); |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 16800 | |
Michael Vassernis | d34990b | 2019-07-29 06:01:16 +0000 | [diff] [blame] | 16801 | cfg80211_sched_dfs_chan_update(rdev); |
| 16802 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16803 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 16804 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16805 | } |
| 16806 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 16807 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 16808 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 16809 | struct cfg80211_chan_def *chandef, |
| 16810 | u8 count) |
| 16811 | { |
| 16812 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16813 | struct wiphy *wiphy = wdev->wiphy; |
| 16814 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16815 | |
| 16816 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 16817 | |
| 16818 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 16819 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 16820 | } |
| 16821 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 16822 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 16823 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16824 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 16825 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16826 | enum nl80211_radar_event event, |
| 16827 | struct net_device *netdev, gfp_t gfp) |
| 16828 | { |
| 16829 | struct sk_buff *msg; |
| 16830 | void *hdr; |
| 16831 | |
| 16832 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16833 | if (!msg) |
| 16834 | return; |
| 16835 | |
| 16836 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 16837 | if (!hdr) { |
| 16838 | nlmsg_free(msg); |
| 16839 | return; |
| 16840 | } |
| 16841 | |
| 16842 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 16843 | goto nla_put_failure; |
| 16844 | |
| 16845 | /* NOP and radar events don't need a netdev parameter */ |
| 16846 | if (netdev) { |
| 16847 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 16848 | |
| 16849 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16850 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16851 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16852 | goto nla_put_failure; |
| 16853 | } |
| 16854 | |
| 16855 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 16856 | goto nla_put_failure; |
| 16857 | |
| 16858 | if (nl80211_send_chandef(msg, chandef)) |
| 16859 | goto nla_put_failure; |
| 16860 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16861 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16862 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16863 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16864 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16865 | return; |
| 16866 | |
| 16867 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 16868 | nlmsg_free(msg); |
| 16869 | } |
| 16870 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 16871 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 16872 | struct sta_opmode_info *sta_opmode, |
| 16873 | gfp_t gfp) |
| 16874 | { |
| 16875 | struct sk_buff *msg; |
| 16876 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16877 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16878 | void *hdr; |
| 16879 | |
| 16880 | if (WARN_ON(!mac)) |
| 16881 | return; |
| 16882 | |
| 16883 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16884 | if (!msg) |
| 16885 | return; |
| 16886 | |
| 16887 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 16888 | if (!hdr) { |
| 16889 | nlmsg_free(msg); |
| 16890 | return; |
| 16891 | } |
| 16892 | |
| 16893 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 16894 | goto nla_put_failure; |
| 16895 | |
| 16896 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 16897 | goto nla_put_failure; |
| 16898 | |
| 16899 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 16900 | goto nla_put_failure; |
| 16901 | |
| 16902 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 16903 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 16904 | goto nla_put_failure; |
| 16905 | |
| 16906 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
Johannes Berg | 0016d32 | 2020-03-25 09:05:32 +0100 | [diff] [blame] | 16907 | nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 16908 | goto nla_put_failure; |
| 16909 | |
| 16910 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 16911 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 16912 | goto nla_put_failure; |
| 16913 | |
| 16914 | genlmsg_end(msg, hdr); |
| 16915 | |
| 16916 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16917 | NL80211_MCGRP_MLME, gfp); |
| 16918 | |
| 16919 | return; |
| 16920 | |
| 16921 | nla_put_failure: |
| 16922 | nlmsg_free(msg); |
| 16923 | } |
| 16924 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 16925 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16926 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 16927 | u64 cookie, bool acked, s32 ack_signal, |
| 16928 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16929 | { |
| 16930 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16931 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16932 | struct sk_buff *msg; |
| 16933 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16934 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 16935 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 16936 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16937 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 16938 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16939 | if (!msg) |
| 16940 | return; |
| 16941 | |
| 16942 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 16943 | if (!hdr) { |
| 16944 | nlmsg_free(msg); |
| 16945 | return; |
| 16946 | } |
| 16947 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16948 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16949 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16950 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16951 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16952 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 16953 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 16954 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 16955 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16956 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16957 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16958 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16959 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16960 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16961 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16962 | return; |
| 16963 | |
| 16964 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 16965 | nlmsg_free(msg); |
| 16966 | } |
| 16967 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 16968 | |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 16969 | void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, |
| 16970 | size_t len, int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16971 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16972 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16973 | struct sk_buff *msg; |
| 16974 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16975 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16976 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 16977 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 16978 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16979 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 16980 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 16981 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 16982 | if (!msg) { |
| 16983 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 16984 | return; |
| 16985 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16986 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16987 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 16988 | if (!hdr) |
| 16989 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 16990 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16991 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16992 | (freq && |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 16993 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 16994 | KHZ_TO_MHZ(freq)) || |
| 16995 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 16996 | freq % 1000))) || |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 16997 | (sig_dbm && |
| 16998 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 16999 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 17000 | goto nla_put_failure; |
| 17001 | |
| 17002 | genlmsg_end(msg, hdr); |
| 17003 | |
| 17004 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17005 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17006 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17007 | return; |
| 17008 | |
| 17009 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17010 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17011 | nlmsg_free(msg); |
| 17012 | } |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17013 | EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17014 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17015 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17016 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 17017 | struct cfg80211_wowlan_wakeup *wakeup) |
| 17018 | { |
| 17019 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 17020 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 17021 | int i, j; |
| 17022 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17023 | nl_results = nla_nest_start_noflag(msg, |
| 17024 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17025 | if (!nl_results) |
| 17026 | return -EMSGSIZE; |
| 17027 | |
| 17028 | for (i = 0; i < nd->n_matches; i++) { |
| 17029 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 17030 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17031 | nl_match = nla_nest_start_noflag(msg, i); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17032 | if (!nl_match) |
| 17033 | break; |
| 17034 | |
| 17035 | /* The SSID attribute is optional in nl80211, but for |
| 17036 | * simplicity reasons it's always present in the |
| 17037 | * cfg80211 structure. If a driver can't pass the |
| 17038 | * SSID, that needs to be changed. A zero length SSID |
| 17039 | * is still a valid SSID (wildcard), so it cannot be |
| 17040 | * used for this purpose. |
| 17041 | */ |
| 17042 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 17043 | match->ssid.ssid)) { |
| 17044 | nla_nest_cancel(msg, nl_match); |
| 17045 | goto out; |
| 17046 | } |
| 17047 | |
| 17048 | if (match->n_channels) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17049 | nl_freqs = nla_nest_start_noflag(msg, |
| 17050 | NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17051 | if (!nl_freqs) { |
| 17052 | nla_nest_cancel(msg, nl_match); |
| 17053 | goto out; |
| 17054 | } |
| 17055 | |
| 17056 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 17057 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17058 | nla_nest_cancel(msg, nl_freqs); |
| 17059 | nla_nest_cancel(msg, nl_match); |
| 17060 | goto out; |
| 17061 | } |
| 17062 | } |
| 17063 | |
| 17064 | nla_nest_end(msg, nl_freqs); |
| 17065 | } |
| 17066 | |
| 17067 | nla_nest_end(msg, nl_match); |
| 17068 | } |
| 17069 | |
| 17070 | out: |
| 17071 | nla_nest_end(msg, nl_results); |
| 17072 | return 0; |
| 17073 | } |
| 17074 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17075 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 17076 | struct cfg80211_wowlan_wakeup *wakeup, |
| 17077 | gfp_t gfp) |
| 17078 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17079 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17080 | struct sk_buff *msg; |
| 17081 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17082 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17083 | |
| 17084 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 17085 | |
| 17086 | if (wakeup) |
| 17087 | size += wakeup->packet_present_len; |
| 17088 | |
| 17089 | msg = nlmsg_new(size, gfp); |
| 17090 | if (!msg) |
| 17091 | return; |
| 17092 | |
| 17093 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 17094 | if (!hdr) |
| 17095 | goto free_msg; |
| 17096 | |
| 17097 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17098 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17099 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17100 | goto free_msg; |
| 17101 | |
| 17102 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17103 | wdev->netdev->ifindex)) |
| 17104 | goto free_msg; |
| 17105 | |
| 17106 | if (wakeup) { |
| 17107 | struct nlattr *reasons; |
| 17108 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17109 | reasons = nla_nest_start_noflag(msg, |
| 17110 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 17111 | if (!reasons) |
| 17112 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17113 | |
| 17114 | if (wakeup->disconnect && |
| 17115 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 17116 | goto free_msg; |
| 17117 | if (wakeup->magic_pkt && |
| 17118 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 17119 | goto free_msg; |
| 17120 | if (wakeup->gtk_rekey_failure && |
| 17121 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 17122 | goto free_msg; |
| 17123 | if (wakeup->eap_identity_req && |
| 17124 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 17125 | goto free_msg; |
| 17126 | if (wakeup->four_way_handshake && |
| 17127 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 17128 | goto free_msg; |
| 17129 | if (wakeup->rfkill_release && |
| 17130 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 17131 | goto free_msg; |
| 17132 | |
| 17133 | if (wakeup->pattern_idx >= 0 && |
| 17134 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 17135 | wakeup->pattern_idx)) |
| 17136 | goto free_msg; |
| 17137 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17138 | if (wakeup->tcp_match && |
| 17139 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 17140 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17141 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17142 | if (wakeup->tcp_connlost && |
| 17143 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 17144 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17145 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17146 | if (wakeup->tcp_nomoretokens && |
| 17147 | nla_put_flag(msg, |
| 17148 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 17149 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17150 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17151 | if (wakeup->packet) { |
| 17152 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 17153 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 17154 | |
| 17155 | if (!wakeup->packet_80211) { |
| 17156 | pkt_attr = |
| 17157 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 17158 | len_attr = |
| 17159 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 17160 | } |
| 17161 | |
| 17162 | if (wakeup->packet_len && |
| 17163 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 17164 | goto free_msg; |
| 17165 | |
| 17166 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 17167 | wakeup->packet)) |
| 17168 | goto free_msg; |
| 17169 | } |
| 17170 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17171 | if (wakeup->net_detect && |
| 17172 | cfg80211_net_detect_results(msg, wakeup)) |
| 17173 | goto free_msg; |
| 17174 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17175 | nla_nest_end(msg, reasons); |
| 17176 | } |
| 17177 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17178 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17179 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17180 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17181 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17182 | return; |
| 17183 | |
| 17184 | free_msg: |
| 17185 | nlmsg_free(msg); |
| 17186 | } |
| 17187 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 17188 | #endif |
| 17189 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17190 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 17191 | enum nl80211_tdls_operation oper, |
| 17192 | u16 reason_code, gfp_t gfp) |
| 17193 | { |
| 17194 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17195 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17196 | struct sk_buff *msg; |
| 17197 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17198 | |
| 17199 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 17200 | reason_code); |
| 17201 | |
| 17202 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17203 | if (!msg) |
| 17204 | return; |
| 17205 | |
| 17206 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 17207 | if (!hdr) { |
| 17208 | nlmsg_free(msg); |
| 17209 | return; |
| 17210 | } |
| 17211 | |
| 17212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17213 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17214 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 17215 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 17216 | (reason_code > 0 && |
| 17217 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 17218 | goto nla_put_failure; |
| 17219 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17220 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17221 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17222 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17223 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17224 | return; |
| 17225 | |
| 17226 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17227 | nlmsg_free(msg); |
| 17228 | } |
| 17229 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 17230 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17231 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 17232 | unsigned long state, |
| 17233 | void *_notify) |
| 17234 | { |
| 17235 | struct netlink_notify *notify = _notify; |
| 17236 | struct cfg80211_registered_device *rdev; |
| 17237 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17238 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17239 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 17240 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17241 | return NOTIFY_DONE; |
| 17242 | |
| 17243 | rcu_read_lock(); |
| 17244 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17245 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17246 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 17247 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17248 | list_for_each_entry_rcu(sched_scan_req, |
| 17249 | &rdev->sched_scan_req_list, |
| 17250 | list) { |
| 17251 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 17252 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17253 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17254 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17255 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17256 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 17257 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17258 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17259 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17260 | if (wdev->owner_nlportid == notify->portid) { |
| 17261 | wdev->nl_owner_dead = true; |
| 17262 | schedule_work(&rdev->destroy_work); |
| 17263 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 17264 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17265 | } |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 17266 | |
| 17267 | cfg80211_release_pmsr(wdev, notify->portid); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17268 | } |
| 17269 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17270 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17271 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 17272 | list) { |
| 17273 | if (reg->nlportid == notify->portid) { |
| 17274 | list_del(®->list); |
| 17275 | kfree(reg); |
| 17276 | break; |
| 17277 | } |
| 17278 | } |
| 17279 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17280 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17281 | |
| 17282 | rcu_read_unlock(); |
| 17283 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 17284 | /* |
| 17285 | * It is possible that the user space process that is controlling the |
| 17286 | * indoor setting disappeared, so notify the regulatory core. |
| 17287 | */ |
| 17288 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 17289 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17290 | } |
| 17291 | |
| 17292 | static struct notifier_block nl80211_netlink_notifier = { |
| 17293 | .notifier_call = nl80211_netlink_notify, |
| 17294 | }; |
| 17295 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17296 | void cfg80211_ft_event(struct net_device *netdev, |
| 17297 | struct cfg80211_ft_event_params *ft_event) |
| 17298 | { |
| 17299 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17300 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17301 | struct sk_buff *msg; |
| 17302 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17303 | |
| 17304 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 17305 | |
| 17306 | if (!ft_event->target_ap) |
| 17307 | return; |
| 17308 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 17309 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 17310 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17311 | if (!msg) |
| 17312 | return; |
| 17313 | |
| 17314 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17315 | if (!hdr) |
| 17316 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17317 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17318 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17319 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17320 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 17321 | goto out; |
| 17322 | |
| 17323 | if (ft_event->ies && |
| 17324 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 17325 | goto out; |
| 17326 | if (ft_event->ric_ies && |
| 17327 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 17328 | ft_event->ric_ies)) |
| 17329 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17330 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17331 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17332 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17333 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17334 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17335 | return; |
| 17336 | out: |
| 17337 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17338 | } |
| 17339 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 17340 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17341 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 17342 | { |
| 17343 | struct cfg80211_registered_device *rdev; |
| 17344 | struct sk_buff *msg; |
| 17345 | void *hdr; |
| 17346 | u32 nlportid; |
| 17347 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17348 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17349 | if (!rdev->crit_proto_nlportid) |
| 17350 | return; |
| 17351 | |
| 17352 | nlportid = rdev->crit_proto_nlportid; |
| 17353 | rdev->crit_proto_nlportid = 0; |
| 17354 | |
| 17355 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17356 | if (!msg) |
| 17357 | return; |
| 17358 | |
| 17359 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 17360 | if (!hdr) |
| 17361 | goto nla_put_failure; |
| 17362 | |
| 17363 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17364 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17365 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17366 | goto nla_put_failure; |
| 17367 | |
| 17368 | genlmsg_end(msg, hdr); |
| 17369 | |
| 17370 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 17371 | return; |
| 17372 | |
| 17373 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17374 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17375 | } |
| 17376 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 17377 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17378 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 17379 | { |
| 17380 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17381 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17382 | struct sk_buff *msg; |
| 17383 | void *hdr; |
| 17384 | |
| 17385 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 17386 | if (!msg) |
| 17387 | return; |
| 17388 | |
| 17389 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 17390 | if (!hdr) |
| 17391 | goto out; |
| 17392 | |
| 17393 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17394 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17395 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17396 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17397 | goto out; |
| 17398 | |
| 17399 | genlmsg_end(msg, hdr); |
| 17400 | |
| 17401 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 17402 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 17403 | return; |
| 17404 | out: |
| 17405 | nlmsg_free(msg); |
| 17406 | } |
| 17407 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 17408 | int cfg80211_external_auth_request(struct net_device *dev, |
| 17409 | struct cfg80211_external_auth_params *params, |
| 17410 | gfp_t gfp) |
| 17411 | { |
| 17412 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17413 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17414 | struct sk_buff *msg; |
| 17415 | void *hdr; |
| 17416 | |
| 17417 | if (!wdev->conn_owner_nlportid) |
| 17418 | return -EINVAL; |
| 17419 | |
| 17420 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17421 | if (!msg) |
| 17422 | return -ENOMEM; |
| 17423 | |
| 17424 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 17425 | if (!hdr) |
| 17426 | goto nla_put_failure; |
| 17427 | |
| 17428 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17429 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17430 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 17431 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 17432 | params->action) || |
| 17433 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 17434 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 17435 | params->ssid.ssid)) |
| 17436 | goto nla_put_failure; |
| 17437 | |
| 17438 | genlmsg_end(msg, hdr); |
| 17439 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 17440 | wdev->conn_owner_nlportid); |
| 17441 | return 0; |
| 17442 | |
| 17443 | nla_put_failure: |
| 17444 | nlmsg_free(msg); |
| 17445 | return -ENOBUFS; |
| 17446 | } |
| 17447 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 17448 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 17449 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
| 17450 | struct cfg80211_update_owe_info *owe_info, |
| 17451 | gfp_t gfp) |
| 17452 | { |
| 17453 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 17454 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17455 | struct sk_buff *msg; |
| 17456 | void *hdr; |
| 17457 | |
| 17458 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); |
| 17459 | |
| 17460 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17461 | if (!msg) |
| 17462 | return; |
| 17463 | |
| 17464 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); |
| 17465 | if (!hdr) |
| 17466 | goto nla_put_failure; |
| 17467 | |
| 17468 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17469 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17470 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) |
| 17471 | goto nla_put_failure; |
| 17472 | |
| 17473 | if (!owe_info->ie_len || |
| 17474 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) |
| 17475 | goto nla_put_failure; |
| 17476 | |
| 17477 | genlmsg_end(msg, hdr); |
| 17478 | |
| 17479 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17480 | NL80211_MCGRP_MLME, gfp); |
| 17481 | return; |
| 17482 | |
| 17483 | nla_put_failure: |
| 17484 | genlmsg_cancel(msg, hdr); |
| 17485 | nlmsg_free(msg); |
| 17486 | } |
| 17487 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); |
| 17488 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17489 | /* initialisation/exit functions */ |
| 17490 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 17491 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17492 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 17493 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17494 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 17495 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17496 | if (err) |
| 17497 | return err; |
| 17498 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17499 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 17500 | if (err) |
| 17501 | goto err_out; |
| 17502 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17503 | return 0; |
| 17504 | err_out: |
| 17505 | genl_unregister_family(&nl80211_fam); |
| 17506 | return err; |
| 17507 | } |
| 17508 | |
| 17509 | void nl80211_exit(void) |
| 17510 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17511 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17512 | genl_unregister_family(&nl80211_fam); |
| 17513 | } |