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 |
Johannes Berg | abaf94e | 2021-04-08 14:28:34 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2021 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 * |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 67 | __cfg80211_wdev_from_attrs(struct cfg80211_registered_device *rdev, |
| 68 | struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 69 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 70 | struct wireless_dev *result = NULL; |
| 71 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 72 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
Jarod Wilson | 239729a | 2021-03-12 11:36:51 -0500 | [diff] [blame] | 73 | u64 wdev_id = 0; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 74 | int wiphy_idx = -1; |
| 75 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 77 | if (!have_ifidx && !have_wdev_id) |
| 78 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 79 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 80 | if (have_ifidx) |
| 81 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 82 | if (have_wdev_id) { |
| 83 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 84 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 87 | if (rdev) { |
| 88 | struct wireless_dev *wdev; |
| 89 | |
| 90 | lockdep_assert_held(&rdev->wiphy.mtx); |
| 91 | |
| 92 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
| 93 | if (have_ifidx && wdev->netdev && |
| 94 | wdev->netdev->ifindex == ifidx) { |
| 95 | result = wdev; |
| 96 | break; |
| 97 | } |
| 98 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 99 | result = wdev; |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return result ?: ERR_PTR(-ENODEV); |
| 105 | } |
| 106 | |
| 107 | ASSERT_RTNL(); |
| 108 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 109 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 110 | struct wireless_dev *wdev; |
| 111 | |
| 112 | if (wiphy_net(&rdev->wiphy) != netns) |
| 113 | continue; |
| 114 | |
| 115 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 116 | continue; |
| 117 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 118 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 119 | if (have_ifidx && wdev->netdev && |
| 120 | wdev->netdev->ifindex == ifidx) { |
| 121 | result = wdev; |
| 122 | break; |
| 123 | } |
| 124 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 125 | result = wdev; |
| 126 | break; |
| 127 | } |
| 128 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 129 | |
| 130 | if (result) |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | if (result) |
| 135 | return result; |
| 136 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 139 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 140 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 141 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 142 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 143 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 144 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 145 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 146 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 147 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 148 | !attrs[NL80211_ATTR_IFINDEX] && |
| 149 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 150 | return ERR_PTR(-EINVAL); |
| 151 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 152 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 153 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 154 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 155 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 156 | if (attrs[NL80211_ATTR_WDEV]) { |
| 157 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 158 | struct wireless_dev *wdev; |
| 159 | bool found = false; |
| 160 | |
| 161 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 162 | if (tmp) { |
| 163 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 164 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 165 | if (wdev->identifier != (u32)wdev_id) |
| 166 | continue; |
| 167 | found = true; |
| 168 | break; |
| 169 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 170 | |
| 171 | if (!found) |
| 172 | tmp = NULL; |
| 173 | |
| 174 | if (rdev && tmp != rdev) |
| 175 | return ERR_PTR(-EINVAL); |
| 176 | rdev = tmp; |
| 177 | } |
| 178 | } |
| 179 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 180 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 181 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 182 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 183 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 184 | if (netdev) { |
| 185 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 186 | tmp = wiphy_to_rdev( |
| 187 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 188 | else |
| 189 | tmp = NULL; |
| 190 | |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 191 | /* not wireless device -- return error */ |
| 192 | if (!tmp) |
| 193 | return ERR_PTR(-EINVAL); |
| 194 | |
| 195 | /* mismatch -- return error */ |
| 196 | if (rdev && tmp != rdev) |
| 197 | return ERR_PTR(-EINVAL); |
| 198 | |
| 199 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 200 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 203 | if (!rdev) |
| 204 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 205 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 206 | if (netns != wiphy_net(&rdev->wiphy)) |
| 207 | return ERR_PTR(-ENODEV); |
| 208 | |
| 209 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* |
| 213 | * This function returns a pointer to the driver |
| 214 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 215 | * |
| 216 | * The result of this can be a PTR_ERR and hence must |
| 217 | * be checked with IS_ERR() for errors. |
| 218 | */ |
| 219 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 220 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 221 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 222 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 225 | static int validate_beacon_head(const struct nlattr *attr, |
| 226 | struct netlink_ext_ack *extack) |
| 227 | { |
| 228 | const u8 *data = nla_data(attr); |
| 229 | unsigned int len = nla_len(attr); |
| 230 | const struct element *elem; |
| 231 | const struct ieee80211_mgmt *mgmt = (void *)data; |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 232 | unsigned int fixedlen, hdrlen; |
Johannes Berg | 9a6847b | 2021-04-08 15:45:20 +0200 | [diff] [blame] | 233 | bool s1g_bcn; |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 234 | |
Johannes Berg | 9a6847b | 2021-04-08 15:45:20 +0200 | [diff] [blame] | 235 | if (len < offsetofend(typeof(*mgmt), frame_control)) |
| 236 | goto err; |
| 237 | |
| 238 | s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 239 | if (s1g_bcn) { |
| 240 | fixedlen = offsetof(struct ieee80211_ext, |
| 241 | u.s1g_beacon.variable); |
| 242 | hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); |
| 243 | } else { |
| 244 | fixedlen = offsetof(struct ieee80211_mgmt, |
| 245 | u.beacon.variable); |
| 246 | hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); |
| 247 | } |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 248 | |
| 249 | if (len < fixedlen) |
| 250 | goto err; |
| 251 | |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 252 | if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 253 | goto err; |
| 254 | |
| 255 | data += fixedlen; |
| 256 | len -= fixedlen; |
| 257 | |
| 258 | for_each_element(elem, data, len) { |
| 259 | /* nothing */ |
| 260 | } |
| 261 | |
| 262 | if (for_each_element_completed(elem, data, len)) |
| 263 | return 0; |
| 264 | |
| 265 | err: |
| 266 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); |
| 267 | return -EINVAL; |
| 268 | } |
| 269 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 270 | static int validate_ie_attr(const struct nlattr *attr, |
| 271 | struct netlink_ext_ack *extack) |
| 272 | { |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 273 | const u8 *data = nla_data(attr); |
| 274 | unsigned int len = nla_len(attr); |
Jouni Malinen | 7388afe | 2019-02-11 16:29:04 +0200 | [diff] [blame] | 275 | const struct element *elem; |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 276 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 277 | for_each_element(elem, data, len) { |
| 278 | /* nothing */ |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 279 | } |
| 280 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 281 | if (for_each_element_completed(elem, data, len)) |
| 282 | return 0; |
| 283 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 284 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 285 | return -EINVAL; |
| 286 | } |
| 287 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 288 | /* policy for the attributes */ |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 289 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; |
| 290 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 291 | static const struct nla_policy |
| 292 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 293 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 294 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 295 | .len = U8_MAX }, |
| 296 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 297 | .len = U8_MAX }, |
| 298 | }; |
| 299 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 300 | static const struct nla_policy |
| 301 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 302 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 303 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 304 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 305 | NLA_POLICY_MAX(NLA_U8, 15), |
| 306 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 307 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 308 | NLA_POLICY_MAX(NLA_U8, 15), |
| 309 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
Aviya Erenfeld | ea18709 | 2019-02-06 13:17:08 +0200 | [diff] [blame] | 310 | NLA_POLICY_MAX(NLA_U8, 31), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 311 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 312 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 313 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 314 | [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, |
| 315 | [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, |
Avraham Stern | 7380752 | 2021-04-09 12:40:25 +0300 | [diff] [blame] | 316 | [NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK] = { .type = NLA_FLAG }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | static const struct nla_policy |
| 320 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 321 | [NL80211_PMSR_TYPE_FTM] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 322 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | static const struct nla_policy |
| 326 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 327 | [NL80211_PMSR_REQ_ATTR_DATA] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 328 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 329 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 330 | }; |
| 331 | |
| 332 | static const struct nla_policy |
Sosthène Guédon | aeddc05 | 2021-06-03 19:39:39 +0200 | [diff] [blame] | 333 | nl80211_pmsr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 334 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 335 | [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 336 | [NL80211_PMSR_PEER_ATTR_REQ] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 337 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 338 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 339 | }; |
| 340 | |
| 341 | static const struct nla_policy |
| 342 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 343 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 344 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 345 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 346 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 347 | [NL80211_PMSR_ATTR_PEERS] = |
Sosthène Guédon | aeddc05 | 2021-06-03 19:39:39 +0200 | [diff] [blame] | 348 | NLA_POLICY_NESTED_ARRAY(nl80211_pmsr_peer_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 349 | }; |
| 350 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 351 | static const struct nla_policy |
| 352 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { |
| 353 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = |
| 354 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 355 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = |
| 356 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 357 | [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = |
| 358 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 359 | [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = |
| 360 | NLA_POLICY_EXACT_LEN(8), |
| 361 | [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = |
| 362 | NLA_POLICY_EXACT_LEN(8), |
| 363 | [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 364 | }; |
| 365 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 366 | static const struct nla_policy |
| 367 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { |
| 368 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), |
| 369 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 370 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, |
| 371 | }; |
| 372 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 373 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 374 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 375 | .len = NL80211_MAX_SUPP_RATES }, |
| 376 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 377 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 378 | [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), |
| 379 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 380 | [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), |
| 381 | [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, |
| 382 | NL80211_RATE_INFO_HE_GI_0_8, |
| 383 | NL80211_RATE_INFO_HE_GI_3_2), |
| 384 | [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, |
| 385 | NL80211_RATE_INFO_HE_1XLTF, |
| 386 | NL80211_RATE_INFO_HE_4XLTF), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 387 | }; |
| 388 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 389 | static const struct nla_policy |
| 390 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 391 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
| 392 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 393 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 394 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 395 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
| 396 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 397 | [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 398 | [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 399 | [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = |
| 400 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 401 | [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = |
| 402 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 403 | [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = |
| 404 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 405 | [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = |
| 406 | NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), |
| 407 | [NL80211_TID_CONFIG_ATTR_TX_RATE] = |
| 408 | NLA_POLICY_NESTED(nl80211_txattr_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 409 | }; |
| 410 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 411 | static const struct nla_policy |
| 412 | nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { |
| 413 | [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 414 | [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), |
Aloka Dixit | 272cd0e | 2021-02-22 13:20:59 -0800 | [diff] [blame] | 415 | [NL80211_FILS_DISCOVERY_ATTR_TMPL] = |
| 416 | NLA_POLICY_RANGE(NLA_BINARY, |
| 417 | NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, |
| 418 | IEEE80211_MAX_DATA_LEN), |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 419 | }; |
| 420 | |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 421 | static const struct nla_policy |
| 422 | nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { |
| 423 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), |
| 424 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, |
| 425 | .len = IEEE80211_MAX_DATA_LEN } |
| 426 | }; |
| 427 | |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 428 | static const struct nla_policy |
| 429 | sar_specs_policy[NL80211_SAR_ATTR_SPECS_MAX + 1] = { |
| 430 | [NL80211_SAR_ATTR_SPECS_POWER] = { .type = NLA_S32 }, |
| 431 | [NL80211_SAR_ATTR_SPECS_RANGE_INDEX] = {.type = NLA_U32 }, |
| 432 | }; |
| 433 | |
| 434 | static const struct nla_policy |
| 435 | sar_policy[NL80211_SAR_ATTR_MAX + 1] = { |
| 436 | [NL80211_SAR_ATTR_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_SAR_TYPE), |
| 437 | [NL80211_SAR_ATTR_SPECS] = NLA_POLICY_NESTED_ARRAY(sar_specs_policy), |
| 438 | }; |
| 439 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 440 | static const struct nla_policy |
| 441 | nl80211_mbssid_config_policy[NL80211_MBSSID_CONFIG_ATTR_MAX + 1] = { |
| 442 | [NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES] = NLA_POLICY_MIN(NLA_U8, 2), |
| 443 | [NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY] = |
| 444 | NLA_POLICY_MIN(NLA_U8, 1), |
| 445 | [NL80211_MBSSID_CONFIG_ATTR_INDEX] = { .type = NLA_U8 }, |
| 446 | [NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX] = { .type = NLA_U32 }, |
| 447 | [NL80211_MBSSID_CONFIG_ATTR_EMA] = { .type = NLA_FLAG }, |
| 448 | }; |
| 449 | |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 450 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 6d4dd4e | 2019-07-31 10:58:20 +0200 | [diff] [blame] | 451 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 452 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 453 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 454 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 455 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 456 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 457 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 458 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 459 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
| 460 | NL80211_EDMG_CHANNELS_MIN, |
| 461 | NL80211_EDMG_CHANNELS_MAX), |
| 462 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, |
| 463 | NL80211_EDMG_BW_CONFIG_MIN, |
| 464 | NL80211_EDMG_BW_CONFIG_MAX), |
| 465 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 466 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 467 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 468 | [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 469 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 470 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 471 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 472 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 473 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 474 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 475 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 476 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 477 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 478 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 479 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 480 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 481 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 482 | [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| 483 | [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 484 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 485 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 486 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 487 | .len = WLAN_MAX_KEY_LEN }, |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 488 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 489 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 490 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 491 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 492 | [NL80211_ATTR_KEY_TYPE] = |
| 493 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 494 | |
| 495 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 496 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 497 | [NL80211_ATTR_BEACON_HEAD] = |
| 498 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, |
| 499 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 500 | [NL80211_ATTR_BEACON_TAIL] = |
| 501 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 502 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 503 | [NL80211_ATTR_STA_AID] = |
| 504 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 505 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 506 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 507 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 508 | .len = NL80211_MAX_SUPP_RATES }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 509 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 510 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 511 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
| 512 | NLA_POLICY_RANGE(NLA_U8, |
| 513 | NL80211_TX_POWER_AUTOMATIC, |
| 514 | NL80211_TX_POWER_FIXED), |
| 515 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 516 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 517 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 518 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 519 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Markus Theil | 1fab1b8 | 2019-10-29 10:30:03 +0100 | [diff] [blame] | 520 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 521 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 522 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 523 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 524 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 525 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 526 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 527 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 528 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 529 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 530 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 531 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 532 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 533 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 534 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 535 | [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] | 536 | |
| 537 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 538 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 539 | validate_ie_attr, |
| 540 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 541 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 542 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 543 | |
| 544 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 545 | .len = IEEE80211_MAX_SSID_LEN }, |
| 546 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 547 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 548 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 549 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 550 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 551 | NL80211_MFP_NO, |
| 552 | NL80211_MFP_OPTIONAL), |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 553 | [NL80211_ATTR_STA_FLAGS2] = { |
| 554 | .len = sizeof(struct nl80211_sta_flag_update), |
| 555 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 556 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 557 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 558 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 559 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 560 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
Sergey Matyukevich | ea75080 | 2020-02-13 13:16:16 +0000 | [diff] [blame] | 561 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 562 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 563 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 564 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 565 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 566 | [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 567 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 568 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 569 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 570 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 571 | .len = IEEE80211_MAX_DATA_LEN }, |
| 572 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 573 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 574 | NL80211_PS_DISABLED, |
| 575 | NL80211_PS_ENABLED), |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 576 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 577 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 578 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 579 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 580 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 581 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 582 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 583 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 584 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 585 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 586 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 587 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 588 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 589 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
Jakub Kicinski | 056e937 | 2020-03-02 21:10:57 -0800 | [diff] [blame] | 590 | [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, |
| 591 | [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 592 | [NL80211_ATTR_MESH_PEER_AID] = |
| 593 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 594 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 595 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 596 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 597 | [NL80211_ATTR_HIDDEN_SSID] = |
| 598 | NLA_POLICY_RANGE(NLA_U32, |
| 599 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 600 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 601 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 602 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 603 | IEEE80211_MAX_DATA_LEN), |
| 604 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 605 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 606 | IEEE80211_MAX_DATA_LEN), |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 607 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 608 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 609 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 610 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 611 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 612 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 613 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 614 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 615 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 616 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 617 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 618 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 619 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 620 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 621 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 622 | .len = NL80211_HT_CAPABILITY_LEN |
| 623 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 624 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 625 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 626 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 627 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 628 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 629 | |
| 630 | /* need to include at least Auth Transaction and Status Code */ |
| 631 | [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), |
| 632 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 633 | [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] | 634 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 635 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 636 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 637 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 638 | NLA_POLICY_RANGE(NLA_U32, |
| 639 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 640 | NL80211_MESH_POWER_MAX), |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 641 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 642 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 643 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 644 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 645 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 646 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 647 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 648 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 649 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 650 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 651 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 652 | .len = IEEE80211_MAX_DATA_LEN }, |
Jakub Kicinski | 0e1a1d8 | 2020-03-02 21:10:56 -0800 | [diff] [blame] | 653 | [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 654 | [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = |
| 655 | NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 656 | [NL80211_ATTR_PEER_AID] = |
| 657 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 658 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 659 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 660 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 661 | [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, |
| 662 | [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 663 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 664 | /* |
| 665 | * The value of the Length field of the Supported Operating |
| 666 | * Classes element is between 2 and 253. |
| 667 | */ |
| 668 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = |
| 669 | NLA_POLICY_RANGE(NLA_BINARY, 2, 253), |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 670 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 671 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 672 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 673 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 674 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 675 | [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, |
| 676 | IEEE80211_QOS_MAP_LEN_MIN, |
| 677 | IEEE80211_QOS_MAP_LEN_MAX), |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 678 | [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 679 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 680 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 681 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 682 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 683 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 684 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 685 | [NL80211_ATTR_USER_PRIO] = |
| 686 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 687 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 688 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Jakub Kicinski | 5cde05c | 2020-03-02 21:10:58 -0800 | [diff] [blame] | 689 | [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 690 | [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 691 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 692 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 693 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 694 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 695 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 696 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 697 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 698 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 699 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 700 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 701 | }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 702 | [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] | 703 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 704 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 705 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 706 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 707 | .len = FILS_MAX_KEK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 708 | [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] | 709 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 710 | [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 711 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 712 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 713 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 714 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 715 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 716 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 717 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 718 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 719 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 720 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 721 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 722 | .len = FILS_ERP_MAX_RRK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 723 | [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 724 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 725 | [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] | 726 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 727 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 728 | |
| 729 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 730 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 731 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 732 | [NL80211_ATTR_HE_CAPABILITY] = |
| 733 | NLA_POLICY_RANGE(NLA_BINARY, |
| 734 | NL80211_HE_MIN_CAPABILITY_LEN, |
| 735 | NL80211_HE_MAX_CAPABILITY_LEN), |
Johannes Berg | 0e012b4 | 2020-04-12 00:40:30 +0200 | [diff] [blame] | 736 | [NL80211_ATTR_FTM_RESPONDER] = |
| 737 | NLA_POLICY_NESTED(nl80211_ftm_responder_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 738 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 739 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 740 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 741 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 742 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
| 743 | .len = SAE_PASSWORD_MAX_LEN }, |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 744 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 745 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 746 | [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] | 747 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 748 | [NL80211_ATTR_TID_CONFIG] = |
| 749 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), |
Markus Theil | 5631d96 | 2020-03-12 10:10:53 +0100 | [diff] [blame] | 750 | [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 751 | [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), |
| 752 | [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 753 | [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 754 | [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 755 | [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, |
Johannes Berg | 8140860 | 2020-08-18 10:17:31 +0200 | [diff] [blame] | 756 | [NL80211_ATTR_HE_6GHZ_CAPABILITY] = |
| 757 | NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 758 | [NL80211_ATTR_FILS_DISCOVERY] = |
| 759 | NLA_POLICY_NESTED(nl80211_fils_discovery_policy), |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 760 | [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = |
| 761 | NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), |
Thomas Pedersen | d2b7588 | 2020-09-21 19:28:04 -0700 | [diff] [blame] | 762 | [NL80211_ATTR_S1G_CAPABILITY] = |
| 763 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), |
| 764 | [NL80211_ATTR_S1G_CAPABILITY_MASK] = |
| 765 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), |
Rohan Dutta | 9f0ffa4 | 2020-10-27 12:09:10 +0200 | [diff] [blame] | 766 | [NL80211_ATTR_SAE_PWE] = |
| 767 | NLA_POLICY_RANGE(NLA_U8, NL80211_SAE_PWE_HUNT_AND_PECK, |
| 768 | NL80211_SAE_PWE_BOTH), |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 769 | [NL80211_ATTR_RECONNECT_REQUESTED] = { .type = NLA_REJECT }, |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 770 | [NL80211_ATTR_SAR_SPEC] = NLA_POLICY_NESTED(sar_policy), |
Ben Greear | b6db0f8 | 2021-02-04 06:46:10 -0800 | [diff] [blame] | 771 | [NL80211_ATTR_DISABLE_HE] = { .type = NLA_FLAG }, |
John Crispin | 0d2ab3ae | 2021-07-02 19:44:07 +0200 | [diff] [blame] | 772 | [NL80211_ATTR_OBSS_COLOR_BITMAP] = { .type = NLA_U64 }, |
| 773 | [NL80211_ATTR_COLOR_CHANGE_COUNT] = { .type = NLA_U8 }, |
| 774 | [NL80211_ATTR_COLOR_CHANGE_COLOR] = { .type = NLA_U8 }, |
| 775 | [NL80211_ATTR_COLOR_CHANGE_ELEMS] = NLA_POLICY_NESTED(nl80211_policy), |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 776 | [NL80211_ATTR_MBSSID_CONFIG] = |
| 777 | NLA_POLICY_NESTED(nl80211_mbssid_config_policy), |
| 778 | [NL80211_ATTR_MBSSID_ELEMS] = { .type = NLA_NESTED }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 779 | }; |
| 780 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 781 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 782 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 783 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 784 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 785 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 786 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 787 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 788 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 789 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 790 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 791 | [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] | 792 | }; |
| 793 | |
| 794 | /* policy for the key default flags */ |
| 795 | static const struct nla_policy |
| 796 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 797 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 798 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 799 | }; |
| 800 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 801 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 802 | /* policy for WoWLAN attributes */ |
| 803 | static const struct nla_policy |
| 804 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 805 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 806 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 807 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 808 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 809 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 810 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 811 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 812 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 813 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 814 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 815 | }; |
| 816 | |
| 817 | static const struct nla_policy |
| 818 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 819 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 820 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 821 | [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 822 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 823 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 824 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 825 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 826 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 827 | }, |
| 828 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 829 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 830 | }, |
| 831 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 832 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
| 833 | [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 834 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 835 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 836 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 837 | /* policy for coalesce rule attributes */ |
| 838 | static const struct nla_policy |
| 839 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 840 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 841 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 842 | NLA_POLICY_RANGE(NLA_U32, |
| 843 | NL80211_COALESCE_CONDITION_MATCH, |
| 844 | NL80211_COALESCE_CONDITION_NO_MATCH), |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 845 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 846 | }; |
| 847 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 848 | /* policy for GTK rekey offload attributes */ |
| 849 | static const struct nla_policy |
| 850 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 851 | [NL80211_REKEY_DATA_KEK] = { |
| 852 | .type = NLA_BINARY, |
| 853 | .len = NL80211_KEK_EXT_LEN |
| 854 | }, |
| 855 | [NL80211_REKEY_DATA_KCK] = { |
| 856 | .type = NLA_BINARY, |
| 857 | .len = NL80211_KCK_EXT_LEN |
| 858 | }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 859 | [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] | 860 | [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 861 | }; |
| 862 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 863 | static const struct nla_policy |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 864 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { |
| 865 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, |
| 866 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, |
Arend van Spriel | e548a1c | 2019-08-02 13:31:02 +0200 | [diff] [blame] | 867 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 868 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
Srinivasan Raju | 63fa042 | 2021-10-18 11:00:54 +0100 | [diff] [blame] | 869 | [NL80211_BAND_LC] = { .type = NLA_S32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 870 | }; |
| 871 | |
| 872 | static const struct nla_policy |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 873 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 874 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 875 | .len = IEEE80211_MAX_SSID_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 876 | [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] | 877 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 878 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
| 879 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 880 | }; |
| 881 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 882 | static const struct nla_policy |
| 883 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 884 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 885 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 886 | }; |
| 887 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 888 | static const struct nla_policy |
| 889 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 890 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 891 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 892 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 893 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 894 | }, |
| 895 | }; |
| 896 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 897 | /* policy for NAN function attributes */ |
| 898 | static const struct nla_policy |
| 899 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 900 | [NL80211_NAN_FUNC_TYPE] = |
| 901 | NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 902 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 903 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 904 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 905 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 906 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 907 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 908 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 909 | [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] | 910 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 911 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 912 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 913 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 914 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 915 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 916 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 917 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 918 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 919 | }; |
| 920 | |
| 921 | /* policy for Service Response Filter attributes */ |
| 922 | static const struct nla_policy |
| 923 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 924 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 925 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 926 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 927 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 928 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 929 | }; |
| 930 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 931 | /* policy for packet pattern attributes */ |
| 932 | static const struct nla_policy |
| 933 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 934 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 935 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 936 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 937 | }; |
| 938 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 939 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 940 | struct cfg80211_registered_device **rdev, |
| 941 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 942 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 943 | int err; |
| 944 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 945 | if (!cb->args[0]) { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 946 | struct nlattr **attrbuf; |
| 947 | |
| 948 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 949 | GFP_KERNEL); |
| 950 | if (!attrbuf) |
| 951 | return -ENOMEM; |
| 952 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 953 | err = nlmsg_parse_deprecated(cb->nlh, |
| 954 | GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 955 | attrbuf, nl80211_fam.maxattr, |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 956 | nl80211_policy, NULL); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 957 | if (err) { |
| 958 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 959 | return err; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 960 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 961 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 962 | rtnl_lock(); |
| 963 | *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(cb->skb->sk), |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 964 | attrbuf); |
| 965 | kfree(attrbuf); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 966 | if (IS_ERR(*wdev)) { |
| 967 | rtnl_unlock(); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 968 | return PTR_ERR(*wdev); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 969 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 970 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 971 | mutex_lock(&(*rdev)->wiphy.mtx); |
| 972 | rtnl_unlock(); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 973 | /* 0 is the first index - add 1 to parse only once */ |
| 974 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 975 | cb->args[1] = (*wdev)->identifier; |
| 976 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 977 | /* subtract the 1 again here */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 978 | struct wiphy *wiphy; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 979 | struct wireless_dev *tmp; |
| 980 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 981 | rtnl_lock(); |
| 982 | wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 983 | if (!wiphy) { |
| 984 | rtnl_unlock(); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 985 | return -ENODEV; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 986 | } |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 987 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 988 | *wdev = NULL; |
| 989 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 990 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 991 | if (tmp->identifier == cb->args[1]) { |
| 992 | *wdev = tmp; |
| 993 | break; |
| 994 | } |
| 995 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 996 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 997 | if (!*wdev) { |
| 998 | rtnl_unlock(); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 999 | return -ENODEV; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 1000 | } |
| 1001 | mutex_lock(&(*rdev)->wiphy.mtx); |
| 1002 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 1003 | } |
| 1004 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 1005 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 1006 | } |
| 1007 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1008 | /* message building helper */ |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1009 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 1010 | int flags, u8 cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1011 | { |
| 1012 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 1013 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1014 | } |
| 1015 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1016 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 1017 | const struct ieee80211_reg_rule *rule) |
| 1018 | { |
| 1019 | int j; |
| 1020 | struct nlattr *nl_wmm_rules = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1021 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1022 | |
| 1023 | if (!nl_wmm_rules) |
| 1024 | goto nla_put_failure; |
| 1025 | |
| 1026 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1027 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1028 | |
| 1029 | if (!nl_wmm_rule) |
| 1030 | goto nla_put_failure; |
| 1031 | |
| 1032 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1033 | rule->wmm_rule.client[j].cw_min) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1034 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1035 | rule->wmm_rule.client[j].cw_max) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1036 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1037 | rule->wmm_rule.client[j].aifsn) || |
Haim Dreyfuss | d3c89bb | 2018-08-21 09:22:19 +0300 | [diff] [blame] | 1038 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 1039 | rule->wmm_rule.client[j].cot)) |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1040 | goto nla_put_failure; |
| 1041 | |
| 1042 | nla_nest_end(msg, nl_wmm_rule); |
| 1043 | } |
| 1044 | nla_nest_end(msg, nl_wmm_rules); |
| 1045 | |
| 1046 | return 0; |
| 1047 | |
| 1048 | nla_put_failure: |
| 1049 | return -ENOBUFS; |
| 1050 | } |
| 1051 | |
| 1052 | 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] | 1053 | struct ieee80211_channel *chan, |
| 1054 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1055 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1056 | /* Some channels must be completely excluded from the |
| 1057 | * list to protect old user-space tools from breaking |
| 1058 | */ |
| 1059 | if (!large && chan->flags & |
| 1060 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 1061 | return 0; |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1062 | if (!large && chan->freq_offset) |
| 1063 | return 0; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1064 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1065 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 1066 | chan->center_freq)) |
| 1067 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1068 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1069 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) |
| 1070 | goto nla_put_failure; |
| 1071 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1072 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 1073 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 1074 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 1075 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 1076 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 1077 | goto nla_put_failure; |
| 1078 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 1079 | goto nla_put_failure; |
| 1080 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1081 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1082 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 1083 | goto nla_put_failure; |
| 1084 | if (large) { |
| 1085 | u32 time; |
| 1086 | |
| 1087 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 1088 | |
| 1089 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 1090 | chan->dfs_state)) |
| 1091 | goto nla_put_failure; |
| 1092 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 1093 | time)) |
| 1094 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 1095 | if (nla_put_u32(msg, |
| 1096 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 1097 | chan->dfs_cac_ms)) |
| 1098 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1099 | } |
| 1100 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1101 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1102 | if (large) { |
| 1103 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 1104 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 1105 | goto nla_put_failure; |
| 1106 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 1107 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 1108 | goto nla_put_failure; |
| 1109 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 1110 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 1111 | goto nla_put_failure; |
| 1112 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 1113 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 1114 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1115 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 1116 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 1117 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1118 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 1119 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1120 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1121 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 1122 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 1123 | goto nla_put_failure; |
| 1124 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 1125 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 1126 | goto nla_put_failure; |
Haim Dreyfuss | 1e61d82 | 2020-01-21 10:12:13 +0200 | [diff] [blame] | 1127 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
| 1128 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) |
| 1129 | goto nla_put_failure; |
Thomas Pedersen | d65a977 | 2020-09-08 12:03:03 -0700 | [diff] [blame] | 1130 | if ((chan->flags & IEEE80211_CHAN_1MHZ) && |
| 1131 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) |
| 1132 | goto nla_put_failure; |
| 1133 | if ((chan->flags & IEEE80211_CHAN_2MHZ) && |
| 1134 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) |
| 1135 | goto nla_put_failure; |
| 1136 | if ((chan->flags & IEEE80211_CHAN_4MHZ) && |
| 1137 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) |
| 1138 | goto nla_put_failure; |
| 1139 | if ((chan->flags & IEEE80211_CHAN_8MHZ) && |
| 1140 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) |
| 1141 | goto nla_put_failure; |
| 1142 | if ((chan->flags & IEEE80211_CHAN_16MHZ) && |
| 1143 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) |
| 1144 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1145 | } |
| 1146 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1147 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 1148 | DBM_TO_MBM(chan->max_power))) |
| 1149 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1150 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1151 | if (large) { |
| 1152 | const struct ieee80211_reg_rule *rule = |
Haim Dreyfuss | b88d26d | 2018-08-21 09:22:20 +0300 | [diff] [blame] | 1153 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1154 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1155 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1156 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 1157 | goto nla_put_failure; |
| 1158 | } |
| 1159 | } |
| 1160 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1161 | return 0; |
| 1162 | |
| 1163 | nla_put_failure: |
| 1164 | return -ENOBUFS; |
| 1165 | } |
| 1166 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1167 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 1168 | struct cfg80211_txq_stats *txqstats, |
| 1169 | int attrtype) |
| 1170 | { |
| 1171 | struct nlattr *txqattr; |
| 1172 | |
| 1173 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 1174 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 1175 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 1176 | return false; \ |
| 1177 | } while (0) |
| 1178 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1179 | txqattr = nla_nest_start_noflag(msg, attrtype); |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1180 | if (!txqattr) |
| 1181 | return false; |
| 1182 | |
| 1183 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 1184 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 1185 | PUT_TXQVAL_U32(FLOWS, flows); |
| 1186 | PUT_TXQVAL_U32(DROPS, drops); |
| 1187 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 1188 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 1189 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 1190 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 1191 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 1192 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 1193 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 1194 | nla_nest_end(msg, txqattr); |
| 1195 | |
| 1196 | #undef PUT_TXQVAL_U32 |
| 1197 | return true; |
| 1198 | } |
| 1199 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1200 | /* netlink command implementations */ |
| 1201 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1202 | struct key_parse { |
| 1203 | struct key_params p; |
| 1204 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1205 | int type; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1206 | bool def, defmgmt, defbeacon; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1207 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1208 | }; |
| 1209 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1210 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 1211 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1212 | { |
| 1213 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1214 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
| 1215 | nl80211_key_policy, |
| 1216 | info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1217 | if (err) |
| 1218 | return err; |
| 1219 | |
| 1220 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 1221 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1222 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1223 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1224 | if (k->def) { |
| 1225 | k->def_uni = true; |
| 1226 | k->def_multi = true; |
| 1227 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1228 | if (k->defmgmt || k->defbeacon) |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1229 | k->def_multi = true; |
| 1230 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1231 | if (tb[NL80211_KEY_IDX]) |
| 1232 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 1233 | |
| 1234 | if (tb[NL80211_KEY_DATA]) { |
| 1235 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 1236 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 1237 | } |
| 1238 | |
| 1239 | if (tb[NL80211_KEY_SEQ]) { |
| 1240 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 1241 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 1242 | } |
| 1243 | |
| 1244 | if (tb[NL80211_KEY_CIPHER]) |
| 1245 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 1246 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1247 | if (tb[NL80211_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1248 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1249 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1250 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 1251 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1252 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1253 | err = nla_parse_nested_deprecated(kdt, |
| 1254 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1255 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 1256 | nl80211_key_default_policy, |
| 1257 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1258 | if (err) |
| 1259 | return err; |
| 1260 | |
| 1261 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1262 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1263 | } |
| 1264 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 1265 | if (tb[NL80211_KEY_MODE]) |
| 1266 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); |
| 1267 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 1272 | { |
| 1273 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1274 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1275 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1276 | } |
| 1277 | |
| 1278 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1279 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1280 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1281 | } |
| 1282 | |
| 1283 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1284 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1285 | |
| 1286 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1287 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1288 | |
| 1289 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1290 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1291 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1292 | if (k->def) { |
| 1293 | k->def_uni = true; |
| 1294 | k->def_multi = true; |
| 1295 | } |
| 1296 | if (k->defmgmt) |
| 1297 | k->def_multi = true; |
| 1298 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1299 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1300 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1301 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1302 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1303 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1304 | int err = nla_parse_nested_deprecated(kdt, |
| 1305 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1306 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 1307 | nl80211_key_default_policy, |
| 1308 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1309 | if (err) |
| 1310 | return err; |
| 1311 | |
| 1312 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1313 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1314 | } |
| 1315 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1316 | return 0; |
| 1317 | } |
| 1318 | |
| 1319 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1320 | { |
| 1321 | int err; |
| 1322 | |
| 1323 | memset(k, 0, sizeof(*k)); |
| 1324 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1325 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1326 | |
| 1327 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1328 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1329 | else |
| 1330 | err = nl80211_parse_key_old(info, k); |
| 1331 | |
| 1332 | if (err) |
| 1333 | return err; |
| 1334 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1335 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
| 1336 | (k->defbeacon ? 1 : 0) > 1) { |
| 1337 | GENL_SET_ERR_MSG(info, |
| 1338 | "key with multiple default flags is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1339 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1340 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1341 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1342 | if (k->defmgmt || k->defbeacon) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1343 | if (k->def_uni || !k->def_multi) { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1344 | GENL_SET_ERR_MSG(info, |
| 1345 | "defmgmt/defbeacon key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1346 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1347 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1348 | } |
| 1349 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1350 | if (k->idx != -1) { |
| 1351 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1352 | if (k->idx < 4 || k->idx > 5) { |
| 1353 | GENL_SET_ERR_MSG(info, |
| 1354 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1355 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1356 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1357 | } else if (k->defbeacon) { |
| 1358 | if (k->idx < 6 || k->idx > 7) { |
| 1359 | GENL_SET_ERR_MSG(info, |
| 1360 | "defbeacon key idx not 6 or 7"); |
| 1361 | return -EINVAL; |
| 1362 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1363 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1364 | if (k->idx < 0 || k->idx > 3) { |
| 1365 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1366 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1367 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1368 | } else { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1369 | if (k->idx < 0 || k->idx > 7) { |
| 1370 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1371 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1372 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1379 | static struct cfg80211_cached_keys * |
| 1380 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1381 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1382 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1383 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1384 | struct key_parse parse; |
| 1385 | struct nlattr *key; |
| 1386 | struct cfg80211_cached_keys *result; |
| 1387 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1388 | bool have_key = false; |
| 1389 | |
| 1390 | nla_for_each_nested(key, keys, rem) { |
| 1391 | have_key = true; |
| 1392 | break; |
| 1393 | } |
| 1394 | |
| 1395 | if (!have_key) |
| 1396 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1397 | |
| 1398 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1399 | if (!result) |
| 1400 | return ERR_PTR(-ENOMEM); |
| 1401 | |
| 1402 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1403 | |
| 1404 | nla_for_each_nested(key, keys, rem) { |
| 1405 | memset(&parse, 0, sizeof(parse)); |
| 1406 | parse.idx = -1; |
| 1407 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1408 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1409 | if (err) |
| 1410 | goto error; |
| 1411 | err = -EINVAL; |
| 1412 | if (!parse.p.key) |
| 1413 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1414 | if (parse.idx < 0 || parse.idx > 3) { |
| 1415 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1416 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1417 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1418 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1419 | if (def) { |
| 1420 | GENL_SET_ERR_MSG(info, |
| 1421 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1422 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1423 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1424 | def = 1; |
| 1425 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1426 | if (!parse.def_uni || !parse.def_multi) |
| 1427 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1428 | } else if (parse.defmgmt) |
| 1429 | goto error; |
| 1430 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1431 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1432 | if (err) |
| 1433 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1434 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1435 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1436 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1437 | err = -EINVAL; |
| 1438 | goto error; |
| 1439 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1440 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1441 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1442 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1443 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1444 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1445 | /* must be WEP key if we got here */ |
| 1446 | if (no_ht) |
| 1447 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1448 | } |
| 1449 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1450 | if (result->def < 0) { |
| 1451 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1452 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1453 | goto error; |
| 1454 | } |
| 1455 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1456 | return result; |
| 1457 | error: |
| 1458 | kfree(result); |
| 1459 | return ERR_PTR(err); |
| 1460 | } |
| 1461 | |
| 1462 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1463 | { |
| 1464 | ASSERT_WDEV_LOCK(wdev); |
| 1465 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1466 | switch (wdev->iftype) { |
| 1467 | case NL80211_IFTYPE_AP: |
| 1468 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1469 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1470 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1471 | break; |
| 1472 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1473 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1474 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1475 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1476 | return -ENOLINK; |
| 1477 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1478 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1479 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1480 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1481 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1482 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1483 | case NL80211_IFTYPE_WDS: |
| 1484 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1485 | return -EINVAL; |
| 1486 | } |
| 1487 | |
| 1488 | return 0; |
| 1489 | } |
| 1490 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1491 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1492 | u32 freq) |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1493 | { |
| 1494 | struct ieee80211_channel *chan; |
| 1495 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1496 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1497 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1498 | return NULL; |
| 1499 | return chan; |
| 1500 | } |
| 1501 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1502 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1503 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1504 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1505 | int i; |
| 1506 | |
| 1507 | if (!nl_modes) |
| 1508 | goto nla_put_failure; |
| 1509 | |
| 1510 | i = 0; |
| 1511 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1512 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1513 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1514 | ifmodes >>= 1; |
| 1515 | i++; |
| 1516 | } |
| 1517 | |
| 1518 | nla_nest_end(msg, nl_modes); |
| 1519 | return 0; |
| 1520 | |
| 1521 | nla_put_failure: |
| 1522 | return -ENOBUFS; |
| 1523 | } |
| 1524 | |
| 1525 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1526 | struct sk_buff *msg, |
| 1527 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1528 | { |
| 1529 | struct nlattr *nl_combis; |
| 1530 | int i, j; |
| 1531 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1532 | nl_combis = nla_nest_start_noflag(msg, |
| 1533 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1534 | if (!nl_combis) |
| 1535 | goto nla_put_failure; |
| 1536 | |
| 1537 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1538 | const struct ieee80211_iface_combination *c; |
| 1539 | struct nlattr *nl_combi, *nl_limits; |
| 1540 | |
| 1541 | c = &wiphy->iface_combinations[i]; |
| 1542 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1543 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1544 | if (!nl_combi) |
| 1545 | goto nla_put_failure; |
| 1546 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1547 | nl_limits = nla_nest_start_noflag(msg, |
| 1548 | NL80211_IFACE_COMB_LIMITS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1549 | if (!nl_limits) |
| 1550 | goto nla_put_failure; |
| 1551 | |
| 1552 | for (j = 0; j < c->n_limits; j++) { |
| 1553 | struct nlattr *nl_limit; |
| 1554 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1555 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1556 | if (!nl_limit) |
| 1557 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1558 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1559 | c->limits[j].max)) |
| 1560 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1561 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1562 | c->limits[j].types)) |
| 1563 | goto nla_put_failure; |
| 1564 | nla_nest_end(msg, nl_limit); |
| 1565 | } |
| 1566 | |
| 1567 | nla_nest_end(msg, nl_limits); |
| 1568 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1569 | if (c->beacon_int_infra_match && |
| 1570 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1571 | goto nla_put_failure; |
| 1572 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1573 | c->num_different_channels) || |
| 1574 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1575 | c->max_interfaces)) |
| 1576 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1577 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1578 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1579 | c->radar_detect_widths) || |
| 1580 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1581 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1582 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1583 | if (c->beacon_int_min_gcd && |
| 1584 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1585 | c->beacon_int_min_gcd)) |
| 1586 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1587 | |
| 1588 | nla_nest_end(msg, nl_combi); |
| 1589 | } |
| 1590 | |
| 1591 | nla_nest_end(msg, nl_combis); |
| 1592 | |
| 1593 | return 0; |
| 1594 | nla_put_failure: |
| 1595 | return -ENOBUFS; |
| 1596 | } |
| 1597 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1598 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1599 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1600 | struct sk_buff *msg) |
| 1601 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1602 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1603 | struct nlattr *nl_tcp; |
| 1604 | |
| 1605 | if (!tcp) |
| 1606 | return 0; |
| 1607 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1608 | nl_tcp = nla_nest_start_noflag(msg, |
| 1609 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1610 | if (!nl_tcp) |
| 1611 | return -ENOBUFS; |
| 1612 | |
| 1613 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1614 | tcp->data_payload_max)) |
| 1615 | return -ENOBUFS; |
| 1616 | |
| 1617 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1618 | tcp->data_payload_max)) |
| 1619 | return -ENOBUFS; |
| 1620 | |
| 1621 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1622 | return -ENOBUFS; |
| 1623 | |
| 1624 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1625 | sizeof(*tcp->tok), tcp->tok)) |
| 1626 | return -ENOBUFS; |
| 1627 | |
| 1628 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1629 | tcp->data_interval_max)) |
| 1630 | return -ENOBUFS; |
| 1631 | |
| 1632 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1633 | tcp->wake_payload_max)) |
| 1634 | return -ENOBUFS; |
| 1635 | |
| 1636 | nla_nest_end(msg, nl_tcp); |
| 1637 | return 0; |
| 1638 | } |
| 1639 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1640 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1641 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1642 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1643 | { |
| 1644 | struct nlattr *nl_wowlan; |
| 1645 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1646 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1647 | return 0; |
| 1648 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1649 | nl_wowlan = nla_nest_start_noflag(msg, |
| 1650 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1651 | if (!nl_wowlan) |
| 1652 | return -ENOBUFS; |
| 1653 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1654 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1655 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1656 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1657 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1658 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1659 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1660 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1661 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1662 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1663 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1664 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1665 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1666 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1667 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1668 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1669 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1670 | return -ENOBUFS; |
| 1671 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1672 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1673 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1674 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1675 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1676 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1677 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1678 | }; |
| 1679 | |
| 1680 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1681 | sizeof(pat), &pat)) |
| 1682 | return -ENOBUFS; |
| 1683 | } |
| 1684 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1685 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1686 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1687 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1688 | return -ENOBUFS; |
| 1689 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1690 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1691 | return -ENOBUFS; |
| 1692 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1693 | nla_nest_end(msg, nl_wowlan); |
| 1694 | |
| 1695 | return 0; |
| 1696 | } |
| 1697 | #endif |
| 1698 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1699 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1700 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1701 | { |
| 1702 | struct nl80211_coalesce_rule_support rule; |
| 1703 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1704 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1705 | return 0; |
| 1706 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1707 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1708 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1709 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1710 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1711 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1712 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1713 | |
| 1714 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1715 | return -ENOBUFS; |
| 1716 | |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1720 | static int |
| 1721 | nl80211_send_iftype_data(struct sk_buff *msg, |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1722 | const struct ieee80211_supported_band *sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1723 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1724 | { |
| 1725 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1726 | |
| 1727 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1728 | iftdata->types_mask)) |
| 1729 | return -ENOBUFS; |
| 1730 | |
| 1731 | if (he_cap->has_he) { |
| 1732 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1733 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1734 | he_cap->he_cap_elem.mac_cap_info) || |
| 1735 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1736 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1737 | he_cap->he_cap_elem.phy_cap_info) || |
| 1738 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1739 | sizeof(he_cap->he_mcs_nss_supp), |
| 1740 | &he_cap->he_mcs_nss_supp) || |
| 1741 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1742 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1743 | return -ENOBUFS; |
| 1744 | } |
| 1745 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1746 | if (sband->band == NL80211_BAND_6GHZ && |
| 1747 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, |
| 1748 | sizeof(iftdata->he_6ghz_capa), |
| 1749 | &iftdata->he_6ghz_capa)) |
| 1750 | return -ENOBUFS; |
| 1751 | |
Johannes Berg | f4f8650 | 2021-06-18 13:41:52 +0300 | [diff] [blame] | 1752 | if (iftdata->vendor_elems.data && iftdata->vendor_elems.len && |
| 1753 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS, |
| 1754 | iftdata->vendor_elems.len, iftdata->vendor_elems.data)) |
| 1755 | return -ENOBUFS; |
| 1756 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1757 | return 0; |
| 1758 | } |
| 1759 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1760 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1761 | struct ieee80211_supported_band *sband, |
| 1762 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1763 | { |
| 1764 | struct nlattr *nl_rates, *nl_rate; |
| 1765 | struct ieee80211_rate *rate; |
| 1766 | int i; |
| 1767 | |
| 1768 | /* add HT info */ |
| 1769 | if (sband->ht_cap.ht_supported && |
| 1770 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1771 | sizeof(sband->ht_cap.mcs), |
| 1772 | &sband->ht_cap.mcs) || |
| 1773 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1774 | sband->ht_cap.cap) || |
| 1775 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1776 | sband->ht_cap.ampdu_factor) || |
| 1777 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1778 | sband->ht_cap.ampdu_density))) |
| 1779 | return -ENOBUFS; |
| 1780 | |
| 1781 | /* add VHT info */ |
| 1782 | if (sband->vht_cap.vht_supported && |
| 1783 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1784 | sizeof(sband->vht_cap.vht_mcs), |
| 1785 | &sband->vht_cap.vht_mcs) || |
| 1786 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1787 | sband->vht_cap.cap))) |
| 1788 | return -ENOBUFS; |
| 1789 | |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1790 | if (large && sband->n_iftype_data) { |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1791 | struct nlattr *nl_iftype_data = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1792 | nla_nest_start_noflag(msg, |
| 1793 | NL80211_BAND_ATTR_IFTYPE_DATA); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1794 | int err; |
| 1795 | |
| 1796 | if (!nl_iftype_data) |
| 1797 | return -ENOBUFS; |
| 1798 | |
| 1799 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1800 | struct nlattr *iftdata; |
| 1801 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1802 | iftdata = nla_nest_start_noflag(msg, i + 1); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1803 | if (!iftdata) |
| 1804 | return -ENOBUFS; |
| 1805 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1806 | err = nl80211_send_iftype_data(msg, sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1807 | &sband->iftype_data[i]); |
| 1808 | if (err) |
| 1809 | return err; |
| 1810 | |
| 1811 | nla_nest_end(msg, iftdata); |
| 1812 | } |
| 1813 | |
| 1814 | nla_nest_end(msg, nl_iftype_data); |
| 1815 | } |
| 1816 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1817 | /* add EDMG info */ |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1818 | if (large && sband->edmg_cap.channels && |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1819 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
| 1820 | sband->edmg_cap.channels) || |
| 1821 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, |
| 1822 | sband->edmg_cap.bw_config))) |
| 1823 | |
| 1824 | return -ENOBUFS; |
| 1825 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1826 | /* add bitrates */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1827 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1828 | if (!nl_rates) |
| 1829 | return -ENOBUFS; |
| 1830 | |
| 1831 | for (i = 0; i < sband->n_bitrates; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1832 | nl_rate = nla_nest_start_noflag(msg, i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1833 | if (!nl_rate) |
| 1834 | return -ENOBUFS; |
| 1835 | |
| 1836 | rate = &sband->bitrates[i]; |
| 1837 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1838 | rate->bitrate)) |
| 1839 | return -ENOBUFS; |
| 1840 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1841 | nla_put_flag(msg, |
| 1842 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1843 | return -ENOBUFS; |
| 1844 | |
| 1845 | nla_nest_end(msg, nl_rate); |
| 1846 | } |
| 1847 | |
| 1848 | nla_nest_end(msg, nl_rates); |
| 1849 | |
| 1850 | return 0; |
| 1851 | } |
| 1852 | |
| 1853 | static int |
| 1854 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1855 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1856 | { |
| 1857 | u16 stypes; |
| 1858 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1859 | enum nl80211_iftype ift; |
| 1860 | int i; |
| 1861 | |
| 1862 | if (!mgmt_stypes) |
| 1863 | return 0; |
| 1864 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1865 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1866 | if (!nl_ifs) |
| 1867 | return -ENOBUFS; |
| 1868 | |
| 1869 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1870 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1871 | if (!nl_ftypes) |
| 1872 | return -ENOBUFS; |
| 1873 | i = 0; |
| 1874 | stypes = mgmt_stypes[ift].tx; |
| 1875 | while (stypes) { |
| 1876 | if ((stypes & 1) && |
| 1877 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1878 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1879 | return -ENOBUFS; |
| 1880 | stypes >>= 1; |
| 1881 | i++; |
| 1882 | } |
| 1883 | nla_nest_end(msg, nl_ftypes); |
| 1884 | } |
| 1885 | |
| 1886 | nla_nest_end(msg, nl_ifs); |
| 1887 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1888 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1889 | if (!nl_ifs) |
| 1890 | return -ENOBUFS; |
| 1891 | |
| 1892 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1893 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1894 | if (!nl_ftypes) |
| 1895 | return -ENOBUFS; |
| 1896 | i = 0; |
| 1897 | stypes = mgmt_stypes[ift].rx; |
| 1898 | while (stypes) { |
| 1899 | if ((stypes & 1) && |
| 1900 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1901 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1902 | return -ENOBUFS; |
| 1903 | stypes >>= 1; |
| 1904 | i++; |
| 1905 | } |
| 1906 | nla_nest_end(msg, nl_ftypes); |
| 1907 | } |
| 1908 | nla_nest_end(msg, nl_ifs); |
| 1909 | |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1913 | #define CMD(op, n) \ |
| 1914 | do { \ |
| 1915 | if (rdev->ops->op) { \ |
| 1916 | i++; \ |
| 1917 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1918 | goto nla_put_failure; \ |
| 1919 | } \ |
| 1920 | } while (0) |
| 1921 | |
| 1922 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1923 | struct sk_buff *msg) |
| 1924 | { |
| 1925 | int i = 0; |
| 1926 | |
| 1927 | /* |
| 1928 | * do *NOT* add anything into this function, new things need to be |
| 1929 | * advertised only to new versions of userspace that can deal with |
| 1930 | * the split (and they can't possibly care about new features... |
| 1931 | */ |
| 1932 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1933 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1934 | CMD(add_key, NEW_KEY); |
| 1935 | CMD(start_ap, START_AP); |
| 1936 | CMD(add_station, NEW_STATION); |
| 1937 | CMD(add_mpath, NEW_MPATH); |
| 1938 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1939 | CMD(change_bss, SET_BSS); |
| 1940 | CMD(auth, AUTHENTICATE); |
| 1941 | CMD(assoc, ASSOCIATE); |
| 1942 | CMD(deauth, DEAUTHENTICATE); |
| 1943 | CMD(disassoc, DISASSOCIATE); |
| 1944 | CMD(join_ibss, JOIN_IBSS); |
| 1945 | CMD(join_mesh, JOIN_MESH); |
| 1946 | CMD(set_pmksa, SET_PMKSA); |
| 1947 | CMD(del_pmksa, DEL_PMKSA); |
| 1948 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1949 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1950 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1951 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1952 | CMD(mgmt_tx, FRAME); |
| 1953 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1954 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1955 | i++; |
| 1956 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1957 | goto nla_put_failure; |
| 1958 | } |
| 1959 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1960 | rdev->ops->join_mesh) { |
| 1961 | i++; |
| 1962 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1963 | goto nla_put_failure; |
| 1964 | } |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1965 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1966 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1967 | CMD(tdls_oper, TDLS_OPER); |
| 1968 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1969 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1970 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1971 | CMD(probe_client, PROBE_CLIENT); |
| 1972 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1973 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1974 | i++; |
| 1975 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1976 | goto nla_put_failure; |
| 1977 | } |
| 1978 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1979 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1980 | #ifdef CONFIG_NL80211_TESTMODE |
| 1981 | CMD(testmode_cmd, TESTMODE); |
| 1982 | #endif |
| 1983 | |
| 1984 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1985 | i++; |
| 1986 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1987 | goto nla_put_failure; |
| 1988 | } |
| 1989 | |
| 1990 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1991 | i++; |
| 1992 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1993 | goto nla_put_failure; |
| 1994 | } |
| 1995 | |
| 1996 | return i; |
| 1997 | nla_put_failure: |
| 1998 | return -ENOBUFS; |
| 1999 | } |
| 2000 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2001 | static int |
| 2002 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 2003 | struct sk_buff *msg) |
| 2004 | { |
| 2005 | struct nlattr *ftm; |
| 2006 | |
| 2007 | if (!cap->ftm.supported) |
| 2008 | return 0; |
| 2009 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2010 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2011 | if (!ftm) |
| 2012 | return -ENOBUFS; |
| 2013 | |
| 2014 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 2015 | return -ENOBUFS; |
| 2016 | if (cap->ftm.non_asap && |
| 2017 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 2018 | return -ENOBUFS; |
| 2019 | if (cap->ftm.request_lci && |
| 2020 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 2021 | return -ENOBUFS; |
| 2022 | if (cap->ftm.request_civicloc && |
| 2023 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 2024 | return -ENOBUFS; |
| 2025 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 2026 | cap->ftm.preambles)) |
| 2027 | return -ENOBUFS; |
| 2028 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 2029 | cap->ftm.bandwidths)) |
| 2030 | return -ENOBUFS; |
| 2031 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 2032 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 2033 | cap->ftm.max_bursts_exponent)) |
| 2034 | return -ENOBUFS; |
| 2035 | if (cap->ftm.max_ftms_per_burst && |
| 2036 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 2037 | cap->ftm.max_ftms_per_burst)) |
| 2038 | return -ENOBUFS; |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 2039 | if (cap->ftm.trigger_based && |
| 2040 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) |
| 2041 | return -ENOBUFS; |
| 2042 | if (cap->ftm.non_trigger_based && |
| 2043 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) |
| 2044 | return -ENOBUFS; |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2045 | |
| 2046 | nla_nest_end(msg, ftm); |
| 2047 | return 0; |
| 2048 | } |
| 2049 | |
| 2050 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 2051 | struct sk_buff *msg) |
| 2052 | { |
| 2053 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 2054 | struct nlattr *pmsr, *caps; |
| 2055 | |
| 2056 | if (!cap) |
| 2057 | return 0; |
| 2058 | |
| 2059 | /* |
| 2060 | * we don't need to clean up anything here since the caller |
| 2061 | * will genlmsg_cancel() if we fail |
| 2062 | */ |
| 2063 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2064 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2065 | if (!pmsr) |
| 2066 | return -ENOBUFS; |
| 2067 | |
| 2068 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 2069 | return -ENOBUFS; |
| 2070 | |
| 2071 | if (cap->report_ap_tsf && |
| 2072 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 2073 | return -ENOBUFS; |
| 2074 | |
| 2075 | if (cap->randomize_mac_addr && |
| 2076 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 2077 | return -ENOBUFS; |
| 2078 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2079 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2080 | if (!caps) |
| 2081 | return -ENOBUFS; |
| 2082 | |
| 2083 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 2084 | return -ENOBUFS; |
| 2085 | |
| 2086 | nla_nest_end(msg, caps); |
| 2087 | nla_nest_end(msg, pmsr); |
| 2088 | |
| 2089 | return 0; |
| 2090 | } |
| 2091 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2092 | static int |
| 2093 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, |
| 2094 | struct sk_buff *msg) |
| 2095 | { |
| 2096 | int i; |
| 2097 | struct nlattr *nested, *nested_akms; |
| 2098 | const struct wiphy_iftype_akm_suites *iftype_akms; |
| 2099 | |
| 2100 | if (!rdev->wiphy.num_iftype_akm_suites || |
| 2101 | !rdev->wiphy.iftype_akm_suites) |
| 2102 | return 0; |
| 2103 | |
| 2104 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); |
| 2105 | if (!nested) |
| 2106 | return -ENOBUFS; |
| 2107 | |
| 2108 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { |
| 2109 | nested_akms = nla_nest_start(msg, i + 1); |
| 2110 | if (!nested_akms) |
| 2111 | return -ENOBUFS; |
| 2112 | |
| 2113 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; |
| 2114 | |
| 2115 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, |
| 2116 | iftype_akms->iftypes_mask)) |
| 2117 | return -ENOBUFS; |
| 2118 | |
| 2119 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, |
| 2120 | sizeof(u32) * iftype_akms->n_akm_suites, |
| 2121 | iftype_akms->akm_suites)) { |
| 2122 | return -ENOBUFS; |
| 2123 | } |
| 2124 | nla_nest_end(msg, nested_akms); |
| 2125 | } |
| 2126 | |
| 2127 | nla_nest_end(msg, nested); |
| 2128 | |
| 2129 | return 0; |
| 2130 | } |
| 2131 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2132 | static int |
| 2133 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, |
| 2134 | struct sk_buff *msg) |
| 2135 | { |
| 2136 | struct nlattr *supp; |
| 2137 | |
| 2138 | if (!rdev->wiphy.tid_config_support.vif && |
| 2139 | !rdev->wiphy.tid_config_support.peer) |
| 2140 | return 0; |
| 2141 | |
| 2142 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); |
| 2143 | if (!supp) |
| 2144 | return -ENOSPC; |
| 2145 | |
| 2146 | if (rdev->wiphy.tid_config_support.vif && |
| 2147 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, |
| 2148 | rdev->wiphy.tid_config_support.vif, |
| 2149 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2150 | goto fail; |
| 2151 | |
| 2152 | if (rdev->wiphy.tid_config_support.peer && |
| 2153 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, |
| 2154 | rdev->wiphy.tid_config_support.peer, |
| 2155 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2156 | goto fail; |
| 2157 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 2158 | /* for now we just use the same value ... makes more sense */ |
| 2159 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, |
| 2160 | rdev->wiphy.tid_config_support.max_retry)) |
| 2161 | goto fail; |
| 2162 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, |
| 2163 | rdev->wiphy.tid_config_support.max_retry)) |
| 2164 | goto fail; |
| 2165 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2166 | nla_nest_end(msg, supp); |
| 2167 | |
| 2168 | return 0; |
| 2169 | fail: |
| 2170 | nla_nest_cancel(msg, supp); |
| 2171 | return -ENOBUFS; |
| 2172 | } |
| 2173 | |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 2174 | static int |
| 2175 | nl80211_put_sar_specs(struct cfg80211_registered_device *rdev, |
| 2176 | struct sk_buff *msg) |
| 2177 | { |
| 2178 | struct nlattr *sar_capa, *specs, *sub_freq_range; |
| 2179 | u8 num_freq_ranges; |
| 2180 | int i; |
| 2181 | |
| 2182 | if (!rdev->wiphy.sar_capa) |
| 2183 | return 0; |
| 2184 | |
| 2185 | num_freq_ranges = rdev->wiphy.sar_capa->num_freq_ranges; |
| 2186 | |
| 2187 | sar_capa = nla_nest_start(msg, NL80211_ATTR_SAR_SPEC); |
| 2188 | if (!sar_capa) |
| 2189 | return -ENOSPC; |
| 2190 | |
| 2191 | if (nla_put_u32(msg, NL80211_SAR_ATTR_TYPE, rdev->wiphy.sar_capa->type)) |
| 2192 | goto fail; |
| 2193 | |
| 2194 | specs = nla_nest_start(msg, NL80211_SAR_ATTR_SPECS); |
| 2195 | if (!specs) |
| 2196 | goto fail; |
| 2197 | |
| 2198 | /* report supported freq_ranges */ |
| 2199 | for (i = 0; i < num_freq_ranges; i++) { |
| 2200 | sub_freq_range = nla_nest_start(msg, i + 1); |
| 2201 | if (!sub_freq_range) |
| 2202 | goto fail; |
| 2203 | |
| 2204 | if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_START_FREQ, |
| 2205 | rdev->wiphy.sar_capa->freq_ranges[i].start_freq)) |
| 2206 | goto fail; |
| 2207 | |
| 2208 | if (nla_put_u32(msg, NL80211_SAR_ATTR_SPECS_END_FREQ, |
| 2209 | rdev->wiphy.sar_capa->freq_ranges[i].end_freq)) |
| 2210 | goto fail; |
| 2211 | |
| 2212 | nla_nest_end(msg, sub_freq_range); |
| 2213 | } |
| 2214 | |
| 2215 | nla_nest_end(msg, specs); |
| 2216 | nla_nest_end(msg, sar_capa); |
| 2217 | |
| 2218 | return 0; |
| 2219 | fail: |
| 2220 | nla_nest_cancel(msg, sar_capa); |
| 2221 | return -ENOBUFS; |
| 2222 | } |
| 2223 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 2224 | static int nl80211_put_mbssid_support(struct wiphy *wiphy, struct sk_buff *msg) |
| 2225 | { |
| 2226 | struct nlattr *config; |
| 2227 | |
| 2228 | if (!wiphy->mbssid_max_interfaces) |
| 2229 | return 0; |
| 2230 | |
| 2231 | config = nla_nest_start(msg, NL80211_ATTR_MBSSID_CONFIG); |
| 2232 | if (!config) |
| 2233 | return -ENOBUFS; |
| 2234 | |
| 2235 | if (nla_put_u8(msg, NL80211_MBSSID_CONFIG_ATTR_MAX_INTERFACES, |
| 2236 | wiphy->mbssid_max_interfaces)) |
| 2237 | goto fail; |
| 2238 | |
| 2239 | if (wiphy->ema_max_profile_periodicity && |
| 2240 | nla_put_u8(msg, |
| 2241 | NL80211_MBSSID_CONFIG_ATTR_MAX_EMA_PROFILE_PERIODICITY, |
| 2242 | wiphy->ema_max_profile_periodicity)) |
| 2243 | goto fail; |
| 2244 | |
| 2245 | nla_nest_end(msg, config); |
| 2246 | return 0; |
| 2247 | |
| 2248 | fail: |
| 2249 | nla_nest_cancel(msg, config); |
| 2250 | return -ENOBUFS; |
| 2251 | } |
| 2252 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2253 | struct nl80211_dump_wiphy_state { |
| 2254 | s64 filter_wiphy; |
| 2255 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2256 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2257 | bool split; |
| 2258 | }; |
| 2259 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2260 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2261 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2262 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2263 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2264 | { |
| 2265 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2266 | struct nlattr *nl_bands, *nl_band; |
| 2267 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2268 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2269 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2270 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2271 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2272 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2273 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2274 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2275 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2276 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2277 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2278 | return -ENOBUFS; |
| 2279 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2280 | if (WARN_ON(!state)) |
| 2281 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2282 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2283 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2284 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2285 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2286 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2287 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2288 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2289 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2290 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 2291 | goto finish; |
| 2292 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2293 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2294 | case 0: |
| 2295 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2296 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2297 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2298 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2299 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2300 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2301 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2302 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2303 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2304 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2305 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2306 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2307 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2308 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2309 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2310 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2311 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2312 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2313 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2314 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2315 | goto nla_put_failure; |
| 2316 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2317 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2318 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 2319 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2320 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2321 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 2322 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2323 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2324 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 2325 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2326 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2327 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 2328 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2329 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2330 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 2331 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2332 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2333 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2334 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2335 | state->split_start++; |
| 2336 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2337 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2338 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2339 | case 1: |
| 2340 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2341 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 2342 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 2343 | goto nla_put_failure; |
| 2344 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2345 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2346 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2347 | goto nla_put_failure; |
| 2348 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2349 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2350 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 2351 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2352 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2353 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2354 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2355 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2356 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2357 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2358 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2359 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2360 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2361 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2362 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 2363 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2364 | if ((rdev->wiphy.available_antennas_tx || |
| 2365 | rdev->wiphy.available_antennas_rx) && |
| 2366 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2367 | u32 tx_ant = 0, rx_ant = 0; |
| 2368 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2369 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2370 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2371 | if (!res) { |
| 2372 | if (nla_put_u32(msg, |
| 2373 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 2374 | tx_ant) || |
| 2375 | nla_put_u32(msg, |
| 2376 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 2377 | rx_ant)) |
| 2378 | goto nla_put_failure; |
| 2379 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2380 | } |
| 2381 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2382 | state->split_start++; |
| 2383 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2384 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2385 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2386 | case 2: |
| 2387 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2388 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2389 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2390 | state->split_start++; |
| 2391 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2392 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2393 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2394 | case 3: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2395 | nl_bands = nla_nest_start_noflag(msg, |
| 2396 | NL80211_ATTR_WIPHY_BANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2397 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2398 | goto nla_put_failure; |
| 2399 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2400 | for (band = state->band_start; |
Johannes Berg | 0d05996 | 2021-07-12 21:53:30 +0200 | [diff] [blame] | 2401 | band < (state->split ? |
| 2402 | NUM_NL80211_BANDS : |
| 2403 | NL80211_BAND_60GHZ + 1); |
| 2404 | band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2405 | struct ieee80211_supported_band *sband; |
| 2406 | |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2407 | /* omit higher bands for ancient software */ |
| 2408 | if (band > NL80211_BAND_5GHZ && !state->split) |
| 2409 | break; |
| 2410 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2411 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2412 | |
| 2413 | if (!sband) |
| 2414 | continue; |
| 2415 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2416 | nl_band = nla_nest_start_noflag(msg, band); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2417 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2418 | goto nla_put_failure; |
| 2419 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2420 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2421 | case 0: |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2422 | if (nl80211_send_band_rateinfo(msg, sband, |
| 2423 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2424 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2425 | state->chan_start++; |
| 2426 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2427 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2428 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2429 | default: |
| 2430 | /* add frequencies */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2431 | nl_freqs = nla_nest_start_noflag(msg, |
| 2432 | NL80211_BAND_ATTR_FREQS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2433 | if (!nl_freqs) |
| 2434 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2435 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2436 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2437 | i < sband->n_channels; |
| 2438 | i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2439 | nl_freq = nla_nest_start_noflag(msg, |
| 2440 | i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2441 | if (!nl_freq) |
| 2442 | goto nla_put_failure; |
| 2443 | |
| 2444 | chan = &sband->channels[i]; |
| 2445 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2446 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 2447 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2448 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2449 | goto nla_put_failure; |
| 2450 | |
| 2451 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2452 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2453 | break; |
| 2454 | } |
| 2455 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2456 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2457 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2458 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2459 | nla_nest_end(msg, nl_freqs); |
| 2460 | } |
| 2461 | |
| 2462 | nla_nest_end(msg, nl_band); |
| 2463 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2464 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2465 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2466 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2467 | band--; |
| 2468 | break; |
| 2469 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2470 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2471 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2472 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2473 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2474 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2475 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2476 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2477 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2478 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2479 | if (state->band_start == 0 && state->chan_start == 0) |
| 2480 | state->split_start++; |
| 2481 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2482 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2483 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2484 | case 4: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2485 | nl_cmds = nla_nest_start_noflag(msg, |
| 2486 | NL80211_ATTR_SUPPORTED_COMMANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2487 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2488 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2489 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 2490 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 2491 | if (i < 0) |
| 2492 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2493 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2494 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2495 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2496 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 2497 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 2498 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 2499 | if (rdev->wiphy.features & |
| 2500 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 2501 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 2502 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 2503 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Matthew Wang | 7010998 | 2019-08-22 10:48:06 -0700 | [diff] [blame] | 2504 | CMD(update_ft_ies, UPDATE_FT_IES); |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 2505 | if (rdev->wiphy.sar_capa) |
| 2506 | CMD(set_sar_specs, SET_SAR_SPECS); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2507 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2508 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2509 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2510 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2511 | state->split_start++; |
| 2512 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2513 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2514 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2515 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2516 | if (rdev->ops->remain_on_channel && |
| 2517 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2518 | nla_put_u32(msg, |
| 2519 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2520 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2521 | goto nla_put_failure; |
| 2522 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2523 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2524 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2525 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2526 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2527 | state->split_start++; |
| 2528 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2529 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2530 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2531 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 2532 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2533 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2534 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2535 | state->split_start++; |
| 2536 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2537 | break; |
| 2538 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2539 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2540 | #endif |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2541 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2542 | case 7: |
| 2543 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2544 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2545 | goto nla_put_failure; |
| 2546 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2547 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2548 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2549 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2550 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2551 | state->split_start++; |
| 2552 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2553 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2554 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2555 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2556 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2557 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2558 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2559 | goto nla_put_failure; |
| 2560 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2561 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2562 | /* |
| 2563 | * We can only add the per-channel limit information if the |
| 2564 | * dump is split, otherwise it makes it too big. Therefore |
| 2565 | * only advertise it in that case. |
| 2566 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2567 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2568 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2569 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2570 | goto nla_put_failure; |
| 2571 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2572 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2573 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2574 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2575 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2576 | goto nla_put_failure; |
| 2577 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2578 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2579 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2580 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2581 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2582 | goto nla_put_failure; |
| 2583 | |
| 2584 | /* |
| 2585 | * Any information below this point is only available to |
| 2586 | * applications that can deal with it being split. This |
| 2587 | * helps ensure that newly added capabilities don't break |
| 2588 | * older tools by overrunning their buffers. |
| 2589 | * |
| 2590 | * We still increment split_start so that in the split |
| 2591 | * case we'll continue with more data in the next round, |
| 2592 | * but break unconditionally so unsplit data stops here. |
| 2593 | */ |
Johannes Berg | ab10c22 | 2020-09-28 13:07:18 +0200 | [diff] [blame] | 2594 | if (state->split) |
| 2595 | state->split_start++; |
| 2596 | else |
| 2597 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2598 | break; |
| 2599 | case 9: |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2600 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2601 | goto nla_put_failure; |
| 2602 | |
| 2603 | if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 2604 | rdev->wiphy.max_sched_scan_plans) || |
| 2605 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 2606 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 2607 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 2608 | rdev->wiphy.max_sched_scan_plan_iterations)) |
| 2609 | goto nla_put_failure; |
| 2610 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2611 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2612 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2613 | rdev->wiphy.extended_capabilities_len, |
| 2614 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2615 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2616 | rdev->wiphy.extended_capabilities_len, |
| 2617 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2618 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2619 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2620 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2621 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2622 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2623 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2624 | goto nla_put_failure; |
| 2625 | |
Denis Kenzior | ae6fa4d | 2019-07-22 06:33:12 -0500 | [diff] [blame] | 2626 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 2627 | rdev->wiphy.perm_addr)) |
| 2628 | goto nla_put_failure; |
| 2629 | |
| 2630 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && |
| 2631 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, |
| 2632 | rdev->wiphy.addr_mask)) |
| 2633 | goto nla_put_failure; |
| 2634 | |
| 2635 | if (rdev->wiphy.n_addresses > 1) { |
| 2636 | void *attr; |
| 2637 | |
| 2638 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 2639 | if (!attr) |
| 2640 | goto nla_put_failure; |
| 2641 | |
| 2642 | for (i = 0; i < rdev->wiphy.n_addresses; i++) |
| 2643 | if (nla_put(msg, i + 1, ETH_ALEN, |
| 2644 | rdev->wiphy.addresses[i].addr)) |
| 2645 | goto nla_put_failure; |
| 2646 | |
| 2647 | nla_nest_end(msg, attr); |
| 2648 | } |
| 2649 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2650 | state->split_start++; |
| 2651 | break; |
| 2652 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2653 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2654 | goto nla_put_failure; |
| 2655 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2656 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2657 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2658 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2659 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2660 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2661 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2662 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2663 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2664 | goto nla_put_failure; |
| 2665 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2666 | state->split_start++; |
| 2667 | break; |
| 2668 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2669 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2670 | const struct nl80211_vendor_cmd_info *info; |
| 2671 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2672 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2673 | nested = nla_nest_start_noflag(msg, |
| 2674 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2675 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2676 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2677 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2678 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2679 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2680 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2681 | goto nla_put_failure; |
| 2682 | } |
| 2683 | nla_nest_end(msg, nested); |
| 2684 | } |
| 2685 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2686 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2687 | const struct nl80211_vendor_cmd_info *info; |
| 2688 | struct nlattr *nested; |
| 2689 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2690 | nested = nla_nest_start_noflag(msg, |
| 2691 | NL80211_ATTR_VENDOR_EVENTS); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2692 | if (!nested) |
| 2693 | goto nla_put_failure; |
| 2694 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2695 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2696 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2697 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2698 | goto nla_put_failure; |
| 2699 | } |
| 2700 | nla_nest_end(msg, nested); |
| 2701 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 2702 | state->split_start++; |
| 2703 | break; |
| 2704 | case 12: |
| 2705 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2706 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2707 | rdev->wiphy.max_num_csa_counters)) |
| 2708 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2709 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 2710 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2711 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2712 | goto nla_put_failure; |
| 2713 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 2714 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2715 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2716 | rdev->wiphy.max_sched_scan_reqs)) |
| 2717 | goto nla_put_failure; |
| 2718 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2719 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2720 | sizeof(rdev->wiphy.ext_features), |
| 2721 | rdev->wiphy.ext_features)) |
| 2722 | goto nla_put_failure; |
| 2723 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2724 | if (rdev->wiphy.bss_select_support) { |
| 2725 | struct nlattr *nested; |
| 2726 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2727 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2728 | nested = nla_nest_start_noflag(msg, |
| 2729 | NL80211_ATTR_BSS_SELECT); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2730 | if (!nested) |
| 2731 | goto nla_put_failure; |
| 2732 | |
| 2733 | i = 0; |
| 2734 | while (bss_select_support) { |
| 2735 | if ((bss_select_support & 1) && |
| 2736 | nla_put_flag(msg, i)) |
| 2737 | goto nla_put_failure; |
| 2738 | i++; |
| 2739 | bss_select_support >>= 1; |
| 2740 | } |
| 2741 | nla_nest_end(msg, nested); |
| 2742 | } |
| 2743 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2744 | state->split_start++; |
| 2745 | break; |
| 2746 | case 13: |
| 2747 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2748 | rdev->wiphy.iftype_ext_capab) { |
| 2749 | struct nlattr *nested_ext_capab, *nested; |
| 2750 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2751 | nested = nla_nest_start_noflag(msg, |
| 2752 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2753 | if (!nested) |
| 2754 | goto nla_put_failure; |
| 2755 | |
| 2756 | for (i = state->capa_start; |
| 2757 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2758 | const struct wiphy_iftype_ext_capab *capab; |
| 2759 | |
| 2760 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2761 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2762 | nested_ext_capab = nla_nest_start_noflag(msg, |
| 2763 | i); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2764 | if (!nested_ext_capab || |
| 2765 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2766 | capab->iftype) || |
| 2767 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2768 | capab->extended_capabilities_len, |
| 2769 | capab->extended_capabilities) || |
| 2770 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2771 | capab->extended_capabilities_len, |
| 2772 | capab->extended_capabilities_mask)) |
| 2773 | goto nla_put_failure; |
| 2774 | |
| 2775 | nla_nest_end(msg, nested_ext_capab); |
| 2776 | if (state->split) |
| 2777 | break; |
| 2778 | } |
| 2779 | nla_nest_end(msg, nested); |
| 2780 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2781 | state->capa_start = i + 1; |
| 2782 | break; |
| 2783 | } |
| 2784 | } |
| 2785 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2786 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2787 | rdev->wiphy.nan_supported_bands)) |
| 2788 | goto nla_put_failure; |
| 2789 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2790 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2791 | NL80211_EXT_FEATURE_TXQS)) { |
| 2792 | struct cfg80211_txq_stats txqstats = {}; |
| 2793 | int res; |
| 2794 | |
| 2795 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2796 | if (!res && |
| 2797 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2798 | NL80211_ATTR_TXQ_STATS)) |
| 2799 | goto nla_put_failure; |
| 2800 | |
| 2801 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2802 | rdev->wiphy.txq_limit)) |
| 2803 | goto nla_put_failure; |
| 2804 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2805 | rdev->wiphy.txq_memory_limit)) |
| 2806 | goto nla_put_failure; |
| 2807 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2808 | rdev->wiphy.txq_quantum)) |
| 2809 | goto nla_put_failure; |
| 2810 | } |
| 2811 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2812 | state->split_start++; |
| 2813 | break; |
| 2814 | case 14: |
| 2815 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2816 | goto nla_put_failure; |
| 2817 | |
Veerendranath Jakkam | ab4dfa2 | 2018-12-19 22:52:25 +0530 | [diff] [blame] | 2818 | state->split_start++; |
| 2819 | break; |
| 2820 | case 15: |
| 2821 | if (rdev->wiphy.akm_suites && |
| 2822 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2823 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2824 | rdev->wiphy.akm_suites)) |
| 2825 | goto nla_put_failure; |
| 2826 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2827 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
| 2828 | goto nla_put_failure; |
| 2829 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2830 | if (nl80211_put_tid_config_support(rdev, msg)) |
| 2831 | goto nla_put_failure; |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 2832 | state->split_start++; |
| 2833 | break; |
| 2834 | case 16: |
| 2835 | if (nl80211_put_sar_specs(rdev, msg)) |
| 2836 | goto nla_put_failure; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2837 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 2838 | if (nl80211_put_mbssid_support(&rdev->wiphy, msg)) |
| 2839 | goto nla_put_failure; |
| 2840 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2841 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2842 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2843 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2844 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2845 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2846 | genlmsg_end(msg, hdr); |
| 2847 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2848 | |
| 2849 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2850 | genlmsg_cancel(msg, hdr); |
| 2851 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2854 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2855 | struct netlink_callback *cb, |
| 2856 | struct nl80211_dump_wiphy_state *state) |
| 2857 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2858 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 2859 | int ret; |
| 2860 | |
| 2861 | if (!tb) |
| 2862 | return -ENOMEM; |
| 2863 | |
| 2864 | ret = nlmsg_parse_deprecated(cb->nlh, |
| 2865 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2866 | tb, nl80211_fam.maxattr, |
| 2867 | nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2868 | /* ignore parse errors for backward compatibility */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2869 | if (ret) { |
| 2870 | ret = 0; |
| 2871 | goto out; |
| 2872 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2873 | |
| 2874 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2875 | if (tb[NL80211_ATTR_WIPHY]) |
| 2876 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2877 | if (tb[NL80211_ATTR_WDEV]) |
| 2878 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2879 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2880 | struct net_device *netdev; |
| 2881 | struct cfg80211_registered_device *rdev; |
| 2882 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2883 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2884 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2885 | if (!netdev) { |
| 2886 | ret = -ENODEV; |
| 2887 | goto out; |
| 2888 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2889 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2890 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2891 | netdev->ieee80211_ptr->wiphy); |
| 2892 | state->filter_wiphy = rdev->wiphy_idx; |
| 2893 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2894 | } |
| 2895 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2896 | ret = 0; |
| 2897 | out: |
| 2898 | kfree(tb); |
| 2899 | return ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2900 | } |
| 2901 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2902 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2903 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2904 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2905 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2906 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2907 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2908 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2909 | if (!state) { |
| 2910 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2911 | if (!state) { |
| 2912 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2913 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2914 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2915 | state->filter_wiphy = -1; |
| 2916 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2917 | if (ret) { |
| 2918 | kfree(state); |
| 2919 | rtnl_unlock(); |
| 2920 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2921 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2922 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2923 | } |
| 2924 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2925 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2926 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2927 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2928 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2929 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2930 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2931 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2932 | continue; |
| 2933 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2934 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2935 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2936 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2937 | NETLINK_CB(cb->skb).portid, |
| 2938 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2939 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2940 | if (ret < 0) { |
| 2941 | /* |
| 2942 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2943 | * or EMSGSIZE returned), this SKB is still |
| 2944 | * empty (so it's not too big because another |
| 2945 | * wiphy dataset is already in the skb) and |
| 2946 | * we've not tried to adjust the dump allocation |
| 2947 | * yet ... then adjust the alloc size to be |
| 2948 | * bigger, and return 1 but with the empty skb. |
| 2949 | * This results in an empty message being RX'ed |
| 2950 | * in userspace, but that is ignored. |
| 2951 | * |
| 2952 | * We can then retry with the larger buffer. |
| 2953 | */ |
| 2954 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2955 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2956 | cb->min_dump_alloc < 4096) { |
| 2957 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2958 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2959 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2960 | return 1; |
| 2961 | } |
| 2962 | idx--; |
| 2963 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2964 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2965 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2966 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2967 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2968 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2969 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2970 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2971 | |
| 2972 | return skb->len; |
| 2973 | } |
| 2974 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2975 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2976 | { |
| 2977 | kfree((void *)cb->args[0]); |
| 2978 | return 0; |
| 2979 | } |
| 2980 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2981 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2982 | { |
| 2983 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2984 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2985 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2986 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2987 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2988 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2989 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2990 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2991 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2992 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2993 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2994 | nlmsg_free(msg); |
| 2995 | return -ENOBUFS; |
| 2996 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2997 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2998 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2999 | } |
| 3000 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3001 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 3002 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 3003 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 3004 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 3005 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 3006 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 3007 | }; |
| 3008 | |
| 3009 | static int parse_txq_params(struct nlattr *tb[], |
| 3010 | struct ieee80211_txq_params *txq_params) |
| 3011 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 3012 | u8 ac; |
| 3013 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 3014 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3015 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 3016 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 3017 | return -EINVAL; |
| 3018 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 3019 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3020 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 3021 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 3022 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 3023 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 3024 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 3025 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 3026 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 3027 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3028 | return 0; |
| 3029 | } |
| 3030 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3031 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 3032 | { |
| 3033 | /* |
Johannes Berg | e7e0517 | 2020-11-09 10:57:47 +0100 | [diff] [blame] | 3034 | * You can only set the channel explicitly for some interfaces, |
| 3035 | * most have their channel managed via their respective |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3036 | * "establish a connection" command (connect, join, ...) |
| 3037 | * |
| 3038 | * For AP/GO and mesh mode, the channel can be set with the |
| 3039 | * channel userspace API, but is only stored and passed to the |
| 3040 | * low-level driver when the AP starts or the mesh is joined. |
| 3041 | * This is for backward compatibility, userspace can also give |
| 3042 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3043 | * |
| 3044 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3045 | * whatever else is going on, so they have their own special |
| 3046 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3047 | */ |
| 3048 | return !wdev || |
| 3049 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3050 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 3051 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 3052 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3053 | } |
| 3054 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 3055 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 3056 | struct genl_info *info, |
| 3057 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3058 | { |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3059 | struct netlink_ext_ack *extack = info->extack; |
| 3060 | struct nlattr **attrs = info->attrs; |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 3061 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3062 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3063 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3064 | return -EINVAL; |
| 3065 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3066 | control_freq = MHZ_TO_KHZ( |
| 3067 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3068 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 3069 | control_freq += |
| 3070 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3071 | |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 3072 | memset(chandef, 0, sizeof(*chandef)); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3073 | chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3074 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3075 | chandef->center_freq1 = KHZ_TO_MHZ(control_freq); |
| 3076 | chandef->freq1_offset = control_freq % 1000; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3077 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3078 | |
| 3079 | /* Primary channel not allowed */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3080 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 3081 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 3082 | "Channel is disabled"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3083 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3084 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3085 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3086 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3087 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3088 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3089 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3090 | |
| 3091 | switch (chantype) { |
| 3092 | case NL80211_CHAN_NO_HT: |
| 3093 | case NL80211_CHAN_HT20: |
| 3094 | case NL80211_CHAN_HT40PLUS: |
| 3095 | case NL80211_CHAN_HT40MINUS: |
| 3096 | cfg80211_chandef_create(chandef, chandef->chan, |
| 3097 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 3098 | /* user input for center_freq is incorrect */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3099 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 3100 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 3101 | NL_SET_ERR_MSG_ATTR(extack, |
| 3102 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 3103 | "bad center frequency 1"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 3104 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3105 | } |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 3106 | /* center_freq2 must be zero */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3107 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 3108 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 3109 | NL_SET_ERR_MSG_ATTR(extack, |
| 3110 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 3111 | "center frequency 2 can't be used"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 3112 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3113 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3114 | break; |
| 3115 | default: |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3116 | NL_SET_ERR_MSG_ATTR(extack, |
| 3117 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 3118 | "invalid channel type"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3119 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3120 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3121 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3122 | chandef->width = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3123 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3124 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3125 | chandef->center_freq1 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3126 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3127 | if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) |
| 3128 | chandef->freq1_offset = nla_get_u32( |
| 3129 | attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); |
| 3130 | else |
| 3131 | chandef->freq1_offset = 0; |
| 3132 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3133 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3134 | chandef->center_freq2 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3135 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3136 | } |
| 3137 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 3138 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 3139 | chandef->edmg.channels = |
| 3140 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 3141 | |
| 3142 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 3143 | chandef->edmg.bw_config = |
| 3144 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 3145 | } else { |
| 3146 | chandef->edmg.bw_config = 0; |
| 3147 | chandef->edmg.channels = 0; |
| 3148 | } |
| 3149 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3150 | if (!cfg80211_chandef_valid(chandef)) { |
| 3151 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3152 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3153 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3154 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 3155 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3156 | IEEE80211_CHAN_DISABLED)) { |
| 3157 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3158 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3159 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3160 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 3161 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 3162 | chandef->width == NL80211_CHAN_WIDTH_10) && |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3163 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 3164 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 3165 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 3166 | } |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 3167 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3168 | return 0; |
| 3169 | } |
| 3170 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3171 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3172 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3173 | struct genl_info *info) |
| 3174 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3175 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3176 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3177 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3178 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3179 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3180 | if (dev) |
| 3181 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3182 | if (!nl80211_can_set_dev_channel(wdev)) |
| 3183 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3184 | if (wdev) |
| 3185 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3186 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3187 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 3188 | if (result) |
| 3189 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3190 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3191 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3192 | case NL80211_IFTYPE_AP: |
| 3193 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3194 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 3195 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3196 | result = -EINVAL; |
| 3197 | break; |
| 3198 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3199 | if (wdev->beacon_interval) { |
| 3200 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 3201 | !(rdev->wiphy.features & |
| 3202 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 3203 | result = -EBUSY; |
| 3204 | break; |
| 3205 | } |
| 3206 | |
| 3207 | /* Only allow dynamic channel width changes */ |
| 3208 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 3209 | result = -EBUSY; |
| 3210 | break; |
| 3211 | } |
| 3212 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 3213 | if (result) |
| 3214 | break; |
| 3215 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3216 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3217 | result = 0; |
| 3218 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3219 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3220 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3221 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3222 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3223 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3224 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3225 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3226 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3227 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3228 | |
| 3229 | return result; |
| 3230 | } |
| 3231 | |
| 3232 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 3233 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3234 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3235 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3236 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3237 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3238 | } |
| 3239 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3240 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 3241 | { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3242 | struct cfg80211_registered_device *rdev = NULL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3243 | struct net_device *netdev = NULL; |
| 3244 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 3245 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3246 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3247 | u32 changed; |
| 3248 | u8 retry_short = 0, retry_long = 0; |
| 3249 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3250 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3251 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3252 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3253 | rtnl_lock(); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3254 | /* |
| 3255 | * Try to find the wiphy and netdev. Normally this |
| 3256 | * function shouldn't need the netdev, but this is |
| 3257 | * done for backward compatibility -- previously |
| 3258 | * setting the channel was done per wiphy, but now |
| 3259 | * it is per netdev. Previous userland like hostapd |
| 3260 | * also passed a netdev to set_wiphy, so that it is |
| 3261 | * possible to let that go to the right netdev! |
| 3262 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3263 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3264 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 3265 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 3266 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3267 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3268 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 3269 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3270 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3271 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3272 | } |
| 3273 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3274 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 3275 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 3276 | info->attrs); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3277 | if (IS_ERR(rdev)) { |
| 3278 | rtnl_unlock(); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3279 | return PTR_ERR(rdev); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3280 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3281 | wdev = NULL; |
| 3282 | netdev = NULL; |
| 3283 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 3284 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3285 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3286 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3287 | wiphy_lock(&rdev->wiphy); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3288 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3289 | /* |
| 3290 | * end workaround code, by now the rdev is available |
| 3291 | * and locked, and wdev may or may not be NULL. |
| 3292 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3293 | |
| 3294 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3295 | result = cfg80211_dev_rename( |
| 3296 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 0391a45 | 2021-01-28 18:35:25 +0100 | [diff] [blame] | 3297 | rtnl_unlock(); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3298 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3299 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3300 | goto out; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3301 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3302 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 3303 | struct ieee80211_txq_params txq_params; |
| 3304 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 3305 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3306 | if (!rdev->ops->set_txq_params) { |
| 3307 | result = -EOPNOTSUPP; |
| 3308 | goto out; |
| 3309 | } |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3310 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3311 | if (!netdev) { |
| 3312 | result = -EINVAL; |
| 3313 | goto out; |
| 3314 | } |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 3315 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3316 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3317 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 3318 | result = -EINVAL; |
| 3319 | goto out; |
| 3320 | } |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3321 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3322 | if (!netif_running(netdev)) { |
| 3323 | result = -ENETDOWN; |
| 3324 | goto out; |
| 3325 | } |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 3326 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3327 | nla_for_each_nested(nl_txq_params, |
| 3328 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 3329 | rem_txq_params) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3330 | result = nla_parse_nested_deprecated(tb, |
| 3331 | NL80211_TXQ_ATTR_MAX, |
| 3332 | nl_txq_params, |
| 3333 | txq_params_policy, |
| 3334 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 3335 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3336 | goto out; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3337 | result = parse_txq_params(tb, &txq_params); |
| 3338 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3339 | goto out; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3340 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3341 | result = rdev_set_txq_params(rdev, netdev, |
| 3342 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3343 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3344 | goto out; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3345 | } |
| 3346 | } |
| 3347 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3348 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3349 | result = __nl80211_set_channel( |
| 3350 | rdev, |
| 3351 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 3352 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3353 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3354 | goto out; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3355 | } |
| 3356 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3357 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3358 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3359 | enum nl80211_tx_power_setting type; |
| 3360 | int idx, mbm = 0; |
| 3361 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3362 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 3363 | txp_wdev = NULL; |
| 3364 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3365 | if (!rdev->ops->set_tx_power) { |
| 3366 | result = -EOPNOTSUPP; |
| 3367 | goto out; |
| 3368 | } |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3369 | |
| 3370 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 3371 | type = nla_get_u32(info->attrs[idx]); |
| 3372 | |
| 3373 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3374 | (type != NL80211_TX_POWER_AUTOMATIC)) { |
| 3375 | result = -EINVAL; |
| 3376 | goto out; |
| 3377 | } |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3378 | |
| 3379 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 3380 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 3381 | mbm = nla_get_u32(info->attrs[idx]); |
| 3382 | } |
| 3383 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3384 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3385 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3386 | goto out; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3387 | } |
| 3388 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3389 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 3390 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 3391 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3392 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3393 | if ((!rdev->wiphy.available_antennas_tx && |
| 3394 | !rdev->wiphy.available_antennas_rx) || |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3395 | !rdev->ops->set_antenna) { |
| 3396 | result = -EOPNOTSUPP; |
| 3397 | goto out; |
| 3398 | } |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3399 | |
| 3400 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 3401 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 3402 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3403 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3404 | * available antenna masks, except for the "all" mask */ |
| 3405 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3406 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { |
| 3407 | result = -EINVAL; |
| 3408 | goto out; |
| 3409 | } |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3410 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3411 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 3412 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3413 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3414 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3415 | if (result) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3416 | goto out; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3417 | } |
| 3418 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3419 | changed = 0; |
| 3420 | |
| 3421 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 3422 | retry_short = nla_get_u8( |
| 3423 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3424 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3425 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 3426 | } |
| 3427 | |
| 3428 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 3429 | retry_long = nla_get_u8( |
| 3430 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3431 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3432 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 3433 | } |
| 3434 | |
| 3435 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 3436 | frag_threshold = nla_get_u32( |
| 3437 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3438 | if (frag_threshold < 256) { |
| 3439 | result = -EINVAL; |
| 3440 | goto out; |
| 3441 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3442 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3443 | if (frag_threshold != (u32) -1) { |
| 3444 | /* |
| 3445 | * Fragments (apart from the last one) are required to |
| 3446 | * have even length. Make the fragmentation code |
| 3447 | * simpler by stripping LSB should someone try to use |
| 3448 | * odd threshold value. |
| 3449 | */ |
| 3450 | frag_threshold &= ~0x1; |
| 3451 | } |
| 3452 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 3453 | } |
| 3454 | |
| 3455 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 3456 | rts_threshold = nla_get_u32( |
| 3457 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 3458 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 3459 | } |
| 3460 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3461 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3462 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 3463 | result = -EINVAL; |
| 3464 | goto out; |
| 3465 | } |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3466 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3467 | coverage_class = nla_get_u8( |
| 3468 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 3469 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 3470 | } |
| 3471 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3472 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3473 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) { |
| 3474 | result = -EOPNOTSUPP; |
| 3475 | goto out; |
| 3476 | } |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3477 | |
| 3478 | changed |= WIPHY_PARAM_DYN_ACK; |
| 3479 | } |
| 3480 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3481 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 3482 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3483 | NL80211_EXT_FEATURE_TXQS)) { |
| 3484 | result = -EOPNOTSUPP; |
| 3485 | goto out; |
| 3486 | } |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3487 | txq_limit = nla_get_u32( |
| 3488 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 3489 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 3490 | } |
| 3491 | |
| 3492 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 3493 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3494 | NL80211_EXT_FEATURE_TXQS)) { |
| 3495 | result = -EOPNOTSUPP; |
| 3496 | goto out; |
| 3497 | } |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3498 | txq_memory_limit = nla_get_u32( |
| 3499 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 3500 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 3501 | } |
| 3502 | |
| 3503 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 3504 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3505 | NL80211_EXT_FEATURE_TXQS)) { |
| 3506 | result = -EOPNOTSUPP; |
| 3507 | goto out; |
| 3508 | } |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3509 | txq_quantum = nla_get_u32( |
| 3510 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 3511 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 3512 | } |
| 3513 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3514 | if (changed) { |
| 3515 | u8 old_retry_short, old_retry_long; |
| 3516 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3517 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3518 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3519 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3520 | if (!rdev->ops->set_wiphy_params) { |
| 3521 | result = -EOPNOTSUPP; |
| 3522 | goto out; |
| 3523 | } |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3524 | |
| 3525 | old_retry_short = rdev->wiphy.retry_short; |
| 3526 | old_retry_long = rdev->wiphy.retry_long; |
| 3527 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 3528 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3529 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3530 | old_txq_limit = rdev->wiphy.txq_limit; |
| 3531 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 3532 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3533 | |
| 3534 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 3535 | rdev->wiphy.retry_short = retry_short; |
| 3536 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 3537 | rdev->wiphy.retry_long = retry_long; |
| 3538 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 3539 | rdev->wiphy.frag_threshold = frag_threshold; |
| 3540 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 3541 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3542 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 3543 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3544 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 3545 | rdev->wiphy.txq_limit = txq_limit; |
| 3546 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 3547 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 3548 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 3549 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3550 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3551 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3552 | if (result) { |
| 3553 | rdev->wiphy.retry_short = old_retry_short; |
| 3554 | rdev->wiphy.retry_long = old_retry_long; |
| 3555 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 3556 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3557 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3558 | rdev->wiphy.txq_limit = old_txq_limit; |
| 3559 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 3560 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3561 | goto out; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3562 | } |
| 3563 | } |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 3564 | |
| 3565 | result = 0; |
| 3566 | |
| 3567 | out: |
| 3568 | wiphy_unlock(&rdev->wiphy); |
| 3569 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3570 | } |
| 3571 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3572 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 3573 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3574 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 3575 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 3576 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3577 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3578 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 3579 | chandef->chan->center_freq)) |
| 3580 | return -ENOBUFS; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3581 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 3582 | chandef->chan->freq_offset)) |
| 3583 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3584 | switch (chandef->width) { |
| 3585 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3586 | case NL80211_CHAN_WIDTH_20: |
| 3587 | case NL80211_CHAN_WIDTH_40: |
| 3588 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3589 | cfg80211_get_chandef_type(chandef))) |
| 3590 | return -ENOBUFS; |
| 3591 | break; |
| 3592 | default: |
| 3593 | break; |
| 3594 | } |
| 3595 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 3596 | return -ENOBUFS; |
| 3597 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 3598 | return -ENOBUFS; |
| 3599 | if (chandef->center_freq2 && |
| 3600 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3601 | return -ENOBUFS; |
| 3602 | return 0; |
| 3603 | } |
| 3604 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3605 | 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] | 3606 | struct cfg80211_registered_device *rdev, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3607 | struct wireless_dev *wdev, |
| 3608 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3609 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3610 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3611 | void *hdr; |
| 3612 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3613 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3614 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3615 | cmd != NL80211_CMD_SET_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3616 | |
| 3617 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3618 | if (!hdr) |
| 3619 | return -1; |
| 3620 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3621 | if (dev && |
| 3622 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3623 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3624 | goto nla_put_failure; |
| 3625 | |
| 3626 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3627 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 3628 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3629 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3630 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3631 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3632 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 3633 | (cfg80211_rdev_list_generation << 2)) || |
| 3634 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3635 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3636 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3637 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3638 | int ret; |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 3639 | struct cfg80211_chan_def chandef = {}; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3640 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3641 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3642 | if (ret == 0) { |
| 3643 | if (nl80211_send_chandef(msg, &chandef)) |
| 3644 | goto nla_put_failure; |
| 3645 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 3646 | } |
| 3647 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 3648 | if (rdev->ops->get_tx_power) { |
| 3649 | int dbm, ret; |
| 3650 | |
| 3651 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3652 | if (ret == 0 && |
| 3653 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3654 | DBM_TO_MBM(dbm))) |
| 3655 | goto nla_put_failure; |
| 3656 | } |
| 3657 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3658 | wdev_lock(wdev); |
| 3659 | switch (wdev->iftype) { |
| 3660 | case NL80211_IFTYPE_AP: |
| 3661 | if (wdev->ssid_len && |
| 3662 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3663 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3664 | break; |
| 3665 | case NL80211_IFTYPE_STATION: |
| 3666 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3667 | case NL80211_IFTYPE_ADHOC: { |
| 3668 | const u8 *ssid_ie; |
| 3669 | if (!wdev->current_bss) |
| 3670 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3671 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3672 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3673 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3674 | if (ssid_ie && |
| 3675 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3676 | goto nla_put_failure_rcu_locked; |
| 3677 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3678 | break; |
| 3679 | } |
| 3680 | default: |
| 3681 | /* nothing */ |
| 3682 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3683 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3684 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3685 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3686 | if (rdev->ops->get_txq_stats) { |
| 3687 | struct cfg80211_txq_stats txqstats = {}; |
| 3688 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3689 | |
| 3690 | if (ret == 0 && |
| 3691 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3692 | NL80211_ATTR_TXQ_STATS)) |
| 3693 | goto nla_put_failure; |
| 3694 | } |
| 3695 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3696 | genlmsg_end(msg, hdr); |
| 3697 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3698 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3699 | nla_put_failure_rcu_locked: |
| 3700 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3701 | nla_put_failure_locked: |
| 3702 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3703 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3704 | genlmsg_cancel(msg, hdr); |
| 3705 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3706 | } |
| 3707 | |
| 3708 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3709 | { |
| 3710 | int wp_idx = 0; |
| 3711 | int if_idx = 0; |
| 3712 | int wp_start = cb->args[0]; |
| 3713 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3714 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3715 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3716 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3717 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3718 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3719 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3720 | if (!cb->args[2]) { |
| 3721 | struct nl80211_dump_wiphy_state state = { |
| 3722 | .filter_wiphy = -1, |
| 3723 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3724 | |
| 3725 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3726 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3727 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3728 | |
| 3729 | filter_wiphy = state.filter_wiphy; |
| 3730 | |
| 3731 | /* |
| 3732 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3733 | * value needed to determine that parsing is necessary. |
| 3734 | */ |
| 3735 | if (filter_wiphy >= 0) |
| 3736 | cb->args[2] = filter_wiphy + 1; |
| 3737 | else |
| 3738 | cb->args[2] = -1; |
| 3739 | } else if (cb->args[2] > 0) { |
| 3740 | filter_wiphy = cb->args[2] - 1; |
| 3741 | } |
| 3742 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3743 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3744 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3745 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3746 | if (wp_idx < wp_start) { |
| 3747 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3748 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3749 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3750 | |
| 3751 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3752 | continue; |
| 3753 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3754 | if_idx = 0; |
| 3755 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3756 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3757 | if (if_idx < if_start) { |
| 3758 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3759 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3760 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3761 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3762 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3763 | rdev, wdev, |
| 3764 | NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3765 | goto out; |
| 3766 | } |
| 3767 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3768 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3769 | |
| 3770 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3771 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3772 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3773 | cb->args[0] = wp_idx; |
| 3774 | cb->args[1] = if_idx; |
| 3775 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3776 | ret = skb->len; |
| 3777 | out_unlock: |
| 3778 | rtnl_unlock(); |
| 3779 | |
| 3780 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3784 | { |
| 3785 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3787 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3788 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3789 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3790 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3791 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3792 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3793 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3794 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3795 | nlmsg_free(msg); |
| 3796 | return -ENOBUFS; |
| 3797 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3798 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3799 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3800 | } |
| 3801 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3802 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3803 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3804 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3805 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3806 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3807 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3808 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3809 | }; |
| 3810 | |
| 3811 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3812 | { |
| 3813 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3814 | int flag; |
| 3815 | |
| 3816 | *mntrflags = 0; |
| 3817 | |
| 3818 | if (!nla) |
| 3819 | return -EINVAL; |
| 3820 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3821 | 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] | 3822 | return -EINVAL; |
| 3823 | |
| 3824 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3825 | if (flags[flag]) |
| 3826 | *mntrflags |= (1<<flag); |
| 3827 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3828 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3829 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3830 | return 0; |
| 3831 | } |
| 3832 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3833 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3834 | enum nl80211_iftype type, |
| 3835 | struct genl_info *info, |
| 3836 | struct vif_params *params) |
| 3837 | { |
| 3838 | bool change = false; |
| 3839 | int err; |
| 3840 | |
| 3841 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3842 | if (type != NL80211_IFTYPE_MONITOR) |
| 3843 | return -EINVAL; |
| 3844 | |
| 3845 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3846 | ¶ms->flags); |
| 3847 | if (err) |
| 3848 | return err; |
| 3849 | |
| 3850 | change = true; |
| 3851 | } |
| 3852 | |
| 3853 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3854 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3855 | return -EOPNOTSUPP; |
| 3856 | |
| 3857 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3858 | const u8 *mumimo_groups; |
| 3859 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3860 | |
| 3861 | if (type != NL80211_IFTYPE_MONITOR) |
| 3862 | return -EINVAL; |
| 3863 | |
| 3864 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3865 | return -EOPNOTSUPP; |
| 3866 | |
| 3867 | mumimo_groups = |
| 3868 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3869 | |
| 3870 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3871 | if ((mumimo_groups[0] & BIT(0)) || |
| 3872 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3873 | return -EINVAL; |
| 3874 | |
| 3875 | params->vht_mumimo_groups = mumimo_groups; |
| 3876 | change = true; |
| 3877 | } |
| 3878 | |
| 3879 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3880 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3881 | |
| 3882 | if (type != NL80211_IFTYPE_MONITOR) |
| 3883 | return -EINVAL; |
| 3884 | |
| 3885 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3886 | return -EOPNOTSUPP; |
| 3887 | |
| 3888 | params->vht_mumimo_follow_addr = |
| 3889 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3890 | change = true; |
| 3891 | } |
| 3892 | |
| 3893 | return change ? 1 : 0; |
| 3894 | } |
| 3895 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3896 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3897 | struct net_device *netdev, u8 use_4addr, |
| 3898 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3899 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3900 | if (!use_4addr) { |
Julian Wiedmann | 2e92a2d | 2020-02-20 09:00:07 +0100 | [diff] [blame] | 3901 | if (netdev && netif_is_bridge_port(netdev)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3902 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3903 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3904 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3905 | |
| 3906 | switch (iftype) { |
| 3907 | case NL80211_IFTYPE_AP_VLAN: |
| 3908 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3909 | return 0; |
| 3910 | break; |
| 3911 | case NL80211_IFTYPE_STATION: |
| 3912 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3913 | return 0; |
| 3914 | break; |
| 3915 | default: |
| 3916 | break; |
| 3917 | } |
| 3918 | |
| 3919 | return -EOPNOTSUPP; |
| 3920 | } |
| 3921 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3922 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3923 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3925 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3926 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3927 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3928 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3929 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3930 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3931 | memset(¶ms, 0, sizeof(params)); |
| 3932 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3933 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3934 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3935 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3936 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3937 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3938 | change = true; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3939 | } |
| 3940 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3941 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3942 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3943 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3944 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3945 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3946 | if (netif_running(dev)) |
| 3947 | return -EBUSY; |
| 3948 | |
| 3949 | wdev_lock(wdev); |
| 3950 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3951 | IEEE80211_MAX_MESH_ID_LEN); |
| 3952 | wdev->mesh_id_up_len = |
| 3953 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3954 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3955 | wdev->mesh_id_up_len); |
| 3956 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3957 | } |
| 3958 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3959 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3960 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3961 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3962 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3963 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3964 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3965 | } else { |
| 3966 | params.use_4addr = -1; |
| 3967 | } |
| 3968 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3969 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3970 | if (err < 0) |
| 3971 | return err; |
| 3972 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3973 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3974 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3975 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3976 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3977 | else |
| 3978 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3979 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3980 | if (!err && params.use_4addr != -1) |
| 3981 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3982 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3983 | if (change && !err) { |
| 3984 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3985 | |
| 3986 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3987 | } |
| 3988 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3989 | return err; |
| 3990 | } |
| 3991 | |
Johannes Berg | ea6b209 | 2021-04-27 11:49:52 +0200 | [diff] [blame] | 3992 | static int _nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3993 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3994 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3995 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3996 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3997 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3998 | int err; |
| 3999 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 4000 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4001 | memset(¶ms, 0, sizeof(params)); |
| 4002 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4003 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 4004 | return -EINVAL; |
| 4005 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 4006 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4007 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4008 | |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 4009 | if (!rdev->ops->add_virtual_intf) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4010 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4011 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 4012 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 4013 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 4014 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 4015 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 4016 | ETH_ALEN); |
| 4017 | if (!is_valid_ether_addr(params.macaddr)) |
| 4018 | return -EADDRNOTAVAIL; |
| 4019 | } |
| 4020 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 4021 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 4022 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 4023 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 4024 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4025 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 4026 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 4027 | |
Manikanta Pubbisetty | e6f4051 | 2019-07-22 12:44:50 +0530 | [diff] [blame] | 4028 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 4029 | return -EOPNOTSUPP; |
| 4030 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 4031 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 4032 | if (err < 0) |
| 4033 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 4034 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 4035 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 4036 | if (!msg) |
| 4037 | return -ENOMEM; |
| 4038 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4039 | wdev = rdev_add_virtual_intf(rdev, |
| 4040 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 4041 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 4042 | if (WARN_ON(!wdev)) { |
| 4043 | nlmsg_free(msg); |
| 4044 | return -EPROTO; |
| 4045 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 4046 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 4047 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 4048 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4049 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 4050 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 4051 | wdev->owner_nlportid = info->snd_portid; |
| 4052 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 4053 | switch (type) { |
| 4054 | case NL80211_IFTYPE_MESH_POINT: |
| 4055 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 4056 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4057 | wdev_lock(wdev); |
| 4058 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 4059 | IEEE80211_MAX_MESH_ID_LEN); |
| 4060 | wdev->mesh_id_up_len = |
| 4061 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 4062 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 4063 | wdev->mesh_id_up_len); |
| 4064 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 4065 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 4066 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 4067 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4068 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 4069 | * 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] | 4070 | * through the netdev notifier and must be added here |
| 4071 | */ |
Johannes Berg | 9bdaf3b | 2020-10-09 13:58:22 +0200 | [diff] [blame] | 4072 | cfg80211_init_wdev(wdev); |
| 4073 | cfg80211_register_wdev(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 4074 | break; |
| 4075 | default: |
| 4076 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4079 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 4080 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 4081 | nlmsg_free(msg); |
| 4082 | return -ENOBUFS; |
| 4083 | } |
| 4084 | |
| 4085 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4086 | } |
| 4087 | |
Johannes Berg | ea6b209 | 2021-04-27 11:49:52 +0200 | [diff] [blame] | 4088 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 4089 | { |
| 4090 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4091 | int ret; |
| 4092 | |
| 4093 | /* to avoid failing a new interface creation due to pending removal */ |
| 4094 | cfg80211_destroy_ifaces(rdev); |
| 4095 | |
| 4096 | wiphy_lock(&rdev->wiphy); |
| 4097 | ret = _nl80211_new_interface(skb, info); |
| 4098 | wiphy_unlock(&rdev->wiphy); |
| 4099 | |
| 4100 | return ret; |
| 4101 | } |
| 4102 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4103 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 4104 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 4106 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4107 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4108 | if (!rdev->ops->del_virtual_intf) |
| 4109 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4110 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 4111 | /* |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 4112 | * We hold RTNL, so this is safe, without RTNL opencount cannot |
| 4113 | * reach 0, and thus the rdev cannot be deleted. |
| 4114 | * |
| 4115 | * We need to do it for the dev_close(), since that will call |
| 4116 | * the netdev notifiers, and we need to acquire the mutex there |
| 4117 | * but don't know if we get there from here or from some other |
| 4118 | * place (e.g. "ip link set ... down"). |
| 4119 | */ |
| 4120 | mutex_unlock(&rdev->wiphy.mtx); |
| 4121 | |
| 4122 | /* |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 4123 | * If we remove a wireless device without a netdev then clear |
| 4124 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 4125 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 4126 | * since the wdev has been freed, unlike with a netdev where |
| 4127 | * we need the dev_put() for the netdev to really be freed. |
| 4128 | */ |
| 4129 | if (!wdev->netdev) |
| 4130 | info->user_ptr[1] = NULL; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 4131 | else |
| 4132 | dev_close(wdev->netdev); |
| 4133 | |
| 4134 | mutex_lock(&rdev->wiphy.mtx); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 4135 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 4136 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4137 | } |
| 4138 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 4139 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 4140 | { |
| 4141 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4142 | struct net_device *dev = info->user_ptr[1]; |
| 4143 | u16 noack_map; |
| 4144 | |
| 4145 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 4146 | return -EINVAL; |
| 4147 | |
| 4148 | if (!rdev->ops->set_noack_map) |
| 4149 | return -EOPNOTSUPP; |
| 4150 | |
| 4151 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 4152 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4153 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 4154 | } |
| 4155 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4156 | struct get_key_cookie { |
| 4157 | struct sk_buff *msg; |
| 4158 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4159 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4160 | }; |
| 4161 | |
| 4162 | static void get_key_callback(void *c, struct key_params *params) |
| 4163 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4164 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4165 | struct get_key_cookie *cookie = c; |
| 4166 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4167 | if ((params->key && |
| 4168 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 4169 | params->key_len, params->key)) || |
| 4170 | (params->seq && |
| 4171 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 4172 | params->seq_len, params->seq)) || |
| 4173 | (params->cipher && |
| 4174 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 4175 | params->cipher))) |
| 4176 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4177 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 4178 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4179 | if (!key) |
| 4180 | goto nla_put_failure; |
| 4181 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4182 | if ((params->key && |
| 4183 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 4184 | params->key_len, params->key)) || |
| 4185 | (params->seq && |
| 4186 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 4187 | params->seq_len, params->seq)) || |
| 4188 | (params->cipher && |
| 4189 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 4190 | params->cipher))) |
| 4191 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4192 | |
Andrew Zaborowski | efdfce7 | 2018-09-24 18:10:22 +0200 | [diff] [blame] | 4193 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4194 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4195 | |
| 4196 | nla_nest_end(cookie->msg, key); |
| 4197 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4198 | return; |
| 4199 | nla_put_failure: |
| 4200 | cookie->error = 1; |
| 4201 | } |
| 4202 | |
| 4203 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 4204 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4205 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4206 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4207 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4208 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4209 | const u8 *mac_addr = NULL; |
| 4210 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4211 | struct get_key_cookie cookie = { |
| 4212 | .error = 0, |
| 4213 | }; |
| 4214 | void *hdr; |
| 4215 | struct sk_buff *msg; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 4216 | bool bigtk_support = false; |
| 4217 | |
| 4218 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 4219 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
| 4220 | bigtk_support = true; |
| 4221 | |
| 4222 | if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || |
| 4223 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && |
| 4224 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4225 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) |
| 4226 | bigtk_support = true; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4227 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4228 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4229 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 4230 | |
| 4231 | if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { |
| 4232 | GENL_SET_ERR_MSG(info, "BIGTK not supported"); |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4233 | return -EINVAL; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 4234 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4235 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4236 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4237 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4238 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4239 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4240 | pairwise = !!mac_addr; |
| 4241 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 4242 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 4243 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4244 | if (kt != NL80211_KEYTYPE_GROUP && |
| 4245 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 4246 | return -EINVAL; |
| 4247 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 4248 | } |
| 4249 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4250 | if (!rdev->ops->get_key) |
| 4251 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4252 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4253 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4254 | return -ENOENT; |
| 4255 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4256 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4257 | if (!msg) |
| 4258 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4259 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4260 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4261 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 4262 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 4263 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4264 | |
| 4265 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4266 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4267 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4268 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4269 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 4270 | goto nla_put_failure; |
| 4271 | if (mac_addr && |
| 4272 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 4273 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4274 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4275 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 4276 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4277 | |
| 4278 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 4279 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4280 | |
| 4281 | if (cookie.error) |
| 4282 | goto nla_put_failure; |
| 4283 | |
| 4284 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4285 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4286 | |
| 4287 | nla_put_failure: |
| 4288 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 4289 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4290 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4291 | return err; |
| 4292 | } |
| 4293 | |
| 4294 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 4295 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4296 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4297 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4298 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4299 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4300 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4301 | err = nl80211_parse_key(info, &key); |
| 4302 | if (err) |
| 4303 | return err; |
| 4304 | |
| 4305 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4306 | return -EINVAL; |
| 4307 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4308 | /* Only support setting default key and |
| 4309 | * Extended Key ID action NL80211_KEY_SET_TX. |
| 4310 | */ |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4311 | if (!key.def && !key.defmgmt && !key.defbeacon && |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4312 | !(key.p.mode == NL80211_KEY_SET_TX)) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4313 | return -EINVAL; |
| 4314 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4315 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4316 | |
| 4317 | if (key.def) { |
| 4318 | if (!rdev->ops->set_default_key) { |
| 4319 | err = -EOPNOTSUPP; |
| 4320 | goto out; |
| 4321 | } |
| 4322 | |
| 4323 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4324 | if (err) |
| 4325 | goto out; |
| 4326 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4327 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4328 | key.def_uni, key.def_multi); |
| 4329 | |
| 4330 | if (err) |
| 4331 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4332 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4333 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4334 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4335 | #endif |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4336 | } else if (key.defmgmt) { |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4337 | if (key.def_uni || !key.def_multi) { |
| 4338 | err = -EINVAL; |
| 4339 | goto out; |
| 4340 | } |
| 4341 | |
| 4342 | if (!rdev->ops->set_default_mgmt_key) { |
| 4343 | err = -EOPNOTSUPP; |
| 4344 | goto out; |
| 4345 | } |
| 4346 | |
| 4347 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4348 | if (err) |
| 4349 | goto out; |
| 4350 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4351 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4352 | if (err) |
| 4353 | goto out; |
| 4354 | |
| 4355 | #ifdef CONFIG_CFG80211_WEXT |
| 4356 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 4357 | #endif |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4358 | } else if (key.defbeacon) { |
| 4359 | if (key.def_uni || !key.def_multi) { |
| 4360 | err = -EINVAL; |
| 4361 | goto out; |
| 4362 | } |
| 4363 | |
| 4364 | if (!rdev->ops->set_default_beacon_key) { |
| 4365 | err = -EOPNOTSUPP; |
| 4366 | goto out; |
| 4367 | } |
| 4368 | |
| 4369 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4370 | if (err) |
| 4371 | goto out; |
| 4372 | |
| 4373 | err = rdev_set_default_beacon_key(rdev, dev, key.idx); |
| 4374 | if (err) |
| 4375 | goto out; |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4376 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
| 4377 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4378 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
| 4379 | u8 *mac_addr = NULL; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4380 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4381 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4382 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4383 | |
| 4384 | if (!mac_addr || key.idx < 0 || key.idx > 1) { |
| 4385 | err = -EINVAL; |
| 4386 | goto out; |
| 4387 | } |
| 4388 | |
| 4389 | err = rdev_add_key(rdev, dev, key.idx, |
| 4390 | NL80211_KEYTYPE_PAIRWISE, |
| 4391 | mac_addr, &key.p); |
| 4392 | } else { |
| 4393 | err = -EINVAL; |
| 4394 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4395 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4396 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4397 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4398 | return err; |
| 4399 | } |
| 4400 | |
| 4401 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 4402 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4403 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4404 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4405 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4406 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4407 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4408 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4409 | err = nl80211_parse_key(info, &key); |
| 4410 | if (err) |
| 4411 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4412 | |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4413 | if (!key.p.key) { |
| 4414 | GENL_SET_ERR_MSG(info, "no key"); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4415 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4416 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4417 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4418 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4419 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4420 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4421 | if (key.type == -1) { |
| 4422 | if (mac_addr) |
| 4423 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4424 | else |
| 4425 | key.type = NL80211_KEYTYPE_GROUP; |
| 4426 | } |
| 4427 | |
| 4428 | /* for now */ |
| 4429 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4430 | key.type != NL80211_KEYTYPE_GROUP) { |
| 4431 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4432 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4433 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4434 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 4435 | if (key.type == NL80211_KEYTYPE_GROUP && |
| 4436 | info->attrs[NL80211_ATTR_VLAN_ID]) |
| 4437 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 4438 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4439 | if (!rdev->ops->add_key) |
| 4440 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4441 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4442 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 4443 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4444 | mac_addr)) { |
| 4445 | GENL_SET_ERR_MSG(info, "key setting validation failed"); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4446 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4447 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4448 | |
| 4449 | wdev_lock(dev->ieee80211_ptr); |
| 4450 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4451 | if (err) |
| 4452 | GENL_SET_ERR_MSG(info, "key not allowed"); |
| 4453 | if (!err) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4454 | err = rdev_add_key(rdev, dev, key.idx, |
| 4455 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4456 | mac_addr, &key.p); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4457 | if (err) |
| 4458 | GENL_SET_ERR_MSG(info, "key addition failed"); |
| 4459 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4460 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4461 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4462 | return err; |
| 4463 | } |
| 4464 | |
| 4465 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 4466 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4468 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4469 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4470 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4471 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4472 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4473 | err = nl80211_parse_key(info, &key); |
| 4474 | if (err) |
| 4475 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4476 | |
| 4477 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4478 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4479 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4480 | if (key.type == -1) { |
| 4481 | if (mac_addr) |
| 4482 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4483 | else |
| 4484 | key.type = NL80211_KEYTYPE_GROUP; |
| 4485 | } |
| 4486 | |
| 4487 | /* for now */ |
| 4488 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 4489 | key.type != NL80211_KEYTYPE_GROUP) |
| 4490 | return -EINVAL; |
| 4491 | |
Anant Thazhemadam | 2d94630 | 2020-12-05 03:28:25 +0530 | [diff] [blame] | 4492 | if (!cfg80211_valid_key_idx(rdev, key.idx, |
| 4493 | key.type == NL80211_KEYTYPE_PAIRWISE)) |
| 4494 | return -EINVAL; |
| 4495 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4496 | if (!rdev->ops->del_key) |
| 4497 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4498 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4499 | wdev_lock(dev->ieee80211_ptr); |
| 4500 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4501 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4502 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4503 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4504 | err = -ENOENT; |
| 4505 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4506 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4507 | err = rdev_del_key(rdev, dev, key.idx, |
| 4508 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4509 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4510 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4511 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4512 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4513 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4514 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4515 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4516 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 4517 | } |
| 4518 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4519 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4520 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4521 | return err; |
| 4522 | } |
| 4523 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4524 | /* This function returns an error or the number of nested attributes */ |
| 4525 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 4526 | { |
| 4527 | struct nlattr *attr; |
| 4528 | int n_entries = 0, tmp; |
| 4529 | |
| 4530 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 4531 | if (nla_len(attr) != ETH_ALEN) |
| 4532 | return -EINVAL; |
| 4533 | |
| 4534 | n_entries++; |
| 4535 | } |
| 4536 | |
| 4537 | return n_entries; |
| 4538 | } |
| 4539 | |
| 4540 | /* |
| 4541 | * This function parses ACL information and allocates memory for ACL data. |
| 4542 | * On successful return, the calling function is responsible to free the |
| 4543 | * ACL buffer returned by this function. |
| 4544 | */ |
| 4545 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 4546 | struct genl_info *info) |
| 4547 | { |
| 4548 | enum nl80211_acl_policy acl_policy; |
| 4549 | struct nlattr *attr; |
| 4550 | struct cfg80211_acl_data *acl; |
| 4551 | int i = 0, n_entries, tmp; |
| 4552 | |
| 4553 | if (!wiphy->max_acl_mac_addrs) |
| 4554 | return ERR_PTR(-EOPNOTSUPP); |
| 4555 | |
| 4556 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 4557 | return ERR_PTR(-EINVAL); |
| 4558 | |
| 4559 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 4560 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 4561 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 4562 | return ERR_PTR(-EINVAL); |
| 4563 | |
| 4564 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 4565 | return ERR_PTR(-EINVAL); |
| 4566 | |
| 4567 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 4568 | if (n_entries < 0) |
| 4569 | return ERR_PTR(n_entries); |
| 4570 | |
| 4571 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 4572 | return ERR_PTR(-ENOTSUPP); |
| 4573 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 4574 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4575 | if (!acl) |
| 4576 | return ERR_PTR(-ENOMEM); |
| 4577 | |
| 4578 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 4579 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 4580 | i++; |
| 4581 | } |
| 4582 | |
| 4583 | acl->n_acl_entries = n_entries; |
| 4584 | acl->acl_policy = acl_policy; |
| 4585 | |
| 4586 | return acl; |
| 4587 | } |
| 4588 | |
| 4589 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 4590 | { |
| 4591 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4592 | struct net_device *dev = info->user_ptr[1]; |
| 4593 | struct cfg80211_acl_data *acl; |
| 4594 | int err; |
| 4595 | |
| 4596 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4597 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4598 | return -EOPNOTSUPP; |
| 4599 | |
| 4600 | if (!dev->ieee80211_ptr->beacon_interval) |
| 4601 | return -EINVAL; |
| 4602 | |
| 4603 | acl = parse_acl_data(&rdev->wiphy, info); |
| 4604 | if (IS_ERR(acl)) |
| 4605 | return PTR_ERR(acl); |
| 4606 | |
| 4607 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 4608 | |
| 4609 | kfree(acl); |
| 4610 | |
| 4611 | return err; |
| 4612 | } |
| 4613 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4614 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4615 | u8 *rates, u8 rates_len) |
| 4616 | { |
| 4617 | u8 i; |
| 4618 | u32 mask = 0; |
| 4619 | |
| 4620 | for (i = 0; i < rates_len; i++) { |
| 4621 | int rate = (rates[i] & 0x7f) * 5; |
| 4622 | int ridx; |
| 4623 | |
| 4624 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4625 | struct ieee80211_rate *srate = |
| 4626 | &sband->bitrates[ridx]; |
| 4627 | if (rate == srate->bitrate) { |
| 4628 | mask |= 1 << ridx; |
| 4629 | break; |
| 4630 | } |
| 4631 | } |
| 4632 | if (ridx == sband->n_bitrates) |
| 4633 | return 0; /* rate not found */ |
| 4634 | } |
| 4635 | |
| 4636 | return mask; |
| 4637 | } |
| 4638 | |
| 4639 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4640 | u8 *rates, u8 rates_len, |
| 4641 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 4642 | { |
| 4643 | u8 i; |
| 4644 | |
| 4645 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 4646 | |
| 4647 | for (i = 0; i < rates_len; i++) { |
| 4648 | int ridx, rbit; |
| 4649 | |
| 4650 | ridx = rates[i] / 8; |
| 4651 | rbit = BIT(rates[i] % 8); |
| 4652 | |
| 4653 | /* check validity */ |
| 4654 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 4655 | return false; |
| 4656 | |
| 4657 | /* check availability */ |
Masashi Honma | 30fe6d5 | 2018-09-25 11:15:00 +0900 | [diff] [blame] | 4658 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4659 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 4660 | mcs[ridx] |= rbit; |
| 4661 | else |
| 4662 | return false; |
| 4663 | } |
| 4664 | |
| 4665 | return true; |
| 4666 | } |
| 4667 | |
| 4668 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 4669 | { |
| 4670 | u16 mcs_mask = 0; |
| 4671 | |
| 4672 | switch (vht_mcs_map) { |
| 4673 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 4674 | break; |
| 4675 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 4676 | mcs_mask = 0x00FF; |
| 4677 | break; |
| 4678 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 4679 | mcs_mask = 0x01FF; |
| 4680 | break; |
| 4681 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 4682 | mcs_mask = 0x03FF; |
| 4683 | break; |
| 4684 | default: |
| 4685 | break; |
| 4686 | } |
| 4687 | |
| 4688 | return mcs_mask; |
| 4689 | } |
| 4690 | |
| 4691 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 4692 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 4693 | { |
| 4694 | u8 nss; |
| 4695 | |
| 4696 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 4697 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 4698 | vht_mcs_map >>= 2; |
| 4699 | } |
| 4700 | } |
| 4701 | |
| 4702 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 4703 | struct nl80211_txrate_vht *txrate, |
| 4704 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 4705 | { |
| 4706 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4707 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 4708 | u8 i; |
| 4709 | |
| 4710 | if (!sband->vht_cap.vht_supported) |
| 4711 | return false; |
| 4712 | |
| 4713 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4714 | |
| 4715 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4716 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4717 | |
| 4718 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4719 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4720 | mcs[i] = txrate->mcs[i]; |
| 4721 | else |
| 4722 | return false; |
| 4723 | } |
| 4724 | |
| 4725 | return true; |
| 4726 | } |
| 4727 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4728 | static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) |
| 4729 | { |
| 4730 | switch (he_mcs_map) { |
| 4731 | case IEEE80211_HE_MCS_NOT_SUPPORTED: |
| 4732 | return 0; |
| 4733 | case IEEE80211_HE_MCS_SUPPORT_0_7: |
| 4734 | return 0x00FF; |
| 4735 | case IEEE80211_HE_MCS_SUPPORT_0_9: |
| 4736 | return 0x03FF; |
| 4737 | case IEEE80211_HE_MCS_SUPPORT_0_11: |
| 4738 | return 0xFFF; |
| 4739 | default: |
| 4740 | break; |
| 4741 | } |
| 4742 | return 0; |
| 4743 | } |
| 4744 | |
| 4745 | static void he_build_mcs_mask(u16 he_mcs_map, |
| 4746 | u16 he_mcs_mask[NL80211_HE_NSS_MAX]) |
| 4747 | { |
| 4748 | u8 nss; |
| 4749 | |
| 4750 | for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { |
| 4751 | he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); |
| 4752 | he_mcs_map >>= 2; |
| 4753 | } |
| 4754 | } |
| 4755 | |
| 4756 | static u16 he_get_txmcsmap(struct genl_info *info, |
| 4757 | const struct ieee80211_sta_he_cap *he_cap) |
| 4758 | { |
| 4759 | struct net_device *dev = info->user_ptr[1]; |
| 4760 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4761 | __le16 tx_mcs; |
| 4762 | |
| 4763 | switch (wdev->chandef.width) { |
| 4764 | case NL80211_CHAN_WIDTH_80P80: |
| 4765 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; |
| 4766 | break; |
| 4767 | case NL80211_CHAN_WIDTH_160: |
| 4768 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; |
| 4769 | break; |
| 4770 | default: |
| 4771 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; |
| 4772 | break; |
| 4773 | } |
| 4774 | return le16_to_cpu(tx_mcs); |
| 4775 | } |
| 4776 | |
| 4777 | static bool he_set_mcs_mask(struct genl_info *info, |
| 4778 | struct wireless_dev *wdev, |
| 4779 | struct ieee80211_supported_band *sband, |
| 4780 | struct nl80211_txrate_he *txrate, |
| 4781 | u16 mcs[NL80211_HE_NSS_MAX]) |
| 4782 | { |
| 4783 | const struct ieee80211_sta_he_cap *he_cap; |
| 4784 | u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; |
| 4785 | u16 tx_mcs_map = 0; |
| 4786 | u8 i; |
| 4787 | |
| 4788 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4789 | if (!he_cap) |
| 4790 | return false; |
| 4791 | |
| 4792 | memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); |
| 4793 | |
| 4794 | tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4795 | |
| 4796 | /* Build he_mcs_mask from HE capabilities */ |
| 4797 | he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4798 | |
| 4799 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 4800 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4801 | mcs[i] = txrate->mcs[i]; |
| 4802 | else |
| 4803 | return false; |
| 4804 | } |
| 4805 | |
| 4806 | return true; |
| 4807 | } |
| 4808 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4809 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4810 | struct nlattr *attrs[], |
| 4811 | enum nl80211_attrs attr, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4812 | struct cfg80211_bitrate_mask *mask, |
Rajkumar Manoharan | 857b34c | 2020-10-16 13:15:26 -0700 | [diff] [blame] | 4813 | struct net_device *dev, |
| 4814 | bool default_all_enabled) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4815 | { |
| 4816 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4818 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4819 | int rem, i; |
| 4820 | struct nlattr *tx_rates; |
| 4821 | struct ieee80211_supported_band *sband; |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4822 | u16 vht_tx_mcs_map, he_tx_mcs_map; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4823 | |
| 4824 | memset(mask, 0, sizeof(*mask)); |
| 4825 | /* Default to all rates enabled */ |
| 4826 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4827 | const struct ieee80211_sta_he_cap *he_cap; |
| 4828 | |
Rajkumar Manoharan | 857b34c | 2020-10-16 13:15:26 -0700 | [diff] [blame] | 4829 | if (!default_all_enabled) |
| 4830 | break; |
| 4831 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4832 | sband = rdev->wiphy.bands[i]; |
| 4833 | |
| 4834 | if (!sband) |
| 4835 | continue; |
| 4836 | |
| 4837 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4838 | memcpy(mask->control[i].ht_mcs, |
| 4839 | sband->ht_cap.mcs.rx_mask, |
| 4840 | sizeof(mask->control[i].ht_mcs)); |
| 4841 | |
Ping-Ke Shih | 9df66d5 | 2021-06-09 15:59:44 +0800 | [diff] [blame] | 4842 | if (sband->vht_cap.vht_supported) { |
| 4843 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4844 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
| 4845 | } |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4846 | |
| 4847 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4848 | if (!he_cap) |
| 4849 | continue; |
| 4850 | |
| 4851 | he_tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4852 | he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); |
| 4853 | |
| 4854 | mask->control[i].he_gi = 0xFF; |
| 4855 | mask->control[i].he_ltf = 0xFF; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4856 | } |
| 4857 | |
| 4858 | /* if no rates are given set it back to the defaults */ |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4859 | if (!attrs[attr]) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4860 | goto out; |
| 4861 | |
| 4862 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4863 | * directly to the enum nl80211_band values used in cfg80211. |
| 4864 | */ |
| 4865 | 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] | 4866 | nla_for_each_nested(tx_rates, attrs[attr], rem) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4867 | enum nl80211_band band = nla_type(tx_rates); |
| 4868 | int err; |
| 4869 | |
| 4870 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4871 | return -EINVAL; |
| 4872 | sband = rdev->wiphy.bands[band]; |
| 4873 | if (sband == NULL) |
| 4874 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4875 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
| 4876 | tx_rates, |
| 4877 | nl80211_txattr_policy, |
| 4878 | info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4879 | if (err) |
| 4880 | return err; |
| 4881 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4882 | mask->control[band].legacy = rateset_to_mask( |
| 4883 | sband, |
| 4884 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4885 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4886 | if ((mask->control[band].legacy == 0) && |
| 4887 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4888 | return -EINVAL; |
| 4889 | } |
| 4890 | if (tb[NL80211_TXRATE_HT]) { |
| 4891 | if (!ht_rateset_to_mask( |
| 4892 | sband, |
| 4893 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4894 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4895 | mask->control[band].ht_mcs)) |
| 4896 | return -EINVAL; |
| 4897 | } |
Rajkumar Manoharan | c4a3044 | 2020-10-16 13:15:27 -0700 | [diff] [blame] | 4898 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4899 | if (tb[NL80211_TXRATE_VHT]) { |
| 4900 | if (!vht_set_mcs_mask( |
| 4901 | sband, |
| 4902 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4903 | mask->control[band].vht_mcs)) |
| 4904 | return -EINVAL; |
| 4905 | } |
Rajkumar Manoharan | c4a3044 | 2020-10-16 13:15:27 -0700 | [diff] [blame] | 4906 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4907 | if (tb[NL80211_TXRATE_GI]) { |
| 4908 | mask->control[band].gi = |
| 4909 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4910 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4911 | return -EINVAL; |
| 4912 | } |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4913 | if (tb[NL80211_TXRATE_HE] && |
| 4914 | !he_set_mcs_mask(info, wdev, sband, |
| 4915 | nla_data(tb[NL80211_TXRATE_HE]), |
| 4916 | mask->control[band].he_mcs)) |
| 4917 | return -EINVAL; |
Rajkumar Manoharan | c4a3044 | 2020-10-16 13:15:27 -0700 | [diff] [blame] | 4918 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4919 | if (tb[NL80211_TXRATE_HE_GI]) |
| 4920 | mask->control[band].he_gi = |
| 4921 | nla_get_u8(tb[NL80211_TXRATE_HE_GI]); |
| 4922 | if (tb[NL80211_TXRATE_HE_LTF]) |
| 4923 | mask->control[band].he_ltf = |
| 4924 | nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4925 | |
| 4926 | if (mask->control[band].legacy == 0) { |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4927 | /* don't allow empty legacy rates if HT, VHT or HE |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4928 | * are not even supported. |
| 4929 | */ |
| 4930 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4931 | rdev->wiphy.bands[band]->vht_cap.vht_supported || |
| 4932 | ieee80211_get_he_iftype_cap(sband, wdev->iftype))) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4933 | return -EINVAL; |
| 4934 | |
| 4935 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4936 | if (mask->control[band].ht_mcs[i]) |
| 4937 | goto out; |
| 4938 | |
| 4939 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4940 | if (mask->control[band].vht_mcs[i]) |
| 4941 | goto out; |
| 4942 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4943 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) |
| 4944 | if (mask->control[band].he_mcs[i]) |
| 4945 | goto out; |
| 4946 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4947 | /* legacy and mcs rates may not be both empty */ |
| 4948 | return -EINVAL; |
| 4949 | } |
| 4950 | } |
| 4951 | |
| 4952 | out: |
| 4953 | return 0; |
| 4954 | } |
| 4955 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4956 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4957 | enum nl80211_band band, |
| 4958 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4959 | { |
Rajkumar Manoharan | c4a3044 | 2020-10-16 13:15:27 -0700 | [diff] [blame] | 4960 | u32 count_ht, count_vht, count_he, i; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4961 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4962 | |
| 4963 | /* Allow only one rate */ |
| 4964 | if (hweight32(rate) > 1) |
| 4965 | return -EINVAL; |
| 4966 | |
| 4967 | count_ht = 0; |
| 4968 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4969 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4970 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4971 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4972 | count_ht++; |
| 4973 | if (count_ht > 1) |
| 4974 | return -EINVAL; |
| 4975 | } |
| 4976 | if (count_ht && rate) |
| 4977 | return -EINVAL; |
| 4978 | } |
| 4979 | |
| 4980 | count_vht = 0; |
| 4981 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4982 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4983 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4984 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4985 | count_vht++; |
| 4986 | if (count_vht > 1) |
| 4987 | return -EINVAL; |
| 4988 | } |
| 4989 | if (count_vht && rate) |
| 4990 | return -EINVAL; |
| 4991 | } |
| 4992 | |
Rajkumar Manoharan | c4a3044 | 2020-10-16 13:15:27 -0700 | [diff] [blame] | 4993 | count_he = 0; |
| 4994 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 4995 | if (hweight16(beacon_rate->control[band].he_mcs[i]) > 1) { |
| 4996 | return -EINVAL; |
| 4997 | } else if (beacon_rate->control[band].he_mcs[i]) { |
| 4998 | count_he++; |
| 4999 | if (count_he > 1) |
| 5000 | return -EINVAL; |
| 5001 | } |
| 5002 | if (count_he && rate) |
| 5003 | return -EINVAL; |
| 5004 | } |
| 5005 | |
| 5006 | if ((count_ht && count_vht && count_he) || |
| 5007 | (!rate && !count_ht && !count_vht && !count_he)) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5008 | return -EINVAL; |
| 5009 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 5010 | if (rate && |
| 5011 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5012 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 5013 | return -EINVAL; |
| 5014 | if (count_ht && |
| 5015 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5016 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 5017 | return -EINVAL; |
| 5018 | if (count_vht && |
| 5019 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5020 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 5021 | return -EINVAL; |
Rajkumar Manoharan | c4a3044 | 2020-10-16 13:15:27 -0700 | [diff] [blame] | 5022 | if (count_he && |
| 5023 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5024 | NL80211_EXT_FEATURE_BEACON_RATE_HE)) |
| 5025 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 5026 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5027 | return 0; |
| 5028 | } |
| 5029 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 5030 | static int nl80211_parse_mbssid_config(struct wiphy *wiphy, |
| 5031 | struct net_device *dev, |
| 5032 | struct nlattr *attrs, |
| 5033 | struct cfg80211_mbssid_config *config, |
| 5034 | u8 num_elems) |
| 5035 | { |
| 5036 | struct nlattr *tb[NL80211_MBSSID_CONFIG_ATTR_MAX + 1]; |
| 5037 | |
| 5038 | if (!wiphy->mbssid_max_interfaces) |
| 5039 | return -EOPNOTSUPP; |
| 5040 | |
| 5041 | if (nla_parse_nested(tb, NL80211_MBSSID_CONFIG_ATTR_MAX, attrs, NULL, |
| 5042 | NULL) || |
| 5043 | !tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]) |
| 5044 | return -EINVAL; |
| 5045 | |
| 5046 | config->ema = nla_get_flag(tb[NL80211_MBSSID_CONFIG_ATTR_EMA]); |
| 5047 | if (config->ema) { |
| 5048 | if (!wiphy->ema_max_profile_periodicity) |
| 5049 | return -EOPNOTSUPP; |
| 5050 | |
| 5051 | if (num_elems > wiphy->ema_max_profile_periodicity) |
| 5052 | return -EINVAL; |
| 5053 | } |
| 5054 | |
| 5055 | config->index = nla_get_u8(tb[NL80211_MBSSID_CONFIG_ATTR_INDEX]); |
| 5056 | if (config->index >= wiphy->mbssid_max_interfaces || |
| 5057 | (!config->index && !num_elems)) |
| 5058 | return -EINVAL; |
| 5059 | |
| 5060 | if (tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]) { |
| 5061 | u32 tx_ifindex = |
| 5062 | nla_get_u32(tb[NL80211_MBSSID_CONFIG_ATTR_TX_IFINDEX]); |
| 5063 | |
| 5064 | if ((!config->index && tx_ifindex != dev->ifindex) || |
| 5065 | (config->index && tx_ifindex == dev->ifindex)) |
| 5066 | return -EINVAL; |
| 5067 | |
| 5068 | if (tx_ifindex != dev->ifindex) { |
| 5069 | struct net_device *tx_netdev = |
| 5070 | dev_get_by_index(wiphy_net(wiphy), tx_ifindex); |
| 5071 | |
| 5072 | if (!tx_netdev || !tx_netdev->ieee80211_ptr || |
| 5073 | tx_netdev->ieee80211_ptr->wiphy != wiphy || |
| 5074 | tx_netdev->ieee80211_ptr->iftype != |
| 5075 | NL80211_IFTYPE_AP) { |
| 5076 | dev_put(tx_netdev); |
| 5077 | return -EINVAL; |
| 5078 | } |
| 5079 | |
| 5080 | config->tx_wdev = tx_netdev->ieee80211_ptr; |
| 5081 | } else { |
| 5082 | config->tx_wdev = dev->ieee80211_ptr; |
| 5083 | } |
| 5084 | } else if (!config->index) { |
| 5085 | config->tx_wdev = dev->ieee80211_ptr; |
| 5086 | } else { |
| 5087 | return -EINVAL; |
| 5088 | } |
| 5089 | |
| 5090 | return 0; |
| 5091 | } |
| 5092 | |
| 5093 | static struct cfg80211_mbssid_elems * |
| 5094 | nl80211_parse_mbssid_elems(struct wiphy *wiphy, struct nlattr *attrs) |
| 5095 | { |
| 5096 | struct nlattr *nl_elems; |
| 5097 | struct cfg80211_mbssid_elems *elems; |
| 5098 | int rem_elems; |
| 5099 | u8 i = 0, num_elems = 0; |
| 5100 | |
| 5101 | if (!wiphy->mbssid_max_interfaces) |
| 5102 | return ERR_PTR(-EINVAL); |
| 5103 | |
| 5104 | nla_for_each_nested(nl_elems, attrs, rem_elems) |
| 5105 | num_elems++; |
| 5106 | |
| 5107 | elems = kzalloc(struct_size(elems, elem, num_elems), GFP_KERNEL); |
| 5108 | if (!elems) |
| 5109 | return ERR_PTR(-ENOMEM); |
| 5110 | |
| 5111 | nla_for_each_nested(nl_elems, attrs, rem_elems) { |
| 5112 | elems->elem[i].data = nla_data(nl_elems); |
| 5113 | elems->elem[i].len = nla_len(nl_elems); |
| 5114 | i++; |
| 5115 | } |
| 5116 | elems->cnt = num_elems; |
| 5117 | return elems; |
| 5118 | } |
| 5119 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5120 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 5121 | struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5122 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5123 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5124 | bool haveinfo = false; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5125 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5126 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5127 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5128 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5129 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 5130 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 5131 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5132 | if (!bcn->head_len) |
| 5133 | return -EINVAL; |
| 5134 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5135 | } |
| 5136 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5137 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 5138 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 5139 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5140 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5141 | } |
| 5142 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5143 | if (!haveinfo) |
| 5144 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5145 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5146 | if (attrs[NL80211_ATTR_IE]) { |
| 5147 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 5148 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 5149 | } |
| 5150 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5151 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5152 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5153 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5154 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5155 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 5156 | } |
| 5157 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5158 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5159 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5160 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5161 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5162 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 5163 | } |
| 5164 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 5165 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 5166 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 5167 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 5168 | } |
| 5169 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5170 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 5171 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 5172 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5173 | err = nla_parse_nested_deprecated(tb, |
| 5174 | NL80211_FTM_RESP_ATTR_MAX, |
| 5175 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 5176 | NULL, NULL); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5177 | if (err) |
| 5178 | return err; |
| 5179 | |
| 5180 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 5181 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 5182 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 5183 | bcn->ftm_responder = 1; |
| 5184 | else |
| 5185 | return -EOPNOTSUPP; |
| 5186 | |
| 5187 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 5188 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 5189 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 5190 | } |
| 5191 | |
| 5192 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 5193 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 5194 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 5195 | } |
| 5196 | } else { |
| 5197 | bcn->ftm_responder = -1; |
| 5198 | } |
| 5199 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 5200 | if (attrs[NL80211_ATTR_MBSSID_ELEMS]) { |
| 5201 | struct cfg80211_mbssid_elems *mbssid = |
| 5202 | nl80211_parse_mbssid_elems(&rdev->wiphy, |
| 5203 | attrs[NL80211_ATTR_MBSSID_ELEMS]); |
| 5204 | |
| 5205 | if (IS_ERR(mbssid)) |
| 5206 | return PTR_ERR(mbssid); |
| 5207 | |
| 5208 | bcn->mbssid_ies = mbssid; |
| 5209 | } |
| 5210 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5211 | return 0; |
| 5212 | } |
| 5213 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5214 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
| 5215 | struct ieee80211_he_obss_pd *he_obss_pd) |
| 5216 | { |
| 5217 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; |
| 5218 | int err; |
| 5219 | |
| 5220 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, |
| 5221 | he_obss_pd_policy, NULL); |
| 5222 | if (err) |
| 5223 | return err; |
| 5224 | |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 5225 | if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) |
| 5226 | return -EINVAL; |
| 5227 | |
| 5228 | he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); |
| 5229 | |
Rajkumar Manoharan | 6c8b6e4 | 2020-09-28 00:28:10 -0700 | [diff] [blame] | 5230 | if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) |
| 5231 | he_obss_pd->min_offset = |
| 5232 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); |
| 5233 | if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) |
| 5234 | he_obss_pd->max_offset = |
| 5235 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 5236 | if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) |
| 5237 | he_obss_pd->non_srg_max_offset = |
| 5238 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]); |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5239 | |
Rajkumar Manoharan | 6c8b6e4 | 2020-09-28 00:28:10 -0700 | [diff] [blame] | 5240 | if (he_obss_pd->min_offset > he_obss_pd->max_offset) |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5241 | return -EINVAL; |
| 5242 | |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 5243 | if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) |
| 5244 | memcpy(he_obss_pd->bss_color_bitmap, |
| 5245 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), |
| 5246 | sizeof(he_obss_pd->bss_color_bitmap)); |
| 5247 | |
| 5248 | if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) |
| 5249 | memcpy(he_obss_pd->partial_bssid_bitmap, |
| 5250 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), |
| 5251 | sizeof(he_obss_pd->partial_bssid_bitmap)); |
| 5252 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5253 | he_obss_pd->enable = true; |
| 5254 | |
| 5255 | return 0; |
| 5256 | } |
| 5257 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5258 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
| 5259 | struct cfg80211_he_bss_color *he_bss_color) |
| 5260 | { |
| 5261 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; |
| 5262 | int err; |
| 5263 | |
| 5264 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, |
| 5265 | he_bss_color_policy, NULL); |
| 5266 | if (err) |
| 5267 | return err; |
| 5268 | |
| 5269 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) |
| 5270 | return -EINVAL; |
| 5271 | |
| 5272 | he_bss_color->color = |
| 5273 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 5274 | he_bss_color->enabled = |
| 5275 | !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5276 | he_bss_color->partial = |
| 5277 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); |
| 5278 | |
| 5279 | return 0; |
| 5280 | } |
| 5281 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 5282 | static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, |
| 5283 | struct nlattr *attrs, |
| 5284 | struct cfg80211_ap_settings *params) |
| 5285 | { |
| 5286 | struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; |
| 5287 | int ret; |
| 5288 | struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; |
| 5289 | |
| 5290 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5291 | NL80211_EXT_FEATURE_FILS_DISCOVERY)) |
| 5292 | return -EINVAL; |
| 5293 | |
| 5294 | ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, |
| 5295 | NULL, NULL); |
| 5296 | if (ret) |
| 5297 | return ret; |
| 5298 | |
| 5299 | if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || |
| 5300 | !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || |
| 5301 | !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) |
| 5302 | return -EINVAL; |
| 5303 | |
| 5304 | fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 5305 | fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 5306 | fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); |
| 5307 | fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); |
| 5308 | |
| 5309 | return 0; |
| 5310 | } |
| 5311 | |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 5312 | static int |
| 5313 | nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, |
| 5314 | struct nlattr *attrs, |
| 5315 | struct cfg80211_ap_settings *params) |
| 5316 | { |
| 5317 | struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; |
| 5318 | int ret; |
| 5319 | struct cfg80211_unsol_bcast_probe_resp *presp = |
| 5320 | ¶ms->unsol_bcast_probe_resp; |
| 5321 | |
| 5322 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5323 | NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) |
| 5324 | return -EINVAL; |
| 5325 | |
| 5326 | ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, |
| 5327 | attrs, NULL, NULL); |
| 5328 | if (ret) |
| 5329 | return ret; |
| 5330 | |
| 5331 | if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || |
| 5332 | !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) |
| 5333 | return -EINVAL; |
| 5334 | |
| 5335 | presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); |
| 5336 | presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); |
| 5337 | presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); |
| 5338 | return 0; |
| 5339 | } |
| 5340 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5341 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5342 | const struct element *rates) |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5343 | { |
| 5344 | int i; |
| 5345 | |
| 5346 | if (!rates) |
| 5347 | return; |
| 5348 | |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5349 | for (i = 0; i < rates->datalen; i++) { |
| 5350 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5351 | params->ht_required = true; |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5352 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5353 | params->vht_required = true; |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5354 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) |
Ilan Peer | 2a39259 | 2020-03-26 15:09:35 +0200 | [diff] [blame] | 5355 | params->he_required = true; |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5356 | if (rates->data[i] == BSS_MEMBERSHIP_SELECTOR_SAE_H2E) |
Ilan Peer | d658760 | 2020-11-29 17:30:46 +0200 | [diff] [blame] | 5357 | params->sae_h2e_required = true; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5358 | } |
| 5359 | } |
| 5360 | |
| 5361 | /* |
| 5362 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 5363 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 5364 | * benefit of drivers that rebuild IEs in the firmware. |
| 5365 | */ |
| 5366 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 5367 | { |
| 5368 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 5369 | size_t ies_len = bcn->tail_len; |
| 5370 | const u8 *ies = bcn->tail; |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5371 | const struct element *rates; |
| 5372 | const struct element *cap; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5373 | |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5374 | rates = cfg80211_find_elem(WLAN_EID_SUPP_RATES, ies, ies_len); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5375 | nl80211_check_ap_rate_selectors(params, rates); |
| 5376 | |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5377 | rates = cfg80211_find_elem(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5378 | nl80211_check_ap_rate_selectors(params, rates); |
| 5379 | |
Johannes Berg | 153e2a1 | 2021-09-30 13:11:29 +0200 | [diff] [blame] | 5380 | cap = cfg80211_find_elem(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 5381 | if (cap && cap->datalen >= sizeof(*params->ht_cap)) |
| 5382 | params->ht_cap = (void *)cap->data; |
| 5383 | cap = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 5384 | if (cap && cap->datalen >= sizeof(*params->vht_cap)) |
| 5385 | params->vht_cap = (void *)cap->data; |
| 5386 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 5387 | if (cap && cap->datalen >= sizeof(*params->he_cap) + 1) |
| 5388 | params->he_cap = (void *)(cap->data + 1); |
| 5389 | cap = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); |
| 5390 | if (cap && cap->datalen >= sizeof(*params->he_oper) + 1) |
| 5391 | params->he_oper = (void *)(cap->data + 1); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5392 | } |
| 5393 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5394 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 5395 | struct cfg80211_ap_settings *params) |
| 5396 | { |
| 5397 | struct wireless_dev *wdev; |
| 5398 | bool ret = false; |
| 5399 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 5400 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5401 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5402 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5403 | continue; |
| 5404 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5405 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5406 | continue; |
| 5407 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5408 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5409 | ret = true; |
| 5410 | break; |
| 5411 | } |
| 5412 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5413 | return ret; |
| 5414 | } |
| 5415 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5416 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 5417 | enum nl80211_auth_type auth_type, |
| 5418 | enum nl80211_commands cmd) |
| 5419 | { |
| 5420 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 5421 | return false; |
| 5422 | |
| 5423 | switch (cmd) { |
| 5424 | case NL80211_CMD_AUTHENTICATE: |
| 5425 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 5426 | auth_type == NL80211_AUTHTYPE_SAE) |
| 5427 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 5428 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5429 | NL80211_EXT_FEATURE_FILS_STA) && |
| 5430 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5431 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5432 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 5433 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5434 | return true; |
| 5435 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5436 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 5437 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5438 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5439 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 5440 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5441 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 5442 | /* FILS with SK PFS or PK not supported yet */ |
| 5443 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5444 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5445 | return false; |
| 5446 | if (!wiphy_ext_feature_isset( |
| 5447 | &rdev->wiphy, |
| 5448 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 5449 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 5450 | return false; |
| 5451 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5452 | case NL80211_CMD_START_AP: |
Chung-Hsien Hsu | 2831a63 | 2020-08-17 02:33:15 -0500 | [diff] [blame] | 5453 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5454 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && |
| 5455 | auth_type == NL80211_AUTHTYPE_SAE) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5456 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 5457 | /* FILS not supported yet */ |
| 5458 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5459 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5460 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5461 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5462 | return true; |
| 5463 | default: |
| 5464 | return false; |
| 5465 | } |
| 5466 | } |
| 5467 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5468 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 5469 | { |
| 5470 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5471 | struct net_device *dev = info->user_ptr[1]; |
| 5472 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5473 | struct cfg80211_ap_settings *params; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5474 | int err; |
| 5475 | |
| 5476 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5477 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5478 | return -EOPNOTSUPP; |
| 5479 | |
| 5480 | if (!rdev->ops->start_ap) |
| 5481 | return -EOPNOTSUPP; |
| 5482 | |
| 5483 | if (wdev->beacon_interval) |
| 5484 | return -EALREADY; |
| 5485 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5486 | /* these are required for START_AP */ |
| 5487 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 5488 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 5489 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 5490 | return -EINVAL; |
| 5491 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5492 | params = kzalloc(sizeof(*params), GFP_KERNEL); |
| 5493 | if (!params) |
| 5494 | return -ENOMEM; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5495 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5496 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms->beacon); |
| 5497 | if (err) |
| 5498 | goto out; |
| 5499 | |
| 5500 | params->beacon_interval = |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5501 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5502 | params->dtim_period = |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5503 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 5504 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 5505 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5506 | params->beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5507 | if (err) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5508 | goto out; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5509 | |
| 5510 | /* |
| 5511 | * In theory, some of these attributes should be required here |
| 5512 | * but since they were not used when the command was originally |
| 5513 | * added, keep them optional for old user space programs to let |
| 5514 | * them continue to work with drivers that do not need the |
| 5515 | * additional information -- drivers must check! |
| 5516 | */ |
| 5517 | if (info->attrs[NL80211_ATTR_SSID]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5518 | params->ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5519 | params->ssid_len = |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5520 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5521 | if (params->ssid_len == 0) { |
| 5522 | err = -EINVAL; |
| 5523 | goto out; |
| 5524 | } |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5525 | } |
| 5526 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5527 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5528 | params->hidden_ssid = nla_get_u32( |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5529 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5530 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5531 | params->privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5532 | |
| 5533 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5534 | params->auth_type = nla_get_u32( |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5535 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5536 | if (!nl80211_valid_auth_type(rdev, params->auth_type, |
| 5537 | NL80211_CMD_START_AP)) { |
| 5538 | err = -EINVAL; |
| 5539 | goto out; |
| 5540 | } |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5541 | } else |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5542 | params->auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5543 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5544 | err = nl80211_crypto_settings(rdev, info, ¶ms->crypto, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5545 | NL80211_MAX_NR_CIPHER_SUITES); |
| 5546 | if (err) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5547 | goto out; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5548 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 5549 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5550 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) { |
| 5551 | err = -EOPNOTSUPP; |
| 5552 | goto out; |
| 5553 | } |
| 5554 | params->inactivity_timeout = nla_get_u16( |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 5555 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 5556 | } |
| 5557 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5558 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5559 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5560 | err = -EINVAL; |
| 5561 | goto out; |
| 5562 | } |
| 5563 | params->p2p_ctwindow = |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5564 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5565 | if (params->p2p_ctwindow != 0 && |
| 5566 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) { |
| 5567 | err = -EINVAL; |
| 5568 | goto out; |
| 5569 | } |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5570 | } |
| 5571 | |
| 5572 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5573 | u8 tmp; |
| 5574 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5575 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 5576 | err = -EINVAL; |
| 5577 | goto out; |
| 5578 | } |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5579 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5580 | params->p2p_opp_ps = tmp; |
| 5581 | if (params->p2p_opp_ps != 0 && |
| 5582 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) { |
| 5583 | err = -EINVAL; |
| 5584 | goto out; |
| 5585 | } |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5586 | } |
| 5587 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5588 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5589 | err = nl80211_parse_chandef(rdev, info, ¶ms->chandef); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5590 | if (err) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5591 | goto out; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5592 | } else if (wdev->preset_chandef.chan) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5593 | params->chandef = wdev->preset_chandef; |
| 5594 | } else if (!nl80211_get_ap_channel(rdev, params)) { |
| 5595 | err = -EINVAL; |
| 5596 | goto out; |
| 5597 | } |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5598 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5599 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms->chandef, |
| 5600 | wdev->iftype)) { |
| 5601 | err = -EINVAL; |
| 5602 | goto out; |
| 5603 | } |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5604 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5605 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 5606 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 5607 | NL80211_ATTR_TX_RATES, |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5608 | ¶ms->beacon_rate, |
Rajkumar Manoharan | 857b34c | 2020-10-16 13:15:26 -0700 | [diff] [blame] | 5609 | dev, false); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5610 | if (err) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5611 | goto out; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5612 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5613 | err = validate_beacon_tx_rate(rdev, params->chandef.chan->band, |
| 5614 | ¶ms->beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5615 | if (err) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5616 | goto out; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5617 | } |
| 5618 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5619 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5620 | params->smps_mode = |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5621 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5622 | switch (params->smps_mode) { |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5623 | case NL80211_SMPS_OFF: |
| 5624 | break; |
| 5625 | case NL80211_SMPS_STATIC: |
| 5626 | if (!(rdev->wiphy.features & |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5627 | NL80211_FEATURE_STATIC_SMPS)) { |
| 5628 | err = -EINVAL; |
| 5629 | goto out; |
| 5630 | } |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5631 | break; |
| 5632 | case NL80211_SMPS_DYNAMIC: |
| 5633 | if (!(rdev->wiphy.features & |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5634 | NL80211_FEATURE_DYNAMIC_SMPS)) { |
| 5635 | err = -EINVAL; |
| 5636 | goto out; |
| 5637 | } |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5638 | break; |
| 5639 | default: |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5640 | err = -EINVAL; |
| 5641 | goto out; |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5642 | } |
| 5643 | } else { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5644 | params->smps_mode = NL80211_SMPS_OFF; |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5645 | } |
| 5646 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5647 | params->pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 5648 | if (params->pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
| 5649 | err = -EOPNOTSUPP; |
| 5650 | goto out; |
| 5651 | } |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 5652 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 5653 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5654 | params->acl = parse_acl_data(&rdev->wiphy, info); |
| 5655 | if (IS_ERR(params->acl)) { |
| 5656 | err = PTR_ERR(params->acl); |
Johannes Berg | 05075fe7 | 2021-09-27 13:44:03 +0200 | [diff] [blame] | 5657 | params->acl = NULL; |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5658 | goto out; |
| 5659 | } |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 5660 | } |
| 5661 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5662 | params->twt_responder = |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 5663 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
| 5664 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5665 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
| 5666 | err = nl80211_parse_he_obss_pd( |
| 5667 | info->attrs[NL80211_ATTR_HE_OBSS_PD], |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5668 | ¶ms->he_obss_pd); |
Luca Coelho | bc7a39b | 2020-06-26 12:49:39 +0300 | [diff] [blame] | 5669 | if (err) |
| 5670 | goto out; |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5671 | } |
| 5672 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5673 | if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
| 5674 | err = nl80211_parse_he_bss_color( |
| 5675 | info->attrs[NL80211_ATTR_HE_BSS_COLOR], |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5676 | ¶ms->he_bss_color); |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5677 | if (err) |
Luca Coelho | 60a0121 | 2020-06-26 12:49:40 +0300 | [diff] [blame] | 5678 | goto out; |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5679 | } |
| 5680 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 5681 | if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { |
| 5682 | err = nl80211_parse_fils_discovery(rdev, |
| 5683 | info->attrs[NL80211_ATTR_FILS_DISCOVERY], |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5684 | params); |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 5685 | if (err) |
| 5686 | goto out; |
| 5687 | } |
| 5688 | |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 5689 | if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { |
| 5690 | err = nl80211_parse_unsol_bcast_probe_resp( |
| 5691 | rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5692 | params); |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 5693 | if (err) |
Johannes Berg | abaf94e | 2021-04-08 14:28:34 +0200 | [diff] [blame] | 5694 | goto out; |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 5697 | if (info->attrs[NL80211_ATTR_MBSSID_CONFIG]) { |
| 5698 | err = nl80211_parse_mbssid_config(&rdev->wiphy, dev, |
| 5699 | info->attrs[NL80211_ATTR_MBSSID_CONFIG], |
| 5700 | ¶ms->mbssid_config, |
| 5701 | params->beacon.mbssid_ies ? |
| 5702 | params->beacon.mbssid_ies->cnt : |
| 5703 | 0); |
| 5704 | if (err) |
| 5705 | goto out; |
| 5706 | } |
| 5707 | |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5708 | nl80211_calculate_ap_params(params); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5709 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 5710 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5711 | params->flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 5712 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5713 | wdev_lock(wdev); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5714 | err = rdev_start_ap(rdev, dev, params); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5715 | if (!err) { |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5716 | wdev->preset_chandef = params->chandef; |
| 5717 | wdev->beacon_interval = params->beacon_interval; |
| 5718 | wdev->chandef = params->chandef; |
| 5719 | wdev->ssid_len = params->ssid_len; |
| 5720 | memcpy(wdev->ssid, params->ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 5721 | |
| 5722 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 5723 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5724 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5725 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5726 | |
Johannes Berg | 9951ebf | 2020-02-21 10:41:43 +0100 | [diff] [blame] | 5727 | out: |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5728 | kfree(params->acl); |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 5729 | kfree(params->beacon.mbssid_ies); |
| 5730 | if (params->mbssid_config.tx_wdev && |
| 5731 | params->mbssid_config.tx_wdev->netdev && |
| 5732 | params->mbssid_config.tx_wdev->netdev != dev) |
| 5733 | dev_put(params->mbssid_config.tx_wdev->netdev); |
Johannes Berg | 9e263e1 | 2021-09-23 16:18:37 +0200 | [diff] [blame] | 5734 | kfree(params); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5735 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 5736 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5737 | } |
| 5738 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5739 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 5740 | { |
| 5741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5742 | struct net_device *dev = info->user_ptr[1]; |
| 5743 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5744 | struct cfg80211_beacon_data params; |
| 5745 | int err; |
| 5746 | |
| 5747 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5748 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5749 | return -EOPNOTSUPP; |
| 5750 | |
| 5751 | if (!rdev->ops->change_beacon) |
| 5752 | return -EOPNOTSUPP; |
| 5753 | |
| 5754 | if (!wdev->beacon_interval) |
| 5755 | return -EINVAL; |
| 5756 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5757 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5758 | if (err) |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 5759 | goto out; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5760 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5761 | wdev_lock(wdev); |
| 5762 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 5763 | wdev_unlock(wdev); |
| 5764 | |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 5765 | out: |
| 5766 | kfree(params.mbssid_ies); |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5767 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5768 | } |
| 5769 | |
| 5770 | 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] | 5771 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5772 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5773 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5774 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 5775 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5776 | } |
| 5777 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5778 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 5779 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 5780 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 5781 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 5782 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 5783 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 5784 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5785 | }; |
| 5786 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5787 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5788 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5789 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5790 | { |
| 5791 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5792 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5793 | int flag; |
| 5794 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5795 | /* |
| 5796 | * Try parsing the new attribute first so userspace |
| 5797 | * can specify both for older kernels. |
| 5798 | */ |
| 5799 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 5800 | if (nla) { |
| 5801 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5802 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5803 | sta_flags = nla_data(nla); |
| 5804 | params->sta_flags_mask = sta_flags->mask; |
| 5805 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5806 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5807 | if ((params->sta_flags_mask | |
| 5808 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 5809 | return -EINVAL; |
| 5810 | return 0; |
| 5811 | } |
| 5812 | |
| 5813 | /* if present, parse the old attribute */ |
| 5814 | |
| 5815 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5816 | if (!nla) |
| 5817 | return 0; |
| 5818 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5819 | 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] | 5820 | return -EINVAL; |
| 5821 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5822 | /* |
| 5823 | * Only allow certain flags for interface types so that |
| 5824 | * other attributes are silently ignored. Remember that |
| 5825 | * this is backward compatibility code with old userspace |
| 5826 | * and shouldn't be hit in other cases anyway. |
| 5827 | */ |
| 5828 | switch (iftype) { |
| 5829 | case NL80211_IFTYPE_AP: |
| 5830 | case NL80211_IFTYPE_AP_VLAN: |
| 5831 | case NL80211_IFTYPE_P2P_GO: |
| 5832 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5833 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5834 | BIT(NL80211_STA_FLAG_WME) | |
| 5835 | BIT(NL80211_STA_FLAG_MFP); |
| 5836 | break; |
| 5837 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5838 | case NL80211_IFTYPE_STATION: |
| 5839 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5840 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5841 | break; |
| 5842 | case NL80211_IFTYPE_MESH_POINT: |
| 5843 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5844 | BIT(NL80211_STA_FLAG_MFP) | |
| 5845 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
Bernd Edlinger | 5cf3006 | 2018-07-08 09:57:22 +0000 | [diff] [blame] | 5846 | break; |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5847 | default: |
| 5848 | return -EINVAL; |
| 5849 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5850 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5851 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 5852 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5853 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5854 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5855 | /* no longer support new API additions in old API */ |
| 5856 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 5857 | return -EINVAL; |
| 5858 | } |
| 5859 | } |
| 5860 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5861 | return 0; |
| 5862 | } |
| 5863 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 5864 | 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] | 5865 | { |
| 5866 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5867 | u32 bitrate; |
| 5868 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 5869 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5870 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5871 | rate = nla_nest_start_noflag(msg, attr); |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5872 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5873 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5874 | |
| 5875 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 5876 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5877 | /* report 16-bit bitrate only if we can */ |
| 5878 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5879 | if (bitrate > 0 && |
| 5880 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 5881 | return false; |
| 5882 | if (bitrate_compat > 0 && |
| 5883 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 5884 | return false; |
| 5885 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5886 | switch (info->bw) { |
| 5887 | case RATE_INFO_BW_5: |
| 5888 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 5889 | break; |
| 5890 | case RATE_INFO_BW_10: |
| 5891 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 5892 | break; |
| 5893 | default: |
| 5894 | WARN_ON(1); |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 5895 | fallthrough; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5896 | case RATE_INFO_BW_20: |
| 5897 | rate_flg = 0; |
| 5898 | break; |
| 5899 | case RATE_INFO_BW_40: |
| 5900 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 5901 | break; |
| 5902 | case RATE_INFO_BW_80: |
| 5903 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 5904 | break; |
| 5905 | case RATE_INFO_BW_160: |
| 5906 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 5907 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5908 | case RATE_INFO_BW_HE_RU: |
| 5909 | rate_flg = 0; |
| 5910 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 5914 | return false; |
| 5915 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5916 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 5917 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 5918 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5919 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5920 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5921 | return false; |
| 5922 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 5923 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 5924 | return false; |
| 5925 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 5926 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5927 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5928 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5929 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5930 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 5931 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 5932 | return false; |
| 5933 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 5934 | return false; |
| 5935 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 5936 | return false; |
| 5937 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 5938 | return false; |
| 5939 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 5940 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 5941 | info->he_ru_alloc)) |
| 5942 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5943 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5944 | |
| 5945 | nla_nest_end(msg, rate); |
| 5946 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5947 | } |
| 5948 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5949 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 5950 | int id) |
| 5951 | { |
| 5952 | void *attr; |
| 5953 | int i = 0; |
| 5954 | |
| 5955 | if (!mask) |
| 5956 | return true; |
| 5957 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5958 | attr = nla_nest_start_noflag(msg, id); |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5959 | if (!attr) |
| 5960 | return false; |
| 5961 | |
| 5962 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 5963 | if (!(mask & BIT(i))) |
| 5964 | continue; |
| 5965 | |
| 5966 | if (nla_put_u8(msg, i, signal[i])) |
| 5967 | return false; |
| 5968 | } |
| 5969 | |
| 5970 | nla_nest_end(msg, attr); |
| 5971 | |
| 5972 | return true; |
| 5973 | } |
| 5974 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5975 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 5976 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5977 | struct cfg80211_registered_device *rdev, |
| 5978 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5979 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5980 | { |
| 5981 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5982 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5983 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5984 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5985 | if (!hdr) { |
| 5986 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5987 | return -1; |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5988 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5989 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5990 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5991 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 5992 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 5993 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5994 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5995 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5996 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5997 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5998 | |
| 5999 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6000 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6001 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6002 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 6003 | sinfo->memb)) \ |
| 6004 | goto nla_put_failure; \ |
| 6005 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6006 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6007 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6008 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 6009 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 6010 | goto nla_put_failure; \ |
| 6011 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6012 | |
| 6013 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 6014 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
Ben Greear | 6c7a003 | 2019-08-09 11:00:00 -0700 | [diff] [blame] | 6015 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6016 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6017 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 6018 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6019 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 6020 | (u32)sinfo->rx_bytes)) |
| 6021 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6022 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6023 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 6024 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 6025 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 6026 | (u32)sinfo->tx_bytes)) |
| 6027 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6028 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6029 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 6030 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6031 | PUT_SINFO(LLID, llid, u16); |
| 6032 | PUT_SINFO(PLID, plid, u16); |
| 6033 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6034 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6035 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 6036 | |
| 6037 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 6038 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6039 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6040 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 6041 | switch (rdev->wiphy.signal_type) { |
| 6042 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6043 | PUT_SINFO(SIGNAL, signal, u8); |
| 6044 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 6045 | break; |
| 6046 | default: |
| 6047 | break; |
| 6048 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6049 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 6050 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 6051 | sinfo->chain_signal, |
| 6052 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 6053 | goto nla_put_failure; |
| 6054 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6055 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 6056 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 6057 | sinfo->chain_signal_avg, |
| 6058 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 6059 | goto nla_put_failure; |
| 6060 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6061 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 6062 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 6063 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 6064 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 6065 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6066 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 6067 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 6068 | NL80211_STA_INFO_RX_BITRATE)) |
| 6069 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 6070 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6071 | |
| 6072 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 6073 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 6074 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 6075 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 6076 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
Narayanraddi Masti | ab60633 | 2019-02-07 12:16:05 -0800 | [diff] [blame] | 6077 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6078 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 6079 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 6080 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 6081 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
Bob Copeland | dbdaee7 | 2018-10-25 15:48:53 -0400 | [diff] [blame] | 6082 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
Markus Theil | 1303a51 | 2020-06-11 16:02:38 +0200 | [diff] [blame] | 6083 | PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6084 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6085 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6086 | bss_param = nla_nest_start_noflag(msg, |
| 6087 | NL80211_STA_INFO_BSS_PARAM); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 6088 | if (!bss_param) |
| 6089 | goto nla_put_failure; |
| 6090 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6091 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 6092 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 6093 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 6094 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 6095 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 6096 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 6097 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 6098 | sinfo->bss_param.dtim_period) || |
| 6099 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 6100 | sinfo->bss_param.beacon_interval)) |
| 6101 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 6102 | |
| 6103 | nla_nest_end(msg, bss_param); |
| 6104 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 6105 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6106 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 6107 | sizeof(struct nl80211_sta_flag_update), |
| 6108 | &sinfo->sta_flags)) |
| 6109 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6110 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6111 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 6112 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 6113 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 6114 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Ankita Bajaj | 0d4e14a | 2018-09-27 18:01:57 +0300 | [diff] [blame] | 6115 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 6116 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 6117 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
Balaji Pothunoori | 9c06602 | 2018-07-19 18:56:27 +0530 | [diff] [blame] | 6118 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 6119 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 6120 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 6121 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6122 | |
| 6123 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6124 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6125 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 6126 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6127 | struct nlattr *tidsattr; |
| 6128 | int tid; |
| 6129 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6130 | tidsattr = nla_nest_start_noflag(msg, |
| 6131 | NL80211_STA_INFO_TID_STATS); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6132 | if (!tidsattr) |
| 6133 | goto nla_put_failure; |
| 6134 | |
| 6135 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 6136 | struct cfg80211_tid_stats *tidstats; |
| 6137 | struct nlattr *tidattr; |
| 6138 | |
| 6139 | tidstats = &sinfo->pertid[tid]; |
| 6140 | |
| 6141 | if (!tidstats->filled) |
| 6142 | continue; |
| 6143 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6144 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6145 | if (!tidattr) |
| 6146 | goto nla_put_failure; |
| 6147 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6148 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6149 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6150 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 6151 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6152 | goto nla_put_failure; \ |
| 6153 | } while (0) |
| 6154 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6155 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 6156 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 6157 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 6158 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6159 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 6160 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 6161 | if ((tidstats->filled & |
| 6162 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 6163 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 6164 | NL80211_TID_STATS_TXQ_STATS)) |
| 6165 | goto nla_put_failure; |
| 6166 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 6167 | nla_nest_end(msg, tidattr); |
| 6168 | } |
| 6169 | |
| 6170 | nla_nest_end(msg, tidsattr); |
| 6171 | } |
| 6172 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6173 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6174 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 6175 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6176 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 6177 | sinfo->assoc_req_ies)) |
| 6178 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 6179 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 6180 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6181 | genlmsg_end(msg, hdr); |
| 6182 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6183 | |
| 6184 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 6185 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 6186 | genlmsg_cancel(msg, hdr); |
| 6187 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6188 | } |
| 6189 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6190 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6191 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6192 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6193 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6194 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6195 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6196 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6197 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6198 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6199 | |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6200 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6201 | if (err) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 6202 | return err; |
| 6203 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ |
| 6204 | __acquire(&rdev->wiphy.mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6205 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6206 | if (!wdev->netdev) { |
| 6207 | err = -EINVAL; |
| 6208 | goto out_err; |
| 6209 | } |
| 6210 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6211 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6212 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6213 | goto out_err; |
| 6214 | } |
| 6215 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6216 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6217 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6218 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6219 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6220 | if (err == -ENOENT) |
| 6221 | break; |
| 6222 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6223 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6224 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 6225 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6226 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6227 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6228 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6229 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6230 | goto out; |
| 6231 | |
| 6232 | sta_idx++; |
| 6233 | } |
| 6234 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6235 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6236 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6237 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6238 | out_err: |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 6239 | wiphy_unlock(&rdev->wiphy); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6240 | |
| 6241 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6242 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6243 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6244 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 6245 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6246 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6247 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6248 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6249 | struct sk_buff *msg; |
| 6250 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6251 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6252 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6253 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6254 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6255 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6256 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6257 | |
| 6258 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6259 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6260 | if (!rdev->ops->get_station) |
| 6261 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6262 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6263 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6264 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6265 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6266 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6267 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 6268 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 6269 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6270 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 6271 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6272 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 6273 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 6274 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6275 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6276 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6277 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6278 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 6279 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 6280 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6281 | } |
| 6282 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6283 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 6284 | struct station_parameters *params, |
| 6285 | enum cfg80211_station_type statype) |
| 6286 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6287 | if (params->listen_interval != -1 && |
| 6288 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6289 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6290 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6291 | if (params->support_p2p_ps != -1 && |
| 6292 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 6293 | return -EINVAL; |
| 6294 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 6295 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6296 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 6297 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6298 | return -EINVAL; |
| 6299 | |
| 6300 | /* When you run into this, adjust the code below for the new flag */ |
| 6301 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6302 | |
| 6303 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 6304 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 6305 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6306 | /* |
| 6307 | * No ignoring the TDLS flag here -- the userspace mesh |
| 6308 | * code doesn't have the bug of including TDLS in the |
| 6309 | * mask everywhere. |
| 6310 | */ |
| 6311 | if (params->sta_flags_mask & |
| 6312 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6313 | BIT(NL80211_STA_FLAG_MFP) | |
| 6314 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 6315 | return -EINVAL; |
| 6316 | break; |
| 6317 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 6318 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 6319 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6320 | return -EINVAL; |
| 6321 | /* ignore since it can't change */ |
| 6322 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 6323 | break; |
| 6324 | default: |
| 6325 | /* disallow mesh-specific things */ |
| 6326 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 6327 | return -EINVAL; |
| 6328 | if (params->local_pm) |
| 6329 | return -EINVAL; |
| 6330 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 6331 | return -EINVAL; |
| 6332 | } |
| 6333 | |
| 6334 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 6335 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 6336 | /* TDLS can't be set, ... */ |
| 6337 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 6338 | return -EINVAL; |
| 6339 | /* |
| 6340 | * ... but don't bother the driver with it. This works around |
| 6341 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 6342 | * TLDS_PEER flag in the mask even for AP mode. |
| 6343 | */ |
| 6344 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 6345 | } |
| 6346 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 6347 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 6348 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6349 | /* reject other things that can't change */ |
| 6350 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 6351 | return -EINVAL; |
| 6352 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 6353 | return -EINVAL; |
| 6354 | if (params->supported_rates) |
| 6355 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6356 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 6357 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6358 | return -EINVAL; |
| 6359 | } |
| 6360 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 6361 | if (statype != CFG80211_STA_AP_CLIENT && |
| 6362 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6363 | if (params->vlan) |
| 6364 | return -EINVAL; |
| 6365 | } |
| 6366 | |
| 6367 | switch (statype) { |
| 6368 | case CFG80211_STA_AP_MLME_CLIENT: |
| 6369 | /* Use this only for authorizing/unauthorizing a station */ |
| 6370 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 6371 | return -EOPNOTSUPP; |
| 6372 | break; |
| 6373 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 6374 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6375 | /* accept only the listed bits */ |
| 6376 | if (params->sta_flags_mask & |
| 6377 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 6378 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6379 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6380 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 6381 | BIT(NL80211_STA_FLAG_WME) | |
| 6382 | BIT(NL80211_STA_FLAG_MFP))) |
| 6383 | return -EINVAL; |
| 6384 | |
| 6385 | /* but authenticated/associated only if driver handles it */ |
| 6386 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 6387 | params->sta_flags_mask & |
| 6388 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6389 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 6390 | return -EINVAL; |
| 6391 | break; |
| 6392 | case CFG80211_STA_IBSS: |
| 6393 | case CFG80211_STA_AP_STA: |
| 6394 | /* reject any changes other than AUTHORIZED */ |
| 6395 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 6396 | return -EINVAL; |
| 6397 | break; |
| 6398 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 6399 | /* reject any changes other than AUTHORIZED or WME */ |
| 6400 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 6401 | BIT(NL80211_STA_FLAG_WME))) |
| 6402 | return -EINVAL; |
| 6403 | /* force (at least) rates when authorizing */ |
| 6404 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 6405 | !params->supported_rates) |
| 6406 | return -EINVAL; |
| 6407 | break; |
| 6408 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 6409 | /* reject any changes */ |
| 6410 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 6411 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6412 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 6413 | return -EINVAL; |
| 6414 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 6415 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 6416 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 6417 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6418 | return -EINVAL; |
| 6419 | break; |
| 6420 | } |
| 6421 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 6422 | /* |
| 6423 | * Older kernel versions ignored this attribute entirely, so don't |
| 6424 | * reject attempts to update it but mark it as unused instead so the |
| 6425 | * driver won't look at the data. |
| 6426 | */ |
| 6427 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 6428 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 6429 | params->opmode_notif_used = false; |
| 6430 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6431 | return 0; |
| 6432 | } |
| 6433 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 6434 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6435 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 6436 | * 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] | 6437 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6438 | static struct net_device *get_vlan(struct genl_info *info, |
| 6439 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6440 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6441 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6442 | struct net_device *v; |
| 6443 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6444 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6445 | if (!vlanattr) |
| 6446 | return NULL; |
| 6447 | |
| 6448 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 6449 | if (!v) |
| 6450 | return ERR_PTR(-ENODEV); |
| 6451 | |
| 6452 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 6453 | ret = -EINVAL; |
| 6454 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6455 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6456 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6457 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 6458 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 6459 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 6460 | ret = -EINVAL; |
| 6461 | goto error; |
| 6462 | } |
| 6463 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6464 | if (!netif_running(v)) { |
| 6465 | ret = -ENETDOWN; |
| 6466 | goto error; |
| 6467 | } |
| 6468 | |
| 6469 | return v; |
| 6470 | error: |
| 6471 | dev_put(v); |
| 6472 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6473 | } |
| 6474 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 6475 | static const struct nla_policy |
| 6476 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6477 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 6478 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 6479 | }; |
| 6480 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6481 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 6482 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6483 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6484 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 6485 | struct nlattr *nla; |
| 6486 | int err; |
| 6487 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6488 | /* parse WME attributes if present */ |
| 6489 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 6490 | return 0; |
| 6491 | |
| 6492 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 6493 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
| 6494 | nl80211_sta_wme_policy, |
| 6495 | info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6496 | if (err) |
| 6497 | return err; |
| 6498 | |
| 6499 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 6500 | params->uapsd_queues = nla_get_u8( |
| 6501 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 6502 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 6503 | return -EINVAL; |
| 6504 | |
| 6505 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 6506 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 6507 | |
| 6508 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 6509 | return -EINVAL; |
| 6510 | |
| 6511 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 6512 | |
| 6513 | return 0; |
| 6514 | } |
| 6515 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6516 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 6517 | struct station_parameters *params) |
| 6518 | { |
| 6519 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 6520 | params->supported_channels = |
| 6521 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6522 | params->supported_channels_len = |
| 6523 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6524 | /* |
| 6525 | * Need to include at least one (first channel, number of |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 6526 | * channels) tuple for each subband (checked in policy), |
| 6527 | * 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] | 6528 | */ |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6529 | if (params->supported_channels_len % 2) |
| 6530 | return -EINVAL; |
| 6531 | } |
| 6532 | |
| 6533 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 6534 | params->supported_oper_classes = |
| 6535 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 6536 | params->supported_oper_classes_len = |
| 6537 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6538 | } |
| 6539 | return 0; |
| 6540 | } |
| 6541 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6542 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 6543 | struct station_parameters *params) |
| 6544 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6545 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6546 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6547 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 6548 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6549 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6550 | params->ht_capa = |
| 6551 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 6552 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6553 | params->vht_capa = |
| 6554 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6555 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6556 | params->he_capa = |
| 6557 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6558 | params->he_capa_len = |
| 6559 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6560 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6561 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6562 | err = nl80211_parse_sta_channel_info(info, params); |
| 6563 | if (err) |
| 6564 | return err; |
| 6565 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6566 | return nl80211_parse_sta_wme(info, params); |
| 6567 | } |
| 6568 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6569 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
| 6570 | struct station_parameters *params) |
| 6571 | { |
| 6572 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6573 | int idx; |
| 6574 | |
| 6575 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { |
| 6576 | if (!rdev->ops->set_tx_power || |
| 6577 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6578 | NL80211_EXT_FEATURE_STA_TX_PWR)) |
| 6579 | return -EOPNOTSUPP; |
| 6580 | |
| 6581 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; |
| 6582 | params->txpwr.type = nla_get_u8(info->attrs[idx]); |
| 6583 | |
| 6584 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { |
| 6585 | idx = NL80211_ATTR_STA_TX_POWER; |
| 6586 | |
| 6587 | if (info->attrs[idx]) |
| 6588 | params->txpwr.power = |
| 6589 | nla_get_s16(info->attrs[idx]); |
| 6590 | else |
| 6591 | return -EINVAL; |
| 6592 | } |
| 6593 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; |
| 6594 | } |
| 6595 | |
| 6596 | return 0; |
| 6597 | } |
| 6598 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6599 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 6600 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6602 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6603 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6604 | u8 *mac_addr; |
| 6605 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6606 | |
| 6607 | memset(¶ms, 0, sizeof(params)); |
| 6608 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6609 | if (!rdev->ops->change_station) |
| 6610 | return -EOPNOTSUPP; |
| 6611 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6612 | /* |
| 6613 | * AID and listen_interval properties can be set only for unassociated |
| 6614 | * station. Include these parameters here and will check them in |
| 6615 | * cfg80211_check_station_change(). |
| 6616 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 6617 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 6618 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6619 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6620 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6621 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6622 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6623 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6624 | params.listen_interval = |
| 6625 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 6626 | else |
| 6627 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6628 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6629 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 6630 | params.support_p2p_ps = |
| 6631 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 6632 | else |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6633 | params.support_p2p_ps = -1; |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6634 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6635 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6636 | return -EINVAL; |
| 6637 | |
| 6638 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6639 | |
| 6640 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 6641 | params.supported_rates = |
| 6642 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6643 | params.supported_rates_len = |
| 6644 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6645 | } |
| 6646 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6647 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6648 | params.capability = |
| 6649 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6650 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6651 | } |
| 6652 | |
| 6653 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6654 | params.ext_capab = |
| 6655 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6656 | params.ext_capab_len = |
| 6657 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6658 | } |
| 6659 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6660 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6661 | return -EINVAL; |
| 6662 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6663 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6664 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6665 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6666 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6667 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 6668 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6669 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6670 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 6671 | params.peer_aid = nla_get_u16( |
| 6672 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6673 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 6674 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 6675 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6676 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 6677 | params.local_pm = nla_get_u32( |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6678 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 6679 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 6680 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6681 | params.opmode_notif_used = true; |
| 6682 | params.opmode_notif = |
| 6683 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6684 | } |
| 6685 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6686 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6687 | params.he_6ghz_capa = |
Johannes Berg | fce2ff7 | 2020-08-05 15:35:18 +0200 | [diff] [blame] | 6688 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6689 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6690 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6691 | params.airtime_weight = |
| 6692 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6693 | |
| 6694 | if (params.airtime_weight && |
| 6695 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6696 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6697 | return -EOPNOTSUPP; |
| 6698 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6699 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6700 | if (err) |
| 6701 | return err; |
| 6702 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6703 | /* Include parameters for TDLS peer (will check later) */ |
| 6704 | err = nl80211_set_station_tdls(info, ¶ms); |
| 6705 | if (err) |
| 6706 | return err; |
| 6707 | |
| 6708 | params.vlan = get_vlan(info, rdev); |
| 6709 | if (IS_ERR(params.vlan)) |
| 6710 | return PTR_ERR(params.vlan); |
| 6711 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6712 | switch (dev->ieee80211_ptr->iftype) { |
| 6713 | case NL80211_IFTYPE_AP: |
| 6714 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6715 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6716 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6717 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6718 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6719 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6720 | break; |
| 6721 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6722 | err = -EOPNOTSUPP; |
| 6723 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 6724 | } |
| 6725 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6726 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6727 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6728 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6729 | out_put_vlan: |
Yajun Deng | 1160dfa | 2021-08-05 19:55:27 +0800 | [diff] [blame] | 6730 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6731 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6732 | return err; |
| 6733 | } |
| 6734 | |
| 6735 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 6736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6738 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6739 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6740 | struct station_parameters params; |
| 6741 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6742 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6743 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6744 | |
| 6745 | memset(¶ms, 0, sizeof(params)); |
| 6746 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6747 | if (!rdev->ops->add_station) |
| 6748 | return -EOPNOTSUPP; |
| 6749 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6750 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6751 | return -EINVAL; |
| 6752 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6753 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6754 | return -EINVAL; |
| 6755 | |
| 6756 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 6757 | return -EINVAL; |
| 6758 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6759 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 6760 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 6761 | return -EINVAL; |
| 6762 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6763 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6764 | params.supported_rates = |
| 6765 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6766 | params.supported_rates_len = |
| 6767 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6768 | params.listen_interval = |
| 6769 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6770 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6771 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6772 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6773 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6774 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6775 | params.support_p2p_ps = |
| 6776 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6777 | } else { |
| 6778 | /* |
| 6779 | * if not specified, assume it's supported for P2P GO interface, |
| 6780 | * and is NOT supported for AP interface |
| 6781 | */ |
| 6782 | params.support_p2p_ps = |
| 6783 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 6784 | } |
| 6785 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6786 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6787 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6788 | else |
| 6789 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6790 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6791 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6792 | params.capability = |
| 6793 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6794 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6795 | } |
| 6796 | |
| 6797 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6798 | params.ext_capab = |
| 6799 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6800 | params.ext_capab_len = |
| 6801 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6802 | } |
| 6803 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 6804 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6805 | params.ht_capa = |
| 6806 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6807 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 6808 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6809 | params.vht_capa = |
| 6810 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6811 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6812 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6813 | params.he_capa = |
| 6814 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6815 | params.he_capa_len = |
| 6816 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6817 | } |
| 6818 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6819 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6820 | params.he_6ghz_capa = |
| 6821 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
| 6822 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 6823 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6824 | params.opmode_notif_used = true; |
| 6825 | params.opmode_notif = |
| 6826 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6827 | } |
| 6828 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6829 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6830 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6831 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6832 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6833 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6834 | params.airtime_weight = |
| 6835 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6836 | |
| 6837 | if (params.airtime_weight && |
| 6838 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6839 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6840 | return -EOPNOTSUPP; |
| 6841 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6842 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6843 | if (err) |
| 6844 | return err; |
| 6845 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6846 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 6847 | if (err) |
| 6848 | return err; |
| 6849 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6850 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 6851 | if (err) |
| 6852 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6853 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6854 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6855 | return -EINVAL; |
| 6856 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6857 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 6858 | * as userspace might just pass through the capabilities from the IEs |
| 6859 | * directly, rather than enforcing this restriction and returning an |
| 6860 | * error in this case. |
| 6861 | */ |
| 6862 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 6863 | params.ht_capa = NULL; |
| 6864 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6865 | |
| 6866 | /* HE requires WME */ |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6867 | if (params.he_capa_len || params.he_6ghz_capa) |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6868 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6869 | } |
| 6870 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6871 | /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ |
| 6872 | if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) |
| 6873 | return -EINVAL; |
| 6874 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6875 | /* When you run into this, adjust the code below for the new flag */ |
| 6876 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6877 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6878 | switch (dev->ieee80211_ptr->iftype) { |
| 6879 | case NL80211_IFTYPE_AP: |
| 6880 | case NL80211_IFTYPE_AP_VLAN: |
| 6881 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6882 | /* ignore WME attributes if iface/sta is not capable */ |
| 6883 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 6884 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 6885 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6886 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6887 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6888 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6889 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6890 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6891 | /* but don't bother the driver with it */ |
| 6892 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6893 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6894 | /* allow authenticated/associated only if driver handles it */ |
| 6895 | if (!(rdev->wiphy.features & |
| 6896 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6897 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6898 | return -EINVAL; |
| 6899 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6900 | /* Older userspace, or userspace wanting to be compatible with |
| 6901 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 6902 | * and assoc flags in the mask, but assumes the station will be |
| 6903 | * added as associated anyway since this was the required driver |
| 6904 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 6905 | * introduced. |
| 6906 | * In order to not bother drivers with this quirk in the API |
| 6907 | * set the flags in both the mask and set for new stations in |
| 6908 | * this case. |
| 6909 | */ |
| 6910 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 6911 | params.sta_flags_mask |= auth_assoc; |
| 6912 | params.sta_flags_set |= auth_assoc; |
| 6913 | } |
| 6914 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6915 | /* must be last in here for error handling */ |
| 6916 | params.vlan = get_vlan(info, rdev); |
| 6917 | if (IS_ERR(params.vlan)) |
| 6918 | return PTR_ERR(params.vlan); |
| 6919 | break; |
| 6920 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6921 | /* ignore uAPSD data */ |
| 6922 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6923 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6924 | /* associated is disallowed */ |
| 6925 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 6926 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6927 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6928 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6929 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6930 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6931 | break; |
| 6932 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 6933 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6934 | /* ignore uAPSD data */ |
| 6935 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6936 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6937 | /* these are disallowed */ |
| 6938 | if (params.sta_flags_mask & |
| 6939 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6940 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6941 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6942 | /* Only TDLS peers can be added */ |
| 6943 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6944 | return -EINVAL; |
| 6945 | /* Can only add if TDLS ... */ |
| 6946 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 6947 | return -EOPNOTSUPP; |
| 6948 | /* ... with external setup is supported */ |
| 6949 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 6950 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6951 | /* |
| 6952 | * Older wpa_supplicant versions always mark the TDLS peer |
| 6953 | * as authorized, but it shouldn't yet be. |
| 6954 | */ |
| 6955 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6956 | break; |
| 6957 | default: |
| 6958 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6959 | } |
| 6960 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6961 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6962 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6963 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6964 | |
Yajun Deng | 1160dfa | 2021-08-05 19:55:27 +0800 | [diff] [blame] | 6965 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6966 | return err; |
| 6967 | } |
| 6968 | |
| 6969 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 6970 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6971 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6972 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6973 | struct station_del_parameters params; |
| 6974 | |
| 6975 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6976 | |
| 6977 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6978 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6979 | |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6980 | switch (dev->ieee80211_ptr->iftype) { |
| 6981 | case NL80211_IFTYPE_AP: |
| 6982 | case NL80211_IFTYPE_AP_VLAN: |
| 6983 | case NL80211_IFTYPE_MESH_POINT: |
| 6984 | case NL80211_IFTYPE_P2P_GO: |
| 6985 | /* always accept these */ |
| 6986 | break; |
| 6987 | case NL80211_IFTYPE_ADHOC: |
| 6988 | /* conditionally accept */ |
| 6989 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 6990 | NL80211_EXT_FEATURE_DEL_IBSS_STA)) |
| 6991 | break; |
Nicolas Cavallari | edafcf4 | 2020-03-05 14:57:53 +0100 | [diff] [blame] | 6992 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6993 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6994 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6995 | } |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 6996 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6997 | if (!rdev->ops->del_station) |
| 6998 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6999 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 7000 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 7001 | params.subtype = |
| 7002 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 7003 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 7004 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 7005 | return -EINVAL; |
| 7006 | } else { |
| 7007 | /* Default to Deauthentication frame */ |
| 7008 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 7009 | } |
| 7010 | |
| 7011 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 7012 | params.reason_code = |
| 7013 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 7014 | if (params.reason_code == 0) |
| 7015 | return -EINVAL; /* 0 is reserved */ |
| 7016 | } else { |
| 7017 | /* Default to reason code 2 */ |
| 7018 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 7019 | } |
| 7020 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 7021 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 7022 | } |
| 7023 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7024 | 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] | 7025 | int flags, struct net_device *dev, |
| 7026 | u8 *dst, u8 *next_hop, |
| 7027 | struct mpath_info *pinfo) |
| 7028 | { |
| 7029 | void *hdr; |
| 7030 | struct nlattr *pinfoattr; |
| 7031 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 7032 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7033 | if (!hdr) |
| 7034 | return -1; |
| 7035 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7036 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7037 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7038 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 7039 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 7040 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 7041 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7042 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7043 | if (!pinfoattr) |
| 7044 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7045 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 7046 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 7047 | pinfo->frame_qlen)) |
| 7048 | goto nla_put_failure; |
| 7049 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 7050 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 7051 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 7052 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 7053 | pinfo->metric)) || |
| 7054 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 7055 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 7056 | pinfo->exptime)) || |
| 7057 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 7058 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 7059 | pinfo->flags)) || |
| 7060 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 7061 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 7062 | pinfo->discovery_timeout)) || |
| 7063 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 7064 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 7065 | pinfo->discovery_retries)) || |
| 7066 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 7067 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 7068 | pinfo->hop_count)) || |
| 7069 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 7070 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 7071 | pinfo->path_change_count))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7072 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7073 | |
| 7074 | nla_nest_end(msg, pinfoattr); |
| 7075 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7076 | genlmsg_end(msg, hdr); |
| 7077 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7078 | |
| 7079 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 7080 | genlmsg_cancel(msg, hdr); |
| 7081 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7082 | } |
| 7083 | |
| 7084 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7085 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7086 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7087 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7088 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7089 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7090 | u8 dst[ETH_ALEN]; |
| 7091 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7092 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7093 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7094 | |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 7095 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 7096 | if (err) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7097 | return err; |
| 7098 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ |
| 7099 | __acquire(&rdev->wiphy.mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7100 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7101 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7102 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7103 | goto out_err; |
| 7104 | } |
| 7105 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7106 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7107 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 7108 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7109 | } |
| 7110 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7111 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 7112 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7113 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7114 | if (err == -ENOENT) |
| 7115 | break; |
| 7116 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7117 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7118 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7119 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7120 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7121 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7122 | &pinfo) < 0) |
| 7123 | goto out; |
| 7124 | |
| 7125 | path_idx++; |
| 7126 | } |
| 7127 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7128 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 7129 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7130 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7131 | out_err: |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7132 | wiphy_unlock(&rdev->wiphy); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 7133 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7134 | } |
| 7135 | |
| 7136 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 7137 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7138 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7139 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7140 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7141 | struct mpath_info pinfo; |
| 7142 | struct sk_buff *msg; |
| 7143 | u8 *dst = NULL; |
| 7144 | u8 next_hop[ETH_ALEN]; |
| 7145 | |
| 7146 | memset(&pinfo, 0, sizeof(pinfo)); |
| 7147 | |
| 7148 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7149 | return -EINVAL; |
| 7150 | |
| 7151 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7152 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7153 | if (!rdev->ops->get_mpath) |
| 7154 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7155 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7156 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7157 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7158 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7159 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7160 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7161 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7162 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7163 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7164 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7165 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7166 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7167 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7168 | dev, dst, next_hop, &pinfo) < 0) { |
| 7169 | nlmsg_free(msg); |
| 7170 | return -ENOBUFS; |
| 7171 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7172 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7173 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7174 | } |
| 7175 | |
| 7176 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 7177 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7178 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7179 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7180 | u8 *dst = NULL; |
| 7181 | u8 *next_hop = NULL; |
| 7182 | |
| 7183 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7184 | return -EINVAL; |
| 7185 | |
| 7186 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 7187 | return -EINVAL; |
| 7188 | |
| 7189 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7190 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 7191 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7192 | if (!rdev->ops->change_mpath) |
| 7193 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7194 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7195 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7196 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7197 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7198 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7199 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7200 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7201 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 7202 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7203 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7204 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7205 | u8 *dst = NULL; |
| 7206 | u8 *next_hop = NULL; |
| 7207 | |
| 7208 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7209 | return -EINVAL; |
| 7210 | |
| 7211 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 7212 | return -EINVAL; |
| 7213 | |
| 7214 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7215 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 7216 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7217 | if (!rdev->ops->add_mpath) |
| 7218 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7219 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7220 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7221 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7222 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7223 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 7227 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7228 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7229 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7230 | u8 *dst = NULL; |
| 7231 | |
| 7232 | if (info->attrs[NL80211_ATTR_MAC]) |
| 7233 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7234 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7235 | if (!rdev->ops->del_mpath) |
| 7236 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7237 | |
Miaoqing Pan | b501426 | 2019-09-26 16:16:50 +0800 | [diff] [blame] | 7238 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7239 | return -EOPNOTSUPP; |
| 7240 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7241 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 7242 | } |
| 7243 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 7244 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 7245 | { |
| 7246 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7247 | int err; |
| 7248 | struct net_device *dev = info->user_ptr[1]; |
| 7249 | struct mpath_info pinfo; |
| 7250 | struct sk_buff *msg; |
| 7251 | u8 *dst = NULL; |
| 7252 | u8 mpp[ETH_ALEN]; |
| 7253 | |
| 7254 | memset(&pinfo, 0, sizeof(pinfo)); |
| 7255 | |
| 7256 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 7257 | return -EINVAL; |
| 7258 | |
| 7259 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 7260 | |
| 7261 | if (!rdev->ops->get_mpp) |
| 7262 | return -EOPNOTSUPP; |
| 7263 | |
| 7264 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7265 | return -EOPNOTSUPP; |
| 7266 | |
| 7267 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 7268 | if (err) |
| 7269 | return err; |
| 7270 | |
| 7271 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7272 | if (!msg) |
| 7273 | return -ENOMEM; |
| 7274 | |
| 7275 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 7276 | dev, dst, mpp, &pinfo) < 0) { |
| 7277 | nlmsg_free(msg); |
| 7278 | return -ENOBUFS; |
| 7279 | } |
| 7280 | |
| 7281 | return genlmsg_reply(msg, info); |
| 7282 | } |
| 7283 | |
| 7284 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 7285 | struct netlink_callback *cb) |
| 7286 | { |
| 7287 | struct mpath_info pinfo; |
| 7288 | struct cfg80211_registered_device *rdev; |
| 7289 | struct wireless_dev *wdev; |
| 7290 | u8 dst[ETH_ALEN]; |
| 7291 | u8 mpp[ETH_ALEN]; |
| 7292 | int path_idx = cb->args[2]; |
| 7293 | int err; |
| 7294 | |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 7295 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 7296 | if (err) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7297 | return err; |
| 7298 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ |
| 7299 | __acquire(&rdev->wiphy.mtx); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 7300 | |
| 7301 | if (!rdev->ops->dump_mpp) { |
| 7302 | err = -EOPNOTSUPP; |
| 7303 | goto out_err; |
| 7304 | } |
| 7305 | |
| 7306 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 7307 | err = -EOPNOTSUPP; |
| 7308 | goto out_err; |
| 7309 | } |
| 7310 | |
| 7311 | while (1) { |
| 7312 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 7313 | mpp, &pinfo); |
| 7314 | if (err == -ENOENT) |
| 7315 | break; |
| 7316 | if (err) |
| 7317 | goto out_err; |
| 7318 | |
| 7319 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 7320 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 7321 | wdev->netdev, dst, mpp, |
| 7322 | &pinfo) < 0) |
| 7323 | goto out; |
| 7324 | |
| 7325 | path_idx++; |
| 7326 | } |
| 7327 | |
| 7328 | out: |
| 7329 | cb->args[2] = path_idx; |
| 7330 | err = skb->len; |
| 7331 | out_err: |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7332 | wiphy_unlock(&rdev->wiphy); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 7333 | return err; |
| 7334 | } |
| 7335 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7336 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 7337 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7338 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7339 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7340 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7341 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7342 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7343 | |
| 7344 | memset(¶ms, 0, sizeof(params)); |
| 7345 | /* default to not changing parameters */ |
| 7346 | params.use_cts_prot = -1; |
| 7347 | params.use_short_preamble = -1; |
| 7348 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 7349 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 7350 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 7351 | params.p2p_ctwindow = -1; |
| 7352 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7353 | |
| 7354 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 7355 | params.use_cts_prot = |
| 7356 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 7357 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 7358 | params.use_short_preamble = |
| 7359 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 7360 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 7361 | params.use_short_slot_time = |
| 7362 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 7363 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 7364 | params.basic_rates = |
| 7365 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7366 | params.basic_rates_len = |
| 7367 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 7368 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 7369 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 7370 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 7371 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 7372 | params.ht_opmode = |
| 7373 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7374 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 7375 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 7376 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 7377 | return -EINVAL; |
| 7378 | params.p2p_ctwindow = |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7379 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 7380 | if (params.p2p_ctwindow != 0 && |
| 7381 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 7382 | return -EINVAL; |
| 7383 | } |
| 7384 | |
| 7385 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 7386 | u8 tmp; |
| 7387 | |
| 7388 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 7389 | return -EINVAL; |
| 7390 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 7391 | params.p2p_opp_ps = tmp; |
| 7392 | if (params.p2p_opp_ps && |
| 7393 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 7394 | return -EINVAL; |
| 7395 | } |
| 7396 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7397 | if (!rdev->ops->change_bss) |
| 7398 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7399 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7400 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7401 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 7402 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7403 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7404 | wdev_lock(wdev); |
| 7405 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 7406 | wdev_unlock(wdev); |
| 7407 | |
| 7408 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7409 | } |
| 7410 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7411 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7412 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7413 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 7414 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 7415 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 7416 | u32 owner_nlportid; |
| 7417 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 7418 | /* |
| 7419 | * You should only get this when cfg80211 hasn't yet initialized |
| 7420 | * completely when built-in to the kernel right between the time |
| 7421 | * window between nl80211_init() and regulatory_init(), if that is |
| 7422 | * even possible. |
| 7423 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7424 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 7425 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 7426 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 7427 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 7428 | user_reg_hint_type = |
| 7429 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 7430 | else |
| 7431 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 7432 | |
| 7433 | switch (user_reg_hint_type) { |
| 7434 | case NL80211_USER_REG_HINT_USER: |
| 7435 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 7436 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7437 | return -EINVAL; |
| 7438 | |
| 7439 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7440 | return regulatory_hint_user(data, user_reg_hint_type); |
| 7441 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 7442 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 7443 | owner_nlportid = info->snd_portid; |
| 7444 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 7445 | } else { |
| 7446 | owner_nlportid = 0; |
| 7447 | is_indoor = true; |
| 7448 | } |
| 7449 | |
| 7450 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 7451 | default: |
| 7452 | return -EINVAL; |
| 7453 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7454 | } |
| 7455 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 7456 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 7457 | { |
| 7458 | return reg_reload_regdb(); |
| 7459 | } |
| 7460 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7461 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7462 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7463 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7465 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7466 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7467 | struct mesh_config cur_params; |
| 7468 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7469 | void *hdr; |
| 7470 | struct nlattr *pinfoattr; |
| 7471 | struct sk_buff *msg; |
| 7472 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7473 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7474 | return -EOPNOTSUPP; |
| 7475 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7476 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7477 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 7478 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7479 | wdev_lock(wdev); |
| 7480 | /* If not connected, get default parameters */ |
| 7481 | if (!wdev->mesh_id_len) |
| 7482 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 7483 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7484 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7485 | wdev_unlock(wdev); |
| 7486 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7487 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7488 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7489 | |
| 7490 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7492 | if (!msg) |
| 7493 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7494 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7495 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7496 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7497 | goto out; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7498 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7499 | if (!pinfoattr) |
| 7500 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7501 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7502 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 7503 | cur_params.dot11MeshRetryTimeout) || |
| 7504 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7505 | cur_params.dot11MeshConfirmTimeout) || |
| 7506 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7507 | cur_params.dot11MeshHoldingTimeout) || |
| 7508 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7509 | cur_params.dot11MeshMaxPeerLinks) || |
| 7510 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 7511 | cur_params.dot11MeshMaxRetries) || |
| 7512 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 7513 | cur_params.dot11MeshTTL) || |
| 7514 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 7515 | cur_params.element_ttl) || |
| 7516 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7517 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 7518 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 7519 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7520 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7521 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 7522 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7523 | cur_params.path_refresh_time) || |
| 7524 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7525 | cur_params.min_discovery_timeout) || |
| 7526 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 7527 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 7528 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 7529 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 7530 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 7531 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 7532 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 7533 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 7534 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 7535 | cur_params.dot11MeshHWMPRootMode) || |
| 7536 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7537 | cur_params.dot11MeshHWMPRannInterval) || |
| 7538 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 7539 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 7540 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 7541 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 7542 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 7543 | cur_params.rssi_threshold) || |
| 7544 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 7545 | cur_params.ht_opmode) || |
| 7546 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7547 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 7548 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7549 | cur_params.dot11MeshHWMProotInterval) || |
| 7550 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 7551 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 7552 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 7553 | cur_params.power_mode) || |
| 7554 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 7555 | cur_params.dot11MeshAwakeWindowDuration) || |
| 7556 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7557 | cur_params.plink_timeout) || |
| 7558 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7559 | cur_params.dot11MeshConnectedToMeshGate) || |
| 7560 | nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7561 | cur_params.dot11MeshNolearn) || |
| 7562 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7563 | cur_params.dot11MeshConnectedToAuthServer)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7564 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7565 | nla_nest_end(msg, pinfoattr); |
| 7566 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7567 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7568 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7569 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7570 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7571 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7572 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7573 | } |
| 7574 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7575 | static const struct nla_policy |
| 7576 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 7577 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 7578 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7579 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 7580 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7581 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 7582 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7583 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 7584 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 7585 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 7586 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7587 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7588 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7589 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 7590 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7591 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 7592 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7593 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7594 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7595 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 7596 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7597 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 7598 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7599 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 7600 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7601 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 7602 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 7603 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7604 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7605 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7606 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 7607 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7608 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 7609 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7610 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 7611 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7612 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 7613 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7614 | [NL80211_MESHCONF_POWER_MODE] = |
| 7615 | NLA_POLICY_RANGE(NLA_U32, |
| 7616 | NL80211_MESH_POWER_ACTIVE, |
| 7617 | NL80211_MESH_POWER_MAX), |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 7618 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 7619 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7620 | [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] | 7621 | [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7622 | [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] | 7623 | }; |
| 7624 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7625 | static const struct nla_policy |
| 7626 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7627 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7628 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 7629 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 7630 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7631 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7632 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 7633 | [NL80211_MESH_SETUP_IE] = |
| 7634 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 7635 | IEEE80211_MAX_DATA_LEN), |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7636 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7637 | }; |
| 7638 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7639 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7640 | struct mesh_config *cfg, |
| 7641 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7642 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7643 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7644 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7645 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7646 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7647 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 7648 | do { \ |
| 7649 | if (tb[attr]) { \ |
| 7650 | cfg->param = fn(tb[attr]); \ |
| 7651 | mask |= BIT((attr) - 1); \ |
| 7652 | } \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7653 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7654 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7655 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7656 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7657 | 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] | 7658 | return -EINVAL; |
| 7659 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7660 | /* This makes sure that there aren't more than 32 mesh config |
| 7661 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 7662 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 7663 | |
| 7664 | /* Fill in the params struct */ |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7665 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 7666 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 7667 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 7668 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7669 | nla_get_u16); |
| 7670 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 7671 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7672 | nla_get_u16); |
| 7673 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 7674 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7675 | nla_get_u16); |
| 7676 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 7677 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 7678 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 7679 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 7680 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 7681 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 7682 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 7683 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7684 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7685 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7686 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7687 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7688 | nla_get_u32); |
| 7689 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 7690 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7691 | nla_get_u8); |
| 7692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 7693 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7694 | nla_get_u32); |
| 7695 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 7696 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 7697 | return -EINVAL; |
| 7698 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 7699 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7700 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7702 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7703 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7704 | nla_get_u32); |
| 7705 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 7706 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 7707 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 7708 | return -EINVAL; |
| 7709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7710 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7711 | nla_get_u16); |
| 7712 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7713 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7714 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7716 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7717 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7718 | nla_get_u16); |
| 7719 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 7720 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 7721 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 7722 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7723 | nla_get_u16); |
| 7724 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7725 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7726 | nla_get_u8); |
| 7727 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 7728 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 7729 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 7730 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 7731 | nla_get_s32); |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7732 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 7733 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 7734 | nla_get_u8); |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7735 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, |
| 7736 | NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7737 | nla_get_u8); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7738 | /* |
| 7739 | * Check HT operation mode based on |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7740 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7741 | */ |
| 7742 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 7743 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 7744 | |
| 7745 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 7746 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 7747 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 7748 | return -EINVAL; |
| 7749 | |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7750 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 7751 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7752 | |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7753 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 7754 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7755 | } |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7756 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7757 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 7758 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7759 | nla_get_u32); |
| 7760 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 7761 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 7762 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 7763 | return -EINVAL; |
| 7764 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 7765 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7766 | nla_get_u16); |
| 7767 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 7768 | mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7769 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7770 | nla_get_u16); |
| 7771 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 7772 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 7773 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 7774 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 7775 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 7776 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7777 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, |
| 7778 | NL80211_MESHCONF_NOLEARN, nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7779 | if (mask_out) |
| 7780 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7781 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7782 | return 0; |
| 7783 | |
| 7784 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 7785 | } |
| 7786 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7787 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 7788 | struct mesh_setup *setup) |
| 7789 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7790 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7791 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 7792 | |
| 7793 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 7794 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7795 | 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] | 7796 | return -EINVAL; |
| 7797 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7798 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 7799 | setup->sync_method = |
| 7800 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 7801 | IEEE80211_SYNC_METHOD_VENDOR : |
| 7802 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 7803 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7804 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 7805 | setup->path_sel_proto = |
| 7806 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 7807 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 7808 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 7809 | |
| 7810 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 7811 | setup->path_metric = |
| 7812 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 7813 | IEEE80211_PATH_METRIC_VENDOR : |
| 7814 | IEEE80211_PATH_METRIC_AIRTIME; |
| 7815 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7816 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7817 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7818 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7819 | setup->ie = nla_data(ieattr); |
| 7820 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7821 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7822 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 7823 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 7824 | return -EINVAL; |
| 7825 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7826 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 7827 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7828 | if (setup->is_secure) |
| 7829 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7830 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7831 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 7832 | if (!setup->user_mpm) |
| 7833 | return -EINVAL; |
| 7834 | setup->auth_id = |
| 7835 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 7836 | } |
| 7837 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7838 | return 0; |
| 7839 | } |
| 7840 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7841 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7842 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7843 | { |
| 7844 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7845 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7846 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7847 | struct mesh_config cfg; |
| 7848 | u32 mask; |
| 7849 | int err; |
| 7850 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7851 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7852 | return -EOPNOTSUPP; |
| 7853 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7854 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7855 | return -EOPNOTSUPP; |
| 7856 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7857 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7858 | if (err) |
| 7859 | return err; |
| 7860 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7861 | wdev_lock(wdev); |
| 7862 | if (!wdev->mesh_id_len) |
| 7863 | err = -ENOLINK; |
| 7864 | |
| 7865 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7866 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7867 | |
| 7868 | wdev_unlock(wdev); |
| 7869 | |
| 7870 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7871 | } |
| 7872 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7873 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 7874 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7875 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7876 | struct nlattr *nl_reg_rules; |
| 7877 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7878 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7879 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 7880 | (regdom->dfs_region && |
| 7881 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7882 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7883 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7884 | 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] | 7885 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7886 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7887 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7888 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7889 | struct nlattr *nl_reg_rule; |
| 7890 | const struct ieee80211_reg_rule *reg_rule; |
| 7891 | const struct ieee80211_freq_range *freq_range; |
| 7892 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7893 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7894 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7895 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7896 | freq_range = ®_rule->freq_range; |
| 7897 | power_rule = ®_rule->power_rule; |
| 7898 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7899 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7900 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7901 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7902 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7903 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 7904 | if (!max_bandwidth_khz) |
| 7905 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 7906 | reg_rule); |
| 7907 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7908 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 7909 | reg_rule->flags) || |
| 7910 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 7911 | freq_range->start_freq_khz) || |
| 7912 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 7913 | freq_range->end_freq_khz) || |
| 7914 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7915 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7916 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 7917 | power_rule->max_antenna_gain) || |
| 7918 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 7919 | power_rule->max_eirp) || |
| 7920 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 7921 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7922 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7923 | |
| 7924 | nla_nest_end(msg, nl_reg_rule); |
| 7925 | } |
| 7926 | |
| 7927 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7928 | return 0; |
| 7929 | |
| 7930 | nla_put_failure: |
| 7931 | return -EMSGSIZE; |
| 7932 | } |
| 7933 | |
| 7934 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 7935 | { |
| 7936 | const struct ieee80211_regdomain *regdom = NULL; |
| 7937 | struct cfg80211_registered_device *rdev; |
| 7938 | struct wiphy *wiphy = NULL; |
| 7939 | struct sk_buff *msg; |
| 7940 | void *hdr; |
| 7941 | |
| 7942 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7943 | if (!msg) |
| 7944 | return -ENOBUFS; |
| 7945 | |
| 7946 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7947 | NL80211_CMD_GET_REG); |
| 7948 | if (!hdr) |
| 7949 | goto put_failure; |
| 7950 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7951 | rtnl_lock(); |
| 7952 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7953 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7954 | bool self_managed; |
| 7955 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7956 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 7957 | if (IS_ERR(rdev)) { |
| 7958 | nlmsg_free(msg); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7959 | rtnl_unlock(); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7960 | return PTR_ERR(rdev); |
| 7961 | } |
| 7962 | |
| 7963 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7964 | self_managed = wiphy->regulatory_flags & |
| 7965 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7966 | regdom = get_wiphy_regdom(wiphy); |
| 7967 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7968 | /* a self-managed-reg device must have a private regdom */ |
| 7969 | if (WARN_ON(!regdom && self_managed)) { |
| 7970 | nlmsg_free(msg); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7971 | rtnl_unlock(); |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7972 | return -EINVAL; |
| 7973 | } |
| 7974 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7975 | if (regdom && |
| 7976 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7977 | goto nla_put_failure; |
| 7978 | } |
| 7979 | |
| 7980 | if (!wiphy && reg_last_request_cell_base() && |
| 7981 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7982 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7983 | goto nla_put_failure; |
| 7984 | |
| 7985 | rcu_read_lock(); |
| 7986 | |
| 7987 | if (!regdom) |
| 7988 | regdom = rcu_dereference(cfg80211_regdomain); |
| 7989 | |
| 7990 | if (nl80211_put_regdom(regdom, msg)) |
| 7991 | goto nla_put_failure_rcu; |
| 7992 | |
| 7993 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7994 | |
| 7995 | genlmsg_end(msg, hdr); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 7996 | rtnl_unlock(); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7997 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7998 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7999 | nla_put_failure_rcu: |
| 8000 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8001 | nla_put_failure: |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 8002 | rtnl_unlock(); |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 8003 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 8004 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 8005 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 8006 | } |
| 8007 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 8008 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 8009 | u32 seq, int flags, struct wiphy *wiphy, |
| 8010 | const struct ieee80211_regdomain *regdom) |
| 8011 | { |
| 8012 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 8013 | NL80211_CMD_GET_REG); |
| 8014 | |
| 8015 | if (!hdr) |
| 8016 | return -1; |
| 8017 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 8018 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 8019 | |
| 8020 | if (nl80211_put_regdom(regdom, msg)) |
| 8021 | goto nla_put_failure; |
| 8022 | |
| 8023 | if (!wiphy && reg_last_request_cell_base() && |
| 8024 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 8025 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 8026 | goto nla_put_failure; |
| 8027 | |
| 8028 | if (wiphy && |
| 8029 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 8030 | goto nla_put_failure; |
| 8031 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 8032 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 8033 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 8034 | goto nla_put_failure; |
| 8035 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 8036 | genlmsg_end(msg, hdr); |
| 8037 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 8038 | |
| 8039 | nla_put_failure: |
| 8040 | genlmsg_cancel(msg, hdr); |
| 8041 | return -EMSGSIZE; |
| 8042 | } |
| 8043 | |
| 8044 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 8045 | struct netlink_callback *cb) |
| 8046 | { |
| 8047 | const struct ieee80211_regdomain *regdom = NULL; |
| 8048 | struct cfg80211_registered_device *rdev; |
| 8049 | int err, reg_idx, start = cb->args[2]; |
| 8050 | |
| 8051 | rtnl_lock(); |
| 8052 | |
| 8053 | if (cfg80211_regdomain && start == 0) { |
| 8054 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 8055 | NLM_F_MULTI, NULL, |
| 8056 | rtnl_dereference(cfg80211_regdomain)); |
| 8057 | if (err < 0) |
| 8058 | goto out_err; |
| 8059 | } |
| 8060 | |
| 8061 | /* the global regdom is idx 0 */ |
| 8062 | reg_idx = 1; |
| 8063 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 8064 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 8065 | if (!regdom) |
| 8066 | continue; |
| 8067 | |
| 8068 | if (++reg_idx <= start) |
| 8069 | continue; |
| 8070 | |
| 8071 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 8072 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 8073 | if (err < 0) { |
| 8074 | reg_idx--; |
| 8075 | break; |
| 8076 | } |
| 8077 | } |
| 8078 | |
| 8079 | cb->args[2] = reg_idx; |
| 8080 | err = skb->len; |
| 8081 | out_err: |
| 8082 | rtnl_unlock(); |
| 8083 | return err; |
| 8084 | } |
| 8085 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 8086 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 8087 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 8088 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 8089 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 8090 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 8091 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 8092 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 8093 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 8094 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 8095 | }; |
| 8096 | |
| 8097 | static int parse_reg_rule(struct nlattr *tb[], |
| 8098 | struct ieee80211_reg_rule *reg_rule) |
| 8099 | { |
| 8100 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 8101 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 8102 | |
| 8103 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 8104 | return -EINVAL; |
| 8105 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 8106 | return -EINVAL; |
| 8107 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 8108 | return -EINVAL; |
| 8109 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 8110 | return -EINVAL; |
| 8111 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 8112 | return -EINVAL; |
| 8113 | |
| 8114 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 8115 | |
| 8116 | freq_range->start_freq_khz = |
| 8117 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 8118 | freq_range->end_freq_khz = |
| 8119 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 8120 | freq_range->max_bandwidth_khz = |
| 8121 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 8122 | |
| 8123 | power_rule->max_eirp = |
| 8124 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 8125 | |
| 8126 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 8127 | power_rule->max_antenna_gain = |
| 8128 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 8129 | |
| 8130 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 8131 | reg_rule->dfs_cac_ms = |
| 8132 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 8133 | |
| 8134 | return 0; |
| 8135 | } |
| 8136 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8137 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 8138 | { |
| 8139 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 8140 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 8141 | char *alpha2; |
| 8142 | int rem_reg_rules, r; |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 8143 | u32 num_rules = 0, rule_idx = 0; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 8144 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 8145 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8146 | |
| 8147 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 8148 | return -EINVAL; |
| 8149 | |
| 8150 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 8151 | return -EINVAL; |
| 8152 | |
| 8153 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 8154 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 8155 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 8156 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 8157 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8158 | 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] | 8159 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8160 | num_rules++; |
| 8161 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 8162 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8163 | } |
| 8164 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 8165 | rtnl_lock(); |
| 8166 | if (!reg_is_valid_request(alpha2)) { |
| 8167 | r = -EINVAL; |
| 8168 | goto out; |
| 8169 | } |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 8170 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 8171 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 8172 | if (!rd) { |
| 8173 | r = -ENOMEM; |
| 8174 | goto out; |
| 8175 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8176 | |
| 8177 | rd->n_reg_rules = num_rules; |
| 8178 | rd->alpha2[0] = alpha2[0]; |
| 8179 | rd->alpha2[1] = alpha2[1]; |
| 8180 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 8181 | /* |
| 8182 | * Disable DFS master mode if the DFS region was |
| 8183 | * not supported or known on this kernel. |
| 8184 | */ |
| 8185 | if (reg_supported_dfs_region(dfs_region)) |
| 8186 | rd->dfs_region = dfs_region; |
| 8187 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8188 | 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] | 8189 | rem_reg_rules) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8190 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
| 8191 | nl_reg_rule, reg_rule_policy, |
| 8192 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8193 | if (r) |
| 8194 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8195 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 8196 | if (r) |
| 8197 | goto bad_reg; |
| 8198 | |
| 8199 | rule_idx++; |
| 8200 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 8201 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 8202 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8203 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 8204 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8205 | } |
| 8206 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 8207 | r = set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 8208 | /* set_regdom takes ownership of rd */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 8209 | rd = NULL; |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 8210 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8211 | kfree(rd); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 8212 | out: |
| 8213 | rtnl_unlock(); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 8214 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8215 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 8216 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 8217 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 8218 | static int validate_scan_freqs(struct nlattr *freqs) |
| 8219 | { |
| 8220 | struct nlattr *attr1, *attr2; |
| 8221 | int n_channels = 0, tmp1, tmp2; |
| 8222 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 8223 | nla_for_each_nested(attr1, freqs, tmp1) |
| 8224 | if (nla_len(attr1) != sizeof(u32)) |
| 8225 | return 0; |
| 8226 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 8227 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 8228 | n_channels++; |
| 8229 | /* |
| 8230 | * Some hardware has a limited channel list for |
| 8231 | * scanning, and it is pretty much nonsensical |
| 8232 | * to scan for a channel twice, so disallow that |
| 8233 | * and don't require drivers to check that the |
| 8234 | * channel list they get isn't longer than what |
| 8235 | * they can scan, as long as they can scan all |
| 8236 | * the channels they registered at once. |
| 8237 | */ |
| 8238 | nla_for_each_nested(attr2, freqs, tmp2) |
| 8239 | if (attr1 != attr2 && |
| 8240 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 8241 | return 0; |
| 8242 | } |
| 8243 | |
| 8244 | return n_channels; |
| 8245 | } |
| 8246 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8247 | 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] | 8248 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8249 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 8253 | struct cfg80211_bss_selection *bss_select) |
| 8254 | { |
| 8255 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 8256 | struct nlattr *nest; |
| 8257 | int err; |
| 8258 | bool found = false; |
| 8259 | int i; |
| 8260 | |
| 8261 | /* only process one nested attribute */ |
| 8262 | nest = nla_data(nla); |
| 8263 | if (!nla_ok(nest, nla_len(nest))) |
| 8264 | return -EINVAL; |
| 8265 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8266 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
| 8267 | nest, nl80211_bss_select_policy, |
| 8268 | NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 8269 | if (err) |
| 8270 | return err; |
| 8271 | |
| 8272 | /* only one attribute may be given */ |
| 8273 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 8274 | if (attr[i]) { |
| 8275 | if (found) |
| 8276 | return -EINVAL; |
| 8277 | found = true; |
| 8278 | } |
| 8279 | } |
| 8280 | |
| 8281 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 8282 | |
| 8283 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 8284 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 8285 | |
| 8286 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 8287 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 8288 | bss_select->param.band_pref = |
| 8289 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 8290 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 8291 | return -EINVAL; |
| 8292 | } |
| 8293 | |
| 8294 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 8295 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 8296 | |
| 8297 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 8298 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 8299 | bss_select->param.adjust.band = adj_param->band; |
| 8300 | bss_select->param.adjust.delta = adj_param->delta; |
| 8301 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 8302 | return -EINVAL; |
| 8303 | } |
| 8304 | |
| 8305 | /* user-space did not provide behaviour attribute */ |
| 8306 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 8307 | return -EINVAL; |
| 8308 | |
| 8309 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 8310 | return -EINVAL; |
| 8311 | |
| 8312 | return 0; |
| 8313 | } |
| 8314 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 8315 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 8316 | u8 *mac_addr, u8 *mac_addr_mask) |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8317 | { |
| 8318 | int i; |
| 8319 | |
| 8320 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 8321 | eth_zero_addr(mac_addr); |
| 8322 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8323 | mac_addr[0] = 0x2; |
| 8324 | mac_addr_mask[0] = 0x3; |
| 8325 | |
| 8326 | return 0; |
| 8327 | } |
| 8328 | |
| 8329 | /* need both or none */ |
| 8330 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 8331 | return -EINVAL; |
| 8332 | |
| 8333 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 8334 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 8335 | |
| 8336 | /* don't allow or configure an mcast address */ |
| 8337 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 8338 | is_multicast_ether_addr(mac_addr)) |
| 8339 | return -EINVAL; |
| 8340 | |
| 8341 | /* |
| 8342 | * allow users to pass a MAC address that has bits set outside |
| 8343 | * of the mask, but don't bother drivers with having to deal |
| 8344 | * with such bits |
| 8345 | */ |
| 8346 | for (i = 0; i < ETH_ALEN; i++) |
| 8347 | mac_addr[i] &= mac_addr_mask[i]; |
| 8348 | |
| 8349 | return 0; |
| 8350 | } |
| 8351 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 8352 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 8353 | { |
| 8354 | ASSERT_WDEV_LOCK(wdev); |
| 8355 | |
| 8356 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 8357 | return true; |
| 8358 | |
| 8359 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 8360 | return true; |
| 8361 | |
| 8362 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 8363 | } |
| 8364 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 8365 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 8366 | enum nl80211_ext_feature_index feat) |
| 8367 | { |
| 8368 | if (!(flags & flag)) |
| 8369 | return true; |
| 8370 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 8371 | return true; |
| 8372 | return false; |
| 8373 | } |
| 8374 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8375 | static int |
| 8376 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 8377 | void *request, struct nlattr **attrs, |
| 8378 | bool is_sched_scan) |
| 8379 | { |
| 8380 | u8 *mac_addr, *mac_addr_mask; |
| 8381 | u32 *flags; |
| 8382 | enum nl80211_feature_flags randomness_flag; |
| 8383 | |
| 8384 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 8385 | return 0; |
| 8386 | |
| 8387 | if (is_sched_scan) { |
| 8388 | struct cfg80211_sched_scan_request *req = request; |
| 8389 | |
| 8390 | randomness_flag = wdev ? |
| 8391 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 8392 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 8393 | flags = &req->flags; |
| 8394 | mac_addr = req->mac_addr; |
| 8395 | mac_addr_mask = req->mac_addr_mask; |
| 8396 | } else { |
| 8397 | struct cfg80211_scan_request *req = request; |
| 8398 | |
| 8399 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 8400 | flags = &req->flags; |
| 8401 | mac_addr = req->mac_addr; |
| 8402 | mac_addr_mask = req->mac_addr_mask; |
| 8403 | } |
| 8404 | |
| 8405 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 8406 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 8407 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 8408 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 8409 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8410 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 8411 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 8412 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8413 | NL80211_SCAN_FLAG_LOW_POWER, |
| 8414 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 8415 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8416 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 8417 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 8418 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8419 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 8420 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 8421 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8422 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 8423 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 8424 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8425 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 8426 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 8427 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8428 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 8429 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 8430 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8431 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 8432 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 8433 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8434 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 8435 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8436 | return -EOPNOTSUPP; |
| 8437 | |
| 8438 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 8439 | int err; |
| 8440 | |
| 8441 | if (!(wiphy->features & randomness_flag) || |
| 8442 | (wdev && wdev->current_bss)) |
| 8443 | return -EOPNOTSUPP; |
| 8444 | |
| 8445 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 8446 | if (err) |
| 8447 | return err; |
| 8448 | } |
| 8449 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8450 | return 0; |
| 8451 | } |
| 8452 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8453 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 8454 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8455 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8456 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8457 | struct cfg80211_scan_request *request; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8458 | struct nlattr *scan_freqs = NULL; |
| 8459 | bool scan_freqs_khz = false; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8460 | struct nlattr *attr; |
| 8461 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 8462 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8463 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8464 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8465 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8466 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 8467 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 8468 | return -EOPNOTSUPP; |
| 8469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8470 | if (!rdev->ops->scan) |
| 8471 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8472 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8473 | if (rdev->scan_req || rdev->scan_msg) |
| 8474 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8475 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8476 | if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { |
| 8477 | if (!wiphy_ext_feature_isset(wiphy, |
| 8478 | NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) |
| 8479 | return -EOPNOTSUPP; |
| 8480 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; |
| 8481 | scan_freqs_khz = true; |
| 8482 | } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) |
| 8483 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; |
| 8484 | |
| 8485 | if (scan_freqs) { |
| 8486 | n_channels = validate_scan_freqs(scan_freqs); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8487 | if (!n_channels) |
| 8488 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8489 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8490 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8491 | } |
| 8492 | |
| 8493 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8494 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 8495 | n_ssids++; |
| 8496 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8497 | if (n_ssids > wiphy->max_scan_ssids) |
| 8498 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8499 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8500 | if (info->attrs[NL80211_ATTR_IE]) |
| 8501 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8502 | else |
| 8503 | ie_len = 0; |
| 8504 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8505 | if (ie_len > wiphy->max_scan_ie_len) |
| 8506 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 8507 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8508 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8509 | + sizeof(*request->ssids) * n_ssids |
| 8510 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8511 | + ie_len, GFP_KERNEL); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8512 | if (!request) |
| 8513 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8514 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8515 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 8516 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8517 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8518 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8519 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8520 | request->ie = (void *)(request->ssids + n_ssids); |
| 8521 | else |
| 8522 | request->ie = (void *)(request->channels + n_channels); |
| 8523 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8524 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8525 | i = 0; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8526 | if (scan_freqs) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8527 | /* user specified, bail out if channel not found */ |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8528 | nla_for_each_nested(attr, scan_freqs, tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8529 | struct ieee80211_channel *chan; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8530 | int freq = nla_get_u32(attr); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8531 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8532 | if (!scan_freqs_khz) |
| 8533 | freq = MHZ_TO_KHZ(freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8534 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8535 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8536 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8537 | err = -EINVAL; |
| 8538 | goto out_free; |
| 8539 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8540 | |
| 8541 | /* ignore disabled channels */ |
| 8542 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8543 | continue; |
| 8544 | |
| 8545 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8546 | i++; |
| 8547 | } |
| 8548 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8549 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8550 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8551 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8552 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8553 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8554 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8555 | if (!wiphy->bands[band]) |
| 8556 | continue; |
| 8557 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8558 | struct ieee80211_channel *chan; |
| 8559 | |
| 8560 | chan = &wiphy->bands[band]->channels[j]; |
| 8561 | |
| 8562 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8563 | continue; |
| 8564 | |
| 8565 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8566 | i++; |
| 8567 | } |
| 8568 | } |
| 8569 | } |
| 8570 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8571 | if (!i) { |
| 8572 | err = -EINVAL; |
| 8573 | goto out_free; |
| 8574 | } |
| 8575 | |
| 8576 | request->n_channels = i; |
| 8577 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 8578 | wdev_lock(wdev); |
| 8579 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 8580 | struct ieee80211_channel *chan; |
| 8581 | |
| 8582 | if (request->n_channels != 1) { |
| 8583 | wdev_unlock(wdev); |
| 8584 | err = -EBUSY; |
| 8585 | goto out_free; |
| 8586 | } |
| 8587 | |
| 8588 | chan = request->channels[0]; |
| 8589 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 8590 | wdev_unlock(wdev); |
| 8591 | err = -EBUSY; |
| 8592 | goto out_free; |
| 8593 | } |
| 8594 | } |
| 8595 | wdev_unlock(wdev); |
| 8596 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8597 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8598 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8599 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8600 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8601 | err = -EINVAL; |
| 8602 | goto out_free; |
| 8603 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8604 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8605 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8606 | i++; |
| 8607 | } |
| 8608 | } |
| 8609 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8610 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8611 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 8612 | memcpy((void *)request->ie, |
| 8613 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8614 | request->ie_len); |
| 8615 | } |
| 8616 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8617 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 8618 | if (wiphy->bands[i]) |
| 8619 | request->rates[i] = |
| 8620 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8621 | |
| 8622 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 8623 | nla_for_each_nested(attr, |
| 8624 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 8625 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8626 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8627 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8628 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8629 | err = -EINVAL; |
| 8630 | goto out_free; |
| 8631 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 8632 | |
| 8633 | if (!wiphy->bands[band]) |
| 8634 | continue; |
| 8635 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8636 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 8637 | nla_data(attr), |
| 8638 | nla_len(attr), |
| 8639 | &request->rates[band]); |
| 8640 | if (err) |
| 8641 | goto out_free; |
| 8642 | } |
| 8643 | } |
| 8644 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8645 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8646 | request->duration = |
| 8647 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 8648 | request->duration_mandatory = |
| 8649 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 8650 | } |
| 8651 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8652 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 8653 | false); |
| 8654 | if (err) |
| 8655 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8656 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 8657 | request->no_cck = |
| 8658 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 8659 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 8660 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 8661 | * BSSID to scan for. This was problematic because that same attribute |
| 8662 | * was already used for another purpose (local random MAC address). The |
| 8663 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 8664 | * compatibility with older userspace components, also use the |
| 8665 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 8666 | * the specific BSSID use case instead of the random MAC address |
| 8667 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 8668 | */ |
| 8669 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 8670 | memcpy(request->bssid, |
| 8671 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 8672 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 8673 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 8674 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 8675 | ETH_ALEN); |
| 8676 | else |
| 8677 | eth_broadcast_addr(request->bssid); |
| 8678 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8679 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8680 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8681 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8682 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8683 | rdev->scan_req = request; |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 8684 | err = cfg80211_scan(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8685 | |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8686 | if (err) |
| 8687 | goto out_free; |
| 8688 | |
| 8689 | nl80211_send_scan_start(rdev, wdev); |
Yajun Deng | 1160dfa | 2021-08-05 19:55:27 +0800 | [diff] [blame] | 8690 | dev_hold(wdev->netdev); |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8691 | |
| 8692 | return 0; |
| 8693 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8694 | out_free: |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8695 | rdev->scan_req = NULL; |
| 8696 | kfree(request); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 8697 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8698 | return err; |
| 8699 | } |
| 8700 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 8701 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 8702 | { |
| 8703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8704 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8705 | |
| 8706 | if (!rdev->ops->abort_scan) |
| 8707 | return -EOPNOTSUPP; |
| 8708 | |
| 8709 | if (rdev->scan_msg) |
| 8710 | return 0; |
| 8711 | |
| 8712 | if (!rdev->scan_req) |
| 8713 | return -ENOENT; |
| 8714 | |
| 8715 | rdev_abort_scan(rdev, wdev); |
| 8716 | return 0; |
| 8717 | } |
| 8718 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8719 | static int |
| 8720 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 8721 | struct cfg80211_sched_scan_request *request, |
| 8722 | struct nlattr **attrs) |
| 8723 | { |
| 8724 | int tmp, err, i = 0; |
| 8725 | struct nlattr *attr; |
| 8726 | |
| 8727 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8728 | u32 interval; |
| 8729 | |
| 8730 | /* |
| 8731 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 8732 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8733 | * case one scan plan will be set with the specified scan |
| 8734 | * interval and infinite number of iterations. |
| 8735 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8736 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 8737 | if (!interval) |
| 8738 | return -EINVAL; |
| 8739 | |
| 8740 | request->scan_plans[0].interval = |
| 8741 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 8742 | if (!request->scan_plans[0].interval) |
| 8743 | return -EINVAL; |
| 8744 | |
| 8745 | if (request->scan_plans[0].interval > |
| 8746 | wiphy->max_sched_scan_plan_interval) |
| 8747 | request->scan_plans[0].interval = |
| 8748 | wiphy->max_sched_scan_plan_interval; |
| 8749 | |
| 8750 | return 0; |
| 8751 | } |
| 8752 | |
| 8753 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 8754 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 8755 | |
| 8756 | if (WARN_ON(i >= n_plans)) |
| 8757 | return -EINVAL; |
| 8758 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8759 | err = nla_parse_nested_deprecated(plan, |
| 8760 | NL80211_SCHED_SCAN_PLAN_MAX, |
| 8761 | attr, nl80211_plan_policy, |
| 8762 | NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8763 | if (err) |
| 8764 | return err; |
| 8765 | |
| 8766 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 8767 | return -EINVAL; |
| 8768 | |
| 8769 | request->scan_plans[i].interval = |
| 8770 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 8771 | if (!request->scan_plans[i].interval || |
| 8772 | request->scan_plans[i].interval > |
| 8773 | wiphy->max_sched_scan_plan_interval) |
| 8774 | return -EINVAL; |
| 8775 | |
| 8776 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 8777 | request->scan_plans[i].iterations = |
| 8778 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 8779 | if (!request->scan_plans[i].iterations || |
| 8780 | (request->scan_plans[i].iterations > |
| 8781 | wiphy->max_sched_scan_plan_iterations)) |
| 8782 | return -EINVAL; |
| 8783 | } else if (i < n_plans - 1) { |
| 8784 | /* |
| 8785 | * All scan plans but the last one must specify |
| 8786 | * a finite number of iterations |
| 8787 | */ |
| 8788 | return -EINVAL; |
| 8789 | } |
| 8790 | |
| 8791 | i++; |
| 8792 | } |
| 8793 | |
| 8794 | /* |
| 8795 | * The last scan plan must not specify the number of |
| 8796 | * iterations, it is supposed to run infinitely |
| 8797 | */ |
| 8798 | if (request->scan_plans[n_plans - 1].iterations) |
| 8799 | return -EINVAL; |
| 8800 | |
| 8801 | return 0; |
| 8802 | } |
| 8803 | |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8804 | static int |
| 8805 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, |
| 8806 | struct cfg80211_match_set *match_sets, |
| 8807 | struct nlattr *tb_band_rssi, |
| 8808 | s32 rssi_thold) |
| 8809 | { |
| 8810 | struct nlattr *attr; |
| 8811 | int i, tmp, ret = 0; |
| 8812 | |
| 8813 | if (!wiphy_ext_feature_isset(wiphy, |
| 8814 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { |
| 8815 | if (tb_band_rssi) |
| 8816 | ret = -EOPNOTSUPP; |
| 8817 | else |
| 8818 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8819 | match_sets->per_band_rssi_thold[i] = |
| 8820 | NL80211_SCAN_RSSI_THOLD_OFF; |
| 8821 | return ret; |
| 8822 | } |
| 8823 | |
| 8824 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8825 | match_sets->per_band_rssi_thold[i] = rssi_thold; |
| 8826 | |
| 8827 | nla_for_each_nested(attr, tb_band_rssi, tmp) { |
| 8828 | enum nl80211_band band = nla_type(attr); |
| 8829 | |
| 8830 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 8831 | return -EINVAL; |
| 8832 | |
| 8833 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); |
| 8834 | } |
| 8835 | |
| 8836 | return 0; |
| 8837 | } |
| 8838 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8839 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8840 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8841 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8842 | { |
| 8843 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8844 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8845 | 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] | 8846 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8847 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8848 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8849 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8850 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8851 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8852 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8853 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8854 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8855 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8856 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8857 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8858 | } |
| 8859 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8860 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8861 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8862 | tmp) |
| 8863 | n_ssids++; |
| 8864 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 8865 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8866 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8867 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8868 | /* |
| 8869 | * First, count the number of 'real' matchsets. Due to an issue with |
| 8870 | * the old implementation, matchsets containing only the RSSI attribute |
| 8871 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 8872 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 8873 | * all APs with a strong RSSI. This is needed to be compatible with |
| 8874 | * older userspace that treated a matchset with only the RSSI as the |
| 8875 | * global RSSI for all other matchsets - if there are other matchsets. |
| 8876 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8877 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8878 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8879 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8880 | tmp) { |
| 8881 | struct nlattr *rssi; |
| 8882 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8883 | err = nla_parse_nested_deprecated(tb, |
| 8884 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8885 | attr, |
| 8886 | nl80211_match_policy, |
| 8887 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8888 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8889 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8890 | |
| 8891 | /* SSID and BSSID are mutually exclusive */ |
| 8892 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 8893 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 8894 | return ERR_PTR(-EINVAL); |
| 8895 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8896 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8897 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 8898 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8899 | n_match_sets++; |
| 8900 | continue; |
| 8901 | } |
| 8902 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8903 | if (rssi) |
| 8904 | default_match_rssi = nla_get_s32(rssi); |
| 8905 | } |
| 8906 | } |
| 8907 | |
| 8908 | /* However, if there's no other matchset, add the RSSI one */ |
| 8909 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 8910 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8911 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8912 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8913 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8914 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8915 | if (attrs[NL80211_ATTR_IE]) |
| 8916 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8917 | else |
| 8918 | ie_len = 0; |
| 8919 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 8920 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8921 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 8922 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8923 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8924 | /* |
| 8925 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 8926 | * each scan plan already specifies its own interval |
| 8927 | */ |
| 8928 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8929 | return ERR_PTR(-EINVAL); |
| 8930 | |
| 8931 | nla_for_each_nested(attr, |
| 8932 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 8933 | n_plans++; |
| 8934 | } else { |
| 8935 | /* |
| 8936 | * The scan interval attribute is kept for backward |
| 8937 | * compatibility. If no scan plans are specified and sched scan |
| 8938 | * interval is specified, one scan plan will be set with this |
| 8939 | * scan interval and infinite number of iterations. |
| 8940 | */ |
| 8941 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8942 | return ERR_PTR(-EINVAL); |
| 8943 | |
| 8944 | n_plans = 1; |
| 8945 | } |
| 8946 | |
| 8947 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 8948 | return ERR_PTR(-EINVAL); |
| 8949 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8950 | if (!wiphy_ext_feature_isset( |
| 8951 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 8952 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 8953 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 8954 | return ERR_PTR(-EINVAL); |
| 8955 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8956 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8957 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8958 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8959 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8960 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8961 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8962 | if (!request) |
| 8963 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8964 | |
| 8965 | if (n_ssids) |
| 8966 | request->ssids = (void *)&request->channels[n_channels]; |
| 8967 | request->n_ssids = n_ssids; |
| 8968 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8969 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8970 | request->ie = (void *)(request->ssids + n_ssids); |
| 8971 | else |
| 8972 | request->ie = (void *)(request->channels + n_channels); |
| 8973 | } |
| 8974 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8975 | if (n_match_sets) { |
| 8976 | if (request->ie) |
| 8977 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8978 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8979 | request->match_sets = |
| 8980 | (void *)(request->ssids + n_ssids); |
| 8981 | else |
| 8982 | request->match_sets = |
| 8983 | (void *)(request->channels + n_channels); |
| 8984 | } |
| 8985 | request->n_match_sets = n_match_sets; |
| 8986 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8987 | if (n_match_sets) |
| 8988 | request->scan_plans = (void *)(request->match_sets + |
| 8989 | n_match_sets); |
| 8990 | else if (request->ie) |
| 8991 | request->scan_plans = (void *)(request->ie + ie_len); |
| 8992 | else if (n_ssids) |
| 8993 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 8994 | else |
| 8995 | request->scan_plans = (void *)(request->channels + n_channels); |
| 8996 | |
| 8997 | request->n_scan_plans = n_plans; |
| 8998 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8999 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9000 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9001 | /* user specified, bail out if channel not found */ |
| 9002 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9003 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9004 | tmp) { |
| 9005 | struct ieee80211_channel *chan; |
| 9006 | |
| 9007 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 9008 | |
| 9009 | if (!chan) { |
| 9010 | err = -EINVAL; |
| 9011 | goto out_free; |
| 9012 | } |
| 9013 | |
| 9014 | /* ignore disabled channels */ |
| 9015 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 9016 | continue; |
| 9017 | |
| 9018 | request->channels[i] = chan; |
| 9019 | i++; |
| 9020 | } |
| 9021 | } else { |
| 9022 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9023 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9024 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9025 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9026 | if (!wiphy->bands[band]) |
| 9027 | continue; |
| 9028 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 9029 | struct ieee80211_channel *chan; |
| 9030 | |
| 9031 | chan = &wiphy->bands[band]->channels[j]; |
| 9032 | |
| 9033 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 9034 | continue; |
| 9035 | |
| 9036 | request->channels[i] = chan; |
| 9037 | i++; |
| 9038 | } |
| 9039 | } |
| 9040 | } |
| 9041 | |
| 9042 | if (!i) { |
| 9043 | err = -EINVAL; |
| 9044 | goto out_free; |
| 9045 | } |
| 9046 | |
| 9047 | request->n_channels = i; |
| 9048 | |
| 9049 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 9050 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9051 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9052 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 9053 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9054 | err = -EINVAL; |
| 9055 | goto out_free; |
| 9056 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 9057 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9058 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 9059 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9060 | i++; |
| 9061 | } |
| 9062 | } |
| 9063 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9064 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9065 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9066 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9067 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9068 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 9069 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9070 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 9071 | err = nla_parse_nested_deprecated(tb, |
| 9072 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 9073 | attr, |
| 9074 | nl80211_match_policy, |
| 9075 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 9076 | if (err) |
| 9077 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 9078 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 9079 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 9080 | |
| 9081 | if (!ssid && !bssid) { |
| 9082 | i++; |
| 9083 | continue; |
| 9084 | } |
| 9085 | |
| 9086 | if (WARN_ON(i >= n_match_sets)) { |
| 9087 | /* this indicates a programming error, |
| 9088 | * the loop above should have verified |
| 9089 | * things properly |
| 9090 | */ |
| 9091 | err = -EINVAL; |
| 9092 | goto out_free; |
| 9093 | } |
| 9094 | |
| 9095 | if (ssid) { |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 9096 | memcpy(request->match_sets[i].ssid.ssid, |
| 9097 | nla_data(ssid), nla_len(ssid)); |
| 9098 | request->match_sets[i].ssid.ssid_len = |
| 9099 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9100 | } |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 9101 | if (bssid) |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 9102 | memcpy(request->match_sets[i].bssid, |
| 9103 | nla_data(bssid), ETH_ALEN); |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 9104 | |
| 9105 | /* special attribute - old implementation w/a */ |
| 9106 | request->match_sets[i].rssi_thold = default_match_rssi; |
| 9107 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 9108 | if (rssi) |
| 9109 | request->match_sets[i].rssi_thold = |
| 9110 | nla_get_s32(rssi); |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 9111 | |
| 9112 | /* Parse per band RSSI attribute */ |
| 9113 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, |
| 9114 | &request->match_sets[i], |
| 9115 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], |
| 9116 | request->match_sets[i].rssi_thold); |
| 9117 | if (err) |
| 9118 | goto out_free; |
| 9119 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9120 | i++; |
| 9121 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 9122 | |
| 9123 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 9124 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 9125 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 9126 | |
| 9127 | request->min_rssi_thold = INT_MAX; |
| 9128 | for (i = 0; i < n_match_sets; i++) |
| 9129 | request->min_rssi_thold = |
| 9130 | min(request->match_sets[i].rssi_thold, |
| 9131 | request->min_rssi_thold); |
| 9132 | } else { |
| 9133 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 9134 | } |
| 9135 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 9136 | if (ie_len) { |
| 9137 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9138 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9139 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9140 | request->ie_len); |
| 9141 | } |
| 9142 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 9143 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 9144 | if (err) |
| 9145 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 9146 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 9147 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 9148 | request->delay = |
| 9149 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 9150 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 9151 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 9152 | request->relative_rssi = nla_get_s8( |
| 9153 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 9154 | request->relative_rssi_set = true; |
| 9155 | } |
| 9156 | |
| 9157 | if (request->relative_rssi_set && |
| 9158 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 9159 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 9160 | |
| 9161 | rssi_adjust = nla_data( |
| 9162 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 9163 | request->rssi_adjust.band = rssi_adjust->band; |
| 9164 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 9165 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 9166 | err = -EINVAL; |
| 9167 | goto out_free; |
| 9168 | } |
| 9169 | } |
| 9170 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 9171 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 9172 | if (err) |
| 9173 | goto out_free; |
| 9174 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 9175 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9176 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9177 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9178 | |
| 9179 | out_free: |
| 9180 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9181 | return ERR_PTR(err); |
| 9182 | } |
| 9183 | |
| 9184 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 9185 | struct genl_info *info) |
| 9186 | { |
| 9187 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9188 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 9189 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 9190 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9191 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9192 | int err; |
| 9193 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9194 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9195 | return -EOPNOTSUPP; |
| 9196 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9197 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 9198 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 9199 | if (err) |
| 9200 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9201 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 9202 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 9203 | info->attrs, |
| 9204 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 9205 | |
| 9206 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9207 | if (err) |
| 9208 | goto out_err; |
| 9209 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9210 | /* leave request id zero for legacy request |
| 9211 | * or if driver does not support multi-scheduled scan |
| 9212 | */ |
Denis Kenzior | 2fd351a | 2019-10-08 11:43:50 -0500 | [diff] [blame] | 9213 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
| 9214 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9215 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 9216 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9217 | if (err) |
| 9218 | goto out_free; |
| 9219 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 9220 | sched_scan_req->dev = dev; |
| 9221 | sched_scan_req->wiphy = &rdev->wiphy; |
| 9222 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 9223 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 9224 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 9225 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9226 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9227 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 9228 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9229 | return 0; |
| 9230 | |
| 9231 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 9232 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 9233 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9234 | return err; |
| 9235 | } |
| 9236 | |
| 9237 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 9238 | struct genl_info *info) |
| 9239 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9240 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9241 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9242 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9243 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9244 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9245 | return -EOPNOTSUPP; |
| 9246 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 9247 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 9248 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 9249 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 9250 | } |
| 9251 | |
| 9252 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 9253 | struct cfg80211_sched_scan_request, |
| 9254 | list); |
| 9255 | if (!req || req->reqid || |
| 9256 | (req->owner_nlportid && |
| 9257 | req->owner_nlportid != info->snd_portid)) |
| 9258 | return -ENOENT; |
| 9259 | |
| 9260 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 9261 | } |
| 9262 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9263 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 9264 | struct genl_info *info) |
| 9265 | { |
| 9266 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9267 | struct net_device *dev = info->user_ptr[1]; |
| 9268 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 9269 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9270 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 9271 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 9272 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9273 | int err; |
| 9274 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 9275 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 9276 | if (dfs_region == NL80211_DFS_UNSET) |
| 9277 | return -EINVAL; |
| 9278 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9279 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9280 | if (err) |
| 9281 | return err; |
| 9282 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 9283 | if (netif_carrier_ok(dev)) |
| 9284 | return -EBUSY; |
| 9285 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9286 | if (wdev->cac_started) |
| 9287 | return -EBUSY; |
| 9288 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 9289 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9290 | if (err < 0) |
| 9291 | return err; |
| 9292 | |
| 9293 | if (err == 0) |
| 9294 | return -EINVAL; |
| 9295 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 9296 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9297 | return -EINVAL; |
| 9298 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 9299 | /* CAC start is offloaded to HW and can't be started manually */ |
| 9300 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 9301 | return -EOPNOTSUPP; |
| 9302 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9303 | if (!rdev->ops->start_radar_detection) |
| 9304 | return -EOPNOTSUPP; |
| 9305 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 9306 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 9307 | if (WARN_ON(!cac_time_ms)) |
| 9308 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 9309 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 9310 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9311 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 9312 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9313 | wdev->cac_started = true; |
| 9314 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 9315 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9316 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 9317 | return err; |
| 9318 | } |
| 9319 | |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 9320 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 9321 | struct genl_info *info) |
| 9322 | { |
| 9323 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9324 | struct net_device *dev = info->user_ptr[1]; |
| 9325 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9326 | struct wiphy *wiphy = wdev->wiphy; |
| 9327 | struct cfg80211_chan_def chandef; |
| 9328 | enum nl80211_dfs_regions dfs_region; |
| 9329 | int err; |
| 9330 | |
| 9331 | dfs_region = reg_get_dfs_region(wiphy); |
| 9332 | if (dfs_region == NL80211_DFS_UNSET) { |
| 9333 | GENL_SET_ERR_MSG(info, |
| 9334 | "DFS Region is not set. Unexpected Radar indication"); |
| 9335 | return -EINVAL; |
| 9336 | } |
| 9337 | |
| 9338 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 9339 | if (err) { |
| 9340 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 9341 | return err; |
| 9342 | } |
| 9343 | |
| 9344 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 9345 | if (err < 0) { |
| 9346 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 9347 | return err; |
| 9348 | } |
| 9349 | |
| 9350 | if (err == 0) { |
| 9351 | GENL_SET_ERR_MSG(info, |
| 9352 | "Unexpected Radar indication for chandef/iftype"); |
| 9353 | return -EINVAL; |
| 9354 | } |
| 9355 | |
| 9356 | /* Do not process this notification if radar is already detected |
| 9357 | * by kernel on this channel, and return success. |
| 9358 | */ |
| 9359 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 9360 | return 0; |
| 9361 | |
| 9362 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 9363 | |
| 9364 | cfg80211_sched_dfs_chan_update(rdev); |
| 9365 | |
Luca Coelho | a680fe4 | 2019-04-17 09:34:40 +0300 | [diff] [blame] | 9366 | rdev->radar_chandef = chandef; |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 9367 | |
| 9368 | /* Propagate this notification to other radios as well */ |
| 9369 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 9370 | |
| 9371 | return 0; |
| 9372 | } |
| 9373 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9374 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 9375 | { |
| 9376 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9377 | struct net_device *dev = info->user_ptr[1]; |
| 9378 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 9379 | struct cfg80211_csa_settings params; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9380 | struct nlattr **csa_attrs = NULL; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9381 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9382 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9383 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9384 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 9385 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9386 | |
| 9387 | if (!rdev->ops->channel_switch || |
| 9388 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 9389 | return -EOPNOTSUPP; |
| 9390 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9391 | switch (dev->ieee80211_ptr->iftype) { |
| 9392 | case NL80211_IFTYPE_AP: |
| 9393 | case NL80211_IFTYPE_P2P_GO: |
| 9394 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9395 | /* For all modes except AP the handle_dfs flag needs to be |
| 9396 | * supplied to tell the kernel that userspace will handle radar |
| 9397 | * events when they happen. Otherwise a switch to a channel |
| 9398 | * requiring DFS will be rejected. |
| 9399 | */ |
| 9400 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9401 | |
| 9402 | /* useless if AP is not running */ |
| 9403 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 9404 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9405 | break; |
| 9406 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 9407 | if (!wdev->ssid_len) |
| 9408 | return -ENOTCONN; |
| 9409 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 9410 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 9411 | if (!wdev->mesh_id_len) |
| 9412 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9413 | break; |
| 9414 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9415 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9416 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9417 | |
| 9418 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | c177db2 | 2018-10-30 09:17:44 +0100 | [diff] [blame] | 9419 | params.beacon_csa.ftm_responder = -1; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9420 | |
| 9421 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9422 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 9423 | return -EINVAL; |
| 9424 | |
| 9425 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 9426 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9427 | return -EINVAL; |
| 9428 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 9429 | /* Even though the attribute is u32, the specification says |
| 9430 | * u8, so let's make sure we don't overflow. |
| 9431 | */ |
| 9432 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 9433 | if (cs_count > 255) |
| 9434 | return -EINVAL; |
| 9435 | |
| 9436 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9437 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9438 | if (!need_new_beacon) |
| 9439 | goto skip_beacons; |
| 9440 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 9441 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9442 | if (err) |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 9443 | goto free; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9444 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9445 | csa_attrs = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*csa_attrs), |
| 9446 | GFP_KERNEL); |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 9447 | if (!csa_attrs) { |
| 9448 | err = -ENOMEM; |
| 9449 | goto free; |
| 9450 | } |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9451 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 9452 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
| 9453 | info->attrs[NL80211_ATTR_CSA_IES], |
| 9454 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9455 | if (err) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9456 | goto free; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9457 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 9458 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9459 | if (err) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9460 | goto free; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9461 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9462 | if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { |
| 9463 | err = -EINVAL; |
| 9464 | goto free; |
| 9465 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9466 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9467 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9468 | if (!len || (len % sizeof(u16))) { |
| 9469 | err = -EINVAL; |
| 9470 | goto free; |
| 9471 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9472 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9473 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 9474 | if (rdev->wiphy.max_num_csa_counters && |
| 9475 | (params.n_counter_offsets_beacon > |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9476 | rdev->wiphy.max_num_csa_counters)) { |
| 9477 | err = -EINVAL; |
| 9478 | goto free; |
| 9479 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9480 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9481 | params.counter_offsets_beacon = |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9482 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9483 | |
| 9484 | /* sanity checks - counters should fit and be the same */ |
| 9485 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 9486 | u16 offset = params.counter_offsets_beacon[i]; |
| 9487 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9488 | if (offset >= params.beacon_csa.tail_len) { |
| 9489 | err = -EINVAL; |
| 9490 | goto free; |
| 9491 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9492 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9493 | if (params.beacon_csa.tail[offset] != params.count) { |
| 9494 | err = -EINVAL; |
| 9495 | goto free; |
| 9496 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9497 | } |
| 9498 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9499 | if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { |
| 9500 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9501 | if (!len || (len % sizeof(u16))) { |
| 9502 | err = -EINVAL; |
| 9503 | goto free; |
| 9504 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9505 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9506 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 9507 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 9508 | (params.n_counter_offsets_presp > |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9509 | rdev->wiphy.max_num_csa_counters)) { |
| 9510 | err = -EINVAL; |
| 9511 | goto free; |
| 9512 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9513 | |
| 9514 | params.counter_offsets_presp = |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9515 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9516 | |
| 9517 | /* sanity checks - counters should fit and be the same */ |
| 9518 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 9519 | u16 offset = params.counter_offsets_presp[i]; |
| 9520 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9521 | if (offset >= params.beacon_csa.probe_resp_len) { |
| 9522 | err = -EINVAL; |
| 9523 | goto free; |
| 9524 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9525 | |
| 9526 | if (params.beacon_csa.probe_resp[offset] != |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9527 | params.count) { |
| 9528 | err = -EINVAL; |
| 9529 | goto free; |
| 9530 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9531 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9532 | } |
| 9533 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9534 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9535 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 9536 | if (err) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9537 | goto free; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9538 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 9539 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9540 | wdev->iftype)) { |
| 9541 | err = -EINVAL; |
| 9542 | goto free; |
| 9543 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9544 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9545 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 9546 | ¶ms.chandef, |
| 9547 | wdev->iftype); |
| 9548 | if (err < 0) |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9549 | goto free; |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9550 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9551 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9552 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9553 | if (need_handle_dfs_flag && |
| 9554 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9555 | err = -EINVAL; |
| 9556 | goto free; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9557 | } |
| 9558 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9559 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9560 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 9561 | params.block_tx = true; |
| 9562 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 9563 | wdev_lock(wdev); |
| 9564 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 9565 | wdev_unlock(wdev); |
| 9566 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9567 | free: |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 9568 | kfree(params.beacon_after.mbssid_ies); |
| 9569 | kfree(params.beacon_csa.mbssid_ies); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9570 | kfree(csa_attrs); |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 9571 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9572 | } |
| 9573 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9574 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 9575 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9576 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9577 | struct wireless_dev *wdev, |
| 9578 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9579 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9580 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9581 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9582 | void *hdr; |
| 9583 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9584 | |
| 9585 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9586 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9587 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9588 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 9589 | if (!hdr) |
| 9590 | return -1; |
| 9591 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 9592 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9593 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9594 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 9595 | goto nla_put_failure; |
| 9596 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9597 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 9598 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9599 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 9600 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9601 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9602 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9603 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9604 | if (!bss) |
| 9605 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9606 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9607 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9608 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9609 | |
| 9610 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9611 | /* indicate whether we have probe response data or not */ |
| 9612 | if (rcu_access_pointer(res->proberesp_ies) && |
| 9613 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 9614 | goto fail_unlock_rcu; |
| 9615 | |
| 9616 | /* this pointer prefers to be pointed to probe response data |
| 9617 | * but is always valid |
| 9618 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9619 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9620 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9621 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 9622 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9623 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9624 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 9625 | ies->len, ies->data)) |
| 9626 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9627 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9628 | |
| 9629 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9630 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9631 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9632 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 9633 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9634 | goto fail_unlock_rcu; |
| 9635 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 9636 | ies->len, ies->data)) |
| 9637 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9638 | } |
| 9639 | rcu_read_unlock(); |
| 9640 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9641 | if (res->beacon_interval && |
| 9642 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 9643 | goto nla_put_failure; |
| 9644 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 9645 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9646 | nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, |
| 9647 | res->channel->freq_offset) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 9648 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9649 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 9650 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 9651 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9652 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 9653 | if (intbss->parent_tsf && |
| 9654 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 9655 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 9656 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 9657 | intbss->parent_bssid))) |
| 9658 | goto nla_put_failure; |
| 9659 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 9660 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9661 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 9662 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 9663 | goto nla_put_failure; |
| 9664 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 9665 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 9666 | intbss->pub.chain_signal, |
| 9667 | NL80211_BSS_CHAIN_SIGNAL)) |
| 9668 | goto nla_put_failure; |
| 9669 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 9670 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9671 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9672 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 9673 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9674 | break; |
| 9675 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9676 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 9677 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9678 | break; |
| 9679 | default: |
| 9680 | break; |
| 9681 | } |
| 9682 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9683 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9684 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9685 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9686 | if (intbss == wdev->current_bss && |
| 9687 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9688 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 9689 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9690 | break; |
| 9691 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9692 | if (intbss == wdev->current_bss && |
| 9693 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9694 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 9695 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9696 | break; |
| 9697 | default: |
| 9698 | break; |
| 9699 | } |
| 9700 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9701 | nla_nest_end(msg, bss); |
| 9702 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9703 | genlmsg_end(msg, hdr); |
| 9704 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9705 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9706 | fail_unlock_rcu: |
| 9707 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9708 | nla_put_failure: |
| 9709 | genlmsg_cancel(msg, hdr); |
| 9710 | return -EMSGSIZE; |
| 9711 | } |
| 9712 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9713 | 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] | 9714 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9715 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9716 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9717 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9718 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9719 | int err; |
| 9720 | |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9721 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9722 | if (err) |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9723 | return err; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9724 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ |
| 9725 | __acquire(&rdev->wiphy.mtx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9726 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9727 | wdev_lock(wdev); |
| 9728 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 9729 | |
| 9730 | /* |
| 9731 | * dump_scan will be called multiple times to break up the scan results |
| 9732 | * into multiple messages. It is unlikely that any more bss-es will be |
| 9733 | * expired after the first call, so only call only call this on the |
| 9734 | * first dump_scan invocation. |
| 9735 | */ |
| 9736 | if (start == 0) |
| 9737 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9738 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9739 | cb->seq = rdev->bss_generation; |
| 9740 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9741 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9742 | if (++idx <= start) |
| 9743 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9744 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9745 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9746 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9747 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9748 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9749 | } |
| 9750 | } |
| 9751 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9752 | spin_unlock_bh(&rdev->bss_lock); |
| 9753 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9754 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9755 | cb->args[2] = idx; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9756 | wiphy_unlock(&rdev->wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9757 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9758 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9759 | } |
| 9760 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9761 | 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] | 9762 | int flags, struct net_device *dev, |
| 9763 | bool allow_radio_stats, |
| 9764 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9765 | { |
| 9766 | void *hdr; |
| 9767 | struct nlattr *infoattr; |
| 9768 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9769 | /* skip radio stats if userspace didn't request them */ |
| 9770 | if (!survey->channel && !allow_radio_stats) |
| 9771 | return 0; |
| 9772 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9773 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9774 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 9775 | if (!hdr) |
| 9776 | return -ENOMEM; |
| 9777 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9778 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 9779 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9780 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9781 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9782 | if (!infoattr) |
| 9783 | goto nla_put_failure; |
| 9784 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9785 | if (survey->channel && |
| 9786 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9787 | survey->channel->center_freq)) |
| 9788 | goto nla_put_failure; |
| 9789 | |
Thomas Pedersen | 58ef7c1 | 2020-09-21 19:28:16 -0700 | [diff] [blame] | 9790 | if (survey->channel && survey->channel->freq_offset && |
| 9791 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, |
| 9792 | survey->channel->freq_offset)) |
| 9793 | goto nla_put_failure; |
| 9794 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9795 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 9796 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 9797 | goto nla_put_failure; |
| 9798 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 9799 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 9800 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9801 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9802 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 9803 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9804 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9805 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9806 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 9807 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9808 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9809 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9810 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 9811 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9812 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9813 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9814 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 9815 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9816 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9817 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9818 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 9819 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9820 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9821 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9822 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 9823 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9824 | goto nla_put_failure; |
Felix Fietkau | c8cd6e7 | 2019-08-28 12:20:42 +0200 | [diff] [blame] | 9825 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
| 9826 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, |
| 9827 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) |
| 9828 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9829 | |
| 9830 | nla_nest_end(msg, infoattr); |
| 9831 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9832 | genlmsg_end(msg, hdr); |
| 9833 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9834 | |
| 9835 | nla_put_failure: |
| 9836 | genlmsg_cancel(msg, hdr); |
| 9837 | return -EMSGSIZE; |
| 9838 | } |
| 9839 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9840 | 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] | 9841 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9842 | struct nlattr **attrbuf; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9843 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9844 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9845 | struct wireless_dev *wdev; |
| 9846 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9847 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9848 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9849 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9850 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 9851 | if (!attrbuf) |
| 9852 | return -ENOMEM; |
| 9853 | |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9854 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9855 | if (res) { |
| 9856 | kfree(attrbuf); |
| 9857 | return res; |
| 9858 | } |
| 9859 | /* nl80211_prepare_wdev_dump acquired it in the successful case */ |
| 9860 | __acquire(&rdev->wiphy.mtx); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9861 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9862 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9863 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9864 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9865 | if (!wdev->netdev) { |
| 9866 | res = -EINVAL; |
| 9867 | goto out_err; |
| 9868 | } |
| 9869 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9870 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9871 | res = -EOPNOTSUPP; |
| 9872 | goto out_err; |
| 9873 | } |
| 9874 | |
| 9875 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9876 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9877 | if (res == -ENOENT) |
| 9878 | break; |
| 9879 | if (res) |
| 9880 | goto out_err; |
| 9881 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9882 | /* don't send disabled channels, but do send non-channel data */ |
| 9883 | if (survey.channel && |
| 9884 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 9885 | survey_idx++; |
| 9886 | continue; |
| 9887 | } |
| 9888 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9889 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9890 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9891 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9892 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9893 | goto out; |
| 9894 | survey_idx++; |
| 9895 | } |
| 9896 | |
| 9897 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9898 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9899 | res = skb->len; |
| 9900 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9901 | kfree(attrbuf); |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 9902 | wiphy_unlock(&rdev->wiphy); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9903 | return res; |
| 9904 | } |
| 9905 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9906 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 9907 | { |
| 9908 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
Chung-Hsien Hsu | cc3e14c | 2019-05-09 09:49:05 +0000 | [diff] [blame] | 9909 | NL80211_WPA_VERSION_2 | |
| 9910 | NL80211_WPA_VERSION_3)); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9911 | } |
| 9912 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9913 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 9914 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9915 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9916 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9917 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9918 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 9919 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9920 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9921 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9922 | bool local_state_change; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9923 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9924 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9925 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9926 | return -EINVAL; |
| 9927 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 9928 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 9929 | return -EINVAL; |
| 9930 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9931 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 9932 | return -EINVAL; |
| 9933 | |
| 9934 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9935 | return -EINVAL; |
| 9936 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9937 | err = nl80211_parse_key(info, &key); |
| 9938 | if (err) |
| 9939 | return err; |
| 9940 | |
| 9941 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 9942 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 9943 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9944 | if (!key.p.key || !key.p.key_len) |
| 9945 | return -EINVAL; |
| 9946 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 9947 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 9948 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 9949 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 9950 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 9951 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9952 | return -EINVAL; |
| 9953 | } else { |
| 9954 | key.p.key_len = 0; |
| 9955 | key.p.key = NULL; |
| 9956 | } |
| 9957 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9958 | if (key.idx >= 0) { |
| 9959 | int i; |
| 9960 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9961 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9962 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 9963 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 9964 | ok = true; |
| 9965 | break; |
| 9966 | } |
| 9967 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9968 | if (!ok) |
| 9969 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9970 | } |
| 9971 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9972 | if (!rdev->ops->auth) |
| 9973 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9974 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9975 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9976 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9977 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9978 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9979 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9980 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9981 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9982 | freq += |
| 9983 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9984 | |
| 9985 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9986 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9987 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9988 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9989 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9990 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9991 | |
| 9992 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9993 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9994 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9995 | } |
| 9996 | |
| 9997 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9998 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9999 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10000 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 10001 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 10002 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 10003 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 10004 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 10005 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10006 | return -EINVAL; |
| 10007 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 10008 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 10009 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 10010 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 10011 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 10012 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10013 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 10014 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 10015 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10016 | } |
| 10017 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 10018 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 10019 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 10020 | /* |
| 10021 | * Since we no longer track auth state, ignore |
| 10022 | * requests to only change local state. |
| 10023 | */ |
| 10024 | if (local_state_change) |
| 10025 | return 0; |
| 10026 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10027 | wdev_lock(dev->ieee80211_ptr); |
| 10028 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 10029 | ssid, ssid_len, ie, ie_len, |
| 10030 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 10031 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10032 | wdev_unlock(dev->ieee80211_ptr); |
| 10033 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10034 | } |
| 10035 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 10036 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 10037 | struct genl_info *info) |
| 10038 | { |
| 10039 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10040 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 10041 | return -EINVAL; |
| 10042 | } |
| 10043 | |
| 10044 | if (!rdev->ops->tx_control_port || |
| 10045 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10046 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 10047 | return -EOPNOTSUPP; |
| 10048 | |
| 10049 | return 0; |
| 10050 | } |
| 10051 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10052 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 10053 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10054 | struct cfg80211_crypto_settings *settings, |
| 10055 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10056 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 10057 | memset(settings, 0, sizeof(*settings)); |
| 10058 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10059 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 10060 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10061 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 10062 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 10063 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10064 | proto = nla_get_u16( |
| 10065 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 10066 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 10067 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 10068 | proto != ETH_P_PAE) |
| 10069 | return -EINVAL; |
| 10070 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 10071 | settings->control_port_no_encrypt = true; |
| 10072 | } else |
| 10073 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 10074 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 10075 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10076 | int r = validate_pae_over_nl80211(rdev, info); |
| 10077 | |
| 10078 | if (r < 0) |
| 10079 | return r; |
| 10080 | |
| 10081 | settings->control_port_over_nl80211 = true; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 10082 | |
| 10083 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) |
| 10084 | settings->control_port_no_preauth = true; |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 10085 | } |
| 10086 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10087 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 10088 | void *data; |
| 10089 | int len, i; |
| 10090 | |
| 10091 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 10092 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 10093 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 10094 | |
| 10095 | if (len % sizeof(u32)) |
| 10096 | return -EINVAL; |
| 10097 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10098 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10099 | return -EINVAL; |
| 10100 | |
| 10101 | memcpy(settings->ciphers_pairwise, data, len); |
| 10102 | |
| 10103 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 10104 | if (!cfg80211_supported_cipher_suite( |
| 10105 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10106 | settings->ciphers_pairwise[i])) |
| 10107 | return -EINVAL; |
| 10108 | } |
| 10109 | |
| 10110 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 10111 | settings->cipher_group = |
| 10112 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 10113 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 10114 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10115 | return -EINVAL; |
| 10116 | } |
| 10117 | |
| 10118 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 10119 | settings->wpa_versions = |
| 10120 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 10121 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 10122 | return -EINVAL; |
| 10123 | } |
| 10124 | |
| 10125 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 10126 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 10127 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10128 | |
| 10129 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 10130 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 10131 | settings->n_akm_suites = len / sizeof(u32); |
| 10132 | |
| 10133 | if (len % sizeof(u32)) |
| 10134 | return -EINVAL; |
| 10135 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 10136 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 10137 | return -EINVAL; |
| 10138 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10139 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10140 | } |
| 10141 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 10142 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 10143 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 10144 | return -EINVAL; |
| 10145 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | f966227 | 2020-06-23 08:49:35 -0500 | [diff] [blame] | 10146 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && |
| 10147 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10148 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 10149 | return -EINVAL; |
| 10150 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 10151 | } |
| 10152 | |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 10153 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
| 10154 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | 2831a63 | 2020-08-17 02:33:15 -0500 | [diff] [blame] | 10155 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
| 10156 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10157 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 10158 | return -EINVAL; |
| 10159 | settings->sae_pwd = |
| 10160 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 10161 | settings->sae_pwd_len = |
| 10162 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 10163 | } |
| 10164 | |
Rohan Dutta | 9f0ffa4 | 2020-10-27 12:09:10 +0200 | [diff] [blame] | 10165 | if (info->attrs[NL80211_ATTR_SAE_PWE]) |
| 10166 | settings->sae_pwe = |
| 10167 | nla_get_u8(info->attrs[NL80211_ATTR_SAE_PWE]); |
| 10168 | else |
| 10169 | settings->sae_pwe = NL80211_SAE_PWE_UNSPECIFIED; |
| 10170 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10171 | return 0; |
| 10172 | } |
| 10173 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10174 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 10175 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10177 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 10178 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10179 | struct cfg80211_assoc_request req = {}; |
| 10180 | const u8 *bssid, *ssid; |
| 10181 | int err, ssid_len = 0; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10182 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10183 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10184 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10185 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10186 | return -EPERM; |
| 10187 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 10188 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10189 | !info->attrs[NL80211_ATTR_SSID] || |
| 10190 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 10191 | return -EINVAL; |
| 10192 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10193 | if (!rdev->ops->assoc) |
| 10194 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10195 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10196 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10197 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10198 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 10199 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10200 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10201 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10202 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 10203 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 10204 | freq += |
| 10205 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 10206 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10207 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10208 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10209 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10210 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10211 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10212 | |
| 10213 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10214 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10215 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10216 | } |
| 10217 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 10218 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 10219 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 10220 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 10221 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10222 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10223 | else if (mfp != NL80211_MFP_NO) |
| 10224 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 10225 | } |
| 10226 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 10227 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10228 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 10229 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10230 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10231 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10232 | |
| 10233 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10234 | memcpy(&req.ht_capa_mask, |
| 10235 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10236 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10237 | |
| 10238 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10239 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10240 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10241 | memcpy(&req.ht_capa, |
| 10242 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10243 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10244 | } |
| 10245 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10246 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10247 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10248 | |
Ben Greear | b6db0f8 | 2021-02-04 06:46:10 -0800 | [diff] [blame] | 10249 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) |
| 10250 | req.flags |= ASSOC_REQ_DISABLE_HE; |
| 10251 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10252 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10253 | memcpy(&req.vht_capa_mask, |
| 10254 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 10255 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10256 | |
| 10257 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10258 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10259 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10260 | memcpy(&req.vht_capa, |
| 10261 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 10262 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10263 | } |
| 10264 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10265 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 10266 | if (!((rdev->wiphy.features & |
| 10267 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 10268 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 10269 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10270 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10271 | return -EINVAL; |
| 10272 | req.flags |= ASSOC_REQ_USE_RRM; |
| 10273 | } |
| 10274 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 10275 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 10276 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 10277 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 10278 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 10279 | return -EINVAL; |
| 10280 | req.fils_nonces = |
| 10281 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 10282 | } |
| 10283 | |
Thomas Pedersen | d2b7588 | 2020-09-21 19:28:04 -0700 | [diff] [blame] | 10284 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { |
| 10285 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) |
| 10286 | return -EINVAL; |
| 10287 | memcpy(&req.s1g_capa_mask, |
| 10288 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), |
| 10289 | sizeof(req.s1g_capa_mask)); |
| 10290 | } |
| 10291 | |
| 10292 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { |
| 10293 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) |
| 10294 | return -EINVAL; |
| 10295 | memcpy(&req.s1g_capa, |
| 10296 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), |
| 10297 | sizeof(req.s1g_capa)); |
| 10298 | } |
| 10299 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10300 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10301 | if (!err) { |
| 10302 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10303 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 10304 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 10305 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10306 | |
| 10307 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10308 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 10309 | info->snd_portid; |
| 10310 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 10311 | bssid, ETH_ALEN); |
| 10312 | } |
| 10313 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10314 | wdev_unlock(dev->ieee80211_ptr); |
| 10315 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10316 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10317 | return err; |
| 10318 | } |
| 10319 | |
| 10320 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 10321 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10322 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10323 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10324 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10325 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10326 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 10327 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10328 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10329 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10330 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10331 | return -EPERM; |
| 10332 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 10333 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10334 | return -EINVAL; |
| 10335 | |
| 10336 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10337 | return -EINVAL; |
| 10338 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10339 | if (!rdev->ops->deauth) |
| 10340 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10341 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10342 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10343 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10344 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 10345 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10346 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10347 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10348 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10349 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 10350 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10351 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 10352 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10353 | |
| 10354 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10355 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10356 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10357 | } |
| 10358 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 10359 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 10360 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10361 | wdev_lock(dev->ieee80211_ptr); |
| 10362 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 10363 | local_state_change); |
| 10364 | wdev_unlock(dev->ieee80211_ptr); |
| 10365 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10366 | } |
| 10367 | |
| 10368 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 10369 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10371 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10372 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10373 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10374 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 10375 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10376 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10377 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10378 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10379 | return -EPERM; |
| 10380 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 10381 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 10382 | return -EINVAL; |
| 10383 | |
| 10384 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10385 | return -EINVAL; |
| 10386 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10387 | if (!rdev->ops->disassoc) |
| 10388 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10389 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10390 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10391 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10392 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 10393 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10394 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10395 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10396 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10397 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 10398 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10399 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 10400 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10401 | |
| 10402 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 10403 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10404 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10405 | } |
| 10406 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 10407 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 10408 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10409 | wdev_lock(dev->ieee80211_ptr); |
| 10410 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 10411 | local_state_change); |
| 10412 | wdev_unlock(dev->ieee80211_ptr); |
| 10413 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 10414 | } |
| 10415 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10416 | static bool |
| 10417 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10418 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10419 | int rateval) |
| 10420 | { |
| 10421 | struct wiphy *wiphy = &rdev->wiphy; |
| 10422 | bool found = false; |
| 10423 | int band, i; |
| 10424 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10425 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10426 | struct ieee80211_supported_band *sband; |
| 10427 | |
| 10428 | sband = wiphy->bands[band]; |
| 10429 | if (!sband) |
| 10430 | continue; |
| 10431 | |
| 10432 | for (i = 0; i < sband->n_bitrates; i++) { |
| 10433 | if (sband->bitrates[i].bitrate == rateval) { |
| 10434 | mcast_rate[band] = i + 1; |
| 10435 | found = true; |
| 10436 | break; |
| 10437 | } |
| 10438 | } |
| 10439 | } |
| 10440 | |
| 10441 | return found; |
| 10442 | } |
| 10443 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10444 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10445 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10446 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10447 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10448 | struct cfg80211_ibss_params ibss; |
| 10449 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10450 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10451 | int err; |
| 10452 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10453 | memset(&ibss, 0, sizeof(ibss)); |
| 10454 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10455 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10456 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10457 | return -EINVAL; |
| 10458 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10459 | ibss.beacon_interval = 100; |
| 10460 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10461 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10462 | ibss.beacon_interval = |
| 10463 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10464 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 10465 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 10466 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10467 | if (err) |
| 10468 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10469 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10470 | if (!rdev->ops->join_ibss) |
| 10471 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10472 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10473 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10474 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10475 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10476 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10477 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 10478 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10479 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 10480 | |
| 10481 | if (!is_valid_ether_addr(ibss.bssid)) |
| 10482 | return -EINVAL; |
| 10483 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10484 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10485 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10486 | |
| 10487 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10488 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10489 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10490 | } |
| 10491 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10492 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 10493 | if (err) |
| 10494 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 10495 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 10496 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 10497 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 10498 | return -EINVAL; |
| 10499 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10500 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 10501 | case NL80211_CHAN_WIDTH_5: |
| 10502 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10503 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 10504 | break; |
| 10505 | case NL80211_CHAN_WIDTH_20: |
| 10506 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 10507 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 10508 | return -EINVAL; |
| 10509 | break; |
| 10510 | case NL80211_CHAN_WIDTH_80: |
| 10511 | case NL80211_CHAN_WIDTH_80P80: |
| 10512 | case NL80211_CHAN_WIDTH_160: |
| 10513 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 10514 | return -EINVAL; |
| 10515 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 10516 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 10517 | return -EINVAL; |
| 10518 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10519 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 10520 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10521 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 10522 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10523 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10524 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10525 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10526 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10527 | u8 *rates = |
| 10528 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10529 | int n_rates = |
| 10530 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10531 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10532 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10533 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 10534 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10535 | &ibss.basic_rates); |
| 10536 | if (err) |
| 10537 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10538 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10539 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 10540 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10541 | memcpy(&ibss.ht_capa_mask, |
| 10542 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10543 | sizeof(ibss.ht_capa_mask)); |
| 10544 | |
| 10545 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 10546 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10547 | return -EINVAL; |
| 10548 | memcpy(&ibss.ht_capa, |
| 10549 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10550 | sizeof(ibss.ht_capa)); |
| 10551 | } |
| 10552 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10553 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10554 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 10555 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10556 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10557 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10558 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10559 | bool no_ht = false; |
| 10560 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10561 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10562 | if (IS_ERR(connkeys)) |
| 10563 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10564 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 10565 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 10566 | no_ht) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10567 | kfree_sensitive(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10568 | return -EINVAL; |
| 10569 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10570 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10571 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 10572 | ibss.control_port = |
| 10573 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 10574 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10575 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10576 | int r = validate_pae_over_nl80211(rdev, info); |
| 10577 | |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 10578 | if (r < 0) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10579 | kfree_sensitive(connkeys); |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10580 | return r; |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 10581 | } |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10582 | |
| 10583 | ibss.control_port_over_nl80211 = true; |
| 10584 | } |
| 10585 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 10586 | ibss.userspace_handles_dfs = |
| 10587 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10588 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 10589 | wdev_lock(dev->ieee80211_ptr); |
| 10590 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10591 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10592 | kfree_sensitive(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 10593 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 10594 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10595 | wdev_unlock(dev->ieee80211_ptr); |
| 10596 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10597 | return err; |
| 10598 | } |
| 10599 | |
| 10600 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10601 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10603 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10604 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10605 | if (!rdev->ops->leave_ibss) |
| 10606 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10607 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10608 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10609 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10610 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10611 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10612 | } |
| 10613 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10614 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 10615 | { |
| 10616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10617 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10618 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10619 | u32 nla_rate; |
| 10620 | int err; |
| 10621 | |
| 10622 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 10623 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 10624 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10625 | return -EOPNOTSUPP; |
| 10626 | |
| 10627 | if (!rdev->ops->set_mcast_rate) |
| 10628 | return -EOPNOTSUPP; |
| 10629 | |
| 10630 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 10631 | |
| 10632 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 10633 | return -EINVAL; |
| 10634 | |
| 10635 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 10636 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 10637 | return -EINVAL; |
| 10638 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10639 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10640 | |
| 10641 | return err; |
| 10642 | } |
| 10643 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10644 | static struct sk_buff * |
| 10645 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10646 | struct wireless_dev *wdev, int approxlen, |
| 10647 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10648 | enum nl80211_attrs attr, |
| 10649 | const struct nl80211_vendor_cmd_info *info, |
| 10650 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10651 | { |
| 10652 | struct sk_buff *skb; |
| 10653 | void *hdr; |
| 10654 | struct nlattr *data; |
| 10655 | |
| 10656 | skb = nlmsg_new(approxlen + 100, gfp); |
| 10657 | if (!skb) |
| 10658 | return NULL; |
| 10659 | |
| 10660 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 10661 | if (!hdr) { |
| 10662 | kfree_skb(skb); |
| 10663 | return NULL; |
| 10664 | } |
| 10665 | |
| 10666 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10667 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10668 | |
| 10669 | if (info) { |
| 10670 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 10671 | info->vendor_id)) |
| 10672 | goto nla_put_failure; |
| 10673 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 10674 | info->subcmd)) |
| 10675 | goto nla_put_failure; |
| 10676 | } |
| 10677 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10678 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10679 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10680 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10681 | goto nla_put_failure; |
| 10682 | if (wdev->netdev && |
| 10683 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 10684 | wdev->netdev->ifindex)) |
| 10685 | goto nla_put_failure; |
| 10686 | } |
| 10687 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10688 | data = nla_nest_start_noflag(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10689 | if (!data) |
| 10690 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10691 | |
| 10692 | ((void **)skb->cb)[0] = rdev; |
| 10693 | ((void **)skb->cb)[1] = hdr; |
| 10694 | ((void **)skb->cb)[2] = data; |
| 10695 | |
| 10696 | return skb; |
| 10697 | |
| 10698 | nla_put_failure: |
| 10699 | kfree_skb(skb); |
| 10700 | return NULL; |
| 10701 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10702 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10703 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10704 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10705 | enum nl80211_commands cmd, |
| 10706 | enum nl80211_attrs attr, |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10707 | unsigned int portid, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10708 | int vendor_event_idx, |
| 10709 | int approxlen, gfp_t gfp) |
| 10710 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10711 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10712 | const struct nl80211_vendor_cmd_info *info; |
| 10713 | |
| 10714 | switch (cmd) { |
| 10715 | case NL80211_CMD_TESTMODE: |
| 10716 | if (WARN_ON(vendor_event_idx != -1)) |
| 10717 | return NULL; |
| 10718 | info = NULL; |
| 10719 | break; |
| 10720 | case NL80211_CMD_VENDOR: |
| 10721 | if (WARN_ON(vendor_event_idx < 0 || |
| 10722 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 10723 | return NULL; |
| 10724 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 10725 | break; |
| 10726 | default: |
| 10727 | WARN_ON(1); |
| 10728 | return NULL; |
| 10729 | } |
| 10730 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10731 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10732 | cmd, attr, info, gfp); |
| 10733 | } |
| 10734 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 10735 | |
| 10736 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 10737 | { |
| 10738 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10739 | void *hdr = ((void **)skb->cb)[1]; |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10740 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10741 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10742 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 10743 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10744 | /* clear CB data for netlink core to own from now on */ |
| 10745 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10746 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10747 | nla_nest_end(skb, data); |
| 10748 | genlmsg_end(skb, hdr); |
| 10749 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10750 | if (nlhdr->nlmsg_pid) { |
| 10751 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, |
| 10752 | nlhdr->nlmsg_pid); |
| 10753 | } else { |
| 10754 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 10755 | mcgrp = NL80211_MCGRP_VENDOR; |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10756 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10757 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 10758 | skb, 0, mcgrp, gfp); |
| 10759 | } |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10760 | } |
| 10761 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 10762 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10763 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10764 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 10765 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10766 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 10767 | struct wireless_dev *wdev; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10768 | int err; |
| 10769 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 10770 | lockdep_assert_held(&rdev->wiphy.mtx); |
| 10771 | |
| 10772 | wdev = __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), |
| 10773 | info->attrs); |
| 10774 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10775 | if (!rdev->ops->testmode_cmd) |
| 10776 | return -EOPNOTSUPP; |
| 10777 | |
| 10778 | if (IS_ERR(wdev)) { |
| 10779 | err = PTR_ERR(wdev); |
| 10780 | if (err != -EINVAL) |
| 10781 | return err; |
| 10782 | wdev = NULL; |
| 10783 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10784 | return -EINVAL; |
| 10785 | } |
| 10786 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10787 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 10788 | return -EINVAL; |
| 10789 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10790 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10791 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10792 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 10793 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10794 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10795 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10796 | return err; |
| 10797 | } |
| 10798 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10799 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 10800 | struct netlink_callback *cb) |
| 10801 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10802 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10803 | struct nlattr **attrbuf = NULL; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10804 | int err; |
| 10805 | long phy_idx; |
| 10806 | void *data = NULL; |
| 10807 | int data_len = 0; |
| 10808 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10809 | rtnl_lock(); |
| 10810 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10811 | if (cb->args[0]) { |
| 10812 | /* |
| 10813 | * 0 is a valid index, but not valid for args[0], |
| 10814 | * so we need to offset by 1. |
| 10815 | */ |
| 10816 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 10817 | |
| 10818 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 10819 | if (!rdev) { |
| 10820 | err = -ENOENT; |
| 10821 | goto out_err; |
| 10822 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10823 | } else { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10824 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 10825 | GFP_KERNEL); |
| 10826 | if (!attrbuf) { |
| 10827 | err = -ENOMEM; |
| 10828 | goto out_err; |
| 10829 | } |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10830 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 10831 | err = nlmsg_parse_deprecated(cb->nlh, |
| 10832 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10833 | attrbuf, nl80211_fam.maxattr, |
| 10834 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10835 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10836 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10837 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10838 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10839 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10840 | err = PTR_ERR(rdev); |
| 10841 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10842 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10843 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10844 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10845 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 10846 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10847 | } |
| 10848 | |
| 10849 | if (cb->args[1]) { |
| 10850 | data = nla_data((void *)cb->args[1]); |
| 10851 | data_len = nla_len((void *)cb->args[1]); |
| 10852 | } |
| 10853 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10854 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10855 | err = -EOPNOTSUPP; |
| 10856 | goto out_err; |
| 10857 | } |
| 10858 | |
| 10859 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10860 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10861 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10862 | NL80211_CMD_TESTMODE); |
| 10863 | struct nlattr *tmdata; |
| 10864 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10865 | if (!hdr) |
| 10866 | break; |
| 10867 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10868 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10869 | genlmsg_cancel(skb, hdr); |
| 10870 | break; |
| 10871 | } |
| 10872 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10873 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10874 | if (!tmdata) { |
| 10875 | genlmsg_cancel(skb, hdr); |
| 10876 | break; |
| 10877 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10878 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10879 | nla_nest_end(skb, tmdata); |
| 10880 | |
| 10881 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10882 | genlmsg_cancel(skb, hdr); |
| 10883 | break; |
| 10884 | } else if (err) { |
| 10885 | genlmsg_cancel(skb, hdr); |
| 10886 | goto out_err; |
| 10887 | } |
| 10888 | |
| 10889 | genlmsg_end(skb, hdr); |
| 10890 | } |
| 10891 | |
| 10892 | err = skb->len; |
| 10893 | /* see above */ |
| 10894 | cb->args[0] = phy_idx + 1; |
| 10895 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10896 | kfree(attrbuf); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10897 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10898 | return err; |
| 10899 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10900 | #endif |
| 10901 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10902 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 10903 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10904 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10905 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10906 | struct cfg80211_connect_params connect; |
| 10907 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10908 | struct cfg80211_cached_keys *connkeys = NULL; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10909 | u32 freq = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10910 | int err; |
| 10911 | |
| 10912 | memset(&connect, 0, sizeof(connect)); |
| 10913 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10914 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10915 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10916 | return -EINVAL; |
| 10917 | |
| 10918 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10919 | connect.auth_type = |
| 10920 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10921 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 10922 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10923 | return -EINVAL; |
| 10924 | } else |
| 10925 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 10926 | |
| 10927 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 10928 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 10929 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 10930 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10931 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 10932 | return -EINVAL; |
| 10933 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 10934 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10935 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10936 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10937 | if (err) |
| 10938 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10939 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10940 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10941 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10942 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10943 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10944 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10945 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 10946 | connect.bg_scan_period = -1; |
| 10947 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 10948 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 10949 | connect.bg_scan_period = |
| 10950 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 10951 | } |
| 10952 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10953 | if (info->attrs[NL80211_ATTR_MAC]) |
| 10954 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10955 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 10956 | connect.bssid_hint = |
| 10957 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10958 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10959 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10960 | |
| 10961 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10962 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10963 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10964 | } |
| 10965 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10966 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 10967 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 10968 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 10969 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10970 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 10971 | return -EOPNOTSUPP; |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10972 | } else { |
| 10973 | connect.mfp = NL80211_MFP_NO; |
| 10974 | } |
| 10975 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 10976 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 10977 | connect.prev_bssid = |
| 10978 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 10979 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10980 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10981 | freq = MHZ_TO_KHZ(nla_get_u32( |
| 10982 | info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 10983 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 10984 | freq += |
| 10985 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 10986 | |
| 10987 | if (freq) { |
| 10988 | connect.channel = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10989 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10990 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10991 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10992 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 10993 | freq = MHZ_TO_KHZ(freq); |
| 10994 | connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10995 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10996 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10997 | } |
| 10998 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 10999 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 11000 | connect.edmg.channels = |
| 11001 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 11002 | |
| 11003 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 11004 | connect.edmg.bw_config = |
| 11005 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 11006 | } |
| 11007 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 11008 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 11009 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11010 | if (IS_ERR(connkeys)) |
| 11011 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 11012 | } |
| 11013 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 11014 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 11015 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 11016 | |
| 11017 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 11018 | memcpy(&connect.ht_capa_mask, |
| 11019 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 11020 | sizeof(connect.ht_capa_mask)); |
| 11021 | |
| 11022 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 11023 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11024 | kfree_sensitive(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 11025 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 11026 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 11027 | memcpy(&connect.ht_capa, |
| 11028 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 11029 | sizeof(connect.ht_capa)); |
| 11030 | } |
| 11031 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 11032 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 11033 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 11034 | |
Ben Greear | b6db0f8 | 2021-02-04 06:46:10 -0800 | [diff] [blame] | 11035 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HE])) |
| 11036 | connect.flags |= ASSOC_REQ_DISABLE_HE; |
| 11037 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 11038 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 11039 | memcpy(&connect.vht_capa_mask, |
| 11040 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 11041 | sizeof(connect.vht_capa_mask)); |
| 11042 | |
| 11043 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 11044 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11045 | kfree_sensitive(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 11046 | return -EINVAL; |
| 11047 | } |
| 11048 | memcpy(&connect.vht_capa, |
| 11049 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 11050 | sizeof(connect.vht_capa)); |
| 11051 | } |
| 11052 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 11053 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 11054 | if (!((rdev->wiphy.features & |
| 11055 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 11056 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 11057 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 11058 | NL80211_EXT_FEATURE_RRM)) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11059 | kfree_sensitive(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 11060 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 11061 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 11062 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 11063 | } |
| 11064 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 11065 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 11066 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11067 | kfree_sensitive(connkeys); |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 11068 | return -EOPNOTSUPP; |
| 11069 | } |
| 11070 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 11071 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 11072 | /* bss selection makes no sense if bssid is set */ |
| 11073 | if (connect.bssid) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11074 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 11075 | return -EINVAL; |
| 11076 | } |
| 11077 | |
| 11078 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 11079 | wiphy, &connect.bss_select); |
| 11080 | if (err) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11081 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 11082 | return err; |
| 11083 | } |
| 11084 | } |
| 11085 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 11086 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 11087 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 11088 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 11089 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 11090 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 11091 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 11092 | connect.fils_erp_username = |
| 11093 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 11094 | connect.fils_erp_username_len = |
| 11095 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 11096 | connect.fils_erp_realm = |
| 11097 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 11098 | connect.fils_erp_realm_len = |
| 11099 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 11100 | connect.fils_erp_next_seq_num = |
| 11101 | nla_get_u16( |
| 11102 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 11103 | connect.fils_erp_rrk = |
| 11104 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 11105 | connect.fils_erp_rrk_len = |
| 11106 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 11107 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 11108 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 11109 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 11110 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11111 | kfree_sensitive(connkeys); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 11112 | return -EINVAL; |
| 11113 | } |
| 11114 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 11115 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 11116 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11117 | kfree_sensitive(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 11118 | GENL_SET_ERR_MSG(info, |
| 11119 | "external auth requires connection ownership"); |
| 11120 | return -EINVAL; |
| 11121 | } |
| 11122 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 11123 | } |
| 11124 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 11125 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 11126 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 11127 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 11128 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 11129 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 11130 | kfree_sensitive(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 11131 | |
| 11132 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 11133 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 11134 | if (connect.bssid) |
| 11135 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 11136 | connect.bssid, ETH_ALEN); |
| 11137 | else |
Miaohe Lin | 3b1648f | 2020-08-01 17:15:49 +0800 | [diff] [blame] | 11138 | eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 11139 | } |
| 11140 | |
| 11141 | wdev_unlock(dev->ieee80211_ptr); |
| 11142 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11143 | return err; |
| 11144 | } |
| 11145 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 11146 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 11147 | struct genl_info *info) |
| 11148 | { |
| 11149 | struct cfg80211_connect_params connect = {}; |
| 11150 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11151 | struct net_device *dev = info->user_ptr[1]; |
| 11152 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 11153 | bool fils_sk_offload; |
| 11154 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 11155 | u32 changed = 0; |
| 11156 | int ret; |
| 11157 | |
| 11158 | if (!rdev->ops->update_connect_params) |
| 11159 | return -EOPNOTSUPP; |
| 11160 | |
| 11161 | if (info->attrs[NL80211_ATTR_IE]) { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 11162 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 11163 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 11164 | changed |= UPDATE_ASSOC_IES; |
| 11165 | } |
| 11166 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 11167 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 11168 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 11169 | |
| 11170 | /* |
| 11171 | * when driver supports fils-sk offload all attributes must be |
| 11172 | * provided. So the else covers "fils-sk-not-all" and |
| 11173 | * "no-fils-sk-any". |
| 11174 | */ |
| 11175 | if (fils_sk_offload && |
| 11176 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 11177 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 11178 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 11179 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 11180 | connect.fils_erp_username = |
| 11181 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 11182 | connect.fils_erp_username_len = |
| 11183 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 11184 | connect.fils_erp_realm = |
| 11185 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 11186 | connect.fils_erp_realm_len = |
| 11187 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 11188 | connect.fils_erp_next_seq_num = |
| 11189 | nla_get_u16( |
| 11190 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 11191 | connect.fils_erp_rrk = |
| 11192 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 11193 | connect.fils_erp_rrk_len = |
| 11194 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 11195 | changed |= UPDATE_FILS_ERP_INFO; |
| 11196 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 11197 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 11198 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 11199 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 11200 | return -EINVAL; |
| 11201 | } |
| 11202 | |
| 11203 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 11204 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 11205 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 11206 | NL80211_CMD_CONNECT)) |
| 11207 | return -EINVAL; |
| 11208 | |
| 11209 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 11210 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 11211 | return -EINVAL; |
| 11212 | |
| 11213 | connect.auth_type = auth_type; |
| 11214 | changed |= UPDATE_AUTH_TYPE; |
| 11215 | } |
| 11216 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 11217 | wdev_lock(dev->ieee80211_ptr); |
| 11218 | if (!wdev->current_bss) |
| 11219 | ret = -ENOLINK; |
| 11220 | else |
| 11221 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 11222 | wdev_unlock(dev->ieee80211_ptr); |
| 11223 | |
| 11224 | return ret; |
| 11225 | } |
| 11226 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11227 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 11228 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11229 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11230 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11231 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 11232 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11233 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 11234 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 11235 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 11236 | return -EPERM; |
| 11237 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11238 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 11239 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 11240 | else |
| 11241 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 11242 | |
| 11243 | if (reason == 0) |
| 11244 | return -EINVAL; |
| 11245 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11246 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11247 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11248 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11249 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 11250 | wdev_lock(dev->ieee80211_ptr); |
| 11251 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 11252 | wdev_unlock(dev->ieee80211_ptr); |
| 11253 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 11254 | } |
| 11255 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11256 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 11257 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11258 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11259 | struct net *net; |
| 11260 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11261 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 11262 | if (info->attrs[NL80211_ATTR_PID]) { |
| 11263 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 11264 | |
| 11265 | net = get_net_ns_by_pid(pid); |
| 11266 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 11267 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 11268 | |
| 11269 | net = get_net_ns_by_fd(fd); |
| 11270 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11271 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 11272 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11273 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11274 | if (IS_ERR(net)) |
| 11275 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11276 | |
| 11277 | err = 0; |
| 11278 | |
| 11279 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11280 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 11281 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11282 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11283 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 11284 | return err; |
| 11285 | } |
| 11286 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11287 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 11288 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11289 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11290 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 11291 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11292 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11293 | struct cfg80211_pmksa pmksa; |
| 11294 | |
| 11295 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 11296 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11297 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 11298 | return -EINVAL; |
| 11299 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11300 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 11301 | |
| 11302 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 11303 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11304 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 11305 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 11306 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 11307 | info->attrs[NL80211_ATTR_PMK])) { |
| 11308 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 11309 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 11310 | pmksa.cache_id = |
| 11311 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 11312 | } else { |
| 11313 | return -EINVAL; |
| 11314 | } |
| 11315 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 11316 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 11317 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 11318 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11319 | |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 11320 | if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) |
| 11321 | pmksa.pmk_lifetime = |
| 11322 | nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); |
| 11323 | |
| 11324 | if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) |
| 11325 | pmksa.pmk_reauth_threshold = |
| 11326 | nla_get_u8( |
| 11327 | info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); |
| 11328 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11329 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Liangwei Dong | 6c90036 | 2019-01-18 16:54:38 +0530 | [diff] [blame] | 11330 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 11331 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && |
| 11332 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 11333 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11334 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11335 | |
| 11336 | switch (info->genlhdr->cmd) { |
| 11337 | case NL80211_CMD_SET_PMKSA: |
| 11338 | rdev_ops = rdev->ops->set_pmksa; |
| 11339 | break; |
| 11340 | case NL80211_CMD_DEL_PMKSA: |
| 11341 | rdev_ops = rdev->ops->del_pmksa; |
| 11342 | break; |
| 11343 | default: |
| 11344 | WARN_ON(1); |
| 11345 | break; |
| 11346 | } |
| 11347 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11348 | if (!rdev_ops) |
| 11349 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11351 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11352 | } |
| 11353 | |
| 11354 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 11355 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11356 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11357 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11358 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11359 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11360 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11361 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11362 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11363 | if (!rdev->ops->flush_pmksa) |
| 11364 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11365 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11366 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 11367 | } |
| 11368 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11369 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 11370 | { |
| 11371 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11372 | struct net_device *dev = info->user_ptr[1]; |
| 11373 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 11374 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11375 | u16 status_code; |
| 11376 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 11377 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11378 | |
| 11379 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 11380 | !rdev->ops->tdls_mgmt) |
| 11381 | return -EOPNOTSUPP; |
| 11382 | |
| 11383 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 11384 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 11385 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 11386 | !info->attrs[NL80211_ATTR_IE] || |
| 11387 | !info->attrs[NL80211_ATTR_MAC]) |
| 11388 | return -EINVAL; |
| 11389 | |
| 11390 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11391 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 11392 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 11393 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 11394 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 11395 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 11396 | peer_capability = |
| 11397 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11398 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11399 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 11400 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 11401 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11402 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 11403 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11404 | } |
| 11405 | |
| 11406 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 11407 | { |
| 11408 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11409 | struct net_device *dev = info->user_ptr[1]; |
| 11410 | enum nl80211_tdls_operation operation; |
| 11411 | u8 *peer; |
| 11412 | |
| 11413 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 11414 | !rdev->ops->tdls_oper) |
| 11415 | return -EOPNOTSUPP; |
| 11416 | |
| 11417 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 11418 | !info->attrs[NL80211_ATTR_MAC]) |
| 11419 | return -EINVAL; |
| 11420 | |
| 11421 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 11422 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 11423 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11424 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 11425 | } |
| 11426 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11427 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 11428 | struct genl_info *info) |
| 11429 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11431 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11432 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 11433 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11434 | struct sk_buff *msg; |
| 11435 | void *hdr; |
| 11436 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11437 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11438 | int err; |
| 11439 | |
| 11440 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 11441 | !info->attrs[NL80211_ATTR_DURATION]) |
| 11442 | return -EINVAL; |
| 11443 | |
| 11444 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 11445 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11446 | if (!rdev->ops->remain_on_channel || |
| 11447 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11448 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11449 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11450 | /* |
| 11451 | * We should be on that channel for at least a minimum amount of |
| 11452 | * time (10ms) but no longer than the driver supports. |
| 11453 | */ |
| 11454 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11455 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 11456 | return -EINVAL; |
| 11457 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11458 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11459 | if (err) |
| 11460 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11461 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 11462 | wdev_lock(wdev); |
| 11463 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 11464 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 11465 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 11466 | &chandef); |
| 11467 | if (compat_chandef != &chandef) { |
| 11468 | wdev_unlock(wdev); |
| 11469 | return -EBUSY; |
| 11470 | } |
| 11471 | } |
| 11472 | wdev_unlock(wdev); |
| 11473 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11474 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11475 | if (!msg) |
| 11476 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11477 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11478 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11479 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11480 | if (!hdr) { |
| 11481 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11482 | goto free_msg; |
| 11483 | } |
| 11484 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11485 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 11486 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11487 | |
| 11488 | if (err) |
| 11489 | goto free_msg; |
| 11490 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11491 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11492 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11493 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11494 | |
| 11495 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11496 | |
| 11497 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11498 | |
| 11499 | nla_put_failure: |
| 11500 | err = -ENOBUFS; |
| 11501 | free_msg: |
| 11502 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11503 | return err; |
| 11504 | } |
| 11505 | |
| 11506 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 11507 | struct genl_info *info) |
| 11508 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11509 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11510 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11511 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11512 | |
| 11513 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11514 | return -EINVAL; |
| 11515 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11516 | if (!rdev->ops->cancel_remain_on_channel) |
| 11517 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11518 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11519 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11520 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11521 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11522 | } |
| 11523 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11524 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 11525 | struct genl_info *info) |
| 11526 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11527 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 11528 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11529 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 11530 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11531 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11532 | if (!rdev->ops->set_bitrate_mask) |
| 11533 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11534 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 11535 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 11536 | NL80211_ATTR_TX_RATES, &mask, |
Rajkumar Manoharan | 857b34c | 2020-10-16 13:15:26 -0700 | [diff] [blame] | 11537 | dev, true); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 11538 | if (err) |
| 11539 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 11540 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11541 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11542 | } |
| 11543 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11544 | 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] | 11545 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11546 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11547 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11548 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11549 | |
| 11550 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 11551 | return -EINVAL; |
| 11552 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11553 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 11554 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11555 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11556 | switch (wdev->iftype) { |
| 11557 | case NL80211_IFTYPE_STATION: |
| 11558 | case NL80211_IFTYPE_ADHOC: |
| 11559 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11560 | case NL80211_IFTYPE_AP: |
| 11561 | case NL80211_IFTYPE_AP_VLAN: |
| 11562 | case NL80211_IFTYPE_MESH_POINT: |
| 11563 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11564 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11565 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11566 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11567 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11568 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11569 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11570 | |
| 11571 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11572 | if (!rdev->ops->mgmt_tx) |
| 11573 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11574 | |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 11575 | if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && |
| 11576 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 11577 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { |
| 11578 | GENL_SET_ERR_MSG(info, |
| 11579 | "multicast RX registrations are not supported"); |
| 11580 | return -EOPNOTSUPP; |
| 11581 | } |
| 11582 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11583 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 11584 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 11585 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 11586 | info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 11587 | info->extack); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11588 | } |
| 11589 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11590 | 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] | 11591 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11593 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11594 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11595 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 11596 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11597 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11598 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11599 | struct cfg80211_mgmt_tx_params params = { |
| 11600 | .dont_wait_for_ack = |
| 11601 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 11602 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11603 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11604 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11605 | return -EINVAL; |
| 11606 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11607 | if (!rdev->ops->mgmt_tx) |
| 11608 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11609 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11610 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11611 | case NL80211_IFTYPE_P2P_DEVICE: |
| 11612 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 11613 | return -EINVAL; |
Gustavo A. R. Silva | d7832c7 | 2020-11-20 12:38:37 -0600 | [diff] [blame] | 11614 | break; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11615 | case NL80211_IFTYPE_STATION: |
| 11616 | case NL80211_IFTYPE_ADHOC: |
| 11617 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11618 | case NL80211_IFTYPE_AP: |
| 11619 | case NL80211_IFTYPE_AP_VLAN: |
| 11620 | case NL80211_IFTYPE_MESH_POINT: |
| 11621 | case NL80211_IFTYPE_P2P_GO: |
| 11622 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11623 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11624 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11625 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11626 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11627 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11628 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11629 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11630 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11631 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11632 | |
| 11633 | /* |
| 11634 | * We should wait on the channel for at least a minimum amount |
| 11635 | * of time (10ms) but no longer than the driver supports. |
| 11636 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11637 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11638 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11639 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11640 | } |
| 11641 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11642 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11643 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11644 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11645 | return -EINVAL; |
| 11646 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11647 | 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] | 11648 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11649 | /* get the channel if any has been specified, otherwise pass NULL to |
| 11650 | * the driver. The latter will use the current one |
| 11651 | */ |
| 11652 | chandef.chan = NULL; |
| 11653 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 11654 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11655 | if (err) |
| 11656 | return err; |
| 11657 | } |
| 11658 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11659 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11660 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11661 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 11662 | wdev_lock(wdev); |
| 11663 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 11664 | wdev_unlock(wdev); |
| 11665 | return -EBUSY; |
| 11666 | } |
| 11667 | wdev_unlock(wdev); |
| 11668 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 11669 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 11670 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 11671 | |
| 11672 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 11673 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11674 | int i; |
| 11675 | |
| 11676 | if (len % sizeof(u16)) |
| 11677 | return -EINVAL; |
| 11678 | |
| 11679 | params.n_csa_offsets = len / sizeof(u16); |
| 11680 | params.csa_offsets = |
| 11681 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11682 | |
| 11683 | /* check that all the offsets fit the frame */ |
| 11684 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 11685 | if (params.csa_offsets[i] >= params.len) |
| 11686 | return -EINVAL; |
| 11687 | } |
| 11688 | } |
| 11689 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11690 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11691 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11692 | if (!msg) |
| 11693 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11694 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11695 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11696 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11697 | if (!hdr) { |
| 11698 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11699 | goto free_msg; |
| 11700 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11701 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11702 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11703 | params.chan = chandef.chan; |
| 11704 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11705 | if (err) |
| 11706 | goto free_msg; |
| 11707 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11708 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11709 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11710 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11711 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11712 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11713 | genlmsg_end(msg, hdr); |
| 11714 | return genlmsg_reply(msg, info); |
| 11715 | } |
| 11716 | |
| 11717 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11718 | |
| 11719 | nla_put_failure: |
| 11720 | err = -ENOBUFS; |
| 11721 | free_msg: |
| 11722 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11723 | return err; |
| 11724 | } |
| 11725 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11726 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 11727 | { |
| 11728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11729 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11730 | u64 cookie; |
| 11731 | |
| 11732 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11733 | return -EINVAL; |
| 11734 | |
| 11735 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 11736 | return -EOPNOTSUPP; |
| 11737 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11738 | switch (wdev->iftype) { |
| 11739 | case NL80211_IFTYPE_STATION: |
| 11740 | case NL80211_IFTYPE_ADHOC: |
| 11741 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11742 | case NL80211_IFTYPE_AP: |
| 11743 | case NL80211_IFTYPE_AP_VLAN: |
| 11744 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11745 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11746 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11747 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11748 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11749 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11750 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11751 | |
| 11752 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11753 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11754 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11755 | } |
| 11756 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11757 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11758 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11759 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11760 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11761 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11762 | u8 ps_state; |
| 11763 | bool state; |
| 11764 | int err; |
| 11765 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11766 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 11767 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11768 | |
| 11769 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 11770 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11771 | wdev = dev->ieee80211_ptr; |
| 11772 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11773 | if (!rdev->ops->set_power_mgmt) |
| 11774 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11775 | |
| 11776 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 11777 | |
| 11778 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11779 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11780 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11781 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11782 | if (!err) |
| 11783 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11784 | return err; |
| 11785 | } |
| 11786 | |
| 11787 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11788 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11789 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11790 | enum nl80211_ps_state ps_state; |
| 11791 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11792 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11793 | struct sk_buff *msg; |
| 11794 | void *hdr; |
| 11795 | int err; |
| 11796 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11797 | wdev = dev->ieee80211_ptr; |
| 11798 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11799 | if (!rdev->ops->set_power_mgmt) |
| 11800 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11801 | |
| 11802 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11803 | if (!msg) |
| 11804 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11805 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11806 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11807 | NL80211_CMD_GET_POWER_SAVE); |
| 11808 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11809 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11810 | goto free_msg; |
| 11811 | } |
| 11812 | |
| 11813 | if (wdev->ps) |
| 11814 | ps_state = NL80211_PS_ENABLED; |
| 11815 | else |
| 11816 | ps_state = NL80211_PS_DISABLED; |
| 11817 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11818 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 11819 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11820 | |
| 11821 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11822 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11823 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11824 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11825 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11826 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11827 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11828 | return err; |
| 11829 | } |
| 11830 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 11831 | static const struct nla_policy |
| 11832 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11833 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11834 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 11835 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11836 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 11837 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 11838 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 11839 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11840 | }; |
| 11841 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11842 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11843 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11844 | { |
| 11845 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11846 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11847 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11848 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11849 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11850 | return -EINVAL; |
| 11851 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11852 | if (!rdev->ops->set_cqm_txe_config) |
| 11853 | return -EOPNOTSUPP; |
| 11854 | |
| 11855 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 11856 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11857 | return -EOPNOTSUPP; |
| 11858 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11859 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11860 | } |
| 11861 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11862 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 11863 | struct net_device *dev) |
| 11864 | { |
| 11865 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11866 | s32 last, low, high; |
| 11867 | u32 hyst; |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11868 | int i, n, low_index; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11869 | int err; |
| 11870 | |
| 11871 | /* RSSI reporting disabled? */ |
| 11872 | if (!wdev->cqm_config) |
| 11873 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 11874 | |
| 11875 | /* |
| 11876 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 11877 | * event has been received yet, we should receive an event after a |
| 11878 | * connection is established and enough beacons received to calculate |
| 11879 | * the average. |
| 11880 | */ |
| 11881 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 11882 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11883 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11884 | u8 *mac_addr; |
| 11885 | |
| 11886 | mac_addr = wdev->current_bss->pub.bssid; |
| 11887 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11888 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 11889 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11890 | return err; |
| 11891 | |
Felix Fietkau | df16737 | 2020-01-08 18:06:30 +0100 | [diff] [blame] | 11892 | cfg80211_sinfo_release_content(&sinfo); |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 11893 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11894 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11895 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11896 | } |
| 11897 | |
| 11898 | last = wdev->cqm_config->last_rssi_event_value; |
| 11899 | hyst = wdev->cqm_config->rssi_hyst; |
| 11900 | n = wdev->cqm_config->n_rssi_thresholds; |
| 11901 | |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11902 | for (i = 0; i < n; i++) { |
| 11903 | i = array_index_nospec(i, n); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11904 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 11905 | break; |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11906 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11907 | |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11908 | low_index = i - 1; |
| 11909 | if (low_index >= 0) { |
| 11910 | low_index = array_index_nospec(low_index, n); |
| 11911 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 11912 | } else { |
| 11913 | low = S32_MIN; |
| 11914 | } |
| 11915 | if (i < n) { |
| 11916 | i = array_index_nospec(i, n); |
| 11917 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 11918 | } else { |
| 11919 | high = S32_MAX; |
| 11920 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11921 | |
| 11922 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 11923 | } |
| 11924 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11925 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11926 | const s32 *thresholds, int n_thresholds, |
| 11927 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11928 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11929 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11930 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11931 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11932 | int i, err; |
| 11933 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11934 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11935 | /* Check all values negative and sorted */ |
| 11936 | for (i = 0; i < n_thresholds; i++) { |
| 11937 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 11938 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11939 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11940 | prev = thresholds[i]; |
| 11941 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11942 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11943 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11944 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11945 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11946 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11947 | wdev_lock(wdev); |
| 11948 | cfg80211_cqm_config_free(wdev); |
| 11949 | wdev_unlock(wdev); |
| 11950 | |
| 11951 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 11952 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 11953 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 11954 | |
| 11955 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 11956 | thresholds[0], hysteresis); |
| 11957 | } |
| 11958 | |
| 11959 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 11960 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 11961 | return -EOPNOTSUPP; |
| 11962 | |
| 11963 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 11964 | n_thresholds = 0; |
| 11965 | |
| 11966 | wdev_lock(wdev); |
| 11967 | if (n_thresholds) { |
| 11968 | struct cfg80211_cqm_config *cqm_config; |
| 11969 | |
Len Baker | 40f231e | 2021-09-19 13:40:40 +0200 | [diff] [blame] | 11970 | cqm_config = kzalloc(struct_size(cqm_config, rssi_thresholds, |
| 11971 | n_thresholds), |
| 11972 | GFP_KERNEL); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11973 | if (!cqm_config) { |
| 11974 | err = -ENOMEM; |
| 11975 | goto unlock; |
| 11976 | } |
| 11977 | |
| 11978 | cqm_config->rssi_hyst = hysteresis; |
| 11979 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 11980 | memcpy(cqm_config->rssi_thresholds, thresholds, |
Len Baker | 40f231e | 2021-09-19 13:40:40 +0200 | [diff] [blame] | 11981 | flex_array_size(cqm_config, rssi_thresholds, |
| 11982 | n_thresholds)); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11983 | |
| 11984 | wdev->cqm_config = cqm_config; |
| 11985 | } |
| 11986 | |
| 11987 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 11988 | |
| 11989 | unlock: |
| 11990 | wdev_unlock(wdev); |
| 11991 | |
| 11992 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11993 | } |
| 11994 | |
| 11995 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 11996 | { |
| 11997 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 11998 | struct nlattr *cqm; |
| 11999 | int err; |
| 12000 | |
| 12001 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 12002 | if (!cqm) |
| 12003 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12004 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12005 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 12006 | nl80211_attr_cqm_policy, |
| 12007 | info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12008 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 12009 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12010 | |
| 12011 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 12012 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 12013 | const s32 *thresholds = |
| 12014 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 12015 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 12016 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12017 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 12018 | if (len % 4) |
| 12019 | return -EINVAL; |
| 12020 | |
| 12021 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 12022 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 12023 | } |
| 12024 | |
| 12025 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 12026 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 12027 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 12028 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 12029 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 12030 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 12031 | |
| 12032 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 12033 | } |
| 12034 | |
| 12035 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 12036 | } |
| 12037 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 12038 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 12039 | { |
| 12040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12041 | struct net_device *dev = info->user_ptr[1]; |
| 12042 | struct ocb_setup setup = {}; |
| 12043 | int err; |
| 12044 | |
| 12045 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 12046 | if (err) |
| 12047 | return err; |
| 12048 | |
| 12049 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 12050 | } |
| 12051 | |
| 12052 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 12053 | { |
| 12054 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12055 | struct net_device *dev = info->user_ptr[1]; |
| 12056 | |
| 12057 | return cfg80211_leave_ocb(rdev, dev); |
| 12058 | } |
| 12059 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12060 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 12061 | { |
| 12062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12063 | struct net_device *dev = info->user_ptr[1]; |
| 12064 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 12065 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12066 | int err; |
| 12067 | |
| 12068 | /* start with default */ |
| 12069 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 12070 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12071 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12072 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12073 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 12074 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12075 | if (err) |
| 12076 | return err; |
| 12077 | } |
| 12078 | |
| 12079 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 12080 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 12081 | return -EINVAL; |
| 12082 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 12083 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 12084 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 12085 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 12086 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 12087 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 12088 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 12089 | return -EINVAL; |
| 12090 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 12091 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 12092 | setup.beacon_interval = |
| 12093 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 12094 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 12095 | err = cfg80211_validate_beacon_int(rdev, |
| 12096 | NL80211_IFTYPE_MESH_POINT, |
| 12097 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 12098 | if (err) |
| 12099 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 12100 | } |
| 12101 | |
| 12102 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 12103 | setup.dtim_period = |
| 12104 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 12105 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 12106 | return -EINVAL; |
| 12107 | } |
| 12108 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 12109 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 12110 | /* parse additional setup parameters if given */ |
| 12111 | err = nl80211_parse_mesh_setup(info, &setup); |
| 12112 | if (err) |
| 12113 | return err; |
| 12114 | } |
| 12115 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 12116 | if (setup.user_mpm) |
| 12117 | cfg.auto_open_plinks = false; |
| 12118 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 12119 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12120 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 12121 | if (err) |
| 12122 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 12123 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 12124 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 12125 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 12126 | } |
| 12127 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 12128 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 12129 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 12130 | int n_rates = |
| 12131 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 12132 | struct ieee80211_supported_band *sband; |
| 12133 | |
| 12134 | if (!setup.chandef.chan) |
| 12135 | return -EINVAL; |
| 12136 | |
| 12137 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 12138 | |
| 12139 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 12140 | &setup.basic_rates); |
| 12141 | if (err) |
| 12142 | return err; |
| 12143 | } |
| 12144 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 12145 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 12146 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 12147 | NL80211_ATTR_TX_RATES, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 12148 | &setup.beacon_rate, |
Rajkumar Manoharan | 857b34c | 2020-10-16 13:15:26 -0700 | [diff] [blame] | 12149 | dev, false); |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 12150 | if (err) |
| 12151 | return err; |
| 12152 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 12153 | if (!setup.chandef.chan) |
| 12154 | return -EINVAL; |
| 12155 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 12156 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 12157 | &setup.beacon_rate); |
| 12158 | if (err) |
| 12159 | return err; |
| 12160 | } |
| 12161 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 12162 | setup.userspace_handles_dfs = |
| 12163 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 12164 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 12165 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 12166 | int r = validate_pae_over_nl80211(rdev, info); |
| 12167 | |
| 12168 | if (r < 0) |
| 12169 | return r; |
| 12170 | |
| 12171 | setup.control_port_over_nl80211 = true; |
| 12172 | } |
| 12173 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 12174 | wdev_lock(dev->ieee80211_ptr); |
| 12175 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 12176 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 12177 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 12178 | wdev_unlock(dev->ieee80211_ptr); |
| 12179 | |
| 12180 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 12181 | } |
| 12182 | |
| 12183 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 12184 | { |
| 12185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12186 | struct net_device *dev = info->user_ptr[1]; |
| 12187 | |
| 12188 | return cfg80211_leave_mesh(rdev, dev); |
| 12189 | } |
| 12190 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12191 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12192 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 12193 | struct cfg80211_registered_device *rdev) |
| 12194 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12195 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12196 | struct nlattr *nl_pats, *nl_pat; |
| 12197 | int i, pat_len; |
| 12198 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12199 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12200 | return 0; |
| 12201 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12202 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12203 | if (!nl_pats) |
| 12204 | return -ENOBUFS; |
| 12205 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12206 | for (i = 0; i < wowlan->n_patterns; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12207 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12208 | if (!nl_pat) |
| 12209 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12210 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12211 | 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] | 12212 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12213 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 12214 | wowlan->patterns[i].pattern) || |
| 12215 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12216 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12217 | return -ENOBUFS; |
| 12218 | nla_nest_end(msg, nl_pat); |
| 12219 | } |
| 12220 | nla_nest_end(msg, nl_pats); |
| 12221 | |
| 12222 | return 0; |
| 12223 | } |
| 12224 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12225 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 12226 | struct cfg80211_wowlan_tcp *tcp) |
| 12227 | { |
| 12228 | struct nlattr *nl_tcp; |
| 12229 | |
| 12230 | if (!tcp) |
| 12231 | return 0; |
| 12232 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12233 | nl_tcp = nla_nest_start_noflag(msg, |
| 12234 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12235 | if (!nl_tcp) |
| 12236 | return -ENOBUFS; |
| 12237 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 12238 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 12239 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12240 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 12241 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 12242 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 12243 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 12244 | tcp->payload_len, tcp->payload) || |
| 12245 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 12246 | tcp->data_interval) || |
| 12247 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 12248 | tcp->wake_len, tcp->wake_data) || |
| 12249 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 12250 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 12251 | return -ENOBUFS; |
| 12252 | |
| 12253 | if (tcp->payload_seq.len && |
| 12254 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 12255 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 12256 | return -ENOBUFS; |
| 12257 | |
| 12258 | if (tcp->payload_tok.len && |
| 12259 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 12260 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 12261 | &tcp->payload_tok)) |
| 12262 | return -ENOBUFS; |
| 12263 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 12264 | nla_nest_end(msg, nl_tcp); |
| 12265 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12266 | return 0; |
| 12267 | } |
| 12268 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12269 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 12270 | struct cfg80211_sched_scan_request *req) |
| 12271 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 12272 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12273 | int i; |
| 12274 | |
| 12275 | if (!req) |
| 12276 | return 0; |
| 12277 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12278 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12279 | if (!nd) |
| 12280 | return -ENOBUFS; |
| 12281 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 12282 | if (req->n_scan_plans == 1 && |
| 12283 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 12284 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12285 | return -ENOBUFS; |
| 12286 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 12287 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 12288 | return -ENOBUFS; |
| 12289 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 12290 | if (req->relative_rssi_set) { |
| 12291 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 12292 | |
| 12293 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 12294 | req->relative_rssi)) |
| 12295 | return -ENOBUFS; |
| 12296 | |
| 12297 | rssi_adjust.band = req->rssi_adjust.band; |
| 12298 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 12299 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 12300 | sizeof(rssi_adjust), &rssi_adjust)) |
| 12301 | return -ENOBUFS; |
| 12302 | } |
| 12303 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12304 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12305 | if (!freqs) |
| 12306 | return -ENOBUFS; |
| 12307 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 12308 | for (i = 0; i < req->n_channels; i++) { |
| 12309 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 12310 | return -ENOBUFS; |
| 12311 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12312 | |
| 12313 | nla_nest_end(msg, freqs); |
| 12314 | |
| 12315 | if (req->n_match_sets) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12316 | matches = nla_nest_start_noflag(msg, |
| 12317 | NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 12318 | if (!matches) |
| 12319 | return -ENOBUFS; |
| 12320 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12321 | for (i = 0; i < req->n_match_sets; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12322 | match = nla_nest_start_noflag(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 12323 | if (!match) |
| 12324 | return -ENOBUFS; |
| 12325 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 12326 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 12327 | req->match_sets[i].ssid.ssid_len, |
| 12328 | req->match_sets[i].ssid.ssid)) |
| 12329 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12330 | nla_nest_end(msg, match); |
| 12331 | } |
| 12332 | nla_nest_end(msg, matches); |
| 12333 | } |
| 12334 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12335 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 12336 | if (!scan_plans) |
| 12337 | return -ENOBUFS; |
| 12338 | |
| 12339 | for (i = 0; i < req->n_scan_plans; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12340 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 12341 | if (!scan_plan) |
| 12342 | return -ENOBUFS; |
| 12343 | |
Colin Ian King | 6762696 | 2018-09-06 10:58:44 +0100 | [diff] [blame] | 12344 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 12345 | req->scan_plans[i].interval) || |
| 12346 | (req->scan_plans[i].iterations && |
| 12347 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 12348 | req->scan_plans[i].iterations))) |
| 12349 | return -ENOBUFS; |
| 12350 | nla_nest_end(msg, scan_plan); |
| 12351 | } |
| 12352 | nla_nest_end(msg, scan_plans); |
| 12353 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12354 | nla_nest_end(msg, nd); |
| 12355 | |
| 12356 | return 0; |
| 12357 | } |
| 12358 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12359 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 12360 | { |
| 12361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12362 | struct sk_buff *msg; |
| 12363 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12364 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12365 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12366 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12367 | return -EOPNOTSUPP; |
| 12368 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12369 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12370 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12371 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 12372 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 12373 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 12374 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12375 | } |
| 12376 | |
| 12377 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12378 | if (!msg) |
| 12379 | return -ENOMEM; |
| 12380 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12381 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12382 | NL80211_CMD_GET_WOWLAN); |
| 12383 | if (!hdr) |
| 12384 | goto nla_put_failure; |
| 12385 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12386 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12387 | struct nlattr *nl_wowlan; |
| 12388 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12389 | nl_wowlan = nla_nest_start_noflag(msg, |
| 12390 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12391 | if (!nl_wowlan) |
| 12392 | goto nla_put_failure; |
| 12393 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12394 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12395 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12396 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12397 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12398 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12399 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12400 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12401 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12402 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12403 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12404 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12405 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12406 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12407 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 12408 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12409 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12410 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 12411 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12412 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12413 | if (nl80211_send_wowlan_tcp(msg, |
| 12414 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12415 | goto nla_put_failure; |
| 12416 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 12417 | if (nl80211_send_wowlan_nd( |
| 12418 | msg, |
| 12419 | rdev->wiphy.wowlan_config->nd_config)) |
| 12420 | goto nla_put_failure; |
| 12421 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12422 | nla_nest_end(msg, nl_wowlan); |
| 12423 | } |
| 12424 | |
| 12425 | genlmsg_end(msg, hdr); |
| 12426 | return genlmsg_reply(msg, info); |
| 12427 | |
| 12428 | nla_put_failure: |
| 12429 | nlmsg_free(msg); |
| 12430 | return -ENOBUFS; |
| 12431 | } |
| 12432 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12433 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 12434 | struct nlattr *attr, |
| 12435 | struct cfg80211_wowlan *trig) |
| 12436 | { |
| 12437 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 12438 | struct cfg80211_wowlan_tcp *cfg; |
| 12439 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 12440 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 12441 | u32 size; |
| 12442 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 12443 | int err, port; |
| 12444 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12445 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12446 | return -EINVAL; |
| 12447 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12448 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 12449 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12450 | if (err) |
| 12451 | return err; |
| 12452 | |
| 12453 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 12454 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 12455 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 12456 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 12457 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 12458 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 12459 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 12460 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 12461 | return -EINVAL; |
| 12462 | |
| 12463 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12464 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12465 | return -EINVAL; |
| 12466 | |
| 12467 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12468 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 12469 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12470 | return -EINVAL; |
| 12471 | |
| 12472 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12473 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12474 | return -EINVAL; |
| 12475 | |
| 12476 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 12477 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 12478 | return -EINVAL; |
| 12479 | |
| 12480 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 12481 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 12482 | |
| 12483 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 12484 | tokens_size = tokln - sizeof(*tok); |
| 12485 | |
| 12486 | if (!tok->len || tokens_size % tok->len) |
| 12487 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12488 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12489 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12490 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12491 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12492 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12493 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12494 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12495 | return -EINVAL; |
| 12496 | if (tok->offset + tok->len > data_size) |
| 12497 | return -EINVAL; |
| 12498 | } |
| 12499 | |
| 12500 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 12501 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12502 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12503 | return -EINVAL; |
| 12504 | if (seq->len == 0 || seq->len > 4) |
| 12505 | return -EINVAL; |
| 12506 | if (seq->len + seq->offset > data_size) |
| 12507 | return -EINVAL; |
| 12508 | } |
| 12509 | |
| 12510 | size = sizeof(*cfg); |
| 12511 | size += data_size; |
| 12512 | size += wake_size + wake_mask_size; |
| 12513 | size += tokens_size; |
| 12514 | |
| 12515 | cfg = kzalloc(size, GFP_KERNEL); |
| 12516 | if (!cfg) |
| 12517 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 12518 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 12519 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12520 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 12521 | ETH_ALEN); |
| 12522 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 12523 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 12524 | else |
| 12525 | port = 0; |
| 12526 | #ifdef CONFIG_INET |
| 12527 | /* allocate a socket and port for it and use it */ |
| 12528 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 12529 | IPPROTO_TCP, &cfg->sock, 1); |
| 12530 | if (err) { |
| 12531 | kfree(cfg); |
| 12532 | return err; |
| 12533 | } |
| 12534 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 12535 | sock_release(cfg->sock); |
| 12536 | kfree(cfg); |
| 12537 | return -EADDRINUSE; |
| 12538 | } |
| 12539 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 12540 | #else |
| 12541 | if (!port) { |
| 12542 | kfree(cfg); |
| 12543 | return -EINVAL; |
| 12544 | } |
| 12545 | cfg->src_port = port; |
| 12546 | #endif |
| 12547 | |
| 12548 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 12549 | cfg->payload_len = data_size; |
| 12550 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 12551 | memcpy((void *)cfg->payload, |
| 12552 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 12553 | data_size); |
| 12554 | if (seq) |
| 12555 | cfg->payload_seq = *seq; |
| 12556 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 12557 | cfg->wake_len = wake_size; |
| 12558 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 12559 | memcpy((void *)cfg->wake_data, |
| 12560 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 12561 | wake_size); |
| 12562 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 12563 | data_size + wake_size; |
| 12564 | memcpy((void *)cfg->wake_mask, |
| 12565 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 12566 | wake_mask_size); |
| 12567 | if (tok) { |
| 12568 | cfg->tokens_size = tokens_size; |
| 12569 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 12570 | } |
| 12571 | |
| 12572 | trig->tcp = cfg; |
| 12573 | |
| 12574 | return 0; |
| 12575 | } |
| 12576 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12577 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 12578 | const struct wiphy_wowlan_support *wowlan, |
| 12579 | struct nlattr *attr, |
| 12580 | struct cfg80211_wowlan *trig) |
| 12581 | { |
| 12582 | struct nlattr **tb; |
| 12583 | int err; |
| 12584 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12585 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12586 | if (!tb) |
| 12587 | return -ENOMEM; |
| 12588 | |
| 12589 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 12590 | err = -EOPNOTSUPP; |
| 12591 | goto out; |
| 12592 | } |
| 12593 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12594 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
| 12595 | nl80211_policy, NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12596 | if (err) |
| 12597 | goto out; |
| 12598 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 12599 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 12600 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12601 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 12602 | if (err) |
| 12603 | trig->nd_config = NULL; |
| 12604 | |
| 12605 | out: |
| 12606 | kfree(tb); |
| 12607 | return err; |
| 12608 | } |
| 12609 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12610 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 12611 | { |
| 12612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12613 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12614 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12615 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12616 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12617 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12618 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12619 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12620 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12621 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12622 | return -EOPNOTSUPP; |
| 12623 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12624 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 12625 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12626 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12627 | goto set_wakeup; |
| 12628 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12629 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12630 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
| 12631 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 12632 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12633 | if (err) |
| 12634 | return err; |
| 12635 | |
| 12636 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 12637 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 12638 | return -EINVAL; |
| 12639 | new_triggers.any = true; |
| 12640 | } |
| 12641 | |
| 12642 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 12643 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 12644 | return -EINVAL; |
| 12645 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12646 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12647 | } |
| 12648 | |
| 12649 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 12650 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 12651 | return -EINVAL; |
| 12652 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12653 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12654 | } |
| 12655 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12656 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 12657 | return -EINVAL; |
| 12658 | |
| 12659 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 12660 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 12661 | return -EINVAL; |
| 12662 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12663 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12664 | } |
| 12665 | |
| 12666 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 12667 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 12668 | return -EINVAL; |
| 12669 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12670 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12671 | } |
| 12672 | |
| 12673 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 12674 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 12675 | return -EINVAL; |
| 12676 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12677 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12678 | } |
| 12679 | |
| 12680 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 12681 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 12682 | return -EINVAL; |
| 12683 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12684 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12685 | } |
| 12686 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12687 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 12688 | struct nlattr *pat; |
| 12689 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12690 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12691 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12692 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12693 | regular = true; |
| 12694 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12695 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12696 | rem) |
| 12697 | n_patterns++; |
| 12698 | if (n_patterns > wowlan->n_patterns) |
| 12699 | return -EINVAL; |
| 12700 | |
| 12701 | new_triggers.patterns = kcalloc(n_patterns, |
| 12702 | sizeof(new_triggers.patterns[0]), |
| 12703 | GFP_KERNEL); |
| 12704 | if (!new_triggers.patterns) |
| 12705 | return -ENOMEM; |
| 12706 | |
| 12707 | new_triggers.n_patterns = n_patterns; |
| 12708 | i = 0; |
| 12709 | |
| 12710 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12711 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12712 | u8 *mask_pat; |
| 12713 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12714 | err = nla_parse_nested_deprecated(pat_tb, |
| 12715 | MAX_NL80211_PKTPAT, |
| 12716 | pat, |
| 12717 | nl80211_packet_pattern_policy, |
| 12718 | info->extack); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12719 | if (err) |
| 12720 | goto error; |
| 12721 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12722 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12723 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12724 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12725 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12726 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12727 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12728 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12729 | goto error; |
| 12730 | if (pat_len > wowlan->pattern_max_len || |
| 12731 | pat_len < wowlan->pattern_min_len) |
| 12732 | goto error; |
| 12733 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12734 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12735 | pkt_offset = 0; |
| 12736 | else |
| 12737 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12738 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12739 | if (pkt_offset > wowlan->max_pkt_offset) |
| 12740 | goto error; |
| 12741 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 12742 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12743 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12744 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12745 | err = -ENOMEM; |
| 12746 | goto error; |
| 12747 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12748 | new_triggers.patterns[i].mask = mask_pat; |
| 12749 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12750 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12751 | mask_pat += mask_len; |
| 12752 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12753 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12754 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12755 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12756 | pat_len); |
| 12757 | i++; |
| 12758 | } |
| 12759 | } |
| 12760 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12761 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12762 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12763 | err = nl80211_parse_wowlan_tcp( |
| 12764 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 12765 | &new_triggers); |
| 12766 | if (err) |
| 12767 | goto error; |
| 12768 | } |
| 12769 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12770 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12771 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12772 | err = nl80211_parse_wowlan_nd( |
| 12773 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 12774 | &new_triggers); |
| 12775 | if (err) |
| 12776 | goto error; |
| 12777 | } |
| 12778 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12779 | /* The 'any' trigger means the device continues operating more or less |
| 12780 | * as in its normal operation mode and wakes up the host on most of the |
| 12781 | * normal interrupts (like packet RX, ...) |
| 12782 | * It therefore makes little sense to combine with the more constrained |
| 12783 | * wakeup trigger modes. |
| 12784 | */ |
| 12785 | if (new_triggers.any && regular) { |
| 12786 | err = -EINVAL; |
| 12787 | goto error; |
| 12788 | } |
| 12789 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12790 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 12791 | if (!ntrig) { |
| 12792 | err = -ENOMEM; |
| 12793 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12794 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12795 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12796 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12797 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12798 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12799 | if (rdev->ops->set_wakeup && |
| 12800 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 12801 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 12802 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12803 | return 0; |
| 12804 | error: |
| 12805 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 12806 | kfree(new_triggers.patterns[i].mask); |
| 12807 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12808 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 12809 | sock_release(new_triggers.tcp->sock); |
| 12810 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 12811 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12812 | return err; |
| 12813 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12814 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12815 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12816 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 12817 | struct cfg80211_registered_device *rdev) |
| 12818 | { |
| 12819 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 12820 | int i, j, pat_len; |
| 12821 | struct cfg80211_coalesce_rules *rule; |
| 12822 | |
| 12823 | if (!rdev->coalesce->n_rules) |
| 12824 | return 0; |
| 12825 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12826 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12827 | if (!nl_rules) |
| 12828 | return -ENOBUFS; |
| 12829 | |
| 12830 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12831 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12832 | if (!nl_rule) |
| 12833 | return -ENOBUFS; |
| 12834 | |
| 12835 | rule = &rdev->coalesce->rules[i]; |
| 12836 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 12837 | rule->delay)) |
| 12838 | return -ENOBUFS; |
| 12839 | |
| 12840 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 12841 | rule->condition)) |
| 12842 | return -ENOBUFS; |
| 12843 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12844 | nl_pats = nla_nest_start_noflag(msg, |
| 12845 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12846 | if (!nl_pats) |
| 12847 | return -ENOBUFS; |
| 12848 | |
| 12849 | for (j = 0; j < rule->n_patterns; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12850 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12851 | if (!nl_pat) |
| 12852 | return -ENOBUFS; |
| 12853 | pat_len = rule->patterns[j].pattern_len; |
| 12854 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 12855 | DIV_ROUND_UP(pat_len, 8), |
| 12856 | rule->patterns[j].mask) || |
| 12857 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 12858 | rule->patterns[j].pattern) || |
| 12859 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 12860 | rule->patterns[j].pkt_offset)) |
| 12861 | return -ENOBUFS; |
| 12862 | nla_nest_end(msg, nl_pat); |
| 12863 | } |
| 12864 | nla_nest_end(msg, nl_pats); |
| 12865 | nla_nest_end(msg, nl_rule); |
| 12866 | } |
| 12867 | nla_nest_end(msg, nl_rules); |
| 12868 | |
| 12869 | return 0; |
| 12870 | } |
| 12871 | |
| 12872 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12873 | { |
| 12874 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12875 | struct sk_buff *msg; |
| 12876 | void *hdr; |
| 12877 | |
| 12878 | if (!rdev->wiphy.coalesce) |
| 12879 | return -EOPNOTSUPP; |
| 12880 | |
| 12881 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12882 | if (!msg) |
| 12883 | return -ENOMEM; |
| 12884 | |
| 12885 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12886 | NL80211_CMD_GET_COALESCE); |
| 12887 | if (!hdr) |
| 12888 | goto nla_put_failure; |
| 12889 | |
| 12890 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 12891 | goto nla_put_failure; |
| 12892 | |
| 12893 | genlmsg_end(msg, hdr); |
| 12894 | return genlmsg_reply(msg, info); |
| 12895 | |
| 12896 | nla_put_failure: |
| 12897 | nlmsg_free(msg); |
| 12898 | return -ENOBUFS; |
| 12899 | } |
| 12900 | |
| 12901 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 12902 | { |
| 12903 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 12904 | int i, j; |
| 12905 | struct cfg80211_coalesce_rules *rule; |
| 12906 | |
| 12907 | if (!coalesce) |
| 12908 | return; |
| 12909 | |
| 12910 | for (i = 0; i < coalesce->n_rules; i++) { |
| 12911 | rule = &coalesce->rules[i]; |
| 12912 | for (j = 0; j < rule->n_patterns; j++) |
| 12913 | kfree(rule->patterns[j].mask); |
| 12914 | kfree(rule->patterns); |
| 12915 | } |
| 12916 | kfree(coalesce->rules); |
| 12917 | kfree(coalesce); |
| 12918 | rdev->coalesce = NULL; |
| 12919 | } |
| 12920 | |
| 12921 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 12922 | struct nlattr *rule, |
| 12923 | struct cfg80211_coalesce_rules *new_rule) |
| 12924 | { |
| 12925 | int err, i; |
| 12926 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12927 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 12928 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 12929 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12930 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12931 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
| 12932 | rule, nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12933 | if (err) |
| 12934 | return err; |
| 12935 | |
| 12936 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 12937 | new_rule->delay = |
| 12938 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 12939 | if (new_rule->delay > coalesce->max_delay) |
| 12940 | return -EINVAL; |
| 12941 | |
| 12942 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 12943 | new_rule->condition = |
| 12944 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12945 | |
| 12946 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 12947 | return -EINVAL; |
| 12948 | |
| 12949 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12950 | rem) |
| 12951 | n_patterns++; |
| 12952 | if (n_patterns > coalesce->n_patterns) |
| 12953 | return -EINVAL; |
| 12954 | |
| 12955 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 12956 | GFP_KERNEL); |
| 12957 | if (!new_rule->patterns) |
| 12958 | return -ENOMEM; |
| 12959 | |
| 12960 | new_rule->n_patterns = n_patterns; |
| 12961 | i = 0; |
| 12962 | |
| 12963 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12964 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12965 | u8 *mask_pat; |
| 12966 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12967 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
| 12968 | pat, |
| 12969 | nl80211_packet_pattern_policy, |
| 12970 | NULL); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12971 | if (err) |
| 12972 | return err; |
| 12973 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12974 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12975 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12976 | return -EINVAL; |
| 12977 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12978 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12979 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12980 | return -EINVAL; |
| 12981 | if (pat_len > coalesce->pattern_max_len || |
| 12982 | pat_len < coalesce->pattern_min_len) |
| 12983 | return -EINVAL; |
| 12984 | |
| 12985 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12986 | pkt_offset = 0; |
| 12987 | else |
| 12988 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12989 | if (pkt_offset > coalesce->max_pkt_offset) |
| 12990 | return -EINVAL; |
| 12991 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 12992 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12993 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12994 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12995 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12996 | |
| 12997 | new_rule->patterns[i].mask = mask_pat; |
| 12998 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12999 | mask_len); |
| 13000 | |
| 13001 | mask_pat += mask_len; |
| 13002 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13003 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 13004 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 13005 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13006 | i++; |
| 13007 | } |
| 13008 | |
| 13009 | return 0; |
| 13010 | } |
| 13011 | |
| 13012 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 13013 | { |
| 13014 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13015 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 13016 | struct cfg80211_coalesce new_coalesce = {}; |
| 13017 | struct cfg80211_coalesce *n_coalesce; |
| 13018 | int err, rem_rule, n_rules = 0, i, j; |
| 13019 | struct nlattr *rule; |
| 13020 | struct cfg80211_coalesce_rules *tmp_rule; |
| 13021 | |
| 13022 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 13023 | return -EOPNOTSUPP; |
| 13024 | |
| 13025 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 13026 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 13027 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13028 | return 0; |
| 13029 | } |
| 13030 | |
| 13031 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 13032 | rem_rule) |
| 13033 | n_rules++; |
| 13034 | if (n_rules > coalesce->n_rules) |
| 13035 | return -EINVAL; |
| 13036 | |
| 13037 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 13038 | GFP_KERNEL); |
| 13039 | if (!new_coalesce.rules) |
| 13040 | return -ENOMEM; |
| 13041 | |
| 13042 | new_coalesce.n_rules = n_rules; |
| 13043 | i = 0; |
| 13044 | |
| 13045 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 13046 | rem_rule) { |
| 13047 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 13048 | &new_coalesce.rules[i]); |
| 13049 | if (err) |
| 13050 | goto error; |
| 13051 | |
| 13052 | i++; |
| 13053 | } |
| 13054 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 13055 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 13056 | if (err) |
| 13057 | goto error; |
| 13058 | |
| 13059 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 13060 | if (!n_coalesce) { |
| 13061 | err = -ENOMEM; |
| 13062 | goto error; |
| 13063 | } |
| 13064 | cfg80211_rdev_free_coalesce(rdev); |
| 13065 | rdev->coalesce = n_coalesce; |
| 13066 | |
| 13067 | return 0; |
| 13068 | error: |
| 13069 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 13070 | tmp_rule = &new_coalesce.rules[i]; |
| 13071 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 13072 | kfree(tmp_rule->patterns[j].mask); |
| 13073 | kfree(tmp_rule->patterns); |
| 13074 | } |
| 13075 | kfree(new_coalesce.rules); |
| 13076 | |
| 13077 | return err; |
| 13078 | } |
| 13079 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13080 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 13081 | { |
| 13082 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13083 | struct net_device *dev = info->user_ptr[1]; |
| 13084 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13085 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
Sara Sharon | f495acd | 2020-11-29 17:30:44 +0200 | [diff] [blame] | 13086 | struct cfg80211_gtk_rekey_data rekey_data = {}; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13087 | int err; |
| 13088 | |
| 13089 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 13090 | return -EINVAL; |
| 13091 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13092 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
| 13093 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 13094 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13095 | if (err) |
| 13096 | return err; |
| 13097 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 13098 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 13099 | !tb[NL80211_REKEY_DATA_KCK]) |
| 13100 | return -EINVAL; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 13101 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && |
| 13102 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 13103 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13104 | return -ERANGE; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 13105 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && |
| 13106 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 13107 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13108 | return -ERANGE; |
| 13109 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 13110 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 13111 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 13112 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 13113 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
| 13114 | rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); |
| 13115 | if (tb[NL80211_REKEY_DATA_AKM]) |
| 13116 | rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13117 | |
| 13118 | wdev_lock(wdev); |
| 13119 | if (!wdev->current_bss) { |
| 13120 | err = -ENOTCONN; |
| 13121 | goto out; |
| 13122 | } |
| 13123 | |
| 13124 | if (!rdev->ops->set_rekey_data) { |
| 13125 | err = -EOPNOTSUPP; |
| 13126 | goto out; |
| 13127 | } |
| 13128 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 13129 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 13130 | out: |
| 13131 | wdev_unlock(wdev); |
| 13132 | return err; |
| 13133 | } |
| 13134 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13135 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 13136 | struct genl_info *info) |
| 13137 | { |
| 13138 | struct net_device *dev = info->user_ptr[1]; |
| 13139 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13140 | |
| 13141 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 13142 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 13143 | return -EINVAL; |
| 13144 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13145 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13146 | return -EBUSY; |
| 13147 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13148 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 13149 | return 0; |
| 13150 | } |
| 13151 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13152 | static int nl80211_probe_client(struct sk_buff *skb, |
| 13153 | struct genl_info *info) |
| 13154 | { |
| 13155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13156 | struct net_device *dev = info->user_ptr[1]; |
| 13157 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13158 | struct sk_buff *msg; |
| 13159 | void *hdr; |
| 13160 | const u8 *addr; |
| 13161 | u64 cookie; |
| 13162 | int err; |
| 13163 | |
| 13164 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 13165 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 13166 | return -EOPNOTSUPP; |
| 13167 | |
| 13168 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 13169 | return -EINVAL; |
| 13170 | |
| 13171 | if (!rdev->ops->probe_client) |
| 13172 | return -EOPNOTSUPP; |
| 13173 | |
| 13174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13175 | if (!msg) |
| 13176 | return -ENOMEM; |
| 13177 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 13178 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13179 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 13180 | if (!hdr) { |
| 13181 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13182 | goto free_msg; |
| 13183 | } |
| 13184 | |
| 13185 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13186 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 13187 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13188 | if (err) |
| 13189 | goto free_msg; |
| 13190 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13191 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13192 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 13193 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 13194 | |
| 13195 | genlmsg_end(msg, hdr); |
| 13196 | |
| 13197 | return genlmsg_reply(msg, info); |
| 13198 | |
| 13199 | nla_put_failure: |
| 13200 | err = -ENOBUFS; |
| 13201 | free_msg: |
| 13202 | nlmsg_free(msg); |
| 13203 | return err; |
| 13204 | } |
| 13205 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13206 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 13207 | { |
| 13208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13209 | struct cfg80211_beacon_registration *reg, *nreg; |
| 13210 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13211 | |
| 13212 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 13213 | return -EOPNOTSUPP; |
| 13214 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13215 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 13216 | if (!nreg) |
| 13217 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13218 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13219 | /* First, check if already registered. */ |
| 13220 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 13221 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 13222 | if (reg->nlportid == info->snd_portid) { |
| 13223 | rv = -EALREADY; |
| 13224 | goto out_err; |
| 13225 | } |
| 13226 | } |
| 13227 | /* Add it to the list */ |
| 13228 | nreg->nlportid = info->snd_portid; |
| 13229 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 13230 | |
| 13231 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13232 | |
| 13233 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 13234 | out_err: |
| 13235 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 13236 | kfree(nreg); |
| 13237 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 13238 | } |
| 13239 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13240 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 13241 | { |
| 13242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13243 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13244 | int err; |
| 13245 | |
| 13246 | if (!rdev->ops->start_p2p_device) |
| 13247 | return -EOPNOTSUPP; |
| 13248 | |
| 13249 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 13250 | return -EOPNOTSUPP; |
| 13251 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13252 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13253 | return 0; |
| 13254 | |
Emmanuel Grumbach | 358ae88 | 2021-06-16 23:28:26 +0300 | [diff] [blame] | 13255 | if (rfkill_blocked(rdev->wiphy.rfkill)) |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 13256 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13257 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 13258 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13259 | if (err) |
| 13260 | return err; |
| 13261 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13262 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13263 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13264 | |
| 13265 | return 0; |
| 13266 | } |
| 13267 | |
| 13268 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 13269 | { |
| 13270 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13271 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13272 | |
| 13273 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 13274 | return -EOPNOTSUPP; |
| 13275 | |
| 13276 | if (!rdev->ops->stop_p2p_device) |
| 13277 | return -EOPNOTSUPP; |
| 13278 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 13279 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 13280 | |
| 13281 | return 0; |
| 13282 | } |
| 13283 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13284 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 13285 | { |
| 13286 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13287 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13288 | struct cfg80211_nan_conf conf = {}; |
| 13289 | int err; |
| 13290 | |
| 13291 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13292 | return -EOPNOTSUPP; |
| 13293 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 13294 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13295 | return -EEXIST; |
| 13296 | |
Emmanuel Grumbach | 358ae88 | 2021-06-16 23:28:26 +0300 | [diff] [blame] | 13297 | if (rfkill_blocked(rdev->wiphy.rfkill)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13298 | return -ERFKILL; |
| 13299 | |
| 13300 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 13301 | return -EINVAL; |
| 13302 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13303 | conf.master_pref = |
| 13304 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13305 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 13306 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 13307 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 13308 | |
| 13309 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 13310 | return -EOPNOTSUPP; |
| 13311 | |
| 13312 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 13313 | return -EINVAL; |
| 13314 | |
| 13315 | conf.bands = bands; |
| 13316 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13317 | |
| 13318 | err = rdev_start_nan(rdev, wdev, &conf); |
| 13319 | if (err) |
| 13320 | return err; |
| 13321 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13322 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 13323 | rdev->opencount++; |
| 13324 | |
| 13325 | return 0; |
| 13326 | } |
| 13327 | |
| 13328 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 13329 | { |
| 13330 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13331 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13332 | |
| 13333 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13334 | return -EOPNOTSUPP; |
| 13335 | |
| 13336 | cfg80211_stop_nan(rdev, wdev); |
| 13337 | |
| 13338 | return 0; |
| 13339 | } |
| 13340 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13341 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 13342 | { |
| 13343 | struct nlattr *attr; |
| 13344 | int len = 0, n_entries = 0, rem; |
| 13345 | |
| 13346 | nla_for_each_nested(attr, filter_attr, rem) { |
| 13347 | len += nla_len(attr); |
| 13348 | n_entries++; |
| 13349 | } |
| 13350 | |
| 13351 | if (len >= U8_MAX) |
| 13352 | return -EINVAL; |
| 13353 | |
| 13354 | return n_entries; |
| 13355 | } |
| 13356 | |
| 13357 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 13358 | struct cfg80211_nan_func *func, |
| 13359 | bool tx) |
| 13360 | { |
| 13361 | struct nlattr *attr; |
| 13362 | int n_entries, rem, i; |
| 13363 | struct cfg80211_nan_func_filter *filter; |
| 13364 | |
| 13365 | n_entries = validate_nan_filter(attr_filter); |
| 13366 | if (n_entries < 0) |
| 13367 | return n_entries; |
| 13368 | |
| 13369 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 13370 | |
| 13371 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 13372 | if (!filter) |
| 13373 | return -ENOMEM; |
| 13374 | |
| 13375 | i = 0; |
| 13376 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 13377 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13378 | filter[i].len = nla_len(attr); |
| 13379 | i++; |
| 13380 | } |
| 13381 | if (tx) { |
| 13382 | func->num_tx_filters = n_entries; |
| 13383 | func->tx_filters = filter; |
| 13384 | } else { |
| 13385 | func->num_rx_filters = n_entries; |
| 13386 | func->rx_filters = filter; |
| 13387 | } |
| 13388 | |
| 13389 | return 0; |
| 13390 | } |
| 13391 | |
| 13392 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 13393 | struct genl_info *info) |
| 13394 | { |
| 13395 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13396 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13397 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 13398 | struct cfg80211_nan_func *func; |
| 13399 | struct sk_buff *msg = NULL; |
| 13400 | void *hdr = NULL; |
| 13401 | int err = 0; |
| 13402 | |
| 13403 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13404 | return -EOPNOTSUPP; |
| 13405 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13406 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13407 | return -ENOTCONN; |
| 13408 | |
| 13409 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 13410 | return -EINVAL; |
| 13411 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13412 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 13413 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 13414 | nl80211_nan_func_policy, |
| 13415 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13416 | if (err) |
| 13417 | return err; |
| 13418 | |
| 13419 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 13420 | if (!func) |
| 13421 | return -ENOMEM; |
| 13422 | |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 13423 | func->cookie = cfg80211_assign_cookie(rdev); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13424 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 13425 | if (!tb[NL80211_NAN_FUNC_TYPE]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13426 | err = -EINVAL; |
| 13427 | goto out; |
| 13428 | } |
| 13429 | |
| 13430 | |
| 13431 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 13432 | |
| 13433 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 13434 | err = -EINVAL; |
| 13435 | goto out; |
| 13436 | } |
| 13437 | |
| 13438 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 13439 | sizeof(func->service_id)); |
| 13440 | |
| 13441 | func->close_range = |
| 13442 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 13443 | |
| 13444 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 13445 | func->serv_spec_info_len = |
| 13446 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 13447 | func->serv_spec_info = |
| 13448 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 13449 | func->serv_spec_info_len, |
| 13450 | GFP_KERNEL); |
| 13451 | if (!func->serv_spec_info) { |
| 13452 | err = -ENOMEM; |
| 13453 | goto out; |
| 13454 | } |
| 13455 | } |
| 13456 | |
| 13457 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 13458 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 13459 | |
| 13460 | switch (func->type) { |
| 13461 | case NL80211_NAN_FUNC_PUBLISH: |
| 13462 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 13463 | err = -EINVAL; |
| 13464 | goto out; |
| 13465 | } |
| 13466 | |
| 13467 | func->publish_type = |
| 13468 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 13469 | func->publish_bcast = |
| 13470 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 13471 | |
| 13472 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 13473 | func->publish_bcast) { |
| 13474 | err = -EINVAL; |
| 13475 | goto out; |
| 13476 | } |
| 13477 | break; |
| 13478 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 13479 | func->subscribe_active = |
| 13480 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 13481 | break; |
| 13482 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 13483 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 13484 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 13485 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13486 | err = -EINVAL; |
| 13487 | goto out; |
| 13488 | } |
| 13489 | |
| 13490 | func->followup_id = |
| 13491 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 13492 | func->followup_reqid = |
| 13493 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 13494 | memcpy(func->followup_dest.addr, |
| 13495 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 13496 | sizeof(func->followup_dest.addr)); |
| 13497 | if (func->ttl) { |
| 13498 | err = -EINVAL; |
| 13499 | goto out; |
| 13500 | } |
| 13501 | break; |
| 13502 | default: |
| 13503 | err = -EINVAL; |
| 13504 | goto out; |
| 13505 | } |
| 13506 | |
| 13507 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 13508 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 13509 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13510 | err = nla_parse_nested_deprecated(srf_tb, |
| 13511 | NL80211_NAN_SRF_ATTR_MAX, |
| 13512 | tb[NL80211_NAN_FUNC_SRF], |
| 13513 | nl80211_nan_srf_policy, |
| 13514 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13515 | if (err) |
| 13516 | goto out; |
| 13517 | |
| 13518 | func->srf_include = |
| 13519 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 13520 | |
| 13521 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 13522 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 13523 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 13524 | err = -EINVAL; |
| 13525 | goto out; |
| 13526 | } |
| 13527 | |
| 13528 | func->srf_bf_len = |
| 13529 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 13530 | func->srf_bf = |
| 13531 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 13532 | func->srf_bf_len, GFP_KERNEL); |
| 13533 | if (!func->srf_bf) { |
| 13534 | err = -ENOMEM; |
| 13535 | goto out; |
| 13536 | } |
| 13537 | |
| 13538 | func->srf_bf_idx = |
| 13539 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 13540 | } else { |
| 13541 | struct nlattr *attr, *mac_attr = |
| 13542 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 13543 | int n_entries, rem, i = 0; |
| 13544 | |
| 13545 | if (!mac_attr) { |
| 13546 | err = -EINVAL; |
| 13547 | goto out; |
| 13548 | } |
| 13549 | |
| 13550 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 13551 | if (n_entries <= 0) { |
| 13552 | err = -EINVAL; |
| 13553 | goto out; |
| 13554 | } |
| 13555 | |
| 13556 | func->srf_num_macs = n_entries; |
| 13557 | func->srf_macs = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 13558 | kcalloc(n_entries, sizeof(*func->srf_macs), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13559 | GFP_KERNEL); |
| 13560 | if (!func->srf_macs) { |
| 13561 | err = -ENOMEM; |
| 13562 | goto out; |
| 13563 | } |
| 13564 | |
| 13565 | nla_for_each_nested(attr, mac_attr, rem) |
| 13566 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 13567 | sizeof(*func->srf_macs)); |
| 13568 | } |
| 13569 | } |
| 13570 | |
| 13571 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 13572 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 13573 | func, true); |
| 13574 | if (err) |
| 13575 | goto out; |
| 13576 | } |
| 13577 | |
| 13578 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 13579 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 13580 | func, false); |
| 13581 | if (err) |
| 13582 | goto out; |
| 13583 | } |
| 13584 | |
| 13585 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13586 | if (!msg) { |
| 13587 | err = -ENOMEM; |
| 13588 | goto out; |
| 13589 | } |
| 13590 | |
| 13591 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13592 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 13593 | /* This can't really happen - we just allocated 4KB */ |
| 13594 | if (WARN_ON(!hdr)) { |
| 13595 | err = -ENOMEM; |
| 13596 | goto out; |
| 13597 | } |
| 13598 | |
| 13599 | err = rdev_add_nan_func(rdev, wdev, func); |
| 13600 | out: |
| 13601 | if (err < 0) { |
| 13602 | cfg80211_free_nan_func(func); |
| 13603 | nlmsg_free(msg); |
| 13604 | return err; |
| 13605 | } |
| 13606 | |
| 13607 | /* propagate the instance id and cookie to userspace */ |
| 13608 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 13609 | NL80211_ATTR_PAD)) |
| 13610 | goto nla_put_failure; |
| 13611 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13612 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13613 | if (!func_attr) |
| 13614 | goto nla_put_failure; |
| 13615 | |
| 13616 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 13617 | func->instance_id)) |
| 13618 | goto nla_put_failure; |
| 13619 | |
| 13620 | nla_nest_end(msg, func_attr); |
| 13621 | |
| 13622 | genlmsg_end(msg, hdr); |
| 13623 | return genlmsg_reply(msg, info); |
| 13624 | |
| 13625 | nla_put_failure: |
| 13626 | nlmsg_free(msg); |
| 13627 | return -ENOBUFS; |
| 13628 | } |
| 13629 | |
| 13630 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 13631 | struct genl_info *info) |
| 13632 | { |
| 13633 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13634 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13635 | u64 cookie; |
| 13636 | |
| 13637 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13638 | return -EOPNOTSUPP; |
| 13639 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13640 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13641 | return -ENOTCONN; |
| 13642 | |
| 13643 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 13644 | return -EINVAL; |
| 13645 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13646 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 13647 | |
| 13648 | rdev_del_nan_func(rdev, wdev, cookie); |
| 13649 | |
| 13650 | return 0; |
| 13651 | } |
| 13652 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13653 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 13654 | struct genl_info *info) |
| 13655 | { |
| 13656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13657 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13658 | struct cfg80211_nan_conf conf = {}; |
| 13659 | u32 changed = 0; |
| 13660 | |
| 13661 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13662 | return -EOPNOTSUPP; |
| 13663 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13664 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13665 | return -ENOTCONN; |
| 13666 | |
| 13667 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 13668 | conf.master_pref = |
| 13669 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 13670 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 13671 | return -EINVAL; |
| 13672 | |
| 13673 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 13674 | } |
| 13675 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 13676 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 13677 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 13678 | |
| 13679 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 13680 | return -EOPNOTSUPP; |
| 13681 | |
| 13682 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 13683 | return -EINVAL; |
| 13684 | |
| 13685 | conf.bands = bands; |
| 13686 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13687 | } |
| 13688 | |
| 13689 | if (!changed) |
| 13690 | return -EINVAL; |
| 13691 | |
| 13692 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 13693 | } |
| 13694 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13695 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 13696 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 13697 | { |
| 13698 | struct wiphy *wiphy = wdev->wiphy; |
| 13699 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13700 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 13701 | struct sk_buff *msg; |
| 13702 | void *hdr; |
| 13703 | |
| 13704 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 13705 | return; |
| 13706 | |
| 13707 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13708 | if (!msg) |
| 13709 | return; |
| 13710 | |
| 13711 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 13712 | if (!hdr) { |
| 13713 | nlmsg_free(msg); |
| 13714 | return; |
| 13715 | } |
| 13716 | |
| 13717 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13718 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13719 | wdev->netdev->ifindex)) || |
| 13720 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13721 | NL80211_ATTR_PAD)) |
| 13722 | goto nla_put_failure; |
| 13723 | |
| 13724 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 13725 | NL80211_ATTR_PAD) || |
| 13726 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 13727 | goto nla_put_failure; |
| 13728 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13729 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13730 | if (!match_attr) |
| 13731 | goto nla_put_failure; |
| 13732 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13733 | local_func_attr = nla_nest_start_noflag(msg, |
| 13734 | NL80211_NAN_MATCH_FUNC_LOCAL); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13735 | if (!local_func_attr) |
| 13736 | goto nla_put_failure; |
| 13737 | |
| 13738 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 13739 | goto nla_put_failure; |
| 13740 | |
| 13741 | nla_nest_end(msg, local_func_attr); |
| 13742 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13743 | peer_func_attr = nla_nest_start_noflag(msg, |
| 13744 | NL80211_NAN_MATCH_FUNC_PEER); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13745 | if (!peer_func_attr) |
| 13746 | goto nla_put_failure; |
| 13747 | |
| 13748 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 13749 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 13750 | goto nla_put_failure; |
| 13751 | |
| 13752 | if (match->info && match->info_len && |
| 13753 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 13754 | match->info)) |
| 13755 | goto nla_put_failure; |
| 13756 | |
| 13757 | nla_nest_end(msg, peer_func_attr); |
| 13758 | nla_nest_end(msg, match_attr); |
| 13759 | genlmsg_end(msg, hdr); |
| 13760 | |
| 13761 | if (!wdev->owner_nlportid) |
| 13762 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13763 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13764 | else |
| 13765 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13766 | wdev->owner_nlportid); |
| 13767 | |
| 13768 | return; |
| 13769 | |
| 13770 | nla_put_failure: |
| 13771 | nlmsg_free(msg); |
| 13772 | } |
| 13773 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 13774 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13775 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 13776 | u8 inst_id, |
| 13777 | enum nl80211_nan_func_term_reason reason, |
| 13778 | u64 cookie, gfp_t gfp) |
| 13779 | { |
| 13780 | struct wiphy *wiphy = wdev->wiphy; |
| 13781 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13782 | struct sk_buff *msg; |
| 13783 | struct nlattr *func_attr; |
| 13784 | void *hdr; |
| 13785 | |
| 13786 | if (WARN_ON(!inst_id)) |
| 13787 | return; |
| 13788 | |
| 13789 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13790 | if (!msg) |
| 13791 | return; |
| 13792 | |
| 13793 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 13794 | if (!hdr) { |
| 13795 | nlmsg_free(msg); |
| 13796 | return; |
| 13797 | } |
| 13798 | |
| 13799 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13800 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13801 | wdev->netdev->ifindex)) || |
| 13802 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13803 | NL80211_ATTR_PAD)) |
| 13804 | goto nla_put_failure; |
| 13805 | |
| 13806 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13807 | NL80211_ATTR_PAD)) |
| 13808 | goto nla_put_failure; |
| 13809 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13810 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13811 | if (!func_attr) |
| 13812 | goto nla_put_failure; |
| 13813 | |
| 13814 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 13815 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 13816 | goto nla_put_failure; |
| 13817 | |
| 13818 | nla_nest_end(msg, func_attr); |
| 13819 | genlmsg_end(msg, hdr); |
| 13820 | |
| 13821 | if (!wdev->owner_nlportid) |
| 13822 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13823 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13824 | else |
| 13825 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13826 | wdev->owner_nlportid); |
| 13827 | |
| 13828 | return; |
| 13829 | |
| 13830 | nla_put_failure: |
| 13831 | nlmsg_free(msg); |
| 13832 | } |
| 13833 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 13834 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13835 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 13836 | struct genl_info *info) |
| 13837 | { |
| 13838 | void *hdr; |
| 13839 | struct sk_buff *msg; |
| 13840 | |
| 13841 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13842 | if (!msg) |
| 13843 | return -ENOMEM; |
| 13844 | |
| 13845 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13846 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 13847 | if (!hdr) |
| 13848 | goto nla_put_failure; |
| 13849 | |
| 13850 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 13851 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 13852 | goto nla_put_failure; |
| 13853 | |
| 13854 | genlmsg_end(msg, hdr); |
| 13855 | return genlmsg_reply(msg, info); |
| 13856 | |
| 13857 | nla_put_failure: |
| 13858 | kfree_skb(msg); |
| 13859 | return -ENOBUFS; |
| 13860 | } |
| 13861 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13862 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 13863 | { |
| 13864 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13865 | struct cfg80211_update_ft_ies_params ft_params; |
| 13866 | struct net_device *dev = info->user_ptr[1]; |
| 13867 | |
| 13868 | if (!rdev->ops->update_ft_ies) |
| 13869 | return -EOPNOTSUPP; |
| 13870 | |
| 13871 | if (!info->attrs[NL80211_ATTR_MDID] || |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 13872 | !info->attrs[NL80211_ATTR_IE]) |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13873 | return -EINVAL; |
| 13874 | |
| 13875 | memset(&ft_params, 0, sizeof(ft_params)); |
| 13876 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 13877 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13878 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13879 | |
| 13880 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 13881 | } |
| 13882 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13883 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 13884 | struct genl_info *info) |
| 13885 | { |
| 13886 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13887 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13888 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 13889 | u16 duration; |
| 13890 | int ret; |
| 13891 | |
| 13892 | if (!rdev->ops->crit_proto_start) |
| 13893 | return -EOPNOTSUPP; |
| 13894 | |
| 13895 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 13896 | return -EINVAL; |
| 13897 | |
| 13898 | if (rdev->crit_proto_nlportid) |
| 13899 | return -EBUSY; |
| 13900 | |
| 13901 | /* determine protocol if provided */ |
| 13902 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 13903 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 13904 | |
| 13905 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 13906 | return -EINVAL; |
| 13907 | |
| 13908 | /* timeout must be provided */ |
| 13909 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 13910 | return -EINVAL; |
| 13911 | |
| 13912 | duration = |
| 13913 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 13914 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13915 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 13916 | if (!ret) |
| 13917 | rdev->crit_proto_nlportid = info->snd_portid; |
| 13918 | |
| 13919 | return ret; |
| 13920 | } |
| 13921 | |
| 13922 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 13923 | struct genl_info *info) |
| 13924 | { |
| 13925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13926 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13927 | |
| 13928 | if (!rdev->ops->crit_proto_stop) |
| 13929 | return -EOPNOTSUPP; |
| 13930 | |
| 13931 | if (rdev->crit_proto_nlportid) { |
| 13932 | rdev->crit_proto_nlportid = 0; |
| 13933 | rdev_crit_proto_stop(rdev, wdev); |
| 13934 | } |
| 13935 | return 0; |
| 13936 | } |
| 13937 | |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13938 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
| 13939 | struct nlattr *attr, |
| 13940 | struct netlink_ext_ack *extack) |
| 13941 | { |
| 13942 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { |
| 13943 | if (attr->nla_type & NLA_F_NESTED) { |
| 13944 | NL_SET_ERR_MSG_ATTR(extack, attr, |
| 13945 | "unexpected nested data"); |
| 13946 | return -EINVAL; |
| 13947 | } |
| 13948 | |
| 13949 | return 0; |
| 13950 | } |
| 13951 | |
| 13952 | if (!(attr->nla_type & NLA_F_NESTED)) { |
| 13953 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); |
| 13954 | return -EINVAL; |
| 13955 | } |
| 13956 | |
Michal Kubecek | 32d5109 | 2019-12-11 10:58:19 +0100 | [diff] [blame] | 13957 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13958 | } |
| 13959 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13960 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 13961 | { |
| 13962 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13963 | struct wireless_dev *wdev = |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 13964 | __cfg80211_wdev_from_attrs(rdev, genl_info_net(info), |
| 13965 | info->attrs); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13966 | int i, err; |
| 13967 | u32 vid, subcmd; |
| 13968 | |
| 13969 | if (!rdev->wiphy.vendor_commands) |
| 13970 | return -EOPNOTSUPP; |
| 13971 | |
| 13972 | if (IS_ERR(wdev)) { |
| 13973 | err = PTR_ERR(wdev); |
| 13974 | if (err != -EINVAL) |
| 13975 | return err; |
| 13976 | wdev = NULL; |
| 13977 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 13978 | return -EINVAL; |
| 13979 | } |
| 13980 | |
| 13981 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 13982 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 13983 | return -EINVAL; |
| 13984 | |
| 13985 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 13986 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13987 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 13988 | const struct wiphy_vendor_command *vcmd; |
| 13989 | void *data = NULL; |
| 13990 | int len = 0; |
| 13991 | |
| 13992 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 13993 | |
| 13994 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13995 | continue; |
| 13996 | |
| 13997 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13998 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13999 | if (!wdev) |
| 14000 | return -EINVAL; |
| 14001 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 14002 | !wdev->netdev) |
| 14003 | return -EINVAL; |
| 14004 | |
| 14005 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14006 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14007 | return -ENETDOWN; |
| 14008 | } |
| 14009 | } else { |
| 14010 | wdev = NULL; |
| 14011 | } |
| 14012 | |
Julian Squires | 4052d3d | 2020-07-06 17:13:53 -0400 | [diff] [blame] | 14013 | if (!vcmd->doit) |
| 14014 | return -EOPNOTSUPP; |
| 14015 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14016 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 14017 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 14018 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 14019 | |
| 14020 | err = nl80211_vendor_check_policy(vcmd, |
| 14021 | info->attrs[NL80211_ATTR_VENDOR_DATA], |
| 14022 | info->extack); |
| 14023 | if (err) |
| 14024 | return err; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14025 | } |
| 14026 | |
| 14027 | rdev->cur_cmd_info = info; |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 14028 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14029 | rdev->cur_cmd_info = NULL; |
| 14030 | return err; |
| 14031 | } |
| 14032 | |
| 14033 | return -EOPNOTSUPP; |
| 14034 | } |
| 14035 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14036 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 14037 | struct netlink_callback *cb, |
| 14038 | struct cfg80211_registered_device **rdev, |
| 14039 | struct wireless_dev **wdev) |
| 14040 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14041 | struct nlattr **attrbuf; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14042 | u32 vid, subcmd; |
| 14043 | unsigned int i; |
| 14044 | int vcmd_idx = -1; |
| 14045 | int err; |
| 14046 | void *data = NULL; |
| 14047 | unsigned int data_len = 0; |
| 14048 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14049 | if (cb->args[0]) { |
| 14050 | /* subtract the 1 again here */ |
| 14051 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 14052 | struct wireless_dev *tmp; |
| 14053 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 14054 | if (!wiphy) |
| 14055 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14056 | *rdev = wiphy_to_rdev(wiphy); |
| 14057 | *wdev = NULL; |
| 14058 | |
| 14059 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 14060 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14061 | if (tmp->identifier == cb->args[1] - 1) { |
| 14062 | *wdev = tmp; |
| 14063 | break; |
| 14064 | } |
| 14065 | } |
| 14066 | } |
| 14067 | |
| 14068 | /* keep rtnl locked in successful case */ |
| 14069 | return 0; |
| 14070 | } |
| 14071 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14072 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 14073 | if (!attrbuf) |
| 14074 | return -ENOMEM; |
| 14075 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 14076 | err = nlmsg_parse_deprecated(cb->nlh, |
| 14077 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 14078 | attrbuf, nl80211_fam.maxattr, |
| 14079 | nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14080 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14081 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14082 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 14083 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14084 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 14085 | err = -EINVAL; |
| 14086 | goto out; |
| 14087 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14088 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 14089 | *wdev = __cfg80211_wdev_from_attrs(NULL, sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14090 | if (IS_ERR(*wdev)) |
| 14091 | *wdev = NULL; |
| 14092 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 14093 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14094 | if (IS_ERR(*rdev)) { |
| 14095 | err = PTR_ERR(*rdev); |
| 14096 | goto out; |
| 14097 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14098 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 14099 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 14100 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14101 | |
| 14102 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 14103 | const struct wiphy_vendor_command *vcmd; |
| 14104 | |
| 14105 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 14106 | |
| 14107 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 14108 | continue; |
| 14109 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14110 | if (!vcmd->dumpit) { |
| 14111 | err = -EOPNOTSUPP; |
| 14112 | goto out; |
| 14113 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14114 | |
| 14115 | vcmd_idx = i; |
| 14116 | break; |
| 14117 | } |
| 14118 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14119 | if (vcmd_idx < 0) { |
| 14120 | err = -EOPNOTSUPP; |
| 14121 | goto out; |
| 14122 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14123 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 14124 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 14125 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 14126 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 14127 | |
| 14128 | err = nl80211_vendor_check_policy( |
| 14129 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], |
| 14130 | attrbuf[NL80211_ATTR_VENDOR_DATA], |
| 14131 | cb->extack); |
| 14132 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14133 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14134 | } |
| 14135 | |
| 14136 | /* 0 is the first index - add 1 to parse only once */ |
| 14137 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 14138 | /* add 1 to know if it was NULL */ |
| 14139 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 14140 | cb->args[2] = vcmd_idx; |
| 14141 | cb->args[3] = (unsigned long)data; |
| 14142 | cb->args[4] = data_len; |
| 14143 | |
| 14144 | /* keep rtnl locked in successful case */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 14145 | err = 0; |
| 14146 | out: |
| 14147 | kfree(attrbuf); |
| 14148 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14149 | } |
| 14150 | |
| 14151 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 14152 | struct netlink_callback *cb) |
| 14153 | { |
| 14154 | struct cfg80211_registered_device *rdev; |
| 14155 | struct wireless_dev *wdev; |
| 14156 | unsigned int vcmd_idx; |
| 14157 | const struct wiphy_vendor_command *vcmd; |
| 14158 | void *data; |
| 14159 | int data_len; |
| 14160 | int err; |
| 14161 | struct nlattr *vendor_data; |
| 14162 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 14163 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14164 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 14165 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 14166 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14167 | |
| 14168 | vcmd_idx = cb->args[2]; |
| 14169 | data = (void *)cb->args[3]; |
| 14170 | data_len = cb->args[4]; |
| 14171 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 14172 | |
| 14173 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 14174 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 14175 | if (!wdev) { |
| 14176 | err = -EINVAL; |
| 14177 | goto out; |
| 14178 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14179 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 14180 | !wdev->netdev) { |
| 14181 | err = -EINVAL; |
| 14182 | goto out; |
| 14183 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14184 | |
| 14185 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 14186 | if (!wdev_running(wdev)) { |
| 14187 | err = -ENETDOWN; |
| 14188 | goto out; |
| 14189 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14190 | } |
| 14191 | } |
| 14192 | |
| 14193 | while (1) { |
| 14194 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 14195 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 14196 | NL80211_CMD_VENDOR); |
| 14197 | if (!hdr) |
| 14198 | break; |
| 14199 | |
| 14200 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 14201 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 14202 | wdev_id(wdev), |
| 14203 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14204 | genlmsg_cancel(skb, hdr); |
| 14205 | break; |
| 14206 | } |
| 14207 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 14208 | vendor_data = nla_nest_start_noflag(skb, |
| 14209 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14210 | if (!vendor_data) { |
| 14211 | genlmsg_cancel(skb, hdr); |
| 14212 | break; |
| 14213 | } |
| 14214 | |
| 14215 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 14216 | (unsigned long *)&cb->args[5]); |
| 14217 | nla_nest_end(skb, vendor_data); |
| 14218 | |
| 14219 | if (err == -ENOBUFS || err == -ENOENT) { |
| 14220 | genlmsg_cancel(skb, hdr); |
| 14221 | break; |
Julian Squires | 9c167b2 | 2020-07-20 12:20:35 -0230 | [diff] [blame] | 14222 | } else if (err <= 0) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 14223 | genlmsg_cancel(skb, hdr); |
| 14224 | goto out; |
| 14225 | } |
| 14226 | |
| 14227 | genlmsg_end(skb, hdr); |
| 14228 | } |
| 14229 | |
| 14230 | err = skb->len; |
| 14231 | out: |
| 14232 | rtnl_unlock(); |
| 14233 | return err; |
| 14234 | } |
| 14235 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14236 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 14237 | enum nl80211_commands cmd, |
| 14238 | enum nl80211_attrs attr, |
| 14239 | int approxlen) |
| 14240 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14241 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14242 | |
| 14243 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 14244 | return NULL; |
| 14245 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 14246 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14247 | rdev->cur_cmd_info->snd_portid, |
| 14248 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 14249 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14250 | } |
| 14251 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 14252 | |
| 14253 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 14254 | { |
| 14255 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 14256 | void *hdr = ((void **)skb->cb)[1]; |
| 14257 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 14258 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 14259 | /* clear CB data for netlink core to own from now on */ |
| 14260 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 14261 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 14262 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 14263 | kfree_skb(skb); |
| 14264 | return -EINVAL; |
| 14265 | } |
| 14266 | |
| 14267 | nla_nest_end(skb, data); |
| 14268 | genlmsg_end(skb, hdr); |
| 14269 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 14270 | } |
| 14271 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 14272 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 14273 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
| 14274 | { |
| 14275 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 14276 | |
| 14277 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 14278 | return 0; |
| 14279 | |
| 14280 | return rdev->cur_cmd_info->snd_portid; |
| 14281 | } |
| 14282 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); |
| 14283 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14284 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 14285 | struct genl_info *info) |
| 14286 | { |
| 14287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14288 | struct cfg80211_qos_map *qos_map = NULL; |
| 14289 | struct net_device *dev = info->user_ptr[1]; |
| 14290 | u8 *pos, len, num_des, des_len, des; |
| 14291 | int ret; |
| 14292 | |
| 14293 | if (!rdev->ops->set_qos_map) |
| 14294 | return -EOPNOTSUPP; |
| 14295 | |
| 14296 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 14297 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 14298 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 14299 | |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 14300 | if (len % 2) |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 14301 | return -EINVAL; |
| 14302 | |
| 14303 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 14304 | if (!qos_map) |
| 14305 | return -ENOMEM; |
| 14306 | |
| 14307 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 14308 | if (num_des) { |
| 14309 | des_len = num_des * |
| 14310 | sizeof(struct cfg80211_dscp_exception); |
| 14311 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 14312 | qos_map->num_des = num_des; |
| 14313 | for (des = 0; des < num_des; des++) { |
| 14314 | if (qos_map->dscp_exception[des].up > 7) { |
| 14315 | kfree(qos_map); |
| 14316 | return -EINVAL; |
| 14317 | } |
| 14318 | } |
| 14319 | pos += des_len; |
| 14320 | } |
| 14321 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 14322 | } |
| 14323 | |
| 14324 | wdev_lock(dev->ieee80211_ptr); |
| 14325 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 14326 | if (!ret) |
| 14327 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 14328 | wdev_unlock(dev->ieee80211_ptr); |
| 14329 | |
| 14330 | kfree(qos_map); |
| 14331 | return ret; |
| 14332 | } |
| 14333 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14334 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 14335 | { |
| 14336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14337 | struct net_device *dev = info->user_ptr[1]; |
| 14338 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14339 | const u8 *peer; |
| 14340 | u8 tsid, up; |
| 14341 | u16 admitted_time = 0; |
| 14342 | int err; |
| 14343 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 14344 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14345 | return -EOPNOTSUPP; |
| 14346 | |
| 14347 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 14348 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 14349 | return -EINVAL; |
| 14350 | |
| 14351 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14352 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14353 | |
| 14354 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 14355 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14356 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 14357 | * need more attributes for that (e.g. BA session requirement); |
| 14358 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 14359 | */ |
| 14360 | return -EINVAL; |
| 14361 | } |
| 14362 | |
| 14363 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14364 | |
| 14365 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 14366 | admitted_time = |
| 14367 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 14368 | if (!admitted_time) |
| 14369 | return -EINVAL; |
| 14370 | } |
| 14371 | |
| 14372 | wdev_lock(wdev); |
| 14373 | switch (wdev->iftype) { |
| 14374 | case NL80211_IFTYPE_STATION: |
| 14375 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14376 | if (wdev->current_bss) |
| 14377 | break; |
| 14378 | err = -ENOTCONN; |
| 14379 | goto out; |
| 14380 | default: |
| 14381 | err = -EOPNOTSUPP; |
| 14382 | goto out; |
| 14383 | } |
| 14384 | |
| 14385 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 14386 | |
| 14387 | out: |
| 14388 | wdev_unlock(wdev); |
| 14389 | return err; |
| 14390 | } |
| 14391 | |
| 14392 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 14393 | { |
| 14394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14395 | struct net_device *dev = info->user_ptr[1]; |
| 14396 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14397 | const u8 *peer; |
| 14398 | u8 tsid; |
| 14399 | int err; |
| 14400 | |
| 14401 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 14402 | return -EINVAL; |
| 14403 | |
| 14404 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 14405 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14406 | |
| 14407 | wdev_lock(wdev); |
| 14408 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 14409 | wdev_unlock(wdev); |
| 14410 | |
| 14411 | return err; |
| 14412 | } |
| 14413 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14414 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 14415 | struct genl_info *info) |
| 14416 | { |
| 14417 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14418 | struct net_device *dev = info->user_ptr[1]; |
| 14419 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14420 | struct cfg80211_chan_def chandef = {}; |
| 14421 | const u8 *addr; |
| 14422 | u8 oper_class; |
| 14423 | int err; |
| 14424 | |
| 14425 | if (!rdev->ops->tdls_channel_switch || |
| 14426 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 14427 | return -EOPNOTSUPP; |
| 14428 | |
| 14429 | switch (dev->ieee80211_ptr->iftype) { |
| 14430 | case NL80211_IFTYPE_STATION: |
| 14431 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14432 | break; |
| 14433 | default: |
| 14434 | return -EOPNOTSUPP; |
| 14435 | } |
| 14436 | |
| 14437 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14438 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 14439 | return -EINVAL; |
| 14440 | |
| 14441 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 14442 | if (err) |
| 14443 | return err; |
| 14444 | |
| 14445 | /* |
| 14446 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 14447 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 14448 | * specification is not defined for them. |
| 14449 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 14450 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14451 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 14452 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 14453 | return -EINVAL; |
| 14454 | |
| 14455 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 14456 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 14457 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14458 | return -EINVAL; |
| 14459 | |
| 14460 | /* don't allow switching to DFS channels */ |
| 14461 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 14462 | return -EINVAL; |
| 14463 | |
| 14464 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14465 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 14466 | |
| 14467 | wdev_lock(wdev); |
| 14468 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 14469 | wdev_unlock(wdev); |
| 14470 | |
| 14471 | return err; |
| 14472 | } |
| 14473 | |
| 14474 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 14475 | struct genl_info *info) |
| 14476 | { |
| 14477 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14478 | struct net_device *dev = info->user_ptr[1]; |
| 14479 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14480 | const u8 *addr; |
| 14481 | |
| 14482 | if (!rdev->ops->tdls_channel_switch || |
| 14483 | !rdev->ops->tdls_cancel_channel_switch || |
| 14484 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 14485 | return -EOPNOTSUPP; |
| 14486 | |
| 14487 | switch (dev->ieee80211_ptr->iftype) { |
| 14488 | case NL80211_IFTYPE_STATION: |
| 14489 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14490 | break; |
| 14491 | default: |
| 14492 | return -EOPNOTSUPP; |
| 14493 | } |
| 14494 | |
| 14495 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14496 | return -EINVAL; |
| 14497 | |
| 14498 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14499 | |
| 14500 | wdev_lock(wdev); |
| 14501 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 14502 | wdev_unlock(wdev); |
| 14503 | |
| 14504 | return 0; |
| 14505 | } |
| 14506 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14507 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 14508 | struct genl_info *info) |
| 14509 | { |
| 14510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14511 | struct net_device *dev = info->user_ptr[1]; |
| 14512 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14513 | const struct nlattr *nla; |
| 14514 | bool enabled; |
| 14515 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14516 | if (!rdev->ops->set_multicast_to_unicast) |
| 14517 | return -EOPNOTSUPP; |
| 14518 | |
| 14519 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 14520 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 14521 | return -EOPNOTSUPP; |
| 14522 | |
| 14523 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 14524 | enabled = nla_get_flag(nla); |
| 14525 | |
| 14526 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 14527 | } |
| 14528 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14529 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14530 | { |
| 14531 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14532 | struct net_device *dev = info->user_ptr[1]; |
| 14533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14534 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 14535 | int ret; |
| 14536 | |
| 14537 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14538 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14539 | return -EOPNOTSUPP; |
| 14540 | |
| 14541 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14542 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14543 | return -EOPNOTSUPP; |
| 14544 | |
| 14545 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 14546 | return -EINVAL; |
| 14547 | |
| 14548 | wdev_lock(wdev); |
| 14549 | if (!wdev->current_bss) { |
| 14550 | ret = -ENOTCONN; |
| 14551 | goto out; |
| 14552 | } |
| 14553 | |
| 14554 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14555 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 14556 | ret = -EINVAL; |
| 14557 | goto out; |
| 14558 | } |
| 14559 | |
| 14560 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 14561 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 14562 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 14563 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 14564 | ret = -EINVAL; |
| 14565 | goto out; |
| 14566 | } |
| 14567 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 14568 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14569 | pmk_conf.pmk_r0_name = |
| 14570 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14571 | |
| 14572 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 14573 | out: |
| 14574 | wdev_unlock(wdev); |
| 14575 | return ret; |
| 14576 | } |
| 14577 | |
| 14578 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14579 | { |
| 14580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14581 | struct net_device *dev = info->user_ptr[1]; |
| 14582 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14583 | const u8 *aa; |
| 14584 | int ret; |
| 14585 | |
| 14586 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14587 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14588 | return -EOPNOTSUPP; |
| 14589 | |
| 14590 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14591 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14592 | return -EOPNOTSUPP; |
| 14593 | |
| 14594 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14595 | return -EINVAL; |
| 14596 | |
| 14597 | wdev_lock(wdev); |
| 14598 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14599 | ret = rdev_del_pmk(rdev, dev, aa); |
| 14600 | wdev_unlock(wdev); |
| 14601 | |
| 14602 | return ret; |
| 14603 | } |
| 14604 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14605 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 14606 | { |
| 14607 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14608 | struct net_device *dev = info->user_ptr[1]; |
| 14609 | struct cfg80211_external_auth_params params; |
| 14610 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 14611 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14612 | return -EOPNOTSUPP; |
| 14613 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14614 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 14615 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 14616 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14617 | return -EINVAL; |
| 14618 | |
| 14619 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 14620 | return -EINVAL; |
| 14621 | |
| 14622 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 14623 | return -EINVAL; |
| 14624 | |
| 14625 | memset(¶ms, 0, sizeof(params)); |
| 14626 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14627 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 14628 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 14629 | if (params.ssid.ssid_len == 0) |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14630 | return -EINVAL; |
| 14631 | memcpy(params.ssid.ssid, |
| 14632 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 14633 | params.ssid.ssid_len); |
| 14634 | } |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14635 | |
| 14636 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 14637 | ETH_ALEN); |
| 14638 | |
| 14639 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14640 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14641 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 14642 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 14643 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14644 | return rdev_external_auth(rdev, dev, ¶ms); |
| 14645 | } |
| 14646 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14647 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 14648 | { |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14649 | 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] | 14650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14651 | struct net_device *dev = info->user_ptr[1]; |
| 14652 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14653 | const u8 *buf; |
| 14654 | size_t len; |
| 14655 | u8 *dest; |
| 14656 | u16 proto; |
| 14657 | bool noencrypt; |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14658 | u64 cookie = 0; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14659 | int err; |
| 14660 | |
| 14661 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14662 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 14663 | return -EOPNOTSUPP; |
| 14664 | |
| 14665 | if (!rdev->ops->tx_control_port) |
| 14666 | return -EOPNOTSUPP; |
| 14667 | |
| 14668 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 14669 | !info->attrs[NL80211_ATTR_MAC] || |
| 14670 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 14671 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 14672 | return -EINVAL; |
| 14673 | } |
| 14674 | |
| 14675 | wdev_lock(wdev); |
| 14676 | |
| 14677 | switch (wdev->iftype) { |
| 14678 | case NL80211_IFTYPE_AP: |
| 14679 | case NL80211_IFTYPE_P2P_GO: |
| 14680 | case NL80211_IFTYPE_MESH_POINT: |
| 14681 | break; |
| 14682 | case NL80211_IFTYPE_ADHOC: |
| 14683 | case NL80211_IFTYPE_STATION: |
| 14684 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14685 | if (wdev->current_bss) |
| 14686 | break; |
| 14687 | err = -ENOTCONN; |
| 14688 | goto out; |
| 14689 | default: |
| 14690 | err = -EOPNOTSUPP; |
| 14691 | goto out; |
| 14692 | } |
| 14693 | |
| 14694 | wdev_unlock(wdev); |
| 14695 | |
| 14696 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14697 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14698 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14699 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 14700 | noencrypt = |
| 14701 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 14702 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14703 | err = rdev_tx_control_port(rdev, dev, buf, len, |
| 14704 | dest, cpu_to_be16(proto), noencrypt, |
| 14705 | dont_wait_for_ack ? NULL : &cookie); |
| 14706 | if (!err && !dont_wait_for_ack) |
| 14707 | nl_set_extack_cookie_u64(info->extack, cookie); |
| 14708 | return err; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14709 | out: |
| 14710 | wdev_unlock(wdev); |
| 14711 | return err; |
| 14712 | } |
| 14713 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14714 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 14715 | struct genl_info *info) |
| 14716 | { |
| 14717 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14718 | struct net_device *dev = info->user_ptr[1]; |
| 14719 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14720 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 14721 | struct sk_buff *msg; |
| 14722 | void *hdr; |
| 14723 | struct nlattr *ftm_stats_attr; |
| 14724 | int err; |
| 14725 | |
| 14726 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 14727 | return -EOPNOTSUPP; |
| 14728 | |
| 14729 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 14730 | if (err) |
| 14731 | return err; |
| 14732 | |
| 14733 | if (!ftm_stats.filled) |
| 14734 | return -ENODATA; |
| 14735 | |
| 14736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14737 | if (!msg) |
| 14738 | return -ENOMEM; |
| 14739 | |
| 14740 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 14741 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 14742 | if (!hdr) |
Navid Emamdoost | 1399c59 | 2019-10-04 14:42:19 -0500 | [diff] [blame] | 14743 | goto nla_put_failure; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14744 | |
| 14745 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 14746 | goto nla_put_failure; |
| 14747 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 14748 | ftm_stats_attr = nla_nest_start_noflag(msg, |
| 14749 | NL80211_ATTR_FTM_RESPONDER_STATS); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14750 | if (!ftm_stats_attr) |
| 14751 | goto nla_put_failure; |
| 14752 | |
| 14753 | #define SET_FTM(field, name, type) \ |
| 14754 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14755 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 14756 | ftm_stats.field)) \ |
| 14757 | goto nla_put_failure; } while (0) |
| 14758 | #define SET_FTM_U64(field, name) \ |
| 14759 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14760 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 14761 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 14762 | goto nla_put_failure; } while (0) |
| 14763 | |
| 14764 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 14765 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 14766 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 14767 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 14768 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 14769 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 14770 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 14771 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 14772 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 14773 | #undef SET_FTM |
| 14774 | |
| 14775 | nla_nest_end(msg, ftm_stats_attr); |
| 14776 | |
| 14777 | genlmsg_end(msg, hdr); |
| 14778 | return genlmsg_reply(msg, info); |
| 14779 | |
| 14780 | nla_put_failure: |
| 14781 | nlmsg_free(msg); |
| 14782 | return -ENOBUFS; |
| 14783 | } |
| 14784 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 14785 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
| 14786 | { |
| 14787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14788 | struct cfg80211_update_owe_info owe_info; |
| 14789 | struct net_device *dev = info->user_ptr[1]; |
| 14790 | |
| 14791 | if (!rdev->ops->update_owe_info) |
| 14792 | return -EOPNOTSUPP; |
| 14793 | |
| 14794 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 14795 | !info->attrs[NL80211_ATTR_MAC]) |
| 14796 | return -EINVAL; |
| 14797 | |
| 14798 | memset(&owe_info, 0, sizeof(owe_info)); |
| 14799 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14800 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); |
| 14801 | |
| 14802 | if (info->attrs[NL80211_ATTR_IE]) { |
| 14803 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 14804 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 14805 | } |
| 14806 | |
| 14807 | return rdev_update_owe_info(rdev, dev, &owe_info); |
| 14808 | } |
| 14809 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14810 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
| 14811 | { |
| 14812 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14813 | struct net_device *dev = info->user_ptr[1]; |
| 14814 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14815 | struct station_info sinfo = {}; |
| 14816 | const u8 *buf; |
| 14817 | size_t len; |
| 14818 | u8 *dest; |
| 14819 | int err; |
| 14820 | |
| 14821 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) |
| 14822 | return -EOPNOTSUPP; |
| 14823 | |
| 14824 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14825 | !info->attrs[NL80211_ATTR_FRAME]) { |
| 14826 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); |
| 14827 | return -EINVAL; |
| 14828 | } |
| 14829 | |
| 14830 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 14831 | return -EOPNOTSUPP; |
| 14832 | |
| 14833 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14834 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14835 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14836 | |
| 14837 | if (len < sizeof(struct ethhdr)) |
| 14838 | return -EINVAL; |
| 14839 | |
| 14840 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || |
| 14841 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) |
| 14842 | return -EINVAL; |
| 14843 | |
| 14844 | err = rdev_get_station(rdev, dev, dest, &sinfo); |
| 14845 | if (err) |
| 14846 | return err; |
| 14847 | |
Felix Fietkau | 2a279b34 | 2020-01-08 18:06:29 +0100 | [diff] [blame] | 14848 | cfg80211_sinfo_release_content(&sinfo); |
| 14849 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14850 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
| 14851 | } |
| 14852 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14853 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
| 14854 | struct nlattr *attrs[], struct net_device *dev, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14855 | struct cfg80211_tid_cfg *tid_conf, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14856 | struct genl_info *info, const u8 *peer) |
| 14857 | { |
| 14858 | struct netlink_ext_ack *extack = info->extack; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14859 | u64 mask; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14860 | int err; |
| 14861 | |
| 14862 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) |
| 14863 | return -EINVAL; |
| 14864 | |
| 14865 | tid_conf->config_override = |
| 14866 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14867 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14868 | |
| 14869 | if (tid_conf->config_override) { |
| 14870 | if (rdev->ops->reset_tid_config) { |
| 14871 | err = rdev_reset_tid_config(rdev, dev, peer, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14872 | tid_conf->tids); |
Sergey Matyukevich | c033695 | 2020-04-24 14:29:04 +0300 | [diff] [blame] | 14873 | if (err) |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14874 | return err; |
| 14875 | } else { |
| 14876 | return -EINVAL; |
| 14877 | } |
| 14878 | } |
| 14879 | |
| 14880 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14881 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14882 | tid_conf->noack = |
| 14883 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); |
| 14884 | } |
| 14885 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 14886 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { |
| 14887 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); |
| 14888 | tid_conf->retry_short = |
| 14889 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); |
| 14890 | |
| 14891 | if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) |
| 14892 | return -EINVAL; |
| 14893 | } |
| 14894 | |
| 14895 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { |
| 14896 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); |
| 14897 | tid_conf->retry_long = |
| 14898 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); |
| 14899 | |
| 14900 | if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) |
| 14901 | return -EINVAL; |
| 14902 | } |
| 14903 | |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 14904 | if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { |
| 14905 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); |
| 14906 | tid_conf->ampdu = |
| 14907 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); |
| 14908 | } |
| 14909 | |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 14910 | if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { |
| 14911 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); |
| 14912 | tid_conf->rtscts = |
| 14913 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); |
| 14914 | } |
| 14915 | |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 14916 | if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { |
| 14917 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); |
| 14918 | tid_conf->amsdu = |
| 14919 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); |
| 14920 | } |
| 14921 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14922 | if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { |
| 14923 | u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; |
| 14924 | |
| 14925 | tid_conf->txrate_type = nla_get_u8(attrs[idx]); |
| 14926 | |
| 14927 | if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { |
| 14928 | attr = NL80211_TID_CONFIG_ATTR_TX_RATE; |
| 14929 | err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, |
Rajkumar Manoharan | 857b34c | 2020-10-16 13:15:26 -0700 | [diff] [blame] | 14930 | &tid_conf->txrate_mask, dev, |
| 14931 | true); |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14932 | if (err) |
| 14933 | return err; |
| 14934 | |
| 14935 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); |
| 14936 | } |
| 14937 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); |
| 14938 | } |
| 14939 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14940 | if (peer) |
| 14941 | mask = rdev->wiphy.tid_config_support.peer; |
| 14942 | else |
| 14943 | mask = rdev->wiphy.tid_config_support.vif; |
| 14944 | |
| 14945 | if (tid_conf->mask & ~mask) { |
| 14946 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); |
| 14947 | return -ENOTSUPP; |
| 14948 | } |
| 14949 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14950 | return 0; |
| 14951 | } |
| 14952 | |
| 14953 | static int nl80211_set_tid_config(struct sk_buff *skb, |
| 14954 | struct genl_info *info) |
| 14955 | { |
| 14956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14957 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; |
| 14958 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14959 | struct cfg80211_tid_config *tid_config; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14960 | struct nlattr *tid; |
| 14961 | int conf_idx = 0, rem_conf; |
| 14962 | int ret = -EINVAL; |
| 14963 | u32 num_conf = 0; |
| 14964 | |
| 14965 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) |
| 14966 | return -EINVAL; |
| 14967 | |
| 14968 | if (!rdev->ops->set_tid_config) |
| 14969 | return -EOPNOTSUPP; |
| 14970 | |
| 14971 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14972 | rem_conf) |
| 14973 | num_conf++; |
| 14974 | |
| 14975 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), |
| 14976 | GFP_KERNEL); |
| 14977 | if (!tid_config) |
| 14978 | return -ENOMEM; |
| 14979 | |
| 14980 | tid_config->n_tid_conf = num_conf; |
| 14981 | |
| 14982 | if (info->attrs[NL80211_ATTR_MAC]) |
| 14983 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14984 | |
| 14985 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14986 | rem_conf) { |
| 14987 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, |
| 14988 | tid, NULL, NULL); |
| 14989 | |
| 14990 | if (ret) |
| 14991 | goto bad_tid_conf; |
| 14992 | |
| 14993 | ret = parse_tid_conf(rdev, attrs, dev, |
| 14994 | &tid_config->tid_conf[conf_idx], |
| 14995 | info, tid_config->peer); |
| 14996 | if (ret) |
| 14997 | goto bad_tid_conf; |
| 14998 | |
| 14999 | conf_idx++; |
| 15000 | } |
| 15001 | |
| 15002 | ret = rdev_set_tid_config(rdev, dev, tid_config); |
| 15003 | |
| 15004 | bad_tid_conf: |
| 15005 | kfree(tid_config); |
| 15006 | return ret; |
| 15007 | } |
| 15008 | |
John Crispin | 0d2ab3ae | 2021-07-02 19:44:07 +0200 | [diff] [blame] | 15009 | static int nl80211_color_change(struct sk_buff *skb, struct genl_info *info) |
| 15010 | { |
| 15011 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 15012 | struct cfg80211_color_change_settings params = {}; |
| 15013 | struct net_device *dev = info->user_ptr[1]; |
| 15014 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15015 | struct nlattr **tb; |
| 15016 | u16 offset; |
| 15017 | int err; |
| 15018 | |
| 15019 | if (!rdev->ops->color_change) |
| 15020 | return -EOPNOTSUPP; |
| 15021 | |
| 15022 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 15023 | NL80211_EXT_FEATURE_BSS_COLOR)) |
| 15024 | return -EOPNOTSUPP; |
| 15025 | |
| 15026 | if (wdev->iftype != NL80211_IFTYPE_AP) |
| 15027 | return -EOPNOTSUPP; |
| 15028 | |
| 15029 | if (!info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT] || |
| 15030 | !info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR] || |
| 15031 | !info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS]) |
| 15032 | return -EINVAL; |
| 15033 | |
| 15034 | params.count = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COUNT]); |
| 15035 | params.color = nla_get_u8(info->attrs[NL80211_ATTR_COLOR_CHANGE_COLOR]); |
| 15036 | |
| 15037 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_next); |
| 15038 | if (err) |
| 15039 | return err; |
| 15040 | |
| 15041 | tb = kcalloc(NL80211_ATTR_MAX + 1, sizeof(*tb), GFP_KERNEL); |
| 15042 | if (!tb) |
| 15043 | return -ENOMEM; |
| 15044 | |
| 15045 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, |
| 15046 | info->attrs[NL80211_ATTR_COLOR_CHANGE_ELEMS], |
| 15047 | nl80211_policy, info->extack); |
| 15048 | if (err) |
| 15049 | goto out; |
| 15050 | |
| 15051 | err = nl80211_parse_beacon(rdev, tb, ¶ms.beacon_color_change); |
| 15052 | if (err) |
| 15053 | goto out; |
| 15054 | |
| 15055 | if (!tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) { |
| 15056 | err = -EINVAL; |
| 15057 | goto out; |
| 15058 | } |
| 15059 | |
| 15060 | if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]) != sizeof(u16)) { |
| 15061 | err = -EINVAL; |
| 15062 | goto out; |
| 15063 | } |
| 15064 | |
| 15065 | offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
| 15066 | if (offset >= params.beacon_color_change.tail_len) { |
| 15067 | err = -EINVAL; |
| 15068 | goto out; |
| 15069 | } |
| 15070 | |
| 15071 | if (params.beacon_color_change.tail[offset] != params.count) { |
| 15072 | err = -EINVAL; |
| 15073 | goto out; |
| 15074 | } |
| 15075 | |
| 15076 | params.counter_offset_beacon = offset; |
| 15077 | |
| 15078 | if (tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { |
| 15079 | if (nla_len(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]) != |
| 15080 | sizeof(u16)) { |
| 15081 | err = -EINVAL; |
| 15082 | goto out; |
| 15083 | } |
| 15084 | |
| 15085 | offset = nla_get_u16(tb[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
| 15086 | if (offset >= params.beacon_color_change.probe_resp_len) { |
| 15087 | err = -EINVAL; |
| 15088 | goto out; |
| 15089 | } |
| 15090 | |
| 15091 | if (params.beacon_color_change.probe_resp[offset] != |
| 15092 | params.count) { |
| 15093 | err = -EINVAL; |
| 15094 | goto out; |
| 15095 | } |
| 15096 | |
| 15097 | params.counter_offset_presp = offset; |
| 15098 | } |
| 15099 | |
| 15100 | wdev_lock(wdev); |
| 15101 | err = rdev_color_change(rdev, dev, ¶ms); |
| 15102 | wdev_unlock(wdev); |
| 15103 | |
| 15104 | out: |
John Crispin | dc1e3cb | 2021-09-15 19:54:34 -0700 | [diff] [blame] | 15105 | kfree(params.beacon_next.mbssid_ies); |
| 15106 | kfree(params.beacon_color_change.mbssid_ies); |
John Crispin | 0d2ab3ae | 2021-07-02 19:44:07 +0200 | [diff] [blame] | 15107 | kfree(tb); |
| 15108 | return err; |
| 15109 | } |
| 15110 | |
Subrat Mishra | e306784 | 2021-09-15 11:22:23 +0530 | [diff] [blame] | 15111 | static int nl80211_set_fils_aad(struct sk_buff *skb, |
| 15112 | struct genl_info *info) |
| 15113 | { |
| 15114 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 15115 | struct net_device *dev = info->user_ptr[1]; |
| 15116 | struct cfg80211_fils_aad fils_aad = {}; |
| 15117 | u8 *nonces; |
| 15118 | |
| 15119 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 15120 | !info->attrs[NL80211_ATTR_FILS_KEK] || |
| 15121 | !info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 15122 | return -EINVAL; |
| 15123 | |
| 15124 | fils_aad.macaddr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 15125 | fils_aad.kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 15126 | fils_aad.kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 15127 | nonces = nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 15128 | fils_aad.snonce = nonces; |
| 15129 | fils_aad.anonce = nonces + FILS_NONCE_LEN; |
| 15130 | |
| 15131 | return rdev_set_fils_aad(rdev, dev, &fils_aad); |
| 15132 | } |
| 15133 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15134 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 15135 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 15136 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15137 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 15138 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 15139 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15140 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15141 | /* 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] | 15142 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 15143 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15144 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 77cbf79 | 2021-03-10 21:58:40 +0100 | [diff] [blame] | 15145 | #define NL80211_FLAG_NO_WIPHY_MTX 0x40 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15146 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 15147 | 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] | 15148 | struct genl_info *info) |
| 15149 | { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15150 | struct cfg80211_registered_device *rdev = NULL; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15151 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15152 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15153 | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15154 | rtnl_lock(); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15155 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 15156 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15157 | if (IS_ERR(rdev)) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15158 | rtnl_unlock(); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15159 | return PTR_ERR(rdev); |
| 15160 | } |
| 15161 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15162 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 15163 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15164 | wdev = __cfg80211_wdev_from_attrs(NULL, genl_info_net(info), |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15165 | info->attrs); |
| 15166 | if (IS_ERR(wdev)) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15167 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15168 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15169 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15170 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15171 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15172 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15173 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15174 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 15175 | if (!dev) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15176 | rtnl_unlock(); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15177 | return -EINVAL; |
| 15178 | } |
| 15179 | |
| 15180 | info->user_ptr[1] = dev; |
| 15181 | } else { |
| 15182 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15183 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 15184 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 15185 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 15186 | !wdev_running(wdev)) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15187 | rtnl_unlock(); |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 15188 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15189 | } |
| 15190 | |
Yajun Deng | 1160dfa | 2021-08-05 19:55:27 +0800 | [diff] [blame] | 15191 | dev_hold(dev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15192 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15193 | } |
| 15194 | |
Johannes Berg | 77cbf79 | 2021-03-10 21:58:40 +0100 | [diff] [blame] | 15195 | if (rdev && !(ops->internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15196 | wiphy_lock(&rdev->wiphy); |
| 15197 | /* we keep the mutex locked until post_doit */ |
| 15198 | __release(&rdev->wiphy.mtx); |
| 15199 | } |
| 15200 | if (!(ops->internal_flags & NL80211_FLAG_NEED_RTNL)) |
| 15201 | rtnl_unlock(); |
| 15202 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15203 | return 0; |
| 15204 | } |
| 15205 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 15206 | 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] | 15207 | struct genl_info *info) |
| 15208 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15209 | if (info->user_ptr[1]) { |
| 15210 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 15211 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 15212 | |
Yajun Deng | 1160dfa | 2021-08-05 19:55:27 +0800 | [diff] [blame] | 15213 | dev_put(wdev->netdev); |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 15214 | } else { |
| 15215 | dev_put(info->user_ptr[1]); |
| 15216 | } |
| 15217 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15218 | |
Johannes Berg | 77cbf79 | 2021-03-10 21:58:40 +0100 | [diff] [blame] | 15219 | if (info->user_ptr[0] && |
| 15220 | !(ops->internal_flags & NL80211_FLAG_NO_WIPHY_MTX)) { |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15221 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 15222 | |
| 15223 | /* we kept the mutex locked since pre_doit */ |
| 15224 | __acquire(&rdev->wiphy.mtx); |
| 15225 | wiphy_unlock(&rdev->wiphy); |
| 15226 | } |
| 15227 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15228 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 15229 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15230 | |
| 15231 | /* If needed, clear the netlink message payload from the SKB |
| 15232 | * as it might contain key data that shouldn't stick around on |
| 15233 | * the heap after the SKB is freed. The netlink message header |
| 15234 | * is still needed for further processing, so leave it intact. |
| 15235 | */ |
| 15236 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 15237 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 15238 | |
| 15239 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 15240 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15241 | } |
| 15242 | |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 15243 | static int nl80211_set_sar_sub_specs(struct cfg80211_registered_device *rdev, |
| 15244 | struct cfg80211_sar_specs *sar_specs, |
| 15245 | struct nlattr *spec[], int index) |
| 15246 | { |
| 15247 | u32 range_index, i; |
| 15248 | |
| 15249 | if (!sar_specs || !spec) |
| 15250 | return -EINVAL; |
| 15251 | |
| 15252 | if (!spec[NL80211_SAR_ATTR_SPECS_POWER] || |
| 15253 | !spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]) |
| 15254 | return -EINVAL; |
| 15255 | |
| 15256 | range_index = nla_get_u32(spec[NL80211_SAR_ATTR_SPECS_RANGE_INDEX]); |
| 15257 | |
| 15258 | /* check if range_index exceeds num_freq_ranges */ |
| 15259 | if (range_index >= rdev->wiphy.sar_capa->num_freq_ranges) |
| 15260 | return -EINVAL; |
| 15261 | |
| 15262 | /* check if range_index duplicates */ |
| 15263 | for (i = 0; i < index; i++) { |
| 15264 | if (sar_specs->sub_specs[i].freq_range_index == range_index) |
| 15265 | return -EINVAL; |
| 15266 | } |
| 15267 | |
| 15268 | sar_specs->sub_specs[index].power = |
| 15269 | nla_get_s32(spec[NL80211_SAR_ATTR_SPECS_POWER]); |
| 15270 | |
| 15271 | sar_specs->sub_specs[index].freq_range_index = range_index; |
| 15272 | |
| 15273 | return 0; |
| 15274 | } |
| 15275 | |
| 15276 | static int nl80211_set_sar_specs(struct sk_buff *skb, struct genl_info *info) |
| 15277 | { |
| 15278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 15279 | struct nlattr *spec[NL80211_SAR_ATTR_SPECS_MAX + 1]; |
| 15280 | struct nlattr *tb[NL80211_SAR_ATTR_MAX + 1]; |
| 15281 | struct cfg80211_sar_specs *sar_spec; |
| 15282 | enum nl80211_sar_type type; |
| 15283 | struct nlattr *spec_list; |
| 15284 | u32 specs; |
| 15285 | int rem, err; |
| 15286 | |
| 15287 | if (!rdev->wiphy.sar_capa || !rdev->ops->set_sar_specs) |
| 15288 | return -EOPNOTSUPP; |
| 15289 | |
| 15290 | if (!info->attrs[NL80211_ATTR_SAR_SPEC]) |
| 15291 | return -EINVAL; |
| 15292 | |
| 15293 | nla_parse_nested(tb, NL80211_SAR_ATTR_MAX, |
| 15294 | info->attrs[NL80211_ATTR_SAR_SPEC], |
| 15295 | NULL, NULL); |
| 15296 | |
| 15297 | if (!tb[NL80211_SAR_ATTR_TYPE] || !tb[NL80211_SAR_ATTR_SPECS]) |
| 15298 | return -EINVAL; |
| 15299 | |
| 15300 | type = nla_get_u32(tb[NL80211_SAR_ATTR_TYPE]); |
| 15301 | if (type != rdev->wiphy.sar_capa->type) |
| 15302 | return -EINVAL; |
| 15303 | |
| 15304 | specs = 0; |
| 15305 | nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) |
| 15306 | specs++; |
| 15307 | |
| 15308 | if (specs > rdev->wiphy.sar_capa->num_freq_ranges) |
| 15309 | return -EINVAL; |
| 15310 | |
Len Baker | 40f231e | 2021-09-19 13:40:40 +0200 | [diff] [blame] | 15311 | sar_spec = kzalloc(struct_size(sar_spec, sub_specs, specs), GFP_KERNEL); |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 15312 | if (!sar_spec) |
| 15313 | return -ENOMEM; |
| 15314 | |
| 15315 | sar_spec->type = type; |
| 15316 | specs = 0; |
| 15317 | nla_for_each_nested(spec_list, tb[NL80211_SAR_ATTR_SPECS], rem) { |
| 15318 | nla_parse_nested(spec, NL80211_SAR_ATTR_SPECS_MAX, |
| 15319 | spec_list, NULL, NULL); |
| 15320 | |
| 15321 | switch (type) { |
| 15322 | case NL80211_SAR_TYPE_POWER: |
| 15323 | if (nl80211_set_sar_sub_specs(rdev, sar_spec, |
| 15324 | spec, specs)) { |
| 15325 | err = -EINVAL; |
| 15326 | goto error; |
| 15327 | } |
| 15328 | break; |
| 15329 | default: |
| 15330 | err = -EINVAL; |
| 15331 | goto error; |
| 15332 | } |
| 15333 | specs++; |
| 15334 | } |
| 15335 | |
| 15336 | sar_spec->num_sub_specs = specs; |
| 15337 | |
| 15338 | rdev->cur_cmd_info = info; |
| 15339 | err = rdev_set_sar_specs(rdev, sar_spec); |
| 15340 | rdev->cur_cmd_info = NULL; |
| 15341 | error: |
| 15342 | kfree(sar_spec); |
| 15343 | return err; |
| 15344 | } |
| 15345 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 15346 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15347 | { |
| 15348 | .cmd = NL80211_CMD_GET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15349 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15350 | .doit = nl80211_get_wiphy, |
| 15351 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 15352 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15353 | /* can be retrieved by unprivileged users */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15354 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15355 | }, |
Jakub Kicinski | 66a9b92 | 2020-10-02 14:49:54 -0700 | [diff] [blame] | 15356 | }; |
| 15357 | |
| 15358 | static const struct genl_small_ops nl80211_small_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15359 | { |
| 15360 | .cmd = NL80211_CMD_SET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15361 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15362 | .doit = nl80211_set_wiphy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15363 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15364 | }, |
| 15365 | { |
| 15366 | .cmd = NL80211_CMD_GET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15367 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15368 | .doit = nl80211_get_interface, |
| 15369 | .dumpit = nl80211_dump_interface, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15370 | /* can be retrieved by unprivileged users */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15371 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15372 | }, |
| 15373 | { |
| 15374 | .cmd = NL80211_CMD_SET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15375 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15376 | .doit = nl80211_set_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15377 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15378 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15379 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15380 | }, |
| 15381 | { |
| 15382 | .cmd = NL80211_CMD_NEW_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15383 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15384 | .doit = nl80211_new_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15385 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15386 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
Johannes Berg | ea6b209 | 2021-04-27 11:49:52 +0200 | [diff] [blame] | 15387 | NL80211_FLAG_NEED_RTNL | |
| 15388 | /* we take the wiphy mutex later ourselves */ |
| 15389 | NL80211_FLAG_NO_WIPHY_MTX, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15390 | }, |
| 15391 | { |
| 15392 | .cmd = NL80211_CMD_DEL_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15393 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15394 | .doit = nl80211_del_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15395 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 15396 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15397 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15398 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15399 | { |
| 15400 | .cmd = NL80211_CMD_GET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15401 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15402 | .doit = nl80211_get_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15403 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15404 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15405 | }, |
| 15406 | { |
| 15407 | .cmd = NL80211_CMD_SET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15408 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15409 | .doit = nl80211_set_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15410 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15412 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15413 | }, |
| 15414 | { |
| 15415 | .cmd = NL80211_CMD_NEW_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15416 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15417 | .doit = nl80211_new_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15418 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15420 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15421 | }, |
| 15422 | { |
| 15423 | .cmd = NL80211_CMD_DEL_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15424 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15425 | .doit = nl80211_del_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15426 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 15428 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 15429 | { |
| 15430 | .cmd = NL80211_CMD_SET_BEACON, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15431 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15432 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 15433 | .doit = nl80211_set_beacon, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15434 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 15435 | }, |
| 15436 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 15437 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15438 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15439 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 15440 | .doit = nl80211_start_ap, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15441 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 15442 | }, |
| 15443 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 15444 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15445 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15446 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 15447 | .doit = nl80211_stop_ap, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15448 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 15449 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15450 | { |
| 15451 | .cmd = NL80211_CMD_GET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15452 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15453 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15454 | .dumpit = nl80211_dump_station, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15455 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15456 | }, |
| 15457 | { |
| 15458 | .cmd = NL80211_CMD_SET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15459 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15460 | .doit = nl80211_set_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15461 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15462 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15463 | }, |
| 15464 | { |
| 15465 | .cmd = NL80211_CMD_NEW_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15466 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15467 | .doit = nl80211_new_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15468 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15469 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15470 | }, |
| 15471 | { |
| 15472 | .cmd = NL80211_CMD_DEL_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15473 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15474 | .doit = nl80211_del_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15475 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15476 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 15477 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15478 | { |
| 15479 | .cmd = NL80211_CMD_GET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15480 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15481 | .doit = nl80211_get_mpath, |
| 15482 | .dumpit = nl80211_dump_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15483 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15484 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15485 | }, |
| 15486 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 15487 | .cmd = NL80211_CMD_GET_MPP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15488 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 15489 | .doit = nl80211_get_mpp, |
| 15490 | .dumpit = nl80211_dump_mpp, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15491 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15492 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 15493 | }, |
| 15494 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15495 | .cmd = NL80211_CMD_SET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15496 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15497 | .doit = nl80211_set_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15498 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15499 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15500 | }, |
| 15501 | { |
| 15502 | .cmd = NL80211_CMD_NEW_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15503 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15504 | .doit = nl80211_new_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15505 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15506 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15507 | }, |
| 15508 | { |
| 15509 | .cmd = NL80211_CMD_DEL_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15510 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15511 | .doit = nl80211_del_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15512 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15513 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 15514 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 15515 | { |
| 15516 | .cmd = NL80211_CMD_SET_BSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15517 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 15518 | .doit = nl80211_set_bss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15519 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15520 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 15521 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15522 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 15523 | .cmd = NL80211_CMD_GET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15524 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15525 | .doit = nl80211_get_reg_do, |
| 15526 | .dumpit = nl80211_get_reg_dump, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15527 | .internal_flags = 0, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 15528 | /* can be retrieved by unprivileged users */ |
| 15529 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 15530 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 15531 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15532 | .cmd = NL80211_CMD_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15533 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15534 | .doit = nl80211_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15535 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15536 | .internal_flags = 0, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15537 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 15538 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15539 | { |
| 15540 | .cmd = NL80211_CMD_REQ_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15541 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15542 | .doit = nl80211_req_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 15543 | .flags = GENL_ADMIN_PERM, |
| 15544 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 15545 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 15546 | .cmd = NL80211_CMD_RELOAD_REGDB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15547 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 15548 | .doit = nl80211_reload_regdb, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 15549 | .flags = GENL_ADMIN_PERM, |
| 15550 | }, |
| 15551 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 15552 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15553 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 15554 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 15555 | /* can be retrieved by unprivileged users */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15556 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 15557 | }, |
| 15558 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 15559 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15560 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 15561 | .doit = nl80211_update_mesh_config, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15562 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15563 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 15564 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 15565 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15566 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15567 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15568 | .doit = nl80211_trigger_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15569 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15570 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15571 | }, |
| 15572 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 15573 | .cmd = NL80211_CMD_ABORT_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15574 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 15575 | .doit = nl80211_abort_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15576 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15577 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 15578 | }, |
| 15579 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15580 | .cmd = NL80211_CMD_GET_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15581 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15582 | .dumpit = nl80211_dump_scan, |
| 15583 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15584 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15585 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15586 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15587 | .doit = nl80211_start_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15588 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15590 | }, |
| 15591 | { |
| 15592 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15593 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15594 | .doit = nl80211_stop_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15595 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15596 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15597 | }, |
| 15598 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15599 | .cmd = NL80211_CMD_AUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15600 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15601 | .doit = nl80211_authenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15602 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15603 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15604 | 0 | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15605 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15606 | }, |
| 15607 | { |
| 15608 | .cmd = NL80211_CMD_ASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15609 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15610 | .doit = nl80211_associate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15611 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15612 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15613 | 0 | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15614 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15615 | }, |
| 15616 | { |
| 15617 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15618 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15619 | .doit = nl80211_deauthenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15620 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15622 | }, |
| 15623 | { |
| 15624 | .cmd = NL80211_CMD_DISASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15625 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15626 | .doit = nl80211_disassociate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15627 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15628 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 15629 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15630 | { |
| 15631 | .cmd = NL80211_CMD_JOIN_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15632 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15633 | .doit = nl80211_join_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15634 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15635 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15636 | }, |
| 15637 | { |
| 15638 | .cmd = NL80211_CMD_LEAVE_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15639 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15640 | .doit = nl80211_leave_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15641 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 15643 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 15644 | #ifdef CONFIG_NL80211_TESTMODE |
| 15645 | { |
| 15646 | .cmd = NL80211_CMD_TESTMODE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15647 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 15648 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 15649 | .dumpit = nl80211_testmode_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15650 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15651 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 15652 | }, |
| 15653 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15654 | { |
| 15655 | .cmd = NL80211_CMD_CONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15656 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15657 | .doit = nl80211_connect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15658 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15659 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15660 | 0 | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15661 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15662 | }, |
| 15663 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15664 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15665 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15666 | .doit = nl80211_update_connect_params, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15667 | .flags = GENL_ADMIN_PERM, |
| 15668 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15669 | 0 | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15670 | NL80211_FLAG_CLEAR_SKB, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15671 | }, |
| 15672 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15673 | .cmd = NL80211_CMD_DISCONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15674 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15675 | .doit = nl80211_disconnect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15676 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15677 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15678 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15679 | { |
| 15680 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15681 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15682 | .doit = nl80211_wiphy_netns, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15683 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 77cbf79 | 2021-03-10 21:58:40 +0100 | [diff] [blame] | 15684 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15685 | NL80211_FLAG_NEED_RTNL | |
| 15686 | NL80211_FLAG_NO_WIPHY_MTX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15687 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 15688 | { |
| 15689 | .cmd = NL80211_CMD_GET_SURVEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15690 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 15691 | .dumpit = nl80211_dump_survey, |
| 15692 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15693 | { |
| 15694 | .cmd = NL80211_CMD_SET_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15695 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15696 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15697 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 15698 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15699 | 0 | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15700 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15701 | }, |
| 15702 | { |
| 15703 | .cmd = NL80211_CMD_DEL_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15704 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15705 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15706 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15707 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15708 | }, |
| 15709 | { |
| 15710 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15711 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15712 | .doit = nl80211_flush_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15713 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15714 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15715 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15716 | { |
| 15717 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15718 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15719 | .doit = nl80211_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15720 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15721 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15722 | }, |
| 15723 | { |
| 15724 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15725 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15726 | .doit = nl80211_cancel_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15727 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15728 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15729 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 15730 | { |
| 15731 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15732 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 15733 | .doit = nl80211_set_tx_bitrate_mask, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15734 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15735 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 15736 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15737 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15738 | .cmd = NL80211_CMD_REGISTER_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15739 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15740 | .doit = nl80211_register_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15741 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15742 | .internal_flags = NL80211_FLAG_NEED_WDEV, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15743 | }, |
| 15744 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15745 | .cmd = NL80211_CMD_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15746 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15747 | .doit = nl80211_tx_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15748 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15749 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15750 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15751 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 15752 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15753 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 15754 | .doit = nl80211_tx_mgmt_cancel_wait, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15755 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15756 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 15757 | }, |
| 15758 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15759 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15760 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15761 | .doit = nl80211_set_power_save, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15762 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15763 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15764 | }, |
| 15765 | { |
| 15766 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15767 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15768 | .doit = nl80211_get_power_save, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15769 | /* can be retrieved by unprivileged users */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15770 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15771 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15772 | { |
| 15773 | .cmd = NL80211_CMD_SET_CQM, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15774 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15775 | .doit = nl80211_set_cqm, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15776 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15777 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15778 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15779 | { |
| 15780 | .cmd = NL80211_CMD_SET_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15781 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15782 | .doit = nl80211_set_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15783 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15784 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15785 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15786 | { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15787 | .cmd = NL80211_CMD_JOIN_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15788 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15789 | .doit = nl80211_join_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15790 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15792 | }, |
| 15793 | { |
| 15794 | .cmd = NL80211_CMD_LEAVE_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15795 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15796 | .doit = nl80211_leave_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15797 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15798 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15799 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15800 | { |
| 15801 | .cmd = NL80211_CMD_JOIN_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15802 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15803 | .doit = nl80211_join_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15804 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15805 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15806 | }, |
| 15807 | { |
| 15808 | .cmd = NL80211_CMD_LEAVE_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15809 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15810 | .doit = nl80211_leave_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15811 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15812 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15813 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 15814 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15815 | { |
| 15816 | .cmd = NL80211_CMD_GET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15817 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15818 | .doit = nl80211_get_wowlan, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15819 | /* can be retrieved by unprivileged users */ |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15820 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15821 | }, |
| 15822 | { |
| 15823 | .cmd = NL80211_CMD_SET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15824 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15825 | .doit = nl80211_set_wowlan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15826 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15827 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15828 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 15829 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15830 | { |
| 15831 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15832 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15833 | .doit = nl80211_set_rekey_data, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15834 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15835 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15836 | 0 | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15837 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15838 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15839 | { |
| 15840 | .cmd = NL80211_CMD_TDLS_MGMT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15841 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15842 | .doit = nl80211_tdls_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15843 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15844 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15845 | }, |
| 15846 | { |
| 15847 | .cmd = NL80211_CMD_TDLS_OPER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15848 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15849 | .doit = nl80211_tdls_oper, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15850 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15852 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15853 | { |
| 15854 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15855 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15856 | .doit = nl80211_register_unexpected_frame, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15857 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15858 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15859 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15860 | { |
| 15861 | .cmd = NL80211_CMD_PROBE_CLIENT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15862 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15863 | .doit = nl80211_probe_client, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15864 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15865 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15866 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15867 | { |
| 15868 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15869 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15870 | .doit = nl80211_register_beacons, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15871 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15872 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15873 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15874 | { |
| 15875 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15876 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15877 | .doit = nl80211_set_noack_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15878 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15879 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15880 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15881 | { |
| 15882 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15883 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15884 | .doit = nl80211_start_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15885 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15886 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15887 | NL80211_FLAG_NEED_RTNL, |
| 15888 | }, |
| 15889 | { |
| 15890 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15891 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15892 | .doit = nl80211_stop_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15893 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15894 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15895 | NL80211_FLAG_NEED_RTNL, |
| 15896 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15897 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15898 | .cmd = NL80211_CMD_START_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15899 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15900 | .doit = nl80211_start_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15901 | .flags = GENL_ADMIN_PERM, |
| 15902 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15903 | NL80211_FLAG_NEED_RTNL, |
| 15904 | }, |
| 15905 | { |
| 15906 | .cmd = NL80211_CMD_STOP_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15907 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15908 | .doit = nl80211_stop_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15909 | .flags = GENL_ADMIN_PERM, |
| 15910 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15911 | NL80211_FLAG_NEED_RTNL, |
| 15912 | }, |
| 15913 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15914 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15915 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15916 | .doit = nl80211_nan_add_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15917 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15918 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15919 | }, |
| 15920 | { |
| 15921 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15922 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15923 | .doit = nl80211_nan_del_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15924 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15925 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15926 | }, |
| 15927 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15928 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15929 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15930 | .doit = nl80211_nan_change_config, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15931 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15932 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15933 | }, |
| 15934 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15935 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15936 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15937 | .doit = nl80211_set_mcast_rate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15938 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15939 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15940 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15941 | { |
| 15942 | .cmd = NL80211_CMD_SET_MAC_ACL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15943 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15944 | .doit = nl80211_set_mac_acl, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15945 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15946 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15947 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15948 | { |
| 15949 | .cmd = NL80211_CMD_RADAR_DETECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15950 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15951 | .doit = nl80211_start_radar_detection, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15952 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15953 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15954 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15955 | { |
| 15956 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15957 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15958 | .doit = nl80211_get_protocol_features, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15959 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15960 | { |
| 15961 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15962 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15963 | .doit = nl80211_update_ft_ies, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15964 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15965 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15966 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15967 | { |
| 15968 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15969 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15970 | .doit = nl80211_crit_protocol_start, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15971 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15972 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15973 | }, |
| 15974 | { |
| 15975 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15976 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15977 | .doit = nl80211_crit_protocol_stop, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15978 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15979 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15980 | }, |
| 15981 | { |
| 15982 | .cmd = NL80211_CMD_GET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15983 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15984 | .doit = nl80211_get_coalesce, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15985 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15986 | }, |
| 15987 | { |
| 15988 | .cmd = NL80211_CMD_SET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15989 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15990 | .doit = nl80211_set_coalesce, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15991 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15992 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15993 | }, |
| 15994 | { |
| 15995 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15996 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15997 | .doit = nl80211_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15998 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 15999 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 16000 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 16001 | { |
| 16002 | .cmd = NL80211_CMD_VENDOR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16003 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 16004 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 16005 | .dumpit = nl80211_vendor_cmd_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 16006 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 16007 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16008 | 0 | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 16009 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 16010 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 16011 | { |
| 16012 | .cmd = NL80211_CMD_SET_QOS_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16013 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 16014 | .doit = nl80211_set_qos_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 16015 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16016 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 16017 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 16018 | { |
| 16019 | .cmd = NL80211_CMD_ADD_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16020 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 16021 | .doit = nl80211_add_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 16022 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16023 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 16024 | }, |
| 16025 | { |
| 16026 | .cmd = NL80211_CMD_DEL_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16027 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 16028 | .doit = nl80211_del_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 16029 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 16031 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 16032 | { |
| 16033 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16034 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 16035 | .doit = nl80211_tdls_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 16036 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16037 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 16038 | }, |
| 16039 | { |
| 16040 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16041 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 16042 | .doit = nl80211_tdls_cancel_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 16043 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16044 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 16045 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 16046 | { |
| 16047 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16048 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 16049 | .doit = nl80211_set_multicast_to_unicast, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 16050 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16051 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 16052 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 16053 | { |
| 16054 | .cmd = NL80211_CMD_SET_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16055 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 16056 | .doit = nl80211_set_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 16057 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16058 | 0 | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 16059 | NL80211_FLAG_CLEAR_SKB, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 16060 | }, |
| 16061 | { |
| 16062 | .cmd = NL80211_CMD_DEL_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16063 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 16064 | .doit = nl80211_del_pmk, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16065 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 16066 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 16067 | { |
| 16068 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16069 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 16070 | .doit = nl80211_external_auth, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 16071 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16072 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 16073 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 16074 | { |
| 16075 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16076 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 16077 | .doit = nl80211_tx_control_port, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 16078 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16079 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 16080 | }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 16081 | { |
| 16082 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16083 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 16084 | .doit = nl80211_get_ftm_responder_stats, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16085 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 16086 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 16087 | { |
| 16088 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16089 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 16090 | .doit = nl80211_pmsr_start, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 16091 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16092 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 16093 | }, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 16094 | { |
| 16095 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 16096 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 16097 | .doit = nl80211_notify_radar_detection, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 16098 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16099 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 16100 | }, |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 16101 | { |
| 16102 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, |
| 16103 | .doit = nl80211_update_owe_info, |
| 16104 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16105 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 16106 | }, |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 16107 | { |
| 16108 | .cmd = NL80211_CMD_PROBE_MESH_LINK, |
| 16109 | .doit = nl80211_probe_mesh_link, |
| 16110 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16111 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 16112 | }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 16113 | { |
| 16114 | .cmd = NL80211_CMD_SET_TID_CONFIG, |
| 16115 | .doit = nl80211_set_tid_config, |
| 16116 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | a05829a | 2021-01-22 16:19:43 +0100 | [diff] [blame] | 16117 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 16118 | }, |
Carl Huang | 6bdb68c | 2020-12-03 05:37:26 -0500 | [diff] [blame] | 16119 | { |
| 16120 | .cmd = NL80211_CMD_SET_SAR_SPECS, |
| 16121 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| 16122 | .doit = nl80211_set_sar_specs, |
| 16123 | .flags = GENL_UNS_ADMIN_PERM, |
| 16124 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 16125 | NL80211_FLAG_NEED_RTNL, |
| 16126 | }, |
John Crispin | 0d2ab3ae | 2021-07-02 19:44:07 +0200 | [diff] [blame] | 16127 | { |
| 16128 | .cmd = NL80211_CMD_COLOR_CHANGE_REQUEST, |
| 16129 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| 16130 | .doit = nl80211_color_change, |
| 16131 | .flags = GENL_UNS_ADMIN_PERM, |
| 16132 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 16133 | NL80211_FLAG_NEED_RTNL, |
| 16134 | }, |
Subrat Mishra | e306784 | 2021-09-15 11:22:23 +0530 | [diff] [blame] | 16135 | { |
| 16136 | .cmd = NL80211_CMD_SET_FILS_AAD, |
| 16137 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
| 16138 | .doit = nl80211_set_fils_aad, |
| 16139 | .flags = GENL_UNS_ADMIN_PERM, |
| 16140 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP, |
| 16141 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16142 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16143 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 16144 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 16145 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 16146 | .hdrsize = 0, /* no private header */ |
| 16147 | .version = 1, /* no particular meaning now */ |
| 16148 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 3b0f31f | 2019-03-21 22:51:02 +0100 | [diff] [blame] | 16149 | .policy = nl80211_policy, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 16150 | .netnsok = true, |
| 16151 | .pre_doit = nl80211_pre_doit, |
| 16152 | .post_doit = nl80211_post_doit, |
| 16153 | .module = THIS_MODULE, |
| 16154 | .ops = nl80211_ops, |
| 16155 | .n_ops = ARRAY_SIZE(nl80211_ops), |
Jakub Kicinski | 66a9b92 | 2020-10-02 14:49:54 -0700 | [diff] [blame] | 16156 | .small_ops = nl80211_small_ops, |
| 16157 | .n_small_ops = ARRAY_SIZE(nl80211_small_ops), |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 16158 | .mcgrps = nl80211_mcgrps, |
| 16159 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 16160 | .parallel_ops = true, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 16161 | }; |
| 16162 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16163 | /* notification functions */ |
| 16164 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 16165 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 16166 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16167 | { |
| 16168 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 16169 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16170 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 16171 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 16172 | cmd != NL80211_CMD_DEL_WIPHY); |
| 16173 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16174 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16175 | if (!msg) |
| 16176 | return; |
| 16177 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 16178 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16179 | nlmsg_free(msg); |
| 16180 | return; |
| 16181 | } |
| 16182 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16183 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16184 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 16185 | } |
| 16186 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 16187 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 16188 | struct wireless_dev *wdev, |
| 16189 | enum nl80211_commands cmd) |
| 16190 | { |
| 16191 | struct sk_buff *msg; |
| 16192 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 16193 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16194 | if (!msg) |
| 16195 | return; |
| 16196 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 16197 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 16198 | nlmsg_free(msg); |
| 16199 | return; |
| 16200 | } |
| 16201 | |
| 16202 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16203 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 16204 | } |
| 16205 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16206 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 16207 | struct cfg80211_registered_device *rdev) |
| 16208 | { |
| 16209 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 16210 | struct nlattr *nest; |
| 16211 | int i; |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 16212 | struct cfg80211_scan_info *info; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16213 | |
| 16214 | if (WARN_ON(!req)) |
| 16215 | return 0; |
| 16216 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16217 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16218 | if (!nest) |
| 16219 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16220 | for (i = 0; i < req->n_ssids; i++) { |
| 16221 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 16222 | goto nla_put_failure; |
| 16223 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16224 | nla_nest_end(msg, nest); |
| 16225 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 16226 | if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { |
| 16227 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); |
| 16228 | if (!nest) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16229 | goto nla_put_failure; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 16230 | for (i = 0; i < req->n_channels; i++) { |
| 16231 | if (nla_put_u32(msg, i, |
| 16232 | ieee80211_channel_to_khz(req->channels[i]))) |
| 16233 | goto nla_put_failure; |
| 16234 | } |
| 16235 | nla_nest_end(msg, nest); |
| 16236 | } else { |
| 16237 | nest = nla_nest_start_noflag(msg, |
| 16238 | NL80211_ATTR_SCAN_FREQUENCIES); |
| 16239 | if (!nest) |
| 16240 | goto nla_put_failure; |
| 16241 | for (i = 0; i < req->n_channels; i++) { |
| 16242 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 16243 | goto nla_put_failure; |
| 16244 | } |
| 16245 | nla_nest_end(msg, nest); |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16246 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16247 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16248 | if (req->ie && |
| 16249 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 16250 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16251 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 16252 | if (req->flags && |
| 16253 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 16254 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 16255 | |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 16256 | info = rdev->int_scan_req ? &rdev->int_scan_req->info : |
| 16257 | &rdev->scan_req->info; |
| 16258 | if (info->scan_start_tsf && |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 16259 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 16260 | info->scan_start_tsf, NL80211_BSS_PAD) || |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 16261 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 16262 | info->tsf_bssid))) |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 16263 | goto nla_put_failure; |
| 16264 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16265 | return 0; |
| 16266 | nla_put_failure: |
| 16267 | return -ENOBUFS; |
| 16268 | } |
| 16269 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 16270 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16271 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 16272 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16273 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16274 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16275 | { |
| 16276 | void *hdr; |
| 16277 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16278 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16279 | if (!hdr) |
| 16280 | return -1; |
| 16281 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16282 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 16283 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16284 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16285 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16286 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16287 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16288 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 16289 | /* ignore errors and send incomplete event anyway */ |
| 16290 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16291 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 16292 | genlmsg_end(msg, hdr); |
| 16293 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16294 | |
| 16295 | nla_put_failure: |
| 16296 | genlmsg_cancel(msg, hdr); |
| 16297 | return -EMSGSIZE; |
| 16298 | } |
| 16299 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16300 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 16301 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 16302 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16303 | { |
| 16304 | void *hdr; |
| 16305 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 16306 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16307 | if (!hdr) |
| 16308 | return -1; |
| 16309 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 16310 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 16311 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 16312 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 16313 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 16314 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16315 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16316 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 16317 | genlmsg_end(msg, hdr); |
| 16318 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16319 | |
| 16320 | nla_put_failure: |
| 16321 | genlmsg_cancel(msg, hdr); |
| 16322 | return -EMSGSIZE; |
| 16323 | } |
| 16324 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16325 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 16326 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16327 | { |
| 16328 | struct sk_buff *msg; |
| 16329 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16330 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16331 | if (!msg) |
| 16332 | return; |
| 16333 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 16334 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16335 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 16336 | nlmsg_free(msg); |
| 16337 | return; |
| 16338 | } |
| 16339 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16340 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16341 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 16342 | } |
| 16343 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 16344 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 16345 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16346 | { |
| 16347 | struct sk_buff *msg; |
| 16348 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16349 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16350 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 16351 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16352 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 16353 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 16354 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 16355 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16356 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 16357 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16358 | } |
| 16359 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 16360 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16361 | } |
| 16362 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 16363 | /* send message created by nl80211_build_scan_msg() */ |
| 16364 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 16365 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16366 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16367 | if (!msg) |
| 16368 | return; |
| 16369 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16370 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16371 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16372 | } |
| 16373 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 16374 | 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] | 16375 | { |
| 16376 | struct sk_buff *msg; |
| 16377 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16378 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16379 | if (!msg) |
| 16380 | return; |
| 16381 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 16382 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16383 | nlmsg_free(msg); |
| 16384 | return; |
| 16385 | } |
| 16386 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 16387 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16388 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 16389 | } |
| 16390 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 16391 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 16392 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16393 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16394 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16395 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 16396 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16397 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16398 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 16399 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 16400 | NL80211_REGDOM_TYPE_WORLD)) |
| 16401 | goto nla_put_failure; |
| 16402 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 16403 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 16404 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 16405 | goto nla_put_failure; |
| 16406 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 16407 | request->intersect) { |
| 16408 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 16409 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 16410 | goto nla_put_failure; |
| 16411 | } else { |
| 16412 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 16413 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 16414 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 16415 | request->alpha2)) |
| 16416 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16417 | } |
| 16418 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 16419 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 16420 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 16421 | |
| 16422 | if (wiphy && |
| 16423 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 16424 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 16425 | |
| 16426 | if (wiphy && |
| 16427 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 16428 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 16429 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 16430 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16431 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 16432 | return true; |
| 16433 | |
| 16434 | nla_put_failure: |
| 16435 | return false; |
| 16436 | } |
| 16437 | |
| 16438 | /* |
| 16439 | * This can happen on global regulatory changes or device specific settings |
| 16440 | * based on custom regulatory domains. |
| 16441 | */ |
| 16442 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 16443 | struct regulatory_request *request) |
| 16444 | { |
| 16445 | struct sk_buff *msg; |
| 16446 | void *hdr; |
| 16447 | |
| 16448 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16449 | if (!msg) |
| 16450 | return; |
| 16451 | |
| 16452 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 16453 | if (!hdr) |
| 16454 | goto nla_put_failure; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 16455 | |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 16456 | if (!nl80211_reg_change_event_fill(msg, request)) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 16457 | goto nla_put_failure; |
| 16458 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16459 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16460 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 16461 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16462 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16463 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 16464 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16465 | |
| 16466 | return; |
| 16467 | |
| 16468 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 16469 | nlmsg_free(msg); |
| 16470 | } |
| 16471 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16472 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 16473 | struct net_device *netdev, |
| 16474 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 16475 | enum nl80211_commands cmd, gfp_t gfp, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 16476 | int uapsd_queues, const u8 *req_ies, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16477 | size_t req_ies_len, bool reconnect) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16478 | { |
| 16479 | struct sk_buff *msg; |
| 16480 | void *hdr; |
| 16481 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 16482 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16483 | if (!msg) |
| 16484 | return; |
| 16485 | |
| 16486 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16487 | if (!hdr) { |
| 16488 | nlmsg_free(msg); |
| 16489 | return; |
| 16490 | } |
| 16491 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16492 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16493 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 16494 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16495 | (req_ies && |
| 16496 | 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] | 16497 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16498 | |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16499 | if (reconnect && nla_put_flag(msg, NL80211_ATTR_RECONNECT_REQUESTED)) |
| 16500 | goto nla_put_failure; |
| 16501 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 16502 | if (uapsd_queues >= 0) { |
| 16503 | struct nlattr *nla_wmm = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16504 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 16505 | if (!nla_wmm) |
| 16506 | goto nla_put_failure; |
| 16507 | |
| 16508 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 16509 | uapsd_queues)) |
| 16510 | goto nla_put_failure; |
| 16511 | |
| 16512 | nla_nest_end(msg, nla_wmm); |
| 16513 | } |
| 16514 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16515 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16516 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16517 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16518 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16519 | return; |
| 16520 | |
| 16521 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16522 | nlmsg_free(msg); |
| 16523 | } |
| 16524 | |
| 16525 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16526 | struct net_device *netdev, const u8 *buf, |
| 16527 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16528 | { |
| 16529 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16530 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0, |
| 16531 | false); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16532 | } |
| 16533 | |
| 16534 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 16535 | struct net_device *netdev, const u8 *buf, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 16536 | size_t len, gfp_t gfp, int uapsd_queues, |
| 16537 | const u8 *req_ies, size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16538 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16539 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 16540 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16541 | req_ies, req_ies_len, false); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16542 | } |
| 16543 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 16544 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16545 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16546 | size_t len, bool reconnect, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16547 | { |
| 16548 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16549 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0, |
| 16550 | reconnect); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16551 | } |
| 16552 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 16553 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 16554 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16555 | size_t len, bool reconnect, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16556 | { |
| 16557 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16558 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0, |
| 16559 | reconnect); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 16560 | } |
| 16561 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16562 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 16563 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 16564 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16565 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16566 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16567 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16568 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 16569 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 16570 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16571 | if (WARN_ON(len < 2)) |
| 16572 | return; |
| 16573 | |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 16574 | if (ieee80211_is_deauth(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16575 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 16576 | } else if (ieee80211_is_disassoc(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16577 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 16578 | } else if (ieee80211_is_beacon(mgmt->frame_control)) { |
| 16579 | if (wdev->unprot_beacon_reported && |
| 16580 | elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) |
| 16581 | return; |
| 16582 | cmd = NL80211_CMD_UNPROT_BEACON; |
| 16583 | wdev->unprot_beacon_reported = jiffies; |
| 16584 | } else { |
| 16585 | return; |
| 16586 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16587 | |
| 16588 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 16589 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
Johannes Berg | 3bb0214 | 2020-12-06 14:54:42 +0200 | [diff] [blame] | 16590 | NULL, 0, false); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 16591 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 16592 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 16593 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 16594 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 16595 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16596 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16597 | { |
| 16598 | struct sk_buff *msg; |
| 16599 | void *hdr; |
| 16600 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16601 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16602 | if (!msg) |
| 16603 | return; |
| 16604 | |
| 16605 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16606 | if (!hdr) { |
| 16607 | nlmsg_free(msg); |
| 16608 | return; |
| 16609 | } |
| 16610 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16611 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16612 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16613 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 16614 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16615 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16616 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16617 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16618 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16619 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16620 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16621 | return; |
| 16622 | |
| 16623 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16624 | nlmsg_free(msg); |
| 16625 | } |
| 16626 | |
| 16627 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16628 | struct net_device *netdev, const u8 *addr, |
| 16629 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16630 | { |
| 16631 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16632 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16633 | } |
| 16634 | |
| 16635 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16636 | struct net_device *netdev, const u8 *addr, |
| 16637 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16638 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16639 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 16640 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16641 | } |
| 16642 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16643 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16644 | struct net_device *netdev, |
| 16645 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 16646 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16647 | { |
| 16648 | struct sk_buff *msg; |
| 16649 | void *hdr; |
| 16650 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16651 | 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] | 16652 | cr->fils.kek_len + cr->fils.pmk_len + |
| 16653 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16654 | if (!msg) |
| 16655 | return; |
| 16656 | |
| 16657 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 16658 | if (!hdr) { |
| 16659 | nlmsg_free(msg); |
| 16660 | return; |
| 16661 | } |
| 16662 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16663 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16664 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16665 | (cr->bssid && |
| 16666 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 16667 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16668 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 16669 | cr->status) || |
| 16670 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 16671 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16672 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 16673 | cr->timeout_reason))) || |
| 16674 | (cr->req_ie && |
| 16675 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 16676 | (cr->resp_ie && |
| 16677 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16678 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 16679 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16680 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 16681 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16682 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 16683 | ((cr->fils.kek && |
| 16684 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 16685 | cr->fils.kek)) || |
| 16686 | (cr->fils.pmk && |
| 16687 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 16688 | (cr->fils.pmkid && |
| 16689 | 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] | 16690 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16691 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16692 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16693 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16694 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16695 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16696 | return; |
| 16697 | |
| 16698 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16699 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16700 | } |
| 16701 | |
| 16702 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 16703 | struct net_device *netdev, |
| 16704 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16705 | { |
| 16706 | struct sk_buff *msg; |
| 16707 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 16708 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16709 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 16710 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 16711 | info->fils.kek_len + info->fils.pmk_len + |
| 16712 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16713 | if (!msg) |
| 16714 | return; |
| 16715 | |
| 16716 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 16717 | if (!hdr) { |
| 16718 | nlmsg_free(msg); |
| 16719 | return; |
| 16720 | } |
| 16721 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16722 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16723 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16724 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 16725 | (info->req_ie && |
| 16726 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 16727 | info->req_ie)) || |
| 16728 | (info->resp_ie && |
| 16729 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 16730 | info->resp_ie)) || |
| 16731 | (info->fils.update_erp_next_seq_num && |
| 16732 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 16733 | info->fils.erp_next_seq_num)) || |
| 16734 | (info->fils.kek && |
| 16735 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 16736 | info->fils.kek)) || |
| 16737 | (info->fils.pmk && |
| 16738 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 16739 | (info->fils.pmkid && |
| 16740 | 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] | 16741 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16742 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16743 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16744 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16745 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16746 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16747 | return; |
| 16748 | |
| 16749 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16750 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16751 | } |
| 16752 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16753 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 16754 | struct net_device *netdev, const u8 *bssid) |
| 16755 | { |
| 16756 | struct sk_buff *msg; |
| 16757 | void *hdr; |
| 16758 | |
| 16759 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16760 | if (!msg) |
| 16761 | return; |
| 16762 | |
| 16763 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 16764 | if (!hdr) { |
| 16765 | nlmsg_free(msg); |
| 16766 | return; |
| 16767 | } |
| 16768 | |
Chung-Hsien Hsu | f4d7599 | 2019-05-09 09:48:25 +0000 | [diff] [blame] | 16769 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16770 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16771 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16772 | goto nla_put_failure; |
| 16773 | |
| 16774 | genlmsg_end(msg, hdr); |
| 16775 | |
| 16776 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16777 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16778 | return; |
| 16779 | |
| 16780 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16781 | nlmsg_free(msg); |
| 16782 | } |
| 16783 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16784 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 16785 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 16786 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16787 | { |
| 16788 | struct sk_buff *msg; |
| 16789 | void *hdr; |
| 16790 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16791 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16792 | if (!msg) |
| 16793 | return; |
| 16794 | |
| 16795 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 16796 | if (!hdr) { |
| 16797 | nlmsg_free(msg); |
| 16798 | return; |
| 16799 | } |
| 16800 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16801 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16802 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 16803 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16804 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 16805 | (from_ap && |
| 16806 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 16807 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 16808 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16809 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16810 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16811 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16812 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16813 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16814 | return; |
| 16815 | |
| 16816 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16817 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16818 | } |
| 16819 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16820 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 16821 | struct net_device *netdev, const u8 *bssid, |
| 16822 | gfp_t gfp) |
| 16823 | { |
| 16824 | struct sk_buff *msg; |
| 16825 | void *hdr; |
| 16826 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16828 | if (!msg) |
| 16829 | return; |
| 16830 | |
| 16831 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 16832 | if (!hdr) { |
| 16833 | nlmsg_free(msg); |
| 16834 | return; |
| 16835 | } |
| 16836 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16837 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16838 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16839 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16840 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16841 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16842 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16843 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16844 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16845 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16846 | return; |
| 16847 | |
| 16848 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16849 | nlmsg_free(msg); |
| 16850 | } |
| 16851 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16852 | 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] | 16853 | const u8 *ie, u8 ie_len, |
| 16854 | int sig_dbm, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16855 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16856 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16857 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16858 | struct sk_buff *msg; |
| 16859 | void *hdr; |
| 16860 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16861 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 16862 | return; |
| 16863 | |
| 16864 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 16865 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16866 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16867 | if (!msg) |
| 16868 | return; |
| 16869 | |
| 16870 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 16871 | if (!hdr) { |
| 16872 | nlmsg_free(msg); |
| 16873 | return; |
| 16874 | } |
| 16875 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16876 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16877 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16878 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16879 | (ie_len && ie && |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 16880 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 16881 | (sig_dbm && |
| 16882 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16883 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16884 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16885 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16886 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16887 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16888 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16889 | return; |
| 16890 | |
| 16891 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16892 | nlmsg_free(msg); |
| 16893 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16894 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16895 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16896 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 16897 | struct net_device *netdev, const u8 *addr, |
| 16898 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16899 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16900 | { |
| 16901 | struct sk_buff *msg; |
| 16902 | void *hdr; |
| 16903 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16904 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16905 | if (!msg) |
| 16906 | return; |
| 16907 | |
| 16908 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 16909 | if (!hdr) { |
| 16910 | nlmsg_free(msg); |
| 16911 | return; |
| 16912 | } |
| 16913 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16914 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16915 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16916 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 16917 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 16918 | (key_id != -1 && |
| 16919 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 16920 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 16921 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16922 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16923 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16924 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16925 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16926 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16927 | return; |
| 16928 | |
| 16929 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16930 | nlmsg_free(msg); |
| 16931 | } |
| 16932 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16933 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 16934 | struct ieee80211_channel *channel_before, |
| 16935 | struct ieee80211_channel *channel_after) |
| 16936 | { |
| 16937 | struct sk_buff *msg; |
| 16938 | void *hdr; |
| 16939 | struct nlattr *nl_freq; |
| 16940 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16941 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16942 | if (!msg) |
| 16943 | return; |
| 16944 | |
| 16945 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 16946 | if (!hdr) { |
| 16947 | nlmsg_free(msg); |
| 16948 | return; |
| 16949 | } |
| 16950 | |
| 16951 | /* |
| 16952 | * Since we are applying the beacon hint to a wiphy we know its |
| 16953 | * wiphy_idx is valid |
| 16954 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16955 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 16956 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16957 | |
| 16958 | /* Before */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16959 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16960 | if (!nl_freq) |
| 16961 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16962 | |
| 16963 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16964 | goto nla_put_failure; |
| 16965 | nla_nest_end(msg, nl_freq); |
| 16966 | |
| 16967 | /* After */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16968 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16969 | if (!nl_freq) |
| 16970 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16971 | |
| 16972 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16973 | goto nla_put_failure; |
| 16974 | nla_nest_end(msg, nl_freq); |
| 16975 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16976 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16977 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16978 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16979 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16980 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16981 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16982 | |
| 16983 | return; |
| 16984 | |
| 16985 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16986 | nlmsg_free(msg); |
| 16987 | } |
| 16988 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16989 | static void nl80211_send_remain_on_chan_event( |
| 16990 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16991 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16992 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16993 | unsigned int duration, gfp_t gfp) |
| 16994 | { |
| 16995 | struct sk_buff *msg; |
| 16996 | void *hdr; |
| 16997 | |
| 16998 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16999 | if (!msg) |
| 17000 | return; |
| 17001 | |
| 17002 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 17003 | if (!hdr) { |
| 17004 | nlmsg_free(msg); |
| 17005 | return; |
| 17006 | } |
| 17007 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17008 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 17009 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17010 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17011 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17012 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17013 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 17014 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 17015 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17016 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 17017 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17018 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17019 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17020 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 17021 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 17022 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17023 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 17024 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17025 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17026 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17027 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17028 | return; |
| 17029 | |
| 17030 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17031 | nlmsg_free(msg); |
| 17032 | } |
| 17033 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17034 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 17035 | struct ieee80211_channel *chan, |
| 17036 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17037 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17038 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17039 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17040 | |
| 17041 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17042 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 17043 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 17044 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17045 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17046 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17047 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17048 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 17049 | struct ieee80211_channel *chan, |
| 17050 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17051 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17052 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17053 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17054 | |
| 17055 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17056 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 17057 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17058 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17059 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 17060 | |
James Prestwood | 1c38c7f | 2019-06-12 12:35:09 -0700 | [diff] [blame] | 17061 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
| 17062 | struct ieee80211_channel *chan, |
| 17063 | gfp_t gfp) |
| 17064 | { |
| 17065 | struct wiphy *wiphy = wdev->wiphy; |
| 17066 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17067 | |
| 17068 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); |
| 17069 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, |
| 17070 | rdev, wdev, cookie, chan, 0, gfp); |
| 17071 | } |
| 17072 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); |
| 17073 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17074 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 17075 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 17076 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17077 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17078 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 17079 | struct sk_buff *msg; |
| 17080 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17081 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 17082 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17083 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 17084 | if (!msg) |
| 17085 | return; |
| 17086 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 17087 | 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] | 17088 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 17089 | nlmsg_free(msg); |
| 17090 | return; |
| 17091 | } |
| 17092 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17093 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17094 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 17095 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17096 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 17097 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 17098 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 17099 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17100 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17101 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17102 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17103 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 17104 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 17105 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 17106 | if (!sinfo) |
| 17107 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17108 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17109 | trace_cfg80211_del_sta(dev, mac_addr); |
| 17110 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17111 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 17112 | if (!msg) { |
| 17113 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 17114 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 17115 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17116 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 17117 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 17118 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17119 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 17120 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17121 | } |
| 17122 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17123 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17124 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17125 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 17126 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 17127 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17128 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 17129 | enum nl80211_connect_failed_reason reason, |
| 17130 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 17131 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17132 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17133 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 17134 | struct sk_buff *msg; |
| 17135 | void *hdr; |
| 17136 | |
| 17137 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 17138 | if (!msg) |
| 17139 | return; |
| 17140 | |
| 17141 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 17142 | if (!hdr) { |
| 17143 | nlmsg_free(msg); |
| 17144 | return; |
| 17145 | } |
| 17146 | |
| 17147 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17148 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 17149 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 17150 | goto nla_put_failure; |
| 17151 | |
| 17152 | genlmsg_end(msg, hdr); |
| 17153 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17154 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17155 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 17156 | return; |
| 17157 | |
| 17158 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 17159 | nlmsg_free(msg); |
| 17160 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17161 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 17162 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 17163 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 17164 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17165 | { |
| 17166 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17167 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17168 | struct sk_buff *msg; |
| 17169 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 17170 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17171 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17172 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17173 | return false; |
| 17174 | |
| 17175 | msg = nlmsg_new(100, gfp); |
| 17176 | if (!msg) |
| 17177 | return true; |
| 17178 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 17179 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17180 | if (!hdr) { |
| 17181 | nlmsg_free(msg); |
| 17182 | return true; |
| 17183 | } |
| 17184 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17185 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17186 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17187 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 17188 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17189 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17190 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17191 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17192 | return true; |
| 17193 | |
| 17194 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 17195 | nlmsg_free(msg); |
| 17196 | return true; |
| 17197 | } |
| 17198 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17199 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 17200 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 17201 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17202 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17203 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 17204 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17205 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 17206 | |
| 17207 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 17208 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 17209 | trace_cfg80211_return_bool(false); |
| 17210 | return false; |
| 17211 | } |
| 17212 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 17213 | addr, gfp); |
| 17214 | trace_cfg80211_return_bool(ret); |
| 17215 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 17216 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17217 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 17218 | |
| 17219 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 17220 | const u8 *addr, gfp_t gfp) |
| 17221 | { |
| 17222 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17223 | bool ret; |
| 17224 | |
| 17225 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 17226 | |
| 17227 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 17228 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 17229 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 17230 | trace_cfg80211_return_bool(false); |
| 17231 | return false; |
| 17232 | } |
| 17233 | ret = __nl80211_unexpected_frame(dev, |
| 17234 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 17235 | addr, gfp); |
| 17236 | trace_cfg80211_return_bool(ret); |
| 17237 | return ret; |
| 17238 | } |
| 17239 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 17240 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 17241 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17242 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 17243 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 17244 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17245 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 17246 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17247 | struct sk_buff *msg; |
| 17248 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17249 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 17250 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17251 | if (!msg) |
| 17252 | return -ENOMEM; |
| 17253 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 17254 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17255 | if (!hdr) { |
| 17256 | nlmsg_free(msg); |
| 17257 | return -ENOMEM; |
| 17258 | } |
| 17259 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17260 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 17261 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17262 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17263 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17264 | NL80211_ATTR_PAD) || |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17265 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 17266 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17267 | (sig_dbm && |
| 17268 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 17269 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 17270 | (flags && |
| 17271 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17272 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17273 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 17274 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17275 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17276 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17277 | |
| 17278 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17279 | nlmsg_free(msg); |
| 17280 | return -ENOBUFS; |
| 17281 | } |
| 17282 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 17283 | static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 17284 | const u8 *buf, size_t len, bool ack, |
| 17285 | gfp_t gfp, enum nl80211_commands command) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17286 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17287 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17288 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 17289 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17290 | struct sk_buff *msg; |
| 17291 | void *hdr; |
| 17292 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 17293 | if (command == NL80211_CMD_FRAME_TX_STATUS) |
| 17294 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 17295 | else |
| 17296 | trace_cfg80211_control_port_tx_status(wdev, cookie, ack); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17297 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 17298 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17299 | if (!msg) |
| 17300 | return; |
| 17301 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 17302 | hdr = nl80211hdr_put(msg, 0, 0, 0, command); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17303 | if (!hdr) { |
| 17304 | nlmsg_free(msg); |
| 17305 | return; |
| 17306 | } |
| 17307 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17308 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 17309 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17310 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17311 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17312 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17313 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17314 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 17315 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17316 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 17317 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17318 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 17319 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17320 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17321 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17322 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17323 | return; |
| 17324 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 17325 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17326 | nlmsg_free(msg); |
| 17327 | } |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 17328 | |
| 17329 | void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 17330 | const u8 *buf, size_t len, bool ack, |
| 17331 | gfp_t gfp) |
| 17332 | { |
| 17333 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 17334 | NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); |
| 17335 | } |
| 17336 | EXPORT_SYMBOL(cfg80211_control_port_tx_status); |
| 17337 | |
| 17338 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 17339 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
| 17340 | { |
| 17341 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 17342 | NL80211_CMD_FRAME_TX_STATUS); |
| 17343 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17344 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17345 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17346 | static int __nl80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17347 | struct sk_buff *skb, |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17348 | bool unencrypted, gfp_t gfp) |
| 17349 | { |
| 17350 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17351 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17352 | struct ethhdr *ehdr = eth_hdr(skb); |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 17353 | const u8 *addr = ehdr->h_source; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17354 | u16 proto = be16_to_cpu(skb->protocol); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17355 | struct sk_buff *msg; |
| 17356 | void *hdr; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17357 | struct nlattr *frame; |
| 17358 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17359 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 17360 | |
| 17361 | if (!nlportid) |
| 17362 | return -ENOENT; |
| 17363 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17364 | msg = nlmsg_new(100 + skb->len, gfp); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17365 | if (!msg) |
| 17366 | return -ENOMEM; |
| 17367 | |
| 17368 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 17369 | if (!hdr) { |
| 17370 | nlmsg_free(msg); |
| 17371 | return -ENOBUFS; |
| 17372 | } |
| 17373 | |
| 17374 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17375 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17376 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17377 | NL80211_ATTR_PAD) || |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 17378 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17379 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 17380 | (unencrypted && nla_put_flag(msg, |
| 17381 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 17382 | goto nla_put_failure; |
| 17383 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17384 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 17385 | if (!frame) |
| 17386 | goto nla_put_failure; |
| 17387 | |
| 17388 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17389 | genlmsg_end(msg, hdr); |
| 17390 | |
| 17391 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 17392 | |
| 17393 | nla_put_failure: |
| 17394 | nlmsg_free(msg); |
| 17395 | return -ENOBUFS; |
| 17396 | } |
| 17397 | |
| 17398 | bool cfg80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17399 | struct sk_buff *skb, bool unencrypted) |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17400 | { |
| 17401 | int ret; |
| 17402 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 17403 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 17404 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 17405 | trace_cfg80211_return_bool(ret == 0); |
| 17406 | return ret == 0; |
| 17407 | } |
| 17408 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 17409 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17410 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 17411 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17412 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17413 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17414 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17415 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17416 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17417 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17418 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17419 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17420 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17421 | cb = (void **)msg->cb; |
| 17422 | |
| 17423 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 17424 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17425 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17426 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17427 | } |
| 17428 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17429 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17430 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17431 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17432 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17433 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17434 | goto nla_put_failure; |
| 17435 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17436 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17437 | if (!cb[1]) |
| 17438 | goto nla_put_failure; |
| 17439 | |
| 17440 | cb[2] = rdev; |
| 17441 | |
| 17442 | return msg; |
| 17443 | nla_put_failure: |
| 17444 | nlmsg_free(msg); |
| 17445 | return NULL; |
| 17446 | } |
| 17447 | |
| 17448 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 17449 | { |
| 17450 | void **cb = (void **)msg->cb; |
| 17451 | struct cfg80211_registered_device *rdev = cb[2]; |
| 17452 | |
| 17453 | nla_nest_end(msg, cb[1]); |
| 17454 | genlmsg_end(msg, cb[0]); |
| 17455 | |
| 17456 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 17457 | |
| 17458 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17459 | NL80211_MCGRP_MLME, gfp); |
| 17460 | } |
| 17461 | |
| 17462 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 17463 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 17464 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17465 | { |
| 17466 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 17467 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17468 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17469 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 17470 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17471 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 17472 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 17473 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 17474 | return; |
| 17475 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 17476 | if (wdev->cqm_config) { |
| 17477 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 17478 | |
| 17479 | cfg80211_cqm_rssi_update(rdev, dev); |
| 17480 | |
| 17481 | if (rssi_level == 0) |
| 17482 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 17483 | } |
| 17484 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17485 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 17486 | if (!msg) |
| 17487 | return; |
| 17488 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17489 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 17490 | rssi_event)) |
| 17491 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17492 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 17493 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 17494 | rssi_level)) |
| 17495 | goto nla_put_failure; |
| 17496 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17497 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17498 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17499 | return; |
| 17500 | |
| 17501 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17502 | nlmsg_free(msg); |
| 17503 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17504 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 17505 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 17506 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 17507 | const u8 *peer, u32 num_packets, |
| 17508 | u32 rate, u32 intvl, gfp_t gfp) |
| 17509 | { |
| 17510 | struct sk_buff *msg; |
| 17511 | |
| 17512 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 17513 | if (!msg) |
| 17514 | return; |
| 17515 | |
| 17516 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 17517 | goto nla_put_failure; |
| 17518 | |
| 17519 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 17520 | goto nla_put_failure; |
| 17521 | |
| 17522 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 17523 | goto nla_put_failure; |
| 17524 | |
| 17525 | cfg80211_send_cqm(msg, gfp); |
| 17526 | return; |
| 17527 | |
| 17528 | nla_put_failure: |
| 17529 | nlmsg_free(msg); |
| 17530 | } |
| 17531 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 17532 | |
| 17533 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 17534 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 17535 | { |
| 17536 | struct sk_buff *msg; |
| 17537 | |
| 17538 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 17539 | |
| 17540 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 17541 | if (!msg) |
| 17542 | return; |
| 17543 | |
| 17544 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 17545 | goto nla_put_failure; |
| 17546 | |
| 17547 | cfg80211_send_cqm(msg, gfp); |
| 17548 | return; |
| 17549 | |
| 17550 | nla_put_failure: |
| 17551 | nlmsg_free(msg); |
| 17552 | } |
| 17553 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 17554 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 17555 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 17556 | { |
| 17557 | struct sk_buff *msg; |
| 17558 | |
| 17559 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 17560 | if (!msg) |
| 17561 | return; |
| 17562 | |
| 17563 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 17564 | goto nla_put_failure; |
| 17565 | |
| 17566 | cfg80211_send_cqm(msg, gfp); |
| 17567 | return; |
| 17568 | |
| 17569 | nla_put_failure: |
| 17570 | nlmsg_free(msg); |
| 17571 | } |
| 17572 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 17573 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17574 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 17575 | struct net_device *netdev, const u8 *bssid, |
| 17576 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17577 | { |
| 17578 | struct sk_buff *msg; |
| 17579 | struct nlattr *rekey_attr; |
| 17580 | void *hdr; |
| 17581 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17582 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17583 | if (!msg) |
| 17584 | return; |
| 17585 | |
| 17586 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 17587 | if (!hdr) { |
| 17588 | nlmsg_free(msg); |
| 17589 | return; |
| 17590 | } |
| 17591 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17592 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17593 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17594 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 17595 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17596 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17597 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17598 | if (!rekey_attr) |
| 17599 | goto nla_put_failure; |
| 17600 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17601 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 17602 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 17603 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17604 | |
| 17605 | nla_nest_end(msg, rekey_attr); |
| 17606 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 17607 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17608 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17609 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17610 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17611 | return; |
| 17612 | |
| 17613 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 17614 | nlmsg_free(msg); |
| 17615 | } |
| 17616 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17617 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 17618 | const u8 *replay_ctr, gfp_t gfp) |
| 17619 | { |
| 17620 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17621 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17622 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17623 | |
| 17624 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 17625 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 17626 | } |
| 17627 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 17628 | |
| 17629 | static void |
| 17630 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 17631 | struct net_device *netdev, int index, |
| 17632 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17633 | { |
| 17634 | struct sk_buff *msg; |
| 17635 | struct nlattr *attr; |
| 17636 | void *hdr; |
| 17637 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17638 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17639 | if (!msg) |
| 17640 | return; |
| 17641 | |
| 17642 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 17643 | if (!hdr) { |
| 17644 | nlmsg_free(msg); |
| 17645 | return; |
| 17646 | } |
| 17647 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17648 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17649 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 17650 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17651 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17652 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17653 | if (!attr) |
| 17654 | goto nla_put_failure; |
| 17655 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17656 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 17657 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 17658 | (preauth && |
| 17659 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 17660 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17661 | |
| 17662 | nla_nest_end(msg, attr); |
| 17663 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 17664 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17665 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17666 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17667 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17668 | return; |
| 17669 | |
| 17670 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17671 | nlmsg_free(msg); |
| 17672 | } |
| 17673 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17674 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 17675 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 17676 | { |
| 17677 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17678 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17679 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17680 | |
| 17681 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 17682 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 17683 | } |
| 17684 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 17685 | |
| 17686 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 17687 | struct net_device *netdev, |
| 17688 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17689 | gfp_t gfp, |
| 17690 | enum nl80211_commands notif, |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 17691 | u8 count, bool quiet) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17692 | { |
| 17693 | struct sk_buff *msg; |
| 17694 | void *hdr; |
| 17695 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17697 | if (!msg) |
| 17698 | return; |
| 17699 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17700 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17701 | if (!hdr) { |
| 17702 | nlmsg_free(msg); |
| 17703 | return; |
| 17704 | } |
| 17705 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 17706 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 17707 | goto nla_put_failure; |
| 17708 | |
| 17709 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 17710 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17711 | |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 17712 | if (notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) { |
| 17713 | if (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)) |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17714 | goto nla_put_failure; |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 17715 | if (quiet && |
| 17716 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)) |
| 17717 | goto nla_put_failure; |
| 17718 | } |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17719 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17720 | genlmsg_end(msg, hdr); |
| 17721 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17722 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17723 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17724 | return; |
| 17725 | |
| 17726 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17727 | nlmsg_free(msg); |
| 17728 | } |
| 17729 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17730 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 17731 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 17732 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17733 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17734 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17735 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17736 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 17737 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17738 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 17739 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17740 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 17741 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 17742 | wdev->preset_chandef = *chandef; |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 17743 | |
| 17744 | if (wdev->iftype == NL80211_IFTYPE_STATION && |
| 17745 | !WARN_ON(!wdev->current_bss)) |
Sergey Matyukevich | 0afd425 | 2019-07-26 16:39:34 +0000 | [diff] [blame] | 17746 | cfg80211_update_assoc_bss_entry(wdev, chandef->chan); |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 17747 | |
Michael Vassernis | d34990b | 2019-07-29 06:01:16 +0000 | [diff] [blame] | 17748 | cfg80211_sched_dfs_chan_update(rdev); |
| 17749 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17750 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 17751 | NL80211_CMD_CH_SWITCH_NOTIFY, 0, false); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17752 | } |
| 17753 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 17754 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17755 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 17756 | struct cfg80211_chan_def *chandef, |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 17757 | u8 count, bool quiet) |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17758 | { |
| 17759 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17760 | struct wiphy *wiphy = wdev->wiphy; |
| 17761 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17762 | |
| 17763 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 17764 | |
| 17765 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
Johannes Berg | 669b841 | 2020-11-29 17:30:55 +0200 | [diff] [blame] | 17766 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, |
| 17767 | count, quiet); |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17768 | } |
| 17769 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 17770 | |
John Crispin | 0d2ab3ae | 2021-07-02 19:44:07 +0200 | [diff] [blame] | 17771 | int cfg80211_bss_color_notify(struct net_device *dev, gfp_t gfp, |
| 17772 | enum nl80211_commands cmd, u8 count, |
| 17773 | u64 color_bitmap) |
| 17774 | { |
| 17775 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17776 | struct wiphy *wiphy = wdev->wiphy; |
| 17777 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17778 | struct sk_buff *msg; |
| 17779 | void *hdr; |
| 17780 | |
| 17781 | ASSERT_WDEV_LOCK(wdev); |
| 17782 | |
| 17783 | trace_cfg80211_bss_color_notify(dev, cmd, count, color_bitmap); |
| 17784 | |
| 17785 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17786 | if (!msg) |
| 17787 | return -ENOMEM; |
| 17788 | |
| 17789 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 17790 | if (!hdr) |
| 17791 | goto nla_put_failure; |
| 17792 | |
| 17793 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 17794 | goto nla_put_failure; |
| 17795 | |
| 17796 | if (cmd == NL80211_CMD_COLOR_CHANGE_STARTED && |
| 17797 | nla_put_u32(msg, NL80211_ATTR_COLOR_CHANGE_COUNT, count)) |
| 17798 | goto nla_put_failure; |
| 17799 | |
| 17800 | if (cmd == NL80211_CMD_OBSS_COLOR_COLLISION && |
| 17801 | nla_put_u64_64bit(msg, NL80211_ATTR_OBSS_COLOR_BITMAP, |
| 17802 | color_bitmap, NL80211_ATTR_PAD)) |
| 17803 | goto nla_put_failure; |
| 17804 | |
| 17805 | genlmsg_end(msg, hdr); |
| 17806 | |
| 17807 | return genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 17808 | msg, 0, NL80211_MCGRP_MLME, gfp); |
| 17809 | |
| 17810 | nla_put_failure: |
| 17811 | nlmsg_free(msg); |
| 17812 | return -EINVAL; |
| 17813 | } |
| 17814 | EXPORT_SYMBOL(cfg80211_bss_color_notify); |
| 17815 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 17816 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17817 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 17818 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17819 | enum nl80211_radar_event event, |
| 17820 | struct net_device *netdev, gfp_t gfp) |
| 17821 | { |
| 17822 | struct sk_buff *msg; |
| 17823 | void *hdr; |
| 17824 | |
| 17825 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17826 | if (!msg) |
| 17827 | return; |
| 17828 | |
| 17829 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 17830 | if (!hdr) { |
| 17831 | nlmsg_free(msg); |
| 17832 | return; |
| 17833 | } |
| 17834 | |
| 17835 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17836 | goto nla_put_failure; |
| 17837 | |
| 17838 | /* NOP and radar events don't need a netdev parameter */ |
| 17839 | if (netdev) { |
| 17840 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 17841 | |
| 17842 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17843 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17844 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17845 | goto nla_put_failure; |
| 17846 | } |
| 17847 | |
| 17848 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 17849 | goto nla_put_failure; |
| 17850 | |
| 17851 | if (nl80211_send_chandef(msg, chandef)) |
| 17852 | goto nla_put_failure; |
| 17853 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17854 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17855 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17856 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17857 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17858 | return; |
| 17859 | |
| 17860 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17861 | nlmsg_free(msg); |
| 17862 | } |
| 17863 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 17864 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 17865 | struct sta_opmode_info *sta_opmode, |
| 17866 | gfp_t gfp) |
| 17867 | { |
| 17868 | struct sk_buff *msg; |
| 17869 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17870 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17871 | void *hdr; |
| 17872 | |
| 17873 | if (WARN_ON(!mac)) |
| 17874 | return; |
| 17875 | |
| 17876 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17877 | if (!msg) |
| 17878 | return; |
| 17879 | |
| 17880 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 17881 | if (!hdr) { |
| 17882 | nlmsg_free(msg); |
| 17883 | return; |
| 17884 | } |
| 17885 | |
| 17886 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17887 | goto nla_put_failure; |
| 17888 | |
| 17889 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 17890 | goto nla_put_failure; |
| 17891 | |
| 17892 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 17893 | goto nla_put_failure; |
| 17894 | |
| 17895 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 17896 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 17897 | goto nla_put_failure; |
| 17898 | |
| 17899 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
Johannes Berg | 0016d32 | 2020-03-25 09:05:32 +0100 | [diff] [blame] | 17900 | nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 17901 | goto nla_put_failure; |
| 17902 | |
| 17903 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 17904 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 17905 | goto nla_put_failure; |
| 17906 | |
| 17907 | genlmsg_end(msg, hdr); |
| 17908 | |
| 17909 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17910 | NL80211_MCGRP_MLME, gfp); |
| 17911 | |
| 17912 | return; |
| 17913 | |
| 17914 | nla_put_failure: |
| 17915 | nlmsg_free(msg); |
| 17916 | } |
| 17917 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 17918 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17919 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 17920 | u64 cookie, bool acked, s32 ack_signal, |
| 17921 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17922 | { |
| 17923 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17924 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17925 | struct sk_buff *msg; |
| 17926 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17927 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17928 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 17929 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17930 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17931 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17932 | if (!msg) |
| 17933 | return; |
| 17934 | |
| 17935 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 17936 | if (!hdr) { |
| 17937 | nlmsg_free(msg); |
| 17938 | return; |
| 17939 | } |
| 17940 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17942 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17943 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17944 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 17945 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 17946 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 17947 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 17948 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17949 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17950 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17951 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17952 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17953 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17954 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17955 | return; |
| 17956 | |
| 17957 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17958 | nlmsg_free(msg); |
| 17959 | } |
| 17960 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 17961 | |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17962 | void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, |
| 17963 | size_t len, int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17964 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17965 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17966 | struct sk_buff *msg; |
| 17967 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17968 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17969 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17970 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 17971 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17972 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17973 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 17974 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 17975 | if (!msg) { |
| 17976 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17977 | return; |
| 17978 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17979 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17980 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 17981 | if (!hdr) |
| 17982 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17983 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17985 | (freq && |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 17986 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 17987 | KHZ_TO_MHZ(freq)) || |
| 17988 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 17989 | freq % 1000))) || |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17990 | (sig_dbm && |
| 17991 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 17992 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 17993 | goto nla_put_failure; |
| 17994 | |
| 17995 | genlmsg_end(msg, hdr); |
| 17996 | |
| 17997 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17998 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17999 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 18000 | return; |
| 18001 | |
| 18002 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 18003 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 18004 | nlmsg_free(msg); |
| 18005 | } |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 18006 | EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 18007 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18008 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 18009 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 18010 | struct cfg80211_wowlan_wakeup *wakeup) |
| 18011 | { |
| 18012 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 18013 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 18014 | int i, j; |
| 18015 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 18016 | nl_results = nla_nest_start_noflag(msg, |
| 18017 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 18018 | if (!nl_results) |
| 18019 | return -EMSGSIZE; |
| 18020 | |
| 18021 | for (i = 0; i < nd->n_matches; i++) { |
| 18022 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 18023 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 18024 | nl_match = nla_nest_start_noflag(msg, i); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 18025 | if (!nl_match) |
| 18026 | break; |
| 18027 | |
| 18028 | /* The SSID attribute is optional in nl80211, but for |
| 18029 | * simplicity reasons it's always present in the |
| 18030 | * cfg80211 structure. If a driver can't pass the |
| 18031 | * SSID, that needs to be changed. A zero length SSID |
| 18032 | * is still a valid SSID (wildcard), so it cannot be |
| 18033 | * used for this purpose. |
| 18034 | */ |
| 18035 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 18036 | match->ssid.ssid)) { |
| 18037 | nla_nest_cancel(msg, nl_match); |
| 18038 | goto out; |
| 18039 | } |
| 18040 | |
| 18041 | if (match->n_channels) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 18042 | nl_freqs = nla_nest_start_noflag(msg, |
| 18043 | NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 18044 | if (!nl_freqs) { |
| 18045 | nla_nest_cancel(msg, nl_match); |
| 18046 | goto out; |
| 18047 | } |
| 18048 | |
| 18049 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 18050 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 18051 | nla_nest_cancel(msg, nl_freqs); |
| 18052 | nla_nest_cancel(msg, nl_match); |
| 18053 | goto out; |
| 18054 | } |
| 18055 | } |
| 18056 | |
| 18057 | nla_nest_end(msg, nl_freqs); |
| 18058 | } |
| 18059 | |
| 18060 | nla_nest_end(msg, nl_match); |
| 18061 | } |
| 18062 | |
| 18063 | out: |
| 18064 | nla_nest_end(msg, nl_results); |
| 18065 | return 0; |
| 18066 | } |
| 18067 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18068 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 18069 | struct cfg80211_wowlan_wakeup *wakeup, |
| 18070 | gfp_t gfp) |
| 18071 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 18072 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18073 | struct sk_buff *msg; |
| 18074 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 18075 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18076 | |
| 18077 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 18078 | |
| 18079 | if (wakeup) |
| 18080 | size += wakeup->packet_present_len; |
| 18081 | |
| 18082 | msg = nlmsg_new(size, gfp); |
| 18083 | if (!msg) |
| 18084 | return; |
| 18085 | |
| 18086 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 18087 | if (!hdr) |
| 18088 | goto free_msg; |
| 18089 | |
| 18090 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 18091 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 18092 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18093 | goto free_msg; |
| 18094 | |
| 18095 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 18096 | wdev->netdev->ifindex)) |
| 18097 | goto free_msg; |
| 18098 | |
| 18099 | if (wakeup) { |
| 18100 | struct nlattr *reasons; |
| 18101 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 18102 | reasons = nla_nest_start_noflag(msg, |
| 18103 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 18104 | if (!reasons) |
| 18105 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18106 | |
| 18107 | if (wakeup->disconnect && |
| 18108 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 18109 | goto free_msg; |
| 18110 | if (wakeup->magic_pkt && |
| 18111 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 18112 | goto free_msg; |
| 18113 | if (wakeup->gtk_rekey_failure && |
| 18114 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 18115 | goto free_msg; |
| 18116 | if (wakeup->eap_identity_req && |
| 18117 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 18118 | goto free_msg; |
| 18119 | if (wakeup->four_way_handshake && |
| 18120 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 18121 | goto free_msg; |
| 18122 | if (wakeup->rfkill_release && |
| 18123 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 18124 | goto free_msg; |
| 18125 | |
| 18126 | if (wakeup->pattern_idx >= 0 && |
| 18127 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 18128 | wakeup->pattern_idx)) |
| 18129 | goto free_msg; |
| 18130 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 18131 | if (wakeup->tcp_match && |
| 18132 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 18133 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 18134 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 18135 | if (wakeup->tcp_connlost && |
| 18136 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 18137 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 18138 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 18139 | if (wakeup->tcp_nomoretokens && |
| 18140 | nla_put_flag(msg, |
| 18141 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 18142 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 18143 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18144 | if (wakeup->packet) { |
| 18145 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 18146 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 18147 | |
| 18148 | if (!wakeup->packet_80211) { |
| 18149 | pkt_attr = |
| 18150 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 18151 | len_attr = |
| 18152 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 18153 | } |
| 18154 | |
| 18155 | if (wakeup->packet_len && |
| 18156 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 18157 | goto free_msg; |
| 18158 | |
| 18159 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 18160 | wakeup->packet)) |
| 18161 | goto free_msg; |
| 18162 | } |
| 18163 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 18164 | if (wakeup->net_detect && |
| 18165 | cfg80211_net_detect_results(msg, wakeup)) |
| 18166 | goto free_msg; |
| 18167 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18168 | nla_nest_end(msg, reasons); |
| 18169 | } |
| 18170 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 18171 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18172 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 18173 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 18174 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 18175 | return; |
| 18176 | |
| 18177 | free_msg: |
| 18178 | nlmsg_free(msg); |
| 18179 | } |
| 18180 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 18181 | #endif |
| 18182 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 18183 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 18184 | enum nl80211_tdls_operation oper, |
| 18185 | u16 reason_code, gfp_t gfp) |
| 18186 | { |
| 18187 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 18188 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 18189 | struct sk_buff *msg; |
| 18190 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 18191 | |
| 18192 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 18193 | reason_code); |
| 18194 | |
| 18195 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 18196 | if (!msg) |
| 18197 | return; |
| 18198 | |
| 18199 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 18200 | if (!hdr) { |
| 18201 | nlmsg_free(msg); |
| 18202 | return; |
| 18203 | } |
| 18204 | |
| 18205 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 18206 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 18207 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 18208 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 18209 | (reason_code > 0 && |
| 18210 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 18211 | goto nla_put_failure; |
| 18212 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 18213 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 18214 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 18215 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 18216 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 18217 | return; |
| 18218 | |
| 18219 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 18220 | nlmsg_free(msg); |
| 18221 | } |
| 18222 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 18223 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18224 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 18225 | unsigned long state, |
| 18226 | void *_notify) |
| 18227 | { |
| 18228 | struct netlink_notify *notify = _notify; |
| 18229 | struct cfg80211_registered_device *rdev; |
| 18230 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 18231 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18232 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 18233 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18234 | return NOTIFY_DONE; |
| 18235 | |
| 18236 | rcu_read_lock(); |
| 18237 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 18238 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 18239 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 18240 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 18241 | list_for_each_entry_rcu(sched_scan_req, |
| 18242 | &rdev->sched_scan_req_list, |
| 18243 | list) { |
| 18244 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 18245 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 18246 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 18247 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 18248 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 18249 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 18250 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 18251 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 18252 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 18253 | if (wdev->owner_nlportid == notify->portid) { |
| 18254 | wdev->nl_owner_dead = true; |
| 18255 | schedule_work(&rdev->destroy_work); |
| 18256 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 18257 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 18258 | } |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 18259 | |
| 18260 | cfg80211_release_pmsr(wdev, notify->portid); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 18261 | } |
| 18262 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 18263 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 18264 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 18265 | list) { |
| 18266 | if (reg->nlportid == notify->portid) { |
| 18267 | list_del(®->list); |
| 18268 | kfree(reg); |
| 18269 | break; |
| 18270 | } |
| 18271 | } |
| 18272 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 18273 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18274 | |
| 18275 | rcu_read_unlock(); |
| 18276 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 18277 | /* |
| 18278 | * It is possible that the user space process that is controlling the |
| 18279 | * indoor setting disappeared, so notify the regulatory core. |
| 18280 | */ |
| 18281 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 18282 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18283 | } |
| 18284 | |
| 18285 | static struct notifier_block nl80211_netlink_notifier = { |
| 18286 | .notifier_call = nl80211_netlink_notify, |
| 18287 | }; |
| 18288 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18289 | void cfg80211_ft_event(struct net_device *netdev, |
| 18290 | struct cfg80211_ft_event_params *ft_event) |
| 18291 | { |
| 18292 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 18293 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18294 | struct sk_buff *msg; |
| 18295 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18296 | |
| 18297 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 18298 | |
| 18299 | if (!ft_event->target_ap) |
| 18300 | return; |
| 18301 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 18302 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 18303 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18304 | if (!msg) |
| 18305 | return; |
| 18306 | |
| 18307 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 18308 | if (!hdr) |
| 18309 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18310 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 18311 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 18312 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 18313 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 18314 | goto out; |
| 18315 | |
| 18316 | if (ft_event->ies && |
| 18317 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 18318 | goto out; |
| 18319 | if (ft_event->ric_ies && |
| 18320 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 18321 | ft_event->ric_ies)) |
| 18322 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18323 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 18324 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18325 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 18326 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 18327 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 18328 | return; |
| 18329 | out: |
| 18330 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 18331 | } |
| 18332 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 18333 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 18334 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 18335 | { |
| 18336 | struct cfg80211_registered_device *rdev; |
| 18337 | struct sk_buff *msg; |
| 18338 | void *hdr; |
| 18339 | u32 nlportid; |
| 18340 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 18341 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 18342 | if (!rdev->crit_proto_nlportid) |
| 18343 | return; |
| 18344 | |
| 18345 | nlportid = rdev->crit_proto_nlportid; |
| 18346 | rdev->crit_proto_nlportid = 0; |
| 18347 | |
| 18348 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 18349 | if (!msg) |
| 18350 | return; |
| 18351 | |
| 18352 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 18353 | if (!hdr) |
| 18354 | goto nla_put_failure; |
| 18355 | |
| 18356 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 18357 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 18358 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 18359 | goto nla_put_failure; |
| 18360 | |
| 18361 | genlmsg_end(msg, hdr); |
| 18362 | |
| 18363 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 18364 | return; |
| 18365 | |
| 18366 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 18367 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 18368 | } |
| 18369 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 18370 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 18371 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 18372 | { |
| 18373 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 18374 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 18375 | struct sk_buff *msg; |
| 18376 | void *hdr; |
| 18377 | |
| 18378 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 18379 | if (!msg) |
| 18380 | return; |
| 18381 | |
| 18382 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 18383 | if (!hdr) |
| 18384 | goto out; |
| 18385 | |
| 18386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 18387 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 18388 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 18389 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 18390 | goto out; |
| 18391 | |
| 18392 | genlmsg_end(msg, hdr); |
| 18393 | |
| 18394 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 18395 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 18396 | return; |
| 18397 | out: |
| 18398 | nlmsg_free(msg); |
| 18399 | } |
| 18400 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 18401 | int cfg80211_external_auth_request(struct net_device *dev, |
| 18402 | struct cfg80211_external_auth_params *params, |
| 18403 | gfp_t gfp) |
| 18404 | { |
| 18405 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 18406 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 18407 | struct sk_buff *msg; |
| 18408 | void *hdr; |
| 18409 | |
| 18410 | if (!wdev->conn_owner_nlportid) |
| 18411 | return -EINVAL; |
| 18412 | |
| 18413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 18414 | if (!msg) |
| 18415 | return -ENOMEM; |
| 18416 | |
| 18417 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 18418 | if (!hdr) |
| 18419 | goto nla_put_failure; |
| 18420 | |
| 18421 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 18422 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 18423 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 18424 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 18425 | params->action) || |
| 18426 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 18427 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 18428 | params->ssid.ssid)) |
| 18429 | goto nla_put_failure; |
| 18430 | |
| 18431 | genlmsg_end(msg, hdr); |
| 18432 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 18433 | wdev->conn_owner_nlportid); |
| 18434 | return 0; |
| 18435 | |
| 18436 | nla_put_failure: |
| 18437 | nlmsg_free(msg); |
| 18438 | return -ENOBUFS; |
| 18439 | } |
| 18440 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 18441 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 18442 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
| 18443 | struct cfg80211_update_owe_info *owe_info, |
| 18444 | gfp_t gfp) |
| 18445 | { |
| 18446 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 18447 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 18448 | struct sk_buff *msg; |
| 18449 | void *hdr; |
| 18450 | |
| 18451 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); |
| 18452 | |
| 18453 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 18454 | if (!msg) |
| 18455 | return; |
| 18456 | |
| 18457 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); |
| 18458 | if (!hdr) |
| 18459 | goto nla_put_failure; |
| 18460 | |
| 18461 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 18462 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 18463 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) |
| 18464 | goto nla_put_failure; |
| 18465 | |
| 18466 | if (!owe_info->ie_len || |
| 18467 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) |
| 18468 | goto nla_put_failure; |
| 18469 | |
| 18470 | genlmsg_end(msg, hdr); |
| 18471 | |
| 18472 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 18473 | NL80211_MCGRP_MLME, gfp); |
| 18474 | return; |
| 18475 | |
| 18476 | nla_put_failure: |
| 18477 | genlmsg_cancel(msg, hdr); |
| 18478 | nlmsg_free(msg); |
| 18479 | } |
| 18480 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); |
| 18481 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18482 | /* initialisation/exit functions */ |
| 18483 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 18484 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18485 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 18486 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18487 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 18488 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18489 | if (err) |
| 18490 | return err; |
| 18491 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18492 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 18493 | if (err) |
| 18494 | goto err_out; |
| 18495 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18496 | return 0; |
| 18497 | err_out: |
| 18498 | genl_unregister_family(&nl80211_fam); |
| 18499 | return err; |
| 18500 | } |
| 18501 | |
| 18502 | void nl80211_exit(void) |
| 18503 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 18504 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18505 | genl_unregister_family(&nl80211_fam); |
| 18506 | } |