Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2 | /* |
| 3 | * This is the new netlink-based wireless configuration interface. |
| 4 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 5 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 2740f0c | 2014-09-03 15:24:58 +0300 | [diff] [blame] | 6 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 7 | * Copyright 2015-2017 Intel Deutschland GmbH |
Shaul Triebitz | 7e8d6f1 | 2020-01-31 13:12:54 +0200 | [diff] [blame] | 8 | * Copyright (C) 2018-2020 Intel Corporation |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/if.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15 | #include <linux/list.h> |
| 16 | #include <linux/if_ether.h> |
| 17 | #include <linux/ieee80211.h> |
| 18 | #include <linux/nl80211.h> |
| 19 | #include <linux/rtnetlink.h> |
| 20 | #include <linux/netlink.h> |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 21 | #include <linux/nospec.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 22 | #include <linux/etherdevice.h> |
Johannes Berg | e3ae39e | 2020-02-24 09:38:15 +0100 | [diff] [blame] | 23 | #include <linux/if_vlan.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 24 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 25 | #include <net/genetlink.h> |
| 26 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 27 | #include <net/sock.h> |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 28 | #include <net/inet_connection_sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 29 | #include "core.h" |
| 30 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 31 | #include "reg.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 32 | #include "rdev-ops.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 33 | |
Jouni Malinen | 5fb628e | 2011-08-10 23:54:35 +0300 | [diff] [blame] | 34 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 35 | struct genl_info *info, |
| 36 | struct cfg80211_crypto_settings *settings, |
| 37 | int cipher_limit); |
| 38 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 39 | /* the netlink family */ |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 40 | static struct genl_family nl80211_fam; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 42 | /* multicast groups */ |
| 43 | enum nl80211_multicast_groups { |
| 44 | NL80211_MCGRP_CONFIG, |
| 45 | NL80211_MCGRP_SCAN, |
| 46 | NL80211_MCGRP_REGULATORY, |
| 47 | NL80211_MCGRP_MLME, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 48 | NL80211_MCGRP_VENDOR, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 49 | NL80211_MCGRP_NAN, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 50 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
| 51 | }; |
| 52 | |
| 53 | static const struct genl_multicast_group nl80211_mcgrps[] = { |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 54 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
| 55 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, |
| 56 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, |
| 57 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, |
| 58 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 59 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 60 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 71b836e | 2014-12-23 17:17:38 +0100 | [diff] [blame] | 61 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 62 | #endif |
| 63 | }; |
| 64 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 65 | /* returns ERR_PTR values */ |
| 66 | static struct wireless_dev * |
| 67 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 69 | struct cfg80211_registered_device *rdev; |
| 70 | struct wireless_dev *result = NULL; |
| 71 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; |
| 72 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; |
| 73 | u64 wdev_id; |
| 74 | int wiphy_idx = -1; |
| 75 | int ifidx = -1; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 76 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 77 | ASSERT_RTNL(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 78 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 79 | if (!have_ifidx && !have_wdev_id) |
| 80 | return ERR_PTR(-EINVAL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 81 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 82 | if (have_ifidx) |
| 83 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
| 84 | if (have_wdev_id) { |
| 85 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 86 | wiphy_idx = wdev_id >> 32; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 89 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 90 | struct wireless_dev *wdev; |
| 91 | |
| 92 | if (wiphy_net(&rdev->wiphy) != netns) |
| 93 | continue; |
| 94 | |
| 95 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) |
| 96 | continue; |
| 97 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 98 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 99 | if (have_ifidx && wdev->netdev && |
| 100 | wdev->netdev->ifindex == ifidx) { |
| 101 | result = wdev; |
| 102 | break; |
| 103 | } |
| 104 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { |
| 105 | result = wdev; |
| 106 | break; |
| 107 | } |
| 108 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 109 | |
| 110 | if (result) |
| 111 | break; |
| 112 | } |
| 113 | |
| 114 | if (result) |
| 115 | return result; |
| 116 | return ERR_PTR(-ENODEV); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 119 | static struct cfg80211_registered_device * |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 120 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 121 | { |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 122 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
| 123 | struct net_device *netdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 124 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 125 | ASSERT_RTNL(); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 126 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 127 | if (!attrs[NL80211_ATTR_WIPHY] && |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 128 | !attrs[NL80211_ATTR_IFINDEX] && |
| 129 | !attrs[NL80211_ATTR_WDEV]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 130 | return ERR_PTR(-EINVAL); |
| 131 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 132 | if (attrs[NL80211_ATTR_WIPHY]) |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 133 | rdev = cfg80211_rdev_by_wiphy_idx( |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 134 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 135 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 136 | if (attrs[NL80211_ATTR_WDEV]) { |
| 137 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); |
| 138 | struct wireless_dev *wdev; |
| 139 | bool found = false; |
| 140 | |
| 141 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); |
| 142 | if (tmp) { |
| 143 | /* make sure wdev exists */ |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 144 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 145 | if (wdev->identifier != (u32)wdev_id) |
| 146 | continue; |
| 147 | found = true; |
| 148 | break; |
| 149 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 150 | |
| 151 | if (!found) |
| 152 | tmp = NULL; |
| 153 | |
| 154 | if (rdev && tmp != rdev) |
| 155 | return ERR_PTR(-EINVAL); |
| 156 | rdev = tmp; |
| 157 | } |
| 158 | } |
| 159 | |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 160 | if (attrs[NL80211_ATTR_IFINDEX]) { |
| 161 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 162 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 163 | netdev = __dev_get_by_index(netns, ifindex); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 164 | if (netdev) { |
| 165 | if (netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 166 | tmp = wiphy_to_rdev( |
| 167 | netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 168 | else |
| 169 | tmp = NULL; |
| 170 | |
Johannes Berg | 7fee4778 | 2012-06-15 14:09:58 +0200 | [diff] [blame] | 171 | /* not wireless device -- return error */ |
| 172 | if (!tmp) |
| 173 | return ERR_PTR(-EINVAL); |
| 174 | |
| 175 | /* mismatch -- return error */ |
| 176 | if (rdev && tmp != rdev) |
| 177 | return ERR_PTR(-EINVAL); |
| 178 | |
| 179 | rdev = tmp; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 180 | } |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 183 | if (!rdev) |
| 184 | return ERR_PTR(-ENODEV); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 185 | |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 186 | if (netns != wiphy_net(&rdev->wiphy)) |
| 187 | return ERR_PTR(-ENODEV); |
| 188 | |
| 189 | return rdev; |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /* |
| 193 | * This function returns a pointer to the driver |
| 194 | * that the genl_info item that is passed refers to. |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 195 | * |
| 196 | * The result of this can be a PTR_ERR and hence must |
| 197 | * be checked with IS_ERR() for errors. |
| 198 | */ |
| 199 | static struct cfg80211_registered_device * |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 200 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 201 | { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 202 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
Johannes Berg | a945540 | 2012-06-15 13:32:49 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 205 | static int validate_beacon_head(const struct nlattr *attr, |
| 206 | struct netlink_ext_ack *extack) |
| 207 | { |
| 208 | const u8 *data = nla_data(attr); |
| 209 | unsigned int len = nla_len(attr); |
| 210 | const struct element *elem; |
| 211 | const struct ieee80211_mgmt *mgmt = (void *)data; |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 212 | bool s1g_bcn = ieee80211_is_s1g_beacon(mgmt->frame_control); |
| 213 | unsigned int fixedlen, hdrlen; |
| 214 | |
| 215 | if (s1g_bcn) { |
| 216 | fixedlen = offsetof(struct ieee80211_ext, |
| 217 | u.s1g_beacon.variable); |
| 218 | hdrlen = offsetof(struct ieee80211_ext, u.s1g_beacon); |
| 219 | } else { |
| 220 | fixedlen = offsetof(struct ieee80211_mgmt, |
| 221 | u.beacon.variable); |
| 222 | hdrlen = offsetof(struct ieee80211_mgmt, u.beacon); |
| 223 | } |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 224 | |
| 225 | if (len < fixedlen) |
| 226 | goto err; |
| 227 | |
Thomas Pedersen | 1d47f11 | 2020-09-08 12:03:05 -0700 | [diff] [blame] | 228 | if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen) |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 229 | goto err; |
| 230 | |
| 231 | data += fixedlen; |
| 232 | len -= fixedlen; |
| 233 | |
| 234 | for_each_element(elem, data, len) { |
| 235 | /* nothing */ |
| 236 | } |
| 237 | |
| 238 | if (for_each_element_completed(elem, data, len)) |
| 239 | return 0; |
| 240 | |
| 241 | err: |
| 242 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head"); |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 246 | static int validate_ie_attr(const struct nlattr *attr, |
| 247 | struct netlink_ext_ack *extack) |
| 248 | { |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 249 | const u8 *data = nla_data(attr); |
| 250 | unsigned int len = nla_len(attr); |
Jouni Malinen | 7388afe | 2019-02-11 16:29:04 +0200 | [diff] [blame] | 251 | const struct element *elem; |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 252 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 253 | for_each_element(elem, data, len) { |
| 254 | /* nothing */ |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 255 | } |
| 256 | |
Johannes Berg | 9f30861 | 2019-02-07 23:39:19 +0100 | [diff] [blame] | 257 | if (for_each_element_completed(elem, data, len)) |
| 258 | return 0; |
| 259 | |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 260 | NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements"); |
| 261 | return -EINVAL; |
| 262 | } |
| 263 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 264 | /* policy for the attributes */ |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 265 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR]; |
| 266 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 267 | static const struct nla_policy |
| 268 | nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = { |
| 269 | [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, }, |
| 270 | [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY, |
| 271 | .len = U8_MAX }, |
| 272 | [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY, |
| 273 | .len = U8_MAX }, |
| 274 | }; |
| 275 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 276 | static const struct nla_policy |
| 277 | nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = { |
| 278 | [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG }, |
| 279 | [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 }, |
| 280 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] = |
| 281 | NLA_POLICY_MAX(NLA_U8, 15), |
| 282 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 }, |
| 283 | [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] = |
| 284 | NLA_POLICY_MAX(NLA_U8, 15), |
| 285 | [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] = |
Aviya Erenfeld | ea18709 | 2019-02-06 13:17:08 +0200 | [diff] [blame] | 286 | NLA_POLICY_MAX(NLA_U8, 31), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 287 | [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 }, |
| 288 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG }, |
| 289 | [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG }, |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 290 | [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG }, |
| 291 | [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 292 | }; |
| 293 | |
| 294 | static const struct nla_policy |
| 295 | nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = { |
| 296 | [NL80211_PMSR_TYPE_FTM] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 297 | NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static const struct nla_policy |
| 301 | nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = { |
| 302 | [NL80211_PMSR_REQ_ATTR_DATA] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 303 | NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 304 | [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG }, |
| 305 | }; |
| 306 | |
| 307 | static const struct nla_policy |
| 308 | nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = { |
| 309 | [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR, |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 310 | [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 311 | [NL80211_PMSR_PEER_ATTR_REQ] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 312 | NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 313 | [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT }, |
| 314 | }; |
| 315 | |
| 316 | static const struct nla_policy |
| 317 | nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = { |
| 318 | [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT }, |
| 319 | [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT }, |
| 320 | [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT }, |
| 321 | [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT }, |
| 322 | [NL80211_PMSR_ATTR_PEERS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 323 | NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 324 | }; |
| 325 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 326 | static const struct nla_policy |
| 327 | he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = { |
| 328 | [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] = |
| 329 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 330 | [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] = |
| 331 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 332 | [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET] = |
| 333 | NLA_POLICY_RANGE(NLA_U8, 1, 20), |
| 334 | [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP] = |
| 335 | NLA_POLICY_EXACT_LEN(8), |
| 336 | [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] = |
| 337 | NLA_POLICY_EXACT_LEN(8), |
| 338 | [NL80211_HE_OBSS_PD_ATTR_SR_CTRL] = { .type = NLA_U8 }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 339 | }; |
| 340 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 341 | static const struct nla_policy |
| 342 | he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = { |
| 343 | [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63), |
| 344 | [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 345 | [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG }, |
| 346 | }; |
| 347 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 348 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
| 349 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
| 350 | .len = NL80211_MAX_SUPP_RATES }, |
| 351 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
| 352 | .len = NL80211_MAX_SUPP_HT_RATES }, |
| 353 | [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)), |
| 354 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 355 | [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)), |
| 356 | [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8, |
| 357 | NL80211_RATE_INFO_HE_GI_0_8, |
| 358 | NL80211_RATE_INFO_HE_GI_3_2), |
| 359 | [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8, |
| 360 | NL80211_RATE_INFO_HE_1XLTF, |
| 361 | NL80211_RATE_INFO_HE_4XLTF), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 362 | }; |
| 363 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 364 | static const struct nla_policy |
| 365 | nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 366 | [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 }, |
| 367 | [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 368 | [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG }, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 369 | [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 370 | [NL80211_TID_CONFIG_ATTR_NOACK] = |
| 371 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 372 | [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 373 | [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 374 | [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] = |
| 375 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 376 | [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] = |
| 377 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 378 | [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] = |
| 379 | NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE), |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 380 | [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] = |
| 381 | NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED), |
| 382 | [NL80211_TID_CONFIG_ATTR_TX_RATE] = |
| 383 | NLA_POLICY_NESTED(nl80211_txattr_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 384 | }; |
| 385 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 386 | static const struct nla_policy |
| 387 | nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = { |
| 388 | [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 389 | [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000), |
| 390 | NLA_POLICY_RANGE(NLA_BINARY, |
| 391 | NL80211_FILS_DISCOVERY_TMPL_MIN_LEN, |
| 392 | IEEE80211_MAX_DATA_LEN), |
| 393 | }; |
| 394 | |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 395 | static const struct nla_policy |
| 396 | nl80211_unsol_bcast_probe_resp_policy[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1] = { |
| 397 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] = NLA_POLICY_MAX(NLA_U32, 20), |
| 398 | [NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL] = { .type = NLA_BINARY, |
| 399 | .len = IEEE80211_MAX_DATA_LEN } |
| 400 | }; |
| 401 | |
Johannes Berg | d15da2a | 2020-04-30 22:13:07 +0200 | [diff] [blame] | 402 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
Johannes Berg | 6d4dd4e | 2019-07-31 10:58:20 +0200 | [diff] [blame] | 403 | [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 404 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 405 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 406 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 407 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 408 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 409 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 410 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 411 | [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8, |
| 412 | NL80211_EDMG_CHANNELS_MIN, |
| 413 | NL80211_EDMG_CHANNELS_MAX), |
| 414 | [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8, |
| 415 | NL80211_EDMG_BW_CONFIG_MIN, |
| 416 | NL80211_EDMG_BW_CONFIG_MAX), |
| 417 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 418 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
| 419 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 420 | [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 421 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, |
| 422 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 423 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1), |
| 424 | [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1), |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 425 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 426 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 427 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 428 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 429 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 430 | [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 431 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 432 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 433 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 434 | [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
| 435 | [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 436 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 437 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 438 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 439 | .len = WLAN_MAX_KEY_LEN }, |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 440 | [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7), |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 441 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 442 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 443 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 444 | [NL80211_ATTR_KEY_TYPE] = |
| 445 | NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES), |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 446 | |
| 447 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 448 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
Johannes Berg | f88eb7c | 2019-09-20 21:54:17 +0200 | [diff] [blame] | 449 | [NL80211_ATTR_BEACON_HEAD] = |
| 450 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head, |
| 451 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 452 | [NL80211_ATTR_BEACON_TAIL] = |
| 453 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 454 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 455 | [NL80211_ATTR_STA_AID] = |
| 456 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 457 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 458 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 459 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 460 | .len = NL80211_MAX_SUPP_RATES }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 461 | [NL80211_ATTR_STA_PLINK_ACTION] = |
| 462 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1), |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 463 | [NL80211_ATTR_STA_TX_POWER_SETTING] = |
| 464 | NLA_POLICY_RANGE(NLA_U8, |
| 465 | NL80211_TX_POWER_AUTOMATIC, |
| 466 | NL80211_TX_POWER_FIXED), |
| 467 | [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 468 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 469 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 470 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 471 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
Markus Theil | 1fab1b8 | 2019-10-29 10:30:03 +0100 | [diff] [blame] | 472 | [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 473 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 474 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 475 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 476 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 477 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 478 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 479 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 480 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 481 | .len = NL80211_MAX_SUPP_RATES }, |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 482 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 483 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 484 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 485 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 486 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 487 | [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] | 488 | |
| 489 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 490 | [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY, |
| 491 | validate_ie_attr, |
| 492 | IEEE80211_MAX_DATA_LEN), |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 493 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 494 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 495 | |
| 496 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 497 | .len = IEEE80211_MAX_SSID_LEN }, |
| 498 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 499 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 500 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 501 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 502 | [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32, |
| 503 | NL80211_MFP_NO, |
| 504 | NL80211_MFP_OPTIONAL), |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 505 | [NL80211_ATTR_STA_FLAGS2] = { |
| 506 | .len = sizeof(struct nl80211_sta_flag_update), |
| 507 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 508 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 509 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
| 510 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 511 | [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 512 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
Sergey Matyukevich | ea75080 | 2020-02-13 13:16:16 +0000 | [diff] [blame] | 513 | [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 514 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 515 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 516 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 517 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 518 | [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN), |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 519 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
| 520 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 521 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 522 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
| 523 | .len = IEEE80211_MAX_DATA_LEN }, |
| 524 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 525 | [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32, |
| 526 | NL80211_PS_DISABLED, |
| 527 | NL80211_PS_ENABLED), |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 528 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 529 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 530 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 531 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
| 532 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 533 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 534 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
| 535 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, |
Felix Fietkau | 885a46d | 2010-11-11 15:07:22 +0100 | [diff] [blame] | 536 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 537 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 538 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 539 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 540 | [NL80211_ATTR_STA_PLINK_STATE] = |
| 541 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1), |
Jakub Kicinski | 056e937 | 2020-03-02 21:10:57 -0800 | [diff] [blame] | 542 | [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 }, |
| 543 | [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 544 | [NL80211_ATTR_MESH_PEER_AID] = |
| 545 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Luciano Coelho | bbe6ad6 | 2011-05-11 17:09:37 +0300 | [diff] [blame] | 546 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 547 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 548 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 549 | [NL80211_ATTR_HIDDEN_SSID] = |
| 550 | NLA_POLICY_RANGE(NLA_U32, |
| 551 | NL80211_HIDDEN_SSID_NOT_IN_USE, |
| 552 | NL80211_HIDDEN_SSID_ZERO_CONTENTS), |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 553 | [NL80211_ATTR_IE_PROBE_RESP] = |
| 554 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 555 | IEEE80211_MAX_DATA_LEN), |
| 556 | [NL80211_ATTR_IE_ASSOC_RESP] = |
| 557 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 558 | IEEE80211_MAX_DATA_LEN), |
Vivek Natarajan | f4b34b5 | 2011-08-29 14:23:03 +0530 | [diff] [blame] | 559 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 560 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 561 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 562 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
| 563 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, |
| 564 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, |
| 565 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, |
| 566 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 567 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 568 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 569 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
| 570 | .len = IEEE80211_MAX_DATA_LEN }, |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 571 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 572 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
| 573 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { |
| 574 | .len = NL80211_HT_CAPABILITY_LEN |
| 575 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 576 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 577 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 578 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 579 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 580 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 581 | |
| 582 | /* need to include at least Auth Transaction and Status Code */ |
| 583 | [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4), |
| 584 | |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 585 | [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] | 586 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 587 | [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127), |
| 588 | [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 589 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = |
| 590 | NLA_POLICY_RANGE(NLA_U32, |
| 591 | NL80211_MESH_POWER_UNKNOWN + 1, |
| 592 | NL80211_MESH_POWER_MAX), |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 593 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
| 594 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 595 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
| 596 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 597 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 598 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
| 599 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { |
| 600 | .len = NL80211_VHT_CAPABILITY_LEN, |
| 601 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 602 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
| 603 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, |
| 604 | .len = IEEE80211_MAX_DATA_LEN }, |
Jakub Kicinski | 0e1a1d8 | 2020-03-02 21:10:56 -0800 | [diff] [blame] | 605 | [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 606 | [NL80211_ATTR_MAX_CRIT_PROT_DURATION] = |
| 607 | NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION), |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 608 | [NL80211_ATTR_PEER_AID] = |
| 609 | NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID), |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 610 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
| 611 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, |
| 612 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 613 | [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY }, |
| 614 | [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 615 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2), |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 616 | /* |
| 617 | * The value of the Length field of the Supported Operating |
| 618 | * Classes element is between 2 and 253. |
| 619 | */ |
| 620 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = |
| 621 | NLA_POLICY_RANGE(NLA_BINARY, 2, 253), |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 622 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 623 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 624 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
| 625 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, |
| 626 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 627 | [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY, |
| 628 | IEEE80211_QOS_MAP_LEN_MIN, |
| 629 | IEEE80211_QOS_MAP_LEN_MAX), |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 630 | [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 631 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 632 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 633 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 634 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 635 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 636 | [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1), |
| 637 | [NL80211_ATTR_USER_PRIO] = |
| 638 | NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1), |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 639 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 640 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
Jakub Kicinski | 5cde05c | 2020-03-02 21:10:58 -0800 | [diff] [blame] | 641 | [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 642 | [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 643 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 644 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 645 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 646 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 647 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 648 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 649 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = |
| 650 | NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1), |
Aviya Erenfeld | c6e6a0c | 2016-07-05 15:23:08 +0300 | [diff] [blame] | 651 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
| 652 | .len = VHT_MUMIMO_GROUPS_DATA_LEN |
| 653 | }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 654 | [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] | 655 | [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1), |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 656 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 657 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 658 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
| 659 | .len = FILS_MAX_KEK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 660 | [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] | 661 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 662 | [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 663 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
| 664 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { |
| 665 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 666 | }, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 667 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 668 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
| 669 | .len = FILS_ERP_MAX_USERNAME_LEN }, |
| 670 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, |
| 671 | .len = FILS_ERP_MAX_REALM_LEN }, |
| 672 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, |
| 673 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, |
| 674 | .len = FILS_ERP_MAX_RRK_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 675 | [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2), |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 676 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 677 | [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] | 678 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 679 | [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG }, |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 680 | |
| 681 | [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 }, |
| 682 | [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 }, |
| 683 | [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 }, |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 684 | [NL80211_ATTR_HE_CAPABILITY] = |
| 685 | NLA_POLICY_RANGE(NLA_BINARY, |
| 686 | NL80211_HE_MIN_CAPABILITY_LEN, |
| 687 | NL80211_HE_MAX_CAPABILITY_LEN), |
Johannes Berg | 0e012b4 | 2020-04-12 00:40:30 +0200 | [diff] [blame] | 688 | [NL80211_ATTR_FTM_RESPONDER] = |
| 689 | NLA_POLICY_NESTED(nl80211_ftm_responder_policy), |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 690 | [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1), |
| 691 | [NL80211_ATTR_PEER_MEASUREMENTS] = |
Johannes Berg | 2332328 | 2019-01-25 10:08:28 +0100 | [diff] [blame] | 692 | NLA_POLICY_NESTED(nl80211_pmsr_attr_policy), |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 693 | [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1), |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 694 | [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY, |
| 695 | .len = SAE_PASSWORD_MAX_LEN }, |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 696 | [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG }, |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 697 | [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy), |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 698 | [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] | 699 | [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy), |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 700 | [NL80211_ATTR_TID_CONFIG] = |
| 701 | NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy), |
Markus Theil | 5631d96 | 2020-03-12 10:10:53 +0100 | [diff] [blame] | 702 | [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG }, |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 703 | [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1), |
| 704 | [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 705 | [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG }, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 706 | [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999), |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 707 | [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED }, |
Johannes Berg | 8140860 | 2020-08-18 10:17:31 +0200 | [diff] [blame] | 708 | [NL80211_ATTR_HE_6GHZ_CAPABILITY] = |
| 709 | NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)), |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 710 | [NL80211_ATTR_FILS_DISCOVERY] = |
| 711 | NLA_POLICY_NESTED(nl80211_fils_discovery_policy), |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 712 | [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] = |
| 713 | NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy), |
Thomas Pedersen | d2b7588 | 2020-09-21 19:28:04 -0700 | [diff] [blame] | 714 | [NL80211_ATTR_S1G_CAPABILITY] = |
| 715 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), |
| 716 | [NL80211_ATTR_S1G_CAPABILITY_MASK] = |
| 717 | NLA_POLICY_EXACT_LEN(IEEE80211_S1G_CAPABILITY_LEN), |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 718 | }; |
| 719 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 720 | /* policy for the key attributes */ |
Alexey Dobriyan | b54452b | 2010-02-18 08:14:31 +0000 | [diff] [blame] | 721 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 722 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 723 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 724 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
Jouni Malinen | 8196226 | 2011-11-02 23:36:31 +0200 | [diff] [blame] | 725 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 726 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 727 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 728 | [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1), |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 729 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 730 | [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] | 731 | }; |
| 732 | |
| 733 | /* policy for the key default flags */ |
| 734 | static const struct nla_policy |
| 735 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { |
| 736 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, |
| 737 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 738 | }; |
| 739 | |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 740 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 741 | /* policy for WoWLAN attributes */ |
| 742 | static const struct nla_policy |
| 743 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { |
| 744 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, |
| 745 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, |
| 746 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, |
| 747 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 748 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
| 749 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, |
| 750 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, |
| 751 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 752 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 753 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 754 | }; |
| 755 | |
| 756 | static const struct nla_policy |
| 757 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { |
| 758 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, |
| 759 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 760 | [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 761 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, |
| 762 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 763 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 764 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { |
| 765 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) |
| 766 | }, |
| 767 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { |
| 768 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) |
| 769 | }, |
| 770 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, |
Johannes Berg | bc04358 | 2020-08-18 10:17:32 +0200 | [diff] [blame] | 771 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1), |
| 772 | [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 773 | }; |
Johannes Berg | f83ace3 | 2016-10-17 08:04:07 +0200 | [diff] [blame] | 774 | #endif /* CONFIG_PM */ |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 775 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 776 | /* policy for coalesce rule attributes */ |
| 777 | static const struct nla_policy |
| 778 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { |
| 779 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 780 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = |
| 781 | NLA_POLICY_RANGE(NLA_U32, |
| 782 | NL80211_COALESCE_CONDITION_MATCH, |
| 783 | NL80211_COALESCE_CONDITION_NO_MATCH), |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 784 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, |
| 785 | }; |
| 786 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 787 | /* policy for GTK rekey offload attributes */ |
| 788 | static const struct nla_policy |
| 789 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 790 | [NL80211_REKEY_DATA_KEK] = { |
| 791 | .type = NLA_BINARY, |
| 792 | .len = NL80211_KEK_EXT_LEN |
| 793 | }, |
| 794 | [NL80211_REKEY_DATA_KCK] = { |
| 795 | .type = NLA_BINARY, |
| 796 | .len = NL80211_KCK_EXT_LEN |
| 797 | }, |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 798 | [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] | 799 | [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 }, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 800 | }; |
| 801 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 802 | static const struct nla_policy |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 803 | nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = { |
| 804 | [NL80211_BAND_2GHZ] = { .type = NLA_S32 }, |
| 805 | [NL80211_BAND_5GHZ] = { .type = NLA_S32 }, |
Arend van Spriel | e548a1c | 2019-08-02 13:31:02 +0200 | [diff] [blame] | 806 | [NL80211_BAND_6GHZ] = { .type = NLA_S32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 807 | [NL80211_BAND_60GHZ] = { .type = NLA_S32 }, |
| 808 | }; |
| 809 | |
| 810 | static const struct nla_policy |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 811 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 812 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 813 | .len = IEEE80211_MAX_SSID_LEN }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 814 | [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] | 815 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 816 | [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] = |
| 817 | NLA_POLICY_NESTED(nl80211_match_band_rssi_policy), |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 818 | }; |
| 819 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 820 | static const struct nla_policy |
| 821 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { |
| 822 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, |
| 823 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, |
| 824 | }; |
| 825 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 826 | static const struct nla_policy |
| 827 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { |
| 828 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, |
| 829 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, |
| 830 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { |
| 831 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) |
| 832 | }, |
| 833 | }; |
| 834 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 835 | /* policy for NAN function attributes */ |
| 836 | static const struct nla_policy |
| 837 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 838 | [NL80211_NAN_FUNC_TYPE] = |
| 839 | NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE), |
Srinivas Dasari | 0a27844 | 2017-07-07 01:43:40 +0300 | [diff] [blame] | 840 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 841 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
| 842 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, |
| 843 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, |
| 844 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, |
| 845 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, |
| 846 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, |
Johannes Berg | c7721c0 | 2020-04-30 22:13:10 +0200 | [diff] [blame] | 847 | [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] | 848 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, |
| 849 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, |
| 850 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, |
| 851 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, |
| 852 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, |
| 853 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 854 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, |
| 855 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, |
| 856 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, |
| 857 | }; |
| 858 | |
| 859 | /* policy for Service Response Filter attributes */ |
| 860 | static const struct nla_policy |
| 861 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { |
| 862 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, |
| 863 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, |
| 864 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, |
| 865 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, |
| 866 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, |
| 867 | }; |
| 868 | |
Peng Xu | ad67023 | 2017-10-03 23:21:51 +0300 | [diff] [blame] | 869 | /* policy for packet pattern attributes */ |
| 870 | static const struct nla_policy |
| 871 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { |
| 872 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, |
| 873 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, |
| 874 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, |
| 875 | }; |
| 876 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 877 | int nl80211_prepare_wdev_dump(struct netlink_callback *cb, |
| 878 | struct cfg80211_registered_device **rdev, |
| 879 | struct wireless_dev **wdev) |
Holger Schurig | a043897 | 2009-11-11 11:30:02 +0100 | [diff] [blame] | 880 | { |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 881 | int err; |
| 882 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 883 | if (!cb->args[0]) { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 884 | struct nlattr **attrbuf; |
| 885 | |
| 886 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 887 | GFP_KERNEL); |
| 888 | if (!attrbuf) |
| 889 | return -ENOMEM; |
| 890 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 891 | err = nlmsg_parse_deprecated(cb->nlh, |
| 892 | GENL_HDRLEN + nl80211_fam.hdrsize, |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 893 | attrbuf, nl80211_fam.maxattr, |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 894 | nl80211_policy, NULL); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 895 | if (err) { |
| 896 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 897 | return err; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 898 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 899 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 900 | *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk), |
| 901 | attrbuf); |
| 902 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 903 | if (IS_ERR(*wdev)) |
| 904 | return PTR_ERR(*wdev); |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 905 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 906 | /* 0 is the first index - add 1 to parse only once */ |
| 907 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 908 | cb->args[1] = (*wdev)->identifier; |
| 909 | } else { |
Johannes Berg | c319d50 | 2013-07-30 22:34:28 +0200 | [diff] [blame] | 910 | /* subtract the 1 again here */ |
| 911 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 912 | struct wireless_dev *tmp; |
| 913 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 914 | if (!wiphy) |
| 915 | return -ENODEV; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 916 | *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 917 | *wdev = NULL; |
| 918 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 919 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 920 | if (tmp->identifier == cb->args[1]) { |
| 921 | *wdev = tmp; |
| 922 | break; |
| 923 | } |
| 924 | } |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 925 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 926 | if (!*wdev) |
| 927 | return -ENODEV; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 930 | return 0; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 931 | } |
| 932 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 933 | /* message building helper */ |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 934 | void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
| 935 | int flags, u8 cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 936 | { |
| 937 | /* since there is no private header just add the generic one */ |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 938 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 941 | static int nl80211_msg_put_wmm_rules(struct sk_buff *msg, |
| 942 | const struct ieee80211_reg_rule *rule) |
| 943 | { |
| 944 | int j; |
| 945 | struct nlattr *nl_wmm_rules = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 946 | nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 947 | |
| 948 | if (!nl_wmm_rules) |
| 949 | goto nla_put_failure; |
| 950 | |
| 951 | for (j = 0; j < IEEE80211_NUM_ACS; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 952 | struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 953 | |
| 954 | if (!nl_wmm_rule) |
| 955 | goto nla_put_failure; |
| 956 | |
| 957 | if (nla_put_u16(msg, NL80211_WMMR_CW_MIN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 958 | rule->wmm_rule.client[j].cw_min) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 959 | nla_put_u16(msg, NL80211_WMMR_CW_MAX, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 960 | rule->wmm_rule.client[j].cw_max) || |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 961 | nla_put_u8(msg, NL80211_WMMR_AIFSN, |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 962 | rule->wmm_rule.client[j].aifsn) || |
Haim Dreyfuss | d3c89bb | 2018-08-21 09:22:19 +0300 | [diff] [blame] | 963 | nla_put_u16(msg, NL80211_WMMR_TXOP, |
| 964 | rule->wmm_rule.client[j].cot)) |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 965 | goto nla_put_failure; |
| 966 | |
| 967 | nla_nest_end(msg, nl_wmm_rule); |
| 968 | } |
| 969 | nla_nest_end(msg, nl_wmm_rules); |
| 970 | |
| 971 | return 0; |
| 972 | |
| 973 | nla_put_failure: |
| 974 | return -ENOBUFS; |
| 975 | } |
| 976 | |
| 977 | 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] | 978 | struct ieee80211_channel *chan, |
| 979 | bool large) |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 980 | { |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 981 | /* Some channels must be completely excluded from the |
| 982 | * list to protect old user-space tools from breaking |
| 983 | */ |
| 984 | if (!large && chan->flags & |
| 985 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) |
| 986 | return 0; |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 987 | if (!large && chan->freq_offset) |
| 988 | return 0; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 989 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 990 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 991 | chan->center_freq)) |
| 992 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 993 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 994 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset)) |
| 995 | goto nla_put_failure; |
| 996 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 997 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
| 998 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) |
| 999 | goto nla_put_failure; |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 1000 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
| 1001 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) |
| 1002 | goto nla_put_failure; |
| 1003 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) |
| 1004 | goto nla_put_failure; |
| 1005 | } |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1006 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
| 1007 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) |
| 1008 | goto nla_put_failure; |
| 1009 | if (large) { |
| 1010 | u32 time; |
| 1011 | |
| 1012 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); |
| 1013 | |
| 1014 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, |
| 1015 | chan->dfs_state)) |
| 1016 | goto nla_put_failure; |
| 1017 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, |
| 1018 | time)) |
| 1019 | goto nla_put_failure; |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 1020 | if (nla_put_u32(msg, |
| 1021 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, |
| 1022 | chan->dfs_cac_ms)) |
| 1023 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1024 | } |
| 1025 | } |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1026 | |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1027 | if (large) { |
| 1028 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && |
| 1029 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) |
| 1030 | goto nla_put_failure; |
| 1031 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && |
| 1032 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) |
| 1033 | goto nla_put_failure; |
| 1034 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && |
| 1035 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) |
| 1036 | goto nla_put_failure; |
| 1037 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && |
| 1038 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) |
| 1039 | goto nla_put_failure; |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1040 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
| 1041 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) |
| 1042 | goto nla_put_failure; |
Arik Nemtsov | 06f207f | 2015-05-06 16:28:31 +0300 | [diff] [blame] | 1043 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
| 1044 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) |
David Spinadel | 570dbde | 2014-02-23 09:12:59 +0200 | [diff] [blame] | 1045 | goto nla_put_failure; |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 1046 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
| 1047 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) |
| 1048 | goto nla_put_failure; |
| 1049 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && |
| 1050 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) |
| 1051 | goto nla_put_failure; |
Haim Dreyfuss | 1e61d82 | 2020-01-21 10:12:13 +0200 | [diff] [blame] | 1052 | if ((chan->flags & IEEE80211_CHAN_NO_HE) && |
| 1053 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE)) |
| 1054 | goto nla_put_failure; |
Thomas Pedersen | d65a977 | 2020-09-08 12:03:03 -0700 | [diff] [blame] | 1055 | if ((chan->flags & IEEE80211_CHAN_1MHZ) && |
| 1056 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ)) |
| 1057 | goto nla_put_failure; |
| 1058 | if ((chan->flags & IEEE80211_CHAN_2MHZ) && |
| 1059 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ)) |
| 1060 | goto nla_put_failure; |
| 1061 | if ((chan->flags & IEEE80211_CHAN_4MHZ) && |
| 1062 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ)) |
| 1063 | goto nla_put_failure; |
| 1064 | if ((chan->flags & IEEE80211_CHAN_8MHZ) && |
| 1065 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ)) |
| 1066 | goto nla_put_failure; |
| 1067 | if ((chan->flags & IEEE80211_CHAN_16MHZ) && |
| 1068 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ)) |
| 1069 | goto nla_put_failure; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 1070 | } |
| 1071 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1072 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 1073 | DBM_TO_MBM(chan->max_power))) |
| 1074 | goto nla_put_failure; |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1075 | |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1076 | if (large) { |
| 1077 | const struct ieee80211_reg_rule *rule = |
Haim Dreyfuss | b88d26d | 2018-08-21 09:22:20 +0300 | [diff] [blame] | 1078 | freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq)); |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1079 | |
Stanislaw Gruszka | 38cb87e | 2018-08-22 13:52:21 +0200 | [diff] [blame] | 1080 | if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) { |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 1081 | if (nl80211_msg_put_wmm_rules(msg, rule)) |
| 1082 | goto nla_put_failure; |
| 1083 | } |
| 1084 | } |
| 1085 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 1086 | return 0; |
| 1087 | |
| 1088 | nla_put_failure: |
| 1089 | return -ENOBUFS; |
| 1090 | } |
| 1091 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1092 | static bool nl80211_put_txq_stats(struct sk_buff *msg, |
| 1093 | struct cfg80211_txq_stats *txqstats, |
| 1094 | int attrtype) |
| 1095 | { |
| 1096 | struct nlattr *txqattr; |
| 1097 | |
| 1098 | #define PUT_TXQVAL_U32(attr, memb) do { \ |
| 1099 | if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \ |
| 1100 | nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \ |
| 1101 | return false; \ |
| 1102 | } while (0) |
| 1103 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1104 | txqattr = nla_nest_start_noflag(msg, attrtype); |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1105 | if (!txqattr) |
| 1106 | return false; |
| 1107 | |
| 1108 | PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes); |
| 1109 | PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets); |
| 1110 | PUT_TXQVAL_U32(FLOWS, flows); |
| 1111 | PUT_TXQVAL_U32(DROPS, drops); |
| 1112 | PUT_TXQVAL_U32(ECN_MARKS, ecn_marks); |
| 1113 | PUT_TXQVAL_U32(OVERLIMIT, overlimit); |
| 1114 | PUT_TXQVAL_U32(OVERMEMORY, overmemory); |
| 1115 | PUT_TXQVAL_U32(COLLISIONS, collisions); |
| 1116 | PUT_TXQVAL_U32(TX_BYTES, tx_bytes); |
| 1117 | PUT_TXQVAL_U32(TX_PACKETS, tx_packets); |
| 1118 | PUT_TXQVAL_U32(MAX_FLOWS, max_flows); |
| 1119 | nla_nest_end(msg, txqattr); |
| 1120 | |
| 1121 | #undef PUT_TXQVAL_U32 |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1125 | /* netlink command implementations */ |
| 1126 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1127 | struct key_parse { |
| 1128 | struct key_params p; |
| 1129 | int idx; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1130 | int type; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1131 | bool def, defmgmt, defbeacon; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1132 | bool def_uni, def_multi; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1133 | }; |
| 1134 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1135 | static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key, |
| 1136 | struct key_parse *k) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1137 | { |
| 1138 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1139 | int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key, |
| 1140 | nl80211_key_policy, |
| 1141 | info->extack); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1142 | if (err) |
| 1143 | return err; |
| 1144 | |
| 1145 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 1146 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1147 | k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1148 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1149 | if (k->def) { |
| 1150 | k->def_uni = true; |
| 1151 | k->def_multi = true; |
| 1152 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1153 | if (k->defmgmt || k->defbeacon) |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1154 | k->def_multi = true; |
| 1155 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1156 | if (tb[NL80211_KEY_IDX]) |
| 1157 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 1158 | |
| 1159 | if (tb[NL80211_KEY_DATA]) { |
| 1160 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 1161 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 1162 | } |
| 1163 | |
| 1164 | if (tb[NL80211_KEY_SEQ]) { |
| 1165 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 1166 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 1167 | } |
| 1168 | |
| 1169 | if (tb[NL80211_KEY_CIPHER]) |
| 1170 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 1171 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1172 | if (tb[NL80211_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1173 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1174 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1175 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
| 1176 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 1177 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1178 | err = nla_parse_nested_deprecated(kdt, |
| 1179 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1180 | tb[NL80211_KEY_DEFAULT_TYPES], |
| 1181 | nl80211_key_default_policy, |
| 1182 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1183 | if (err) |
| 1184 | return err; |
| 1185 | |
| 1186 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1187 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1188 | } |
| 1189 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 1190 | if (tb[NL80211_KEY_MODE]) |
| 1191 | k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]); |
| 1192 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1193 | return 0; |
| 1194 | } |
| 1195 | |
| 1196 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 1197 | { |
| 1198 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1199 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1200 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1201 | } |
| 1202 | |
| 1203 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1204 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1205 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1206 | } |
| 1207 | |
| 1208 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1209 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1210 | |
| 1211 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1212 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1213 | |
| 1214 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 1215 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 1216 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1217 | if (k->def) { |
| 1218 | k->def_uni = true; |
| 1219 | k->def_multi = true; |
| 1220 | } |
| 1221 | if (k->defmgmt) |
| 1222 | k->def_multi = true; |
| 1223 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 1224 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1225 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1226 | |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1227 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
| 1228 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1229 | int err = nla_parse_nested_deprecated(kdt, |
| 1230 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
| 1231 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], |
| 1232 | nl80211_key_default_policy, |
| 1233 | info->extack); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1234 | if (err) |
| 1235 | return err; |
| 1236 | |
| 1237 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; |
| 1238 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; |
| 1239 | } |
| 1240 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1241 | return 0; |
| 1242 | } |
| 1243 | |
| 1244 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 1245 | { |
| 1246 | int err; |
| 1247 | |
| 1248 | memset(k, 0, sizeof(*k)); |
| 1249 | k->idx = -1; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1250 | k->type = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1251 | |
| 1252 | if (info->attrs[NL80211_ATTR_KEY]) |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1253 | err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1254 | else |
| 1255 | err = nl80211_parse_key_old(info, k); |
| 1256 | |
| 1257 | if (err) |
| 1258 | return err; |
| 1259 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1260 | if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) + |
| 1261 | (k->defbeacon ? 1 : 0) > 1) { |
| 1262 | GENL_SET_ERR_MSG(info, |
| 1263 | "key with multiple default flags is invalid"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1264 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1265 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1266 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1267 | if (k->defmgmt || k->defbeacon) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1268 | if (k->def_uni || !k->def_multi) { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1269 | GENL_SET_ERR_MSG(info, |
| 1270 | "defmgmt/defbeacon key must be mcast"); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1271 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1272 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1275 | if (k->idx != -1) { |
| 1276 | if (k->defmgmt) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1277 | if (k->idx < 4 || k->idx > 5) { |
| 1278 | GENL_SET_ERR_MSG(info, |
| 1279 | "defmgmt key idx not 4 or 5"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1280 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1281 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1282 | } else if (k->defbeacon) { |
| 1283 | if (k->idx < 6 || k->idx > 7) { |
| 1284 | GENL_SET_ERR_MSG(info, |
| 1285 | "defbeacon key idx not 6 or 7"); |
| 1286 | return -EINVAL; |
| 1287 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1288 | } else if (k->def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1289 | if (k->idx < 0 || k->idx > 3) { |
| 1290 | GENL_SET_ERR_MSG(info, "def key idx not 0-3"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1291 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1292 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1293 | } else { |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 1294 | if (k->idx < 0 || k->idx > 7) { |
| 1295 | GENL_SET_ERR_MSG(info, "key idx not 0-7"); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1296 | return -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1297 | } |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1304 | static struct cfg80211_cached_keys * |
| 1305 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1306 | struct genl_info *info, bool *no_ht) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1307 | { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1308 | struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1309 | struct key_parse parse; |
| 1310 | struct nlattr *key; |
| 1311 | struct cfg80211_cached_keys *result; |
| 1312 | int rem, err, def = 0; |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1313 | bool have_key = false; |
| 1314 | |
| 1315 | nla_for_each_nested(key, keys, rem) { |
| 1316 | have_key = true; |
| 1317 | break; |
| 1318 | } |
| 1319 | |
| 1320 | if (!have_key) |
| 1321 | return NULL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1322 | |
| 1323 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 1324 | if (!result) |
| 1325 | return ERR_PTR(-ENOMEM); |
| 1326 | |
| 1327 | result->def = -1; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1328 | |
| 1329 | nla_for_each_nested(key, keys, rem) { |
| 1330 | memset(&parse, 0, sizeof(parse)); |
| 1331 | parse.idx = -1; |
| 1332 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1333 | err = nl80211_parse_key_new(info, key, &parse); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1334 | if (err) |
| 1335 | goto error; |
| 1336 | err = -EINVAL; |
| 1337 | if (!parse.p.key) |
| 1338 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1339 | if (parse.idx < 0 || parse.idx > 3) { |
| 1340 | GENL_SET_ERR_MSG(info, "key index out of range [0-3]"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1341 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1342 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1343 | if (parse.def) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1344 | if (def) { |
| 1345 | GENL_SET_ERR_MSG(info, |
| 1346 | "only one key can be default"); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1347 | goto error; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1348 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1349 | def = 1; |
| 1350 | result->def = parse.idx; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 1351 | if (!parse.def_uni || !parse.def_multi) |
| 1352 | goto error; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1353 | } else if (parse.defmgmt) |
| 1354 | goto error; |
| 1355 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 1356 | parse.idx, false, NULL); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1357 | if (err) |
| 1358 | goto error; |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1359 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1360 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1361 | GENL_SET_ERR_MSG(info, "connect key must be WEP"); |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1362 | err = -EINVAL; |
| 1363 | goto error; |
| 1364 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1365 | result->params[parse.idx].cipher = parse.p.cipher; |
| 1366 | result->params[parse.idx].key_len = parse.p.key_len; |
| 1367 | result->params[parse.idx].key = result->data[parse.idx]; |
| 1368 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 1369 | |
Johannes Berg | 386b1f2 | 2016-09-13 16:10:02 +0200 | [diff] [blame] | 1370 | /* must be WEP key if we got here */ |
| 1371 | if (no_ht) |
| 1372 | *no_ht = true; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1373 | } |
| 1374 | |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1375 | if (result->def < 0) { |
| 1376 | err = -EINVAL; |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 1377 | GENL_SET_ERR_MSG(info, "need a default/TX key"); |
Johannes Berg | f1c1f17 | 2016-09-13 17:08:23 +0200 | [diff] [blame] | 1378 | goto error; |
| 1379 | } |
| 1380 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1381 | return result; |
| 1382 | error: |
| 1383 | kfree(result); |
| 1384 | return ERR_PTR(err); |
| 1385 | } |
| 1386 | |
| 1387 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 1388 | { |
| 1389 | ASSERT_WDEV_LOCK(wdev); |
| 1390 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1391 | switch (wdev->iftype) { |
| 1392 | case NL80211_IFTYPE_AP: |
| 1393 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1394 | case NL80211_IFTYPE_P2P_GO: |
Thomas Pedersen | ff973af | 2011-05-03 16:57:12 -0700 | [diff] [blame] | 1395 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1396 | break; |
| 1397 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1398 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 1399 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | ceca7b7 | 2013-05-16 00:55:45 +0200 | [diff] [blame] | 1400 | if (!wdev->current_bss) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1401 | return -ENOLINK; |
| 1402 | break; |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1403 | case NL80211_IFTYPE_UNSPECIFIED: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 1404 | case NL80211_IFTYPE_OCB: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1405 | case NL80211_IFTYPE_MONITOR: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 1406 | case NL80211_IFTYPE_NAN: |
Johannes Berg | de4fcba | 2014-10-31 14:16:12 +0100 | [diff] [blame] | 1407 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1408 | case NL80211_IFTYPE_WDS: |
| 1409 | case NUM_NL80211_IFTYPES: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1410 | return -EINVAL; |
| 1411 | } |
| 1412 | |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1416 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1417 | u32 freq) |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1418 | { |
| 1419 | struct ieee80211_channel *chan; |
| 1420 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 1421 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 1422 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
| 1423 | return NULL; |
| 1424 | return chan; |
| 1425 | } |
| 1426 | |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1427 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
| 1428 | { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1429 | struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1430 | int i; |
| 1431 | |
| 1432 | if (!nl_modes) |
| 1433 | goto nla_put_failure; |
| 1434 | |
| 1435 | i = 0; |
| 1436 | while (ifmodes) { |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1437 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
| 1438 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1439 | ifmodes >>= 1; |
| 1440 | i++; |
| 1441 | } |
| 1442 | |
| 1443 | nla_nest_end(msg, nl_modes); |
| 1444 | return 0; |
| 1445 | |
| 1446 | nla_put_failure: |
| 1447 | return -ENOBUFS; |
| 1448 | } |
| 1449 | |
| 1450 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1451 | struct sk_buff *msg, |
| 1452 | bool large) |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1453 | { |
| 1454 | struct nlattr *nl_combis; |
| 1455 | int i, j; |
| 1456 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1457 | nl_combis = nla_nest_start_noflag(msg, |
| 1458 | NL80211_ATTR_INTERFACE_COMBINATIONS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1459 | if (!nl_combis) |
| 1460 | goto nla_put_failure; |
| 1461 | |
| 1462 | for (i = 0; i < wiphy->n_iface_combinations; i++) { |
| 1463 | const struct ieee80211_iface_combination *c; |
| 1464 | struct nlattr *nl_combi, *nl_limits; |
| 1465 | |
| 1466 | c = &wiphy->iface_combinations[i]; |
| 1467 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1468 | nl_combi = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1469 | if (!nl_combi) |
| 1470 | goto nla_put_failure; |
| 1471 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1472 | nl_limits = nla_nest_start_noflag(msg, |
| 1473 | NL80211_IFACE_COMB_LIMITS); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1474 | if (!nl_limits) |
| 1475 | goto nla_put_failure; |
| 1476 | |
| 1477 | for (j = 0; j < c->n_limits; j++) { |
| 1478 | struct nlattr *nl_limit; |
| 1479 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1480 | nl_limit = nla_nest_start_noflag(msg, j + 1); |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1481 | if (!nl_limit) |
| 1482 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1483 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
| 1484 | c->limits[j].max)) |
| 1485 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1486 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
| 1487 | c->limits[j].types)) |
| 1488 | goto nla_put_failure; |
| 1489 | nla_nest_end(msg, nl_limit); |
| 1490 | } |
| 1491 | |
| 1492 | nla_nest_end(msg, nl_limits); |
| 1493 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 1494 | if (c->beacon_int_infra_match && |
| 1495 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) |
| 1496 | goto nla_put_failure; |
| 1497 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, |
| 1498 | c->num_different_channels) || |
| 1499 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, |
| 1500 | c->max_interfaces)) |
| 1501 | goto nla_put_failure; |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1502 | if (large && |
Felix Fietkau | 8c48b50 | 2014-05-05 11:48:40 +0200 | [diff] [blame] | 1503 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
| 1504 | c->radar_detect_widths) || |
| 1505 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, |
| 1506 | c->radar_detect_regions))) |
Johannes Berg | cdc89b9 | 2013-02-18 23:54:36 +0100 | [diff] [blame] | 1507 | goto nla_put_failure; |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 1508 | if (c->beacon_int_min_gcd && |
| 1509 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, |
| 1510 | c->beacon_int_min_gcd)) |
| 1511 | goto nla_put_failure; |
Johannes Berg | 7527a78 | 2011-05-13 10:58:57 +0200 | [diff] [blame] | 1512 | |
| 1513 | nla_nest_end(msg, nl_combi); |
| 1514 | } |
| 1515 | |
| 1516 | nla_nest_end(msg, nl_combis); |
| 1517 | |
| 1518 | return 0; |
| 1519 | nla_put_failure: |
| 1520 | return -ENOBUFS; |
| 1521 | } |
| 1522 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1523 | #ifdef CONFIG_PM |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1524 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
| 1525 | struct sk_buff *msg) |
| 1526 | { |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 1527 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1528 | struct nlattr *nl_tcp; |
| 1529 | |
| 1530 | if (!tcp) |
| 1531 | return 0; |
| 1532 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1533 | nl_tcp = nla_nest_start_noflag(msg, |
| 1534 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1535 | if (!nl_tcp) |
| 1536 | return -ENOBUFS; |
| 1537 | |
| 1538 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1539 | tcp->data_payload_max)) |
| 1540 | return -ENOBUFS; |
| 1541 | |
| 1542 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 1543 | tcp->data_payload_max)) |
| 1544 | return -ENOBUFS; |
| 1545 | |
| 1546 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) |
| 1547 | return -ENOBUFS; |
| 1548 | |
| 1549 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 1550 | sizeof(*tcp->tok), tcp->tok)) |
| 1551 | return -ENOBUFS; |
| 1552 | |
| 1553 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 1554 | tcp->data_interval_max)) |
| 1555 | return -ENOBUFS; |
| 1556 | |
| 1557 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 1558 | tcp->wake_payload_max)) |
| 1559 | return -ENOBUFS; |
| 1560 | |
| 1561 | nla_nest_end(msg, nl_tcp); |
| 1562 | return 0; |
| 1563 | } |
| 1564 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1565 | static int nl80211_send_wowlan(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1566 | struct cfg80211_registered_device *rdev, |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1567 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1568 | { |
| 1569 | struct nlattr *nl_wowlan; |
| 1570 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1571 | if (!rdev->wiphy.wowlan) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1572 | return 0; |
| 1573 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1574 | nl_wowlan = nla_nest_start_noflag(msg, |
| 1575 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1576 | if (!nl_wowlan) |
| 1577 | return -ENOBUFS; |
| 1578 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1579 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1580 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1581 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1582 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1583 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1584 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1585 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1586 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1587 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1588 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1589 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1590 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1591 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1592 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1593 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1594 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 1595 | return -ENOBUFS; |
| 1596 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1597 | if (rdev->wiphy.wowlan->n_patterns) { |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 1598 | struct nl80211_pattern_support pat = { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1599 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
| 1600 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, |
| 1601 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, |
| 1602 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1603 | }; |
| 1604 | |
| 1605 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 1606 | sizeof(pat), &pat)) |
| 1607 | return -ENOBUFS; |
| 1608 | } |
| 1609 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 1610 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
| 1611 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, |
| 1612 | rdev->wiphy.wowlan->max_nd_match_sets)) |
| 1613 | return -ENOBUFS; |
| 1614 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1615 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
Johannes Berg | b56cf72 | 2013-02-20 01:02:38 +0100 | [diff] [blame] | 1616 | return -ENOBUFS; |
| 1617 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1618 | nla_nest_end(msg, nl_wowlan); |
| 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | #endif |
| 1623 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1624 | static int nl80211_send_coalesce(struct sk_buff *msg, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1625 | struct cfg80211_registered_device *rdev) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1626 | { |
| 1627 | struct nl80211_coalesce_rule_support rule; |
| 1628 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1629 | if (!rdev->wiphy.coalesce) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1630 | return 0; |
| 1631 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 1632 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
| 1633 | rule.max_delay = rdev->wiphy.coalesce->max_delay; |
| 1634 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; |
| 1635 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; |
| 1636 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; |
| 1637 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 1638 | |
| 1639 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) |
| 1640 | return -ENOBUFS; |
| 1641 | |
| 1642 | return 0; |
| 1643 | } |
| 1644 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1645 | static int |
| 1646 | nl80211_send_iftype_data(struct sk_buff *msg, |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1647 | const struct ieee80211_supported_band *sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1648 | const struct ieee80211_sband_iftype_data *iftdata) |
| 1649 | { |
| 1650 | const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap; |
| 1651 | |
| 1652 | if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES, |
| 1653 | iftdata->types_mask)) |
| 1654 | return -ENOBUFS; |
| 1655 | |
| 1656 | if (he_cap->has_he) { |
| 1657 | if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC, |
| 1658 | sizeof(he_cap->he_cap_elem.mac_cap_info), |
| 1659 | he_cap->he_cap_elem.mac_cap_info) || |
| 1660 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY, |
| 1661 | sizeof(he_cap->he_cap_elem.phy_cap_info), |
| 1662 | he_cap->he_cap_elem.phy_cap_info) || |
| 1663 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET, |
| 1664 | sizeof(he_cap->he_mcs_nss_supp), |
| 1665 | &he_cap->he_mcs_nss_supp) || |
| 1666 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE, |
| 1667 | sizeof(he_cap->ppe_thres), he_cap->ppe_thres)) |
| 1668 | return -ENOBUFS; |
| 1669 | } |
| 1670 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1671 | if (sband->band == NL80211_BAND_6GHZ && |
| 1672 | nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA, |
| 1673 | sizeof(iftdata->he_6ghz_capa), |
| 1674 | &iftdata->he_6ghz_capa)) |
| 1675 | return -ENOBUFS; |
| 1676 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1677 | return 0; |
| 1678 | } |
| 1679 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1680 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1681 | struct ieee80211_supported_band *sband, |
| 1682 | bool large) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1683 | { |
| 1684 | struct nlattr *nl_rates, *nl_rate; |
| 1685 | struct ieee80211_rate *rate; |
| 1686 | int i; |
| 1687 | |
| 1688 | /* add HT info */ |
| 1689 | if (sband->ht_cap.ht_supported && |
| 1690 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 1691 | sizeof(sband->ht_cap.mcs), |
| 1692 | &sband->ht_cap.mcs) || |
| 1693 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 1694 | sband->ht_cap.cap) || |
| 1695 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 1696 | sband->ht_cap.ampdu_factor) || |
| 1697 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 1698 | sband->ht_cap.ampdu_density))) |
| 1699 | return -ENOBUFS; |
| 1700 | |
| 1701 | /* add VHT info */ |
| 1702 | if (sband->vht_cap.vht_supported && |
| 1703 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, |
| 1704 | sizeof(sband->vht_cap.vht_mcs), |
| 1705 | &sband->vht_cap.vht_mcs) || |
| 1706 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, |
| 1707 | sband->vht_cap.cap))) |
| 1708 | return -ENOBUFS; |
| 1709 | |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1710 | if (large && sband->n_iftype_data) { |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1711 | struct nlattr *nl_iftype_data = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1712 | nla_nest_start_noflag(msg, |
| 1713 | NL80211_BAND_ATTR_IFTYPE_DATA); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1714 | int err; |
| 1715 | |
| 1716 | if (!nl_iftype_data) |
| 1717 | return -ENOBUFS; |
| 1718 | |
| 1719 | for (i = 0; i < sband->n_iftype_data; i++) { |
| 1720 | struct nlattr *iftdata; |
| 1721 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1722 | iftdata = nla_nest_start_noflag(msg, i + 1); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1723 | if (!iftdata) |
| 1724 | return -ENOBUFS; |
| 1725 | |
Johannes Berg | 2239521 | 2020-05-28 21:34:31 +0200 | [diff] [blame] | 1726 | err = nl80211_send_iftype_data(msg, sband, |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 1727 | &sband->iftype_data[i]); |
| 1728 | if (err) |
| 1729 | return err; |
| 1730 | |
| 1731 | nla_nest_end(msg, iftdata); |
| 1732 | } |
| 1733 | |
| 1734 | nla_nest_end(msg, nl_iftype_data); |
| 1735 | } |
| 1736 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1737 | /* add EDMG info */ |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 1738 | if (large && sband->edmg_cap.channels && |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 1739 | (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS, |
| 1740 | sband->edmg_cap.channels) || |
| 1741 | nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG, |
| 1742 | sband->edmg_cap.bw_config))) |
| 1743 | |
| 1744 | return -ENOBUFS; |
| 1745 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1746 | /* add bitrates */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1747 | nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1748 | if (!nl_rates) |
| 1749 | return -ENOBUFS; |
| 1750 | |
| 1751 | for (i = 0; i < sband->n_bitrates; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1752 | nl_rate = nla_nest_start_noflag(msg, i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1753 | if (!nl_rate) |
| 1754 | return -ENOBUFS; |
| 1755 | |
| 1756 | rate = &sband->bitrates[i]; |
| 1757 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
| 1758 | rate->bitrate)) |
| 1759 | return -ENOBUFS; |
| 1760 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
| 1761 | nla_put_flag(msg, |
| 1762 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) |
| 1763 | return -ENOBUFS; |
| 1764 | |
| 1765 | nla_nest_end(msg, nl_rate); |
| 1766 | } |
| 1767 | |
| 1768 | nla_nest_end(msg, nl_rates); |
| 1769 | |
| 1770 | return 0; |
| 1771 | } |
| 1772 | |
| 1773 | static int |
| 1774 | nl80211_send_mgmt_stypes(struct sk_buff *msg, |
| 1775 | const struct ieee80211_txrx_stypes *mgmt_stypes) |
| 1776 | { |
| 1777 | u16 stypes; |
| 1778 | struct nlattr *nl_ftypes, *nl_ifs; |
| 1779 | enum nl80211_iftype ift; |
| 1780 | int i; |
| 1781 | |
| 1782 | if (!mgmt_stypes) |
| 1783 | return 0; |
| 1784 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1785 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1786 | if (!nl_ifs) |
| 1787 | return -ENOBUFS; |
| 1788 | |
| 1789 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1790 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1791 | if (!nl_ftypes) |
| 1792 | return -ENOBUFS; |
| 1793 | i = 0; |
| 1794 | stypes = mgmt_stypes[ift].tx; |
| 1795 | while (stypes) { |
| 1796 | if ((stypes & 1) && |
| 1797 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1798 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1799 | return -ENOBUFS; |
| 1800 | stypes >>= 1; |
| 1801 | i++; |
| 1802 | } |
| 1803 | nla_nest_end(msg, nl_ftypes); |
| 1804 | } |
| 1805 | |
| 1806 | nla_nest_end(msg, nl_ifs); |
| 1807 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1808 | nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1809 | if (!nl_ifs) |
| 1810 | return -ENOBUFS; |
| 1811 | |
| 1812 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1813 | nl_ftypes = nla_nest_start_noflag(msg, ift); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 1814 | if (!nl_ftypes) |
| 1815 | return -ENOBUFS; |
| 1816 | i = 0; |
| 1817 | stypes = mgmt_stypes[ift].rx; |
| 1818 | while (stypes) { |
| 1819 | if ((stypes & 1) && |
| 1820 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, |
| 1821 | (i << 4) | IEEE80211_FTYPE_MGMT)) |
| 1822 | return -ENOBUFS; |
| 1823 | stypes >>= 1; |
| 1824 | i++; |
| 1825 | } |
| 1826 | nla_nest_end(msg, nl_ftypes); |
| 1827 | } |
| 1828 | nla_nest_end(msg, nl_ifs); |
| 1829 | |
| 1830 | return 0; |
| 1831 | } |
| 1832 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1833 | #define CMD(op, n) \ |
| 1834 | do { \ |
| 1835 | if (rdev->ops->op) { \ |
| 1836 | i++; \ |
| 1837 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
| 1838 | goto nla_put_failure; \ |
| 1839 | } \ |
| 1840 | } while (0) |
| 1841 | |
| 1842 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, |
| 1843 | struct sk_buff *msg) |
| 1844 | { |
| 1845 | int i = 0; |
| 1846 | |
| 1847 | /* |
| 1848 | * do *NOT* add anything into this function, new things need to be |
| 1849 | * advertised only to new versions of userspace that can deal with |
| 1850 | * the split (and they can't possibly care about new features... |
| 1851 | */ |
| 1852 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 1853 | CMD(change_virtual_intf, SET_INTERFACE); |
| 1854 | CMD(add_key, NEW_KEY); |
| 1855 | CMD(start_ap, START_AP); |
| 1856 | CMD(add_station, NEW_STATION); |
| 1857 | CMD(add_mpath, NEW_MPATH); |
| 1858 | CMD(update_mesh_config, SET_MESH_CONFIG); |
| 1859 | CMD(change_bss, SET_BSS); |
| 1860 | CMD(auth, AUTHENTICATE); |
| 1861 | CMD(assoc, ASSOCIATE); |
| 1862 | CMD(deauth, DEAUTHENTICATE); |
| 1863 | CMD(disassoc, DISASSOCIATE); |
| 1864 | CMD(join_ibss, JOIN_IBSS); |
| 1865 | CMD(join_mesh, JOIN_MESH); |
| 1866 | CMD(set_pmksa, SET_PMKSA); |
| 1867 | CMD(del_pmksa, DEL_PMKSA); |
| 1868 | CMD(flush_pmksa, FLUSH_PMKSA); |
| 1869 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
| 1870 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
| 1871 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
| 1872 | CMD(mgmt_tx, FRAME); |
| 1873 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
| 1874 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
| 1875 | i++; |
| 1876 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
| 1877 | goto nla_put_failure; |
| 1878 | } |
| 1879 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
| 1880 | rdev->ops->join_mesh) { |
| 1881 | i++; |
| 1882 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) |
| 1883 | goto nla_put_failure; |
| 1884 | } |
| 1885 | CMD(set_wds_peer, SET_WDS_PEER); |
| 1886 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 1887 | CMD(tdls_mgmt, TDLS_MGMT); |
| 1888 | CMD(tdls_oper, TDLS_OPER); |
| 1889 | } |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 1890 | if (rdev->wiphy.max_sched_scan_reqs) |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 1891 | CMD(sched_scan_start, START_SCHED_SCAN); |
| 1892 | CMD(probe_client, PROBE_CLIENT); |
| 1893 | CMD(set_noack_map, SET_NOACK_MAP); |
| 1894 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
| 1895 | i++; |
| 1896 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
| 1897 | goto nla_put_failure; |
| 1898 | } |
| 1899 | CMD(start_p2p_device, START_P2P_DEVICE); |
| 1900 | CMD(set_mcast_rate, SET_MCAST_RATE); |
| 1901 | #ifdef CONFIG_NL80211_TESTMODE |
| 1902 | CMD(testmode_cmd, TESTMODE); |
| 1903 | #endif |
| 1904 | |
| 1905 | if (rdev->ops->connect || rdev->ops->auth) { |
| 1906 | i++; |
| 1907 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
| 1908 | goto nla_put_failure; |
| 1909 | } |
| 1910 | |
| 1911 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
| 1912 | i++; |
| 1913 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
| 1914 | goto nla_put_failure; |
| 1915 | } |
| 1916 | |
| 1917 | return i; |
| 1918 | nla_put_failure: |
| 1919 | return -ENOBUFS; |
| 1920 | } |
| 1921 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1922 | static int |
| 1923 | nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap, |
| 1924 | struct sk_buff *msg) |
| 1925 | { |
| 1926 | struct nlattr *ftm; |
| 1927 | |
| 1928 | if (!cap->ftm.supported) |
| 1929 | return 0; |
| 1930 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1931 | ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1932 | if (!ftm) |
| 1933 | return -ENOBUFS; |
| 1934 | |
| 1935 | if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP)) |
| 1936 | return -ENOBUFS; |
| 1937 | if (cap->ftm.non_asap && |
| 1938 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP)) |
| 1939 | return -ENOBUFS; |
| 1940 | if (cap->ftm.request_lci && |
| 1941 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI)) |
| 1942 | return -ENOBUFS; |
| 1943 | if (cap->ftm.request_civicloc && |
| 1944 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC)) |
| 1945 | return -ENOBUFS; |
| 1946 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES, |
| 1947 | cap->ftm.preambles)) |
| 1948 | return -ENOBUFS; |
| 1949 | if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS, |
| 1950 | cap->ftm.bandwidths)) |
| 1951 | return -ENOBUFS; |
| 1952 | if (cap->ftm.max_bursts_exponent >= 0 && |
| 1953 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT, |
| 1954 | cap->ftm.max_bursts_exponent)) |
| 1955 | return -ENOBUFS; |
| 1956 | if (cap->ftm.max_ftms_per_burst && |
| 1957 | nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST, |
| 1958 | cap->ftm.max_ftms_per_burst)) |
| 1959 | return -ENOBUFS; |
Avraham Stern | efb5520 | 2020-01-31 13:12:38 +0200 | [diff] [blame] | 1960 | if (cap->ftm.trigger_based && |
| 1961 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED)) |
| 1962 | return -ENOBUFS; |
| 1963 | if (cap->ftm.non_trigger_based && |
| 1964 | nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED)) |
| 1965 | return -ENOBUFS; |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1966 | |
| 1967 | nla_nest_end(msg, ftm); |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev, |
| 1972 | struct sk_buff *msg) |
| 1973 | { |
| 1974 | const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa; |
| 1975 | struct nlattr *pmsr, *caps; |
| 1976 | |
| 1977 | if (!cap) |
| 1978 | return 0; |
| 1979 | |
| 1980 | /* |
| 1981 | * we don't need to clean up anything here since the caller |
| 1982 | * will genlmsg_cancel() if we fail |
| 1983 | */ |
| 1984 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1985 | pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 1986 | if (!pmsr) |
| 1987 | return -ENOBUFS; |
| 1988 | |
| 1989 | if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers)) |
| 1990 | return -ENOBUFS; |
| 1991 | |
| 1992 | if (cap->report_ap_tsf && |
| 1993 | nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF)) |
| 1994 | return -ENOBUFS; |
| 1995 | |
| 1996 | if (cap->randomize_mac_addr && |
| 1997 | nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR)) |
| 1998 | return -ENOBUFS; |
| 1999 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2000 | caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA); |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2001 | if (!caps) |
| 2002 | return -ENOBUFS; |
| 2003 | |
| 2004 | if (nl80211_send_pmsr_ftm_capa(cap, msg)) |
| 2005 | return -ENOBUFS; |
| 2006 | |
| 2007 | nla_nest_end(msg, caps); |
| 2008 | nla_nest_end(msg, pmsr); |
| 2009 | |
| 2010 | return 0; |
| 2011 | } |
| 2012 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2013 | static int |
| 2014 | nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev, |
| 2015 | struct sk_buff *msg) |
| 2016 | { |
| 2017 | int i; |
| 2018 | struct nlattr *nested, *nested_akms; |
| 2019 | const struct wiphy_iftype_akm_suites *iftype_akms; |
| 2020 | |
| 2021 | if (!rdev->wiphy.num_iftype_akm_suites || |
| 2022 | !rdev->wiphy.iftype_akm_suites) |
| 2023 | return 0; |
| 2024 | |
| 2025 | nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES); |
| 2026 | if (!nested) |
| 2027 | return -ENOBUFS; |
| 2028 | |
| 2029 | for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) { |
| 2030 | nested_akms = nla_nest_start(msg, i + 1); |
| 2031 | if (!nested_akms) |
| 2032 | return -ENOBUFS; |
| 2033 | |
| 2034 | iftype_akms = &rdev->wiphy.iftype_akm_suites[i]; |
| 2035 | |
| 2036 | if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES, |
| 2037 | iftype_akms->iftypes_mask)) |
| 2038 | return -ENOBUFS; |
| 2039 | |
| 2040 | if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES, |
| 2041 | sizeof(u32) * iftype_akms->n_akm_suites, |
| 2042 | iftype_akms->akm_suites)) { |
| 2043 | return -ENOBUFS; |
| 2044 | } |
| 2045 | nla_nest_end(msg, nested_akms); |
| 2046 | } |
| 2047 | |
| 2048 | nla_nest_end(msg, nested); |
| 2049 | |
| 2050 | return 0; |
| 2051 | } |
| 2052 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2053 | static int |
| 2054 | nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev, |
| 2055 | struct sk_buff *msg) |
| 2056 | { |
| 2057 | struct nlattr *supp; |
| 2058 | |
| 2059 | if (!rdev->wiphy.tid_config_support.vif && |
| 2060 | !rdev->wiphy.tid_config_support.peer) |
| 2061 | return 0; |
| 2062 | |
| 2063 | supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG); |
| 2064 | if (!supp) |
| 2065 | return -ENOSPC; |
| 2066 | |
| 2067 | if (rdev->wiphy.tid_config_support.vif && |
| 2068 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP, |
| 2069 | rdev->wiphy.tid_config_support.vif, |
| 2070 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2071 | goto fail; |
| 2072 | |
| 2073 | if (rdev->wiphy.tid_config_support.peer && |
| 2074 | nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP, |
| 2075 | rdev->wiphy.tid_config_support.peer, |
| 2076 | NL80211_TID_CONFIG_ATTR_PAD)) |
| 2077 | goto fail; |
| 2078 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 2079 | /* for now we just use the same value ... makes more sense */ |
| 2080 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT, |
| 2081 | rdev->wiphy.tid_config_support.max_retry)) |
| 2082 | goto fail; |
| 2083 | if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG, |
| 2084 | rdev->wiphy.tid_config_support.max_retry)) |
| 2085 | goto fail; |
| 2086 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2087 | nla_nest_end(msg, supp); |
| 2088 | |
| 2089 | return 0; |
| 2090 | fail: |
| 2091 | nla_nest_cancel(msg, supp); |
| 2092 | return -ENOBUFS; |
| 2093 | } |
| 2094 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2095 | struct nl80211_dump_wiphy_state { |
| 2096 | s64 filter_wiphy; |
| 2097 | long start; |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2098 | long split_start, band_start, chan_start, capa_start; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2099 | bool split; |
| 2100 | }; |
| 2101 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2102 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2103 | enum nl80211_commands cmd, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2104 | struct sk_buff *msg, u32 portid, u32 seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2105 | int flags, struct nl80211_dump_wiphy_state *state) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2106 | { |
| 2107 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2108 | struct nlattr *nl_bands, *nl_band; |
| 2109 | struct nlattr *nl_freqs, *nl_freq; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2110 | struct nlattr *nl_cmds; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2111 | enum nl80211_band band; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2112 | struct ieee80211_channel *chan; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2113 | int i; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2114 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2115 | rdev->wiphy.mgmt_stypes; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2116 | u32 features; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2117 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2118 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2119 | if (!hdr) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2120 | return -ENOBUFS; |
| 2121 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2122 | if (WARN_ON(!state)) |
| 2123 | return -EINVAL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2124 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2125 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2126 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2127 | wiphy_name(&rdev->wiphy)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2128 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2129 | cfg80211_rdev_list_generation)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2130 | goto nla_put_failure; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2131 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2132 | if (cmd != NL80211_CMD_NEW_WIPHY) |
| 2133 | goto finish; |
| 2134 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2135 | switch (state->split_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2136 | case 0: |
| 2137 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2138 | rdev->wiphy.retry_short) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2139 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2140 | rdev->wiphy.retry_long) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2141 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2142 | rdev->wiphy.frag_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2143 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2144 | rdev->wiphy.rts_threshold) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2145 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2146 | rdev->wiphy.coverage_class) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2147 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2148 | rdev->wiphy.max_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2149 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2150 | rdev->wiphy.max_sched_scan_ssids) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2151 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2152 | rdev->wiphy.max_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2153 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2154 | rdev->wiphy.max_sched_scan_ie_len) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2155 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2156 | rdev->wiphy.max_match_sets)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2157 | goto nla_put_failure; |
| 2158 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2159 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2160 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
| 2161 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2162 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2163 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
| 2164 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2165 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2166 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
| 2167 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2168 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2169 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
| 2170 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2171 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2172 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
| 2173 | goto nla_put_failure; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2174 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2175 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2176 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2177 | state->split_start++; |
| 2178 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2179 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2180 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2181 | case 1: |
| 2182 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2183 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
| 2184 | rdev->wiphy.cipher_suites)) |
Mahesh Palivela | bf0c111e | 2012-06-22 07:27:46 +0000 | [diff] [blame] | 2185 | goto nla_put_failure; |
| 2186 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2187 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2188 | rdev->wiphy.max_num_pmkids)) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2189 | goto nla_put_failure; |
| 2190 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2191 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2192 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
| 2193 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2194 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2195 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2196 | rdev->wiphy.available_antennas_tx) || |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2197 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2198 | rdev->wiphy.available_antennas_rx)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2199 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2200 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2201 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2202 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2203 | rdev->wiphy.probe_resp_offload)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2204 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 2205 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2206 | if ((rdev->wiphy.available_antennas_tx || |
| 2207 | rdev->wiphy.available_antennas_rx) && |
| 2208 | rdev->ops->get_antenna) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2209 | u32 tx_ant = 0, rx_ant = 0; |
| 2210 | int res; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 2211 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2212 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2213 | if (!res) { |
| 2214 | if (nla_put_u32(msg, |
| 2215 | NL80211_ATTR_WIPHY_ANTENNA_TX, |
| 2216 | tx_ant) || |
| 2217 | nla_put_u32(msg, |
| 2218 | NL80211_ATTR_WIPHY_ANTENNA_RX, |
| 2219 | rx_ant)) |
| 2220 | goto nla_put_failure; |
| 2221 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2224 | state->split_start++; |
| 2225 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2226 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2227 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2228 | case 2: |
| 2229 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2230 | rdev->wiphy.interface_modes)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2231 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2232 | state->split_start++; |
| 2233 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2234 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2235 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2236 | case 3: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2237 | nl_bands = nla_nest_start_noflag(msg, |
| 2238 | NL80211_ATTR_WIPHY_BANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2239 | if (!nl_bands) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2240 | goto nla_put_failure; |
| 2241 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2242 | for (band = state->band_start; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2243 | band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2244 | struct ieee80211_supported_band *sband; |
| 2245 | |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2246 | /* omit higher bands for ancient software */ |
| 2247 | if (band > NL80211_BAND_5GHZ && !state->split) |
| 2248 | break; |
| 2249 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2250 | sband = rdev->wiphy.bands[band]; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2251 | |
| 2252 | if (!sband) |
| 2253 | continue; |
| 2254 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2255 | nl_band = nla_nest_start_noflag(msg, band); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2256 | if (!nl_band) |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2257 | goto nla_put_failure; |
| 2258 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2259 | switch (state->chan_start) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2260 | case 0: |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2261 | if (nl80211_send_band_rateinfo(msg, sband, |
| 2262 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2263 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2264 | state->chan_start++; |
| 2265 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2266 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2267 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2268 | default: |
| 2269 | /* add frequencies */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2270 | nl_freqs = nla_nest_start_noflag(msg, |
| 2271 | NL80211_BAND_ATTR_FREQS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2272 | if (!nl_freqs) |
| 2273 | goto nla_put_failure; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2274 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2275 | for (i = state->chan_start - 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2276 | i < sband->n_channels; |
| 2277 | i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2278 | nl_freq = nla_nest_start_noflag(msg, |
| 2279 | i); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2280 | if (!nl_freq) |
| 2281 | goto nla_put_failure; |
| 2282 | |
| 2283 | chan = &sband->channels[i]; |
| 2284 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2285 | if (nl80211_msg_put_channel( |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 2286 | msg, &rdev->wiphy, chan, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2287 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2288 | goto nla_put_failure; |
| 2289 | |
| 2290 | nla_nest_end(msg, nl_freq); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2291 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2292 | break; |
| 2293 | } |
| 2294 | if (i < sband->n_channels) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2295 | state->chan_start = i + 2; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2296 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2297 | state->chan_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2298 | nla_nest_end(msg, nl_freqs); |
| 2299 | } |
| 2300 | |
| 2301 | nla_nest_end(msg, nl_band); |
| 2302 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2303 | if (state->split) { |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2304 | /* start again here */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2305 | if (state->chan_start) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2306 | band--; |
| 2307 | break; |
| 2308 | } |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2309 | } |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2310 | nla_nest_end(msg, nl_bands); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2311 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2312 | if (band < NUM_NL80211_BANDS) |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2313 | state->band_start = band + 1; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2314 | else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2315 | state->band_start = 0; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 2316 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2317 | /* if bands & channels are done, continue outside */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2318 | if (state->band_start == 0 && state->chan_start == 0) |
| 2319 | state->split_start++; |
| 2320 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2321 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2322 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2323 | case 4: |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2324 | nl_cmds = nla_nest_start_noflag(msg, |
| 2325 | NL80211_ATTR_SUPPORTED_COMMANDS); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2326 | if (!nl_cmds) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 2327 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2328 | |
Johannes Berg | 1794899 | 2016-10-26 11:42:04 +0200 | [diff] [blame] | 2329 | i = nl80211_add_commands_unsplit(rdev, msg); |
| 2330 | if (i < 0) |
| 2331 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2332 | if (state->split) { |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2333 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
| 2334 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2335 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 2336 | CMD(channel_switch, CHANNEL_SWITCH); |
Johannes Berg | 02df00e | 2014-06-10 14:06:25 +0200 | [diff] [blame] | 2337 | CMD(set_qos_map, SET_QOS_MAP); |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 2338 | if (rdev->wiphy.features & |
| 2339 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 2340 | CMD(add_tx_ts, ADD_TX_TS); |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 2341 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 2342 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
Matthew Wang | 7010998 | 2019-08-22 10:48:06 -0700 | [diff] [blame] | 2343 | CMD(update_ft_ies, UPDATE_FT_IES); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 2344 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 2345 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 2346 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2347 | nla_nest_end(msg, nl_cmds); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2348 | state->split_start++; |
| 2349 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2350 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2351 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2352 | case 5: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2353 | if (rdev->ops->remain_on_channel && |
| 2354 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2355 | nla_put_u32(msg, |
| 2356 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2357 | rdev->wiphy.max_remain_on_channel_duration)) |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2358 | goto nla_put_failure; |
| 2359 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2360 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2361 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
| 2362 | goto nla_put_failure; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 2363 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2364 | state->split_start++; |
| 2365 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2366 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2367 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2368 | case 6: |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 2369 | #ifdef CONFIG_PM |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2370 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2371 | goto nla_put_failure; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2372 | state->split_start++; |
| 2373 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2374 | break; |
| 2375 | #else |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2376 | state->split_start++; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2377 | #endif |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2378 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2379 | case 7: |
| 2380 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2381 | rdev->wiphy.software_iftypes)) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2382 | goto nla_put_failure; |
| 2383 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2384 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2385 | state->split)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2386 | goto nla_put_failure; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2387 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2388 | state->split_start++; |
| 2389 | if (state->split) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2390 | break; |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 2391 | fallthrough; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2392 | case 8: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2393 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2394 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2395 | rdev->wiphy.ap_sme_capa)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2396 | goto nla_put_failure; |
| 2397 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2398 | features = rdev->wiphy.features; |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2399 | /* |
| 2400 | * We can only add the per-channel limit information if the |
| 2401 | * dump is split, otherwise it makes it too big. Therefore |
| 2402 | * only advertise it in that case. |
| 2403 | */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2404 | if (state->split) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2405 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
| 2406 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2407 | goto nla_put_failure; |
| 2408 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2409 | if (rdev->wiphy.ht_capa_mod_mask && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2410 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2411 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
| 2412 | rdev->wiphy.ht_capa_mod_mask)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2413 | goto nla_put_failure; |
| 2414 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2415 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
| 2416 | rdev->wiphy.max_acl_mac_addrs && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2417 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2418 | rdev->wiphy.max_acl_mac_addrs)) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2419 | goto nla_put_failure; |
| 2420 | |
| 2421 | /* |
| 2422 | * Any information below this point is only available to |
| 2423 | * applications that can deal with it being split. This |
| 2424 | * helps ensure that newly added capabilities don't break |
| 2425 | * older tools by overrunning their buffers. |
| 2426 | * |
| 2427 | * We still increment split_start so that in the split |
| 2428 | * case we'll continue with more data in the next round, |
| 2429 | * but break unconditionally so unsplit data stops here. |
| 2430 | */ |
Johannes Berg | ab10c22 | 2020-09-28 13:07:18 +0200 | [diff] [blame] | 2431 | if (state->split) |
| 2432 | state->split_start++; |
| 2433 | else |
| 2434 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2435 | break; |
| 2436 | case 9: |
Johannes Berg | f8d504c | 2020-09-28 13:06:56 +0200 | [diff] [blame] | 2437 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) |
| 2438 | goto nla_put_failure; |
| 2439 | |
| 2440 | if (nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, |
| 2441 | rdev->wiphy.max_sched_scan_plans) || |
| 2442 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, |
| 2443 | rdev->wiphy.max_sched_scan_plan_interval) || |
| 2444 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, |
| 2445 | rdev->wiphy.max_sched_scan_plan_iterations)) |
| 2446 | goto nla_put_failure; |
| 2447 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2448 | if (rdev->wiphy.extended_capabilities && |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2449 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2450 | rdev->wiphy.extended_capabilities_len, |
| 2451 | rdev->wiphy.extended_capabilities) || |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2452 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2453 | rdev->wiphy.extended_capabilities_len, |
| 2454 | rdev->wiphy.extended_capabilities_mask))) |
Johannes Berg | fe1abaf | 2013-02-27 15:39:45 +0100 | [diff] [blame] | 2455 | goto nla_put_failure; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2456 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2457 | if (rdev->wiphy.vht_capa_mod_mask && |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2458 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2459 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
| 2460 | rdev->wiphy.vht_capa_mod_mask)) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 2461 | goto nla_put_failure; |
| 2462 | |
Denis Kenzior | ae6fa4d | 2019-07-22 06:33:12 -0500 | [diff] [blame] | 2463 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, |
| 2464 | rdev->wiphy.perm_addr)) |
| 2465 | goto nla_put_failure; |
| 2466 | |
| 2467 | if (!is_zero_ether_addr(rdev->wiphy.addr_mask) && |
| 2468 | nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN, |
| 2469 | rdev->wiphy.addr_mask)) |
| 2470 | goto nla_put_failure; |
| 2471 | |
| 2472 | if (rdev->wiphy.n_addresses > 1) { |
| 2473 | void *attr; |
| 2474 | |
| 2475 | attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS); |
| 2476 | if (!attr) |
| 2477 | goto nla_put_failure; |
| 2478 | |
| 2479 | for (i = 0; i < rdev->wiphy.n_addresses; i++) |
| 2480 | if (nla_put(msg, i + 1, ETH_ALEN, |
| 2481 | rdev->wiphy.addresses[i].addr)) |
| 2482 | goto nla_put_failure; |
| 2483 | |
| 2484 | nla_nest_end(msg, attr); |
| 2485 | } |
| 2486 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2487 | state->split_start++; |
| 2488 | break; |
| 2489 | case 10: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2490 | if (nl80211_send_coalesce(msg, rdev)) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 2491 | goto nla_put_failure; |
| 2492 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2493 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2494 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
| 2495 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) |
| 2496 | goto nla_put_failure; |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2497 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2498 | if (rdev->wiphy.max_ap_assoc_sta && |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2499 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2500 | rdev->wiphy.max_ap_assoc_sta)) |
Jouni Malinen | b43504c | 2014-01-15 00:01:08 +0200 | [diff] [blame] | 2501 | goto nla_put_failure; |
| 2502 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2503 | state->split_start++; |
| 2504 | break; |
| 2505 | case 11: |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2506 | if (rdev->wiphy.n_vendor_commands) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2507 | const struct nl80211_vendor_cmd_info *info; |
| 2508 | struct nlattr *nested; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2509 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2510 | nested = nla_nest_start_noflag(msg, |
| 2511 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2512 | if (!nested) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 2513 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2514 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2515 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 2516 | info = &rdev->wiphy.vendor_commands[i].info; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2517 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2518 | goto nla_put_failure; |
| 2519 | } |
| 2520 | nla_nest_end(msg, nested); |
| 2521 | } |
| 2522 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2523 | if (rdev->wiphy.n_vendor_events) { |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2524 | const struct nl80211_vendor_cmd_info *info; |
| 2525 | struct nlattr *nested; |
| 2526 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2527 | nested = nla_nest_start_noflag(msg, |
| 2528 | NL80211_ATTR_VENDOR_EVENTS); |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2529 | if (!nested) |
| 2530 | goto nla_put_failure; |
| 2531 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2532 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
| 2533 | info = &rdev->wiphy.vendor_events[i]; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 2534 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
| 2535 | goto nla_put_failure; |
| 2536 | } |
| 2537 | nla_nest_end(msg, nested); |
| 2538 | } |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 2539 | state->split_start++; |
| 2540 | break; |
| 2541 | case 12: |
| 2542 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && |
| 2543 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, |
| 2544 | rdev->wiphy.max_num_csa_counters)) |
| 2545 | goto nla_put_failure; |
Felix Fietkau | 01e0daa | 2013-11-09 14:57:54 +0100 | [diff] [blame] | 2546 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 2547 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 2548 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 2549 | goto nla_put_failure; |
| 2550 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 2551 | if (rdev->wiphy.max_sched_scan_reqs && |
| 2552 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, |
| 2553 | rdev->wiphy.max_sched_scan_reqs)) |
| 2554 | goto nla_put_failure; |
| 2555 | |
Gautam Kumar Shukla | d75bb06 | 2014-12-23 16:55:19 +0100 | [diff] [blame] | 2556 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
| 2557 | sizeof(rdev->wiphy.ext_features), |
| 2558 | rdev->wiphy.ext_features)) |
| 2559 | goto nla_put_failure; |
| 2560 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2561 | if (rdev->wiphy.bss_select_support) { |
| 2562 | struct nlattr *nested; |
| 2563 | u32 bss_select_support = rdev->wiphy.bss_select_support; |
| 2564 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2565 | nested = nla_nest_start_noflag(msg, |
| 2566 | NL80211_ATTR_BSS_SELECT); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 2567 | if (!nested) |
| 2568 | goto nla_put_failure; |
| 2569 | |
| 2570 | i = 0; |
| 2571 | while (bss_select_support) { |
| 2572 | if ((bss_select_support & 1) && |
| 2573 | nla_put_flag(msg, i)) |
| 2574 | goto nla_put_failure; |
| 2575 | i++; |
| 2576 | bss_select_support >>= 1; |
| 2577 | } |
| 2578 | nla_nest_end(msg, nested); |
| 2579 | } |
| 2580 | |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2581 | state->split_start++; |
| 2582 | break; |
| 2583 | case 13: |
| 2584 | if (rdev->wiphy.num_iftype_ext_capab && |
| 2585 | rdev->wiphy.iftype_ext_capab) { |
| 2586 | struct nlattr *nested_ext_capab, *nested; |
| 2587 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2588 | nested = nla_nest_start_noflag(msg, |
| 2589 | NL80211_ATTR_IFTYPE_EXT_CAPA); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2590 | if (!nested) |
| 2591 | goto nla_put_failure; |
| 2592 | |
| 2593 | for (i = state->capa_start; |
| 2594 | i < rdev->wiphy.num_iftype_ext_capab; i++) { |
| 2595 | const struct wiphy_iftype_ext_capab *capab; |
| 2596 | |
| 2597 | capab = &rdev->wiphy.iftype_ext_capab[i]; |
| 2598 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 2599 | nested_ext_capab = nla_nest_start_noflag(msg, |
| 2600 | i); |
Kanchanapally, Vidyullatha | 019ae3a | 2016-05-16 10:41:04 +0530 | [diff] [blame] | 2601 | if (!nested_ext_capab || |
| 2602 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, |
| 2603 | capab->iftype) || |
| 2604 | nla_put(msg, NL80211_ATTR_EXT_CAPA, |
| 2605 | capab->extended_capabilities_len, |
| 2606 | capab->extended_capabilities) || |
| 2607 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
| 2608 | capab->extended_capabilities_len, |
| 2609 | capab->extended_capabilities_mask)) |
| 2610 | goto nla_put_failure; |
| 2611 | |
| 2612 | nla_nest_end(msg, nested_ext_capab); |
| 2613 | if (state->split) |
| 2614 | break; |
| 2615 | } |
| 2616 | nla_nest_end(msg, nested); |
| 2617 | if (i < rdev->wiphy.num_iftype_ext_capab) { |
| 2618 | state->capa_start = i + 1; |
| 2619 | break; |
| 2620 | } |
| 2621 | } |
| 2622 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 2623 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
| 2624 | rdev->wiphy.nan_supported_bands)) |
| 2625 | goto nla_put_failure; |
| 2626 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2627 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 2628 | NL80211_EXT_FEATURE_TXQS)) { |
| 2629 | struct cfg80211_txq_stats txqstats = {}; |
| 2630 | int res; |
| 2631 | |
| 2632 | res = rdev_get_txq_stats(rdev, NULL, &txqstats); |
| 2633 | if (!res && |
| 2634 | !nl80211_put_txq_stats(msg, &txqstats, |
| 2635 | NL80211_ATTR_TXQ_STATS)) |
| 2636 | goto nla_put_failure; |
| 2637 | |
| 2638 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT, |
| 2639 | rdev->wiphy.txq_limit)) |
| 2640 | goto nla_put_failure; |
| 2641 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT, |
| 2642 | rdev->wiphy.txq_memory_limit)) |
| 2643 | goto nla_put_failure; |
| 2644 | if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM, |
| 2645 | rdev->wiphy.txq_quantum)) |
| 2646 | goto nla_put_failure; |
| 2647 | } |
| 2648 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2649 | state->split_start++; |
| 2650 | break; |
| 2651 | case 14: |
| 2652 | if (nl80211_send_pmsr_capa(rdev, msg)) |
| 2653 | goto nla_put_failure; |
| 2654 | |
Veerendranath Jakkam | ab4dfa2 | 2018-12-19 22:52:25 +0530 | [diff] [blame] | 2655 | state->split_start++; |
| 2656 | break; |
| 2657 | case 15: |
| 2658 | if (rdev->wiphy.akm_suites && |
| 2659 | nla_put(msg, NL80211_ATTR_AKM_SUITES, |
| 2660 | sizeof(u32) * rdev->wiphy.n_akm_suites, |
| 2661 | rdev->wiphy.akm_suites)) |
| 2662 | goto nla_put_failure; |
| 2663 | |
Veerendranath Jakkam | d6039a3 | 2020-01-27 02:00:32 +0530 | [diff] [blame] | 2664 | if (nl80211_put_iftype_akm_suites(rdev, msg)) |
| 2665 | goto nla_put_failure; |
| 2666 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 2667 | if (nl80211_put_tid_config_support(rdev, msg)) |
| 2668 | goto nla_put_failure; |
| 2669 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2670 | /* done */ |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2671 | state->split_start = 0; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2672 | break; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2673 | } |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2674 | finish: |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 2675 | genlmsg_end(msg, hdr); |
| 2676 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2677 | |
| 2678 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2679 | genlmsg_cancel(msg, hdr); |
| 2680 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2681 | } |
| 2682 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2683 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
| 2684 | struct netlink_callback *cb, |
| 2685 | struct nl80211_dump_wiphy_state *state) |
| 2686 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2687 | struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
| 2688 | int ret; |
| 2689 | |
| 2690 | if (!tb) |
| 2691 | return -ENOMEM; |
| 2692 | |
| 2693 | ret = nlmsg_parse_deprecated(cb->nlh, |
| 2694 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2695 | tb, nl80211_fam.maxattr, |
| 2696 | nl80211_policy, NULL); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2697 | /* ignore parse errors for backward compatibility */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2698 | if (ret) { |
| 2699 | ret = 0; |
| 2700 | goto out; |
| 2701 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2702 | |
| 2703 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; |
| 2704 | if (tb[NL80211_ATTR_WIPHY]) |
| 2705 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 2706 | if (tb[NL80211_ATTR_WDEV]) |
| 2707 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; |
| 2708 | if (tb[NL80211_ATTR_IFINDEX]) { |
| 2709 | struct net_device *netdev; |
| 2710 | struct cfg80211_registered_device *rdev; |
| 2711 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 2712 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 2713 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2714 | if (!netdev) { |
| 2715 | ret = -ENODEV; |
| 2716 | goto out; |
| 2717 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2718 | if (netdev->ieee80211_ptr) { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 2719 | rdev = wiphy_to_rdev( |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2720 | netdev->ieee80211_ptr->wiphy); |
| 2721 | state->filter_wiphy = rdev->wiphy_idx; |
| 2722 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2723 | } |
| 2724 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 2725 | ret = 0; |
| 2726 | out: |
| 2727 | kfree(tb); |
| 2728 | return ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2729 | } |
| 2730 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2731 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 2732 | { |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2733 | int idx = 0, ret; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2734 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2735 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 3a5a423 | 2013-06-19 10:09:57 +0200 | [diff] [blame] | 2736 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2737 | rtnl_lock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2738 | if (!state) { |
| 2739 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
John W. Linville | 57ed5cd | 2013-06-28 13:18:21 -0400 | [diff] [blame] | 2740 | if (!state) { |
| 2741 | rtnl_unlock(); |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2742 | return -ENOMEM; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2743 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2744 | state->filter_wiphy = -1; |
| 2745 | ret = nl80211_dump_wiphy_parse(skb, cb, state); |
| 2746 | if (ret) { |
| 2747 | kfree(state); |
| 2748 | rtnl_unlock(); |
| 2749 | return ret; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2750 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2751 | cb->args[0] = (long)state; |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2752 | } |
| 2753 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2754 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 2755 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2756 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2757 | if (++idx <= state->start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2758 | continue; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2759 | if (state->filter_wiphy != -1 && |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2760 | state->filter_wiphy != rdev->wiphy_idx) |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2761 | continue; |
| 2762 | /* attempt to fit multiple wiphy data chunks into the skb */ |
| 2763 | do { |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2764 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
| 2765 | skb, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2766 | NETLINK_CB(cb->skb).portid, |
| 2767 | cb->nlh->nlmsg_seq, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2768 | NLM_F_MULTI, state); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2769 | if (ret < 0) { |
| 2770 | /* |
| 2771 | * If sending the wiphy data didn't fit (ENOBUFS |
| 2772 | * or EMSGSIZE returned), this SKB is still |
| 2773 | * empty (so it's not too big because another |
| 2774 | * wiphy dataset is already in the skb) and |
| 2775 | * we've not tried to adjust the dump allocation |
| 2776 | * yet ... then adjust the alloc size to be |
| 2777 | * bigger, and return 1 but with the empty skb. |
| 2778 | * This results in an empty message being RX'ed |
| 2779 | * in userspace, but that is ignored. |
| 2780 | * |
| 2781 | * We can then retry with the larger buffer. |
| 2782 | */ |
| 2783 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2784 | !skb->len && !state->split && |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2785 | cb->min_dump_alloc < 4096) { |
| 2786 | cb->min_dump_alloc = 4096; |
Pontus Fuchs | f12cb28 | 2014-01-16 15:00:40 +0100 | [diff] [blame] | 2787 | state->split_start = 0; |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 2788 | rtnl_unlock(); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2789 | return 1; |
| 2790 | } |
| 2791 | idx--; |
| 2792 | break; |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2793 | } |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2794 | } while (state->split_start > 0); |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 2795 | break; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2796 | } |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 2797 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2798 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2799 | state->start = idx; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2800 | |
| 2801 | return skb->len; |
| 2802 | } |
| 2803 | |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2804 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
| 2805 | { |
| 2806 | kfree((void *)cb->args[0]); |
| 2807 | return 0; |
| 2808 | } |
| 2809 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2810 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 2811 | { |
| 2812 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 2813 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2814 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2815 | |
Johannes Berg | 645e77d | 2013-03-01 14:03:49 +0100 | [diff] [blame] | 2816 | msg = nlmsg_new(4096, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2817 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2818 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2819 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 2820 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
| 2821 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 2822 | &state) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 2823 | nlmsg_free(msg); |
| 2824 | return -ENOBUFS; |
| 2825 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2826 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2827 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2828 | } |
| 2829 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2830 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 2831 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 2832 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 2833 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 2834 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 2835 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 2836 | }; |
| 2837 | |
| 2838 | static int parse_txq_params(struct nlattr *tb[], |
| 2839 | struct ieee80211_txq_params *txq_params) |
| 2840 | { |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2841 | u8 ac; |
| 2842 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2843 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2844 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 2845 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 2846 | return -EINVAL; |
| 2847 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2848 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2849 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 2850 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 2851 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 2852 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 2853 | |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2854 | if (ac >= NL80211_NUM_ACS) |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2855 | return -EINVAL; |
Dan Williams | 259d8c1 | 2018-01-29 17:03:15 -0800 | [diff] [blame] | 2856 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2857 | return 0; |
| 2858 | } |
| 2859 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2860 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
| 2861 | { |
| 2862 | /* |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2863 | * You can only set the channel explicitly for WDS interfaces, |
| 2864 | * all others have their channel managed via their respective |
| 2865 | * "establish a connection" command (connect, join, ...) |
| 2866 | * |
| 2867 | * For AP/GO and mesh mode, the channel can be set with the |
| 2868 | * channel userspace API, but is only stored and passed to the |
| 2869 | * low-level driver when the AP starts or the mesh is joined. |
| 2870 | * This is for backward compatibility, userspace can also give |
| 2871 | * the channel in the start-ap or join-mesh commands instead. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2872 | * |
| 2873 | * Monitors are special as they are normally slaved to |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 2874 | * whatever else is going on, so they have their own special |
| 2875 | * operation to set the monitor channel if possible. |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2876 | */ |
| 2877 | return !wdev || |
| 2878 | wdev->iftype == NL80211_IFTYPE_AP || |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2879 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 2880 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
| 2881 | wdev->iftype == NL80211_IFTYPE_P2P_GO; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 2882 | } |
| 2883 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 2884 | int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
| 2885 | struct genl_info *info, |
| 2886 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2887 | { |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2888 | struct netlink_ext_ack *extack = info->extack; |
| 2889 | struct nlattr **attrs = info->attrs; |
Mahesh Palivela | dbeca2e | 2012-11-29 14:11:07 +0530 | [diff] [blame] | 2890 | u32 control_freq; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2891 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2892 | if (!attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2893 | return -EINVAL; |
| 2894 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2895 | control_freq = MHZ_TO_KHZ( |
| 2896 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2897 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 2898 | control_freq += |
| 2899 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2900 | |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 2901 | memset(chandef, 0, sizeof(*chandef)); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2902 | chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2903 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2904 | chandef->center_freq1 = KHZ_TO_MHZ(control_freq); |
| 2905 | chandef->freq1_offset = control_freq % 1000; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2906 | chandef->center_freq2 = 0; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2907 | |
| 2908 | /* Primary channel not allowed */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2909 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) { |
| 2910 | NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ], |
| 2911 | "Channel is disabled"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2912 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2913 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2914 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2915 | if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2916 | enum nl80211_channel_type chantype; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2917 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2918 | chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2919 | |
| 2920 | switch (chantype) { |
| 2921 | case NL80211_CHAN_NO_HT: |
| 2922 | case NL80211_CHAN_HT20: |
| 2923 | case NL80211_CHAN_HT40PLUS: |
| 2924 | case NL80211_CHAN_HT40MINUS: |
| 2925 | cfg80211_chandef_create(chandef, chandef->chan, |
| 2926 | chantype); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2927 | /* user input for center_freq is incorrect */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2928 | if (attrs[NL80211_ATTR_CENTER_FREQ1] && |
| 2929 | chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) { |
| 2930 | NL_SET_ERR_MSG_ATTR(extack, |
| 2931 | attrs[NL80211_ATTR_CENTER_FREQ1], |
| 2932 | "bad center frequency 1"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2933 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2934 | } |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2935 | /* center_freq2 must be zero */ |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2936 | if (attrs[NL80211_ATTR_CENTER_FREQ2] && |
| 2937 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) { |
| 2938 | NL_SET_ERR_MSG_ATTR(extack, |
| 2939 | attrs[NL80211_ATTR_CENTER_FREQ2], |
| 2940 | "center frequency 2 can't be used"); |
Tova Mussai | ffa4629 | 2017-08-05 11:44:38 +0300 | [diff] [blame] | 2941 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2942 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2943 | break; |
| 2944 | default: |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2945 | NL_SET_ERR_MSG_ATTR(extack, |
| 2946 | attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE], |
| 2947 | "invalid channel type"); |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2948 | return -EINVAL; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2949 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2950 | } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2951 | chandef->width = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2952 | nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2953 | if (attrs[NL80211_ATTR_CENTER_FREQ1]) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2954 | chandef->center_freq1 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2955 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 2956 | if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]) |
| 2957 | chandef->freq1_offset = nla_get_u32( |
| 2958 | attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]); |
| 2959 | else |
| 2960 | chandef->freq1_offset = 0; |
| 2961 | } |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2962 | if (attrs[NL80211_ATTR_CENTER_FREQ2]) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2963 | chandef->center_freq2 = |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2964 | nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2965 | } |
| 2966 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 2967 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 2968 | chandef->edmg.channels = |
| 2969 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 2970 | |
| 2971 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 2972 | chandef->edmg.bw_config = |
| 2973 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 2974 | } else { |
| 2975 | chandef->edmg.bw_config = 0; |
| 2976 | chandef->edmg.channels = 0; |
| 2977 | } |
| 2978 | |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2979 | if (!cfg80211_chandef_valid(chandef)) { |
| 2980 | NL_SET_ERR_MSG(extack, "invalid channel definition"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2981 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2982 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2983 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 2984 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2985 | IEEE80211_CHAN_DISABLED)) { |
| 2986 | NL_SET_ERR_MSG(extack, "(extension) channel is disabled"); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2987 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2988 | } |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 2989 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2990 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
| 2991 | chandef->width == NL80211_CHAN_WIDTH_10) && |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2992 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) { |
| 2993 | NL_SET_ERR_MSG(extack, "5/10 MHz not supported"); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2994 | return -EINVAL; |
Johannes Berg | 49f9cf0 | 2018-10-01 11:55:09 +0200 | [diff] [blame] | 2995 | } |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 2996 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 2997 | return 0; |
| 2998 | } |
| 2999 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3000 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3001 | struct net_device *dev, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3002 | struct genl_info *info) |
| 3003 | { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3004 | struct cfg80211_chan_def chandef; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3005 | int result; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3006 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3007 | struct wireless_dev *wdev = NULL; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3008 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3009 | if (dev) |
| 3010 | wdev = dev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3011 | if (!nl80211_can_set_dev_channel(wdev)) |
| 3012 | return -EOPNOTSUPP; |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3013 | if (wdev) |
| 3014 | iftype = wdev->iftype; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3015 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3016 | result = nl80211_parse_chandef(rdev, info, &chandef); |
| 3017 | if (result) |
| 3018 | return result; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3019 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3020 | switch (iftype) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3021 | case NL80211_IFTYPE_AP: |
| 3022 | case NL80211_IFTYPE_P2P_GO: |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 3023 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 3024 | iftype)) { |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3025 | result = -EINVAL; |
| 3026 | break; |
| 3027 | } |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3028 | if (wdev->beacon_interval) { |
| 3029 | if (!dev || !rdev->ops->set_ap_chanwidth || |
| 3030 | !(rdev->wiphy.features & |
| 3031 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { |
| 3032 | result = -EBUSY; |
| 3033 | break; |
| 3034 | } |
| 3035 | |
| 3036 | /* Only allow dynamic channel width changes */ |
| 3037 | if (chandef.chan != wdev->preset_chandef.chan) { |
| 3038 | result = -EBUSY; |
| 3039 | break; |
| 3040 | } |
| 3041 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); |
| 3042 | if (result) |
| 3043 | break; |
| 3044 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3045 | wdev->preset_chandef = chandef; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3046 | result = 0; |
| 3047 | break; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3048 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3049 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 3050 | break; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3051 | case NL80211_IFTYPE_MONITOR: |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3052 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3053 | break; |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 3054 | default: |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3055 | result = -EINVAL; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3056 | } |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3057 | |
| 3058 | return result; |
| 3059 | } |
| 3060 | |
| 3061 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
| 3062 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3063 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3064 | struct net_device *netdev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3065 | |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3066 | return __nl80211_set_channel(rdev, netdev, info); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3067 | } |
| 3068 | |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3069 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
| 3070 | { |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3072 | struct net_device *dev = info->user_ptr[1]; |
| 3073 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 3074 | const u8 *bssid; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3075 | |
| 3076 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3077 | return -EINVAL; |
| 3078 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3079 | if (netif_running(dev)) |
| 3080 | return -EBUSY; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3081 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3082 | if (!rdev->ops->set_wds_peer) |
| 3083 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3084 | |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 3085 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
| 3086 | return -EOPNOTSUPP; |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3087 | |
| 3088 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3089 | return rdev_set_wds_peer(rdev, dev, bssid); |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 3090 | } |
| 3091 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3092 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 3093 | { |
| 3094 | struct cfg80211_registered_device *rdev; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3095 | struct net_device *netdev = NULL; |
| 3096 | struct wireless_dev *wdev; |
Bill Jordan | a1e567c | 2010-09-10 11:22:32 -0400 | [diff] [blame] | 3097 | int result = 0, rem_txq_params = 0; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3098 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3099 | u32 changed; |
| 3100 | u8 retry_short = 0, retry_long = 0; |
| 3101 | u32 frag_threshold = 0, rts_threshold = 0; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3102 | u8 coverage_class = 0; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3103 | u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3104 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3105 | ASSERT_RTNL(); |
| 3106 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3107 | /* |
| 3108 | * Try to find the wiphy and netdev. Normally this |
| 3109 | * function shouldn't need the netdev, but this is |
| 3110 | * done for backward compatibility -- previously |
| 3111 | * setting the channel was done per wiphy, but now |
| 3112 | * it is per netdev. Previous userland like hostapd |
| 3113 | * also passed a netdev to set_wiphy, so that it is |
| 3114 | * possible to let that go to the right netdev! |
| 3115 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3116 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3117 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
| 3118 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); |
| 3119 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3120 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3121 | if (netdev && netdev->ieee80211_ptr) |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 3122 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3123 | else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3124 | netdev = NULL; |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3125 | } |
| 3126 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3127 | if (!netdev) { |
Johannes Berg | 878d9ec | 2012-06-15 14:18:32 +0200 | [diff] [blame] | 3128 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
| 3129 | info->attrs); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3130 | if (IS_ERR(rdev)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3131 | return PTR_ERR(rdev); |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3132 | wdev = NULL; |
| 3133 | netdev = NULL; |
| 3134 | result = 0; |
Johannes Berg | 71fe96b | 2012-10-24 10:04:58 +0200 | [diff] [blame] | 3135 | } else |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3136 | wdev = netdev->ieee80211_ptr; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 3137 | |
| 3138 | /* |
| 3139 | * end workaround code, by now the rdev is available |
| 3140 | * and locked, and wdev may or may not be NULL. |
| 3141 | */ |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3142 | |
| 3143 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3144 | result = cfg80211_dev_rename( |
| 3145 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3146 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 3147 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3148 | return result; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3149 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3150 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 3151 | struct ieee80211_txq_params txq_params; |
| 3152 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 3153 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3154 | if (!rdev->ops->set_txq_params) |
| 3155 | return -EOPNOTSUPP; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3156 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3157 | if (!netdev) |
| 3158 | return -EINVAL; |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 3159 | |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3160 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3161 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 3162 | return -EINVAL; |
Johannes Berg | 133a3ff | 2011-11-03 14:50:13 +0100 | [diff] [blame] | 3163 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3164 | if (!netif_running(netdev)) |
| 3165 | return -ENETDOWN; |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 3166 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3167 | nla_for_each_nested(nl_txq_params, |
| 3168 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 3169 | rem_txq_params) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3170 | result = nla_parse_nested_deprecated(tb, |
| 3171 | NL80211_TXQ_ATTR_MAX, |
| 3172 | nl_txq_params, |
| 3173 | txq_params_policy, |
| 3174 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 3175 | if (result) |
| 3176 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3177 | result = parse_txq_params(tb, &txq_params); |
| 3178 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3179 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3180 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3181 | result = rdev_set_txq_params(rdev, netdev, |
| 3182 | &txq_params); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3183 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3184 | return result; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3185 | } |
| 3186 | } |
| 3187 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3188 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Jouni Malinen | e16821b | 2014-04-28 11:22:08 +0300 | [diff] [blame] | 3189 | result = __nl80211_set_channel( |
| 3190 | rdev, |
| 3191 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, |
| 3192 | info); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3193 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3194 | return result; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 3195 | } |
| 3196 | |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3197 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3198 | struct wireless_dev *txp_wdev = wdev; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3199 | enum nl80211_tx_power_setting type; |
| 3200 | int idx, mbm = 0; |
| 3201 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3202 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
| 3203 | txp_wdev = NULL; |
| 3204 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3205 | if (!rdev->ops->set_tx_power) |
| 3206 | return -EOPNOTSUPP; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3207 | |
| 3208 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; |
| 3209 | type = nla_get_u32(info->attrs[idx]); |
| 3210 | |
| 3211 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3212 | (type != NL80211_TX_POWER_AUTOMATIC)) |
| 3213 | return -EINVAL; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3214 | |
| 3215 | if (type != NL80211_TX_POWER_AUTOMATIC) { |
| 3216 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; |
| 3217 | mbm = nla_get_u32(info->attrs[idx]); |
| 3218 | } |
| 3219 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 3220 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3221 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3222 | return result; |
Juuso Oikarinen | 98d2ff8 | 2010-06-23 12:12:38 +0300 | [diff] [blame] | 3223 | } |
| 3224 | |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3225 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
| 3226 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { |
| 3227 | u32 tx_ant, rx_ant; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 3228 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3229 | if ((!rdev->wiphy.available_antennas_tx && |
| 3230 | !rdev->wiphy.available_antennas_rx) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3231 | !rdev->ops->set_antenna) |
| 3232 | return -EOPNOTSUPP; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3233 | |
| 3234 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); |
| 3235 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); |
| 3236 | |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3237 | /* reject antenna configurations which don't match the |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3238 | * available antenna masks, except for the "all" mask */ |
| 3239 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3240 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
| 3241 | return -EINVAL; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3242 | |
Bruno Randolf | 7f531e0 | 2010-12-16 11:30:22 +0900 | [diff] [blame] | 3243 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
| 3244 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; |
Bruno Randolf | a7ffac9 | 2010-12-08 13:59:24 +0900 | [diff] [blame] | 3245 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3246 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3247 | if (result) |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3248 | return result; |
Bruno Randolf | afe0cbf | 2010-11-10 12:50:50 +0900 | [diff] [blame] | 3249 | } |
| 3250 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3251 | changed = 0; |
| 3252 | |
| 3253 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 3254 | retry_short = nla_get_u8( |
| 3255 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3256 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3257 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 3258 | } |
| 3259 | |
| 3260 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 3261 | retry_long = nla_get_u8( |
| 3262 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3263 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3264 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 3265 | } |
| 3266 | |
| 3267 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 3268 | frag_threshold = nla_get_u32( |
| 3269 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3270 | if (frag_threshold < 256) |
| 3271 | return -EINVAL; |
| 3272 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3273 | if (frag_threshold != (u32) -1) { |
| 3274 | /* |
| 3275 | * Fragments (apart from the last one) are required to |
| 3276 | * have even length. Make the fragmentation code |
| 3277 | * simpler by stripping LSB should someone try to use |
| 3278 | * odd threshold value. |
| 3279 | */ |
| 3280 | frag_threshold &= ~0x1; |
| 3281 | } |
| 3282 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 3283 | } |
| 3284 | |
| 3285 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 3286 | rts_threshold = nla_get_u32( |
| 3287 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 3288 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 3289 | } |
| 3290 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3291 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3292 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
| 3293 | return -EINVAL; |
| 3294 | |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3295 | coverage_class = nla_get_u8( |
| 3296 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); |
| 3297 | changed |= WIPHY_PARAM_COVERAGE_CLASS; |
| 3298 | } |
| 3299 | |
Lorenzo Bianconi | 3057dbf | 2014-09-04 23:57:40 +0200 | [diff] [blame] | 3300 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
| 3301 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) |
| 3302 | return -EOPNOTSUPP; |
| 3303 | |
| 3304 | changed |= WIPHY_PARAM_DYN_ACK; |
| 3305 | } |
| 3306 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3307 | if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) { |
| 3308 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3309 | NL80211_EXT_FEATURE_TXQS)) |
| 3310 | return -EOPNOTSUPP; |
| 3311 | txq_limit = nla_get_u32( |
| 3312 | info->attrs[NL80211_ATTR_TXQ_LIMIT]); |
| 3313 | changed |= WIPHY_PARAM_TXQ_LIMIT; |
| 3314 | } |
| 3315 | |
| 3316 | if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) { |
| 3317 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3318 | NL80211_EXT_FEATURE_TXQS)) |
| 3319 | return -EOPNOTSUPP; |
| 3320 | txq_memory_limit = nla_get_u32( |
| 3321 | info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]); |
| 3322 | changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT; |
| 3323 | } |
| 3324 | |
| 3325 | if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) { |
| 3326 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 3327 | NL80211_EXT_FEATURE_TXQS)) |
| 3328 | return -EOPNOTSUPP; |
| 3329 | txq_quantum = nla_get_u32( |
| 3330 | info->attrs[NL80211_ATTR_TXQ_QUANTUM]); |
| 3331 | changed |= WIPHY_PARAM_TXQ_QUANTUM; |
| 3332 | } |
| 3333 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3334 | if (changed) { |
| 3335 | u8 old_retry_short, old_retry_long; |
| 3336 | u32 old_frag_threshold, old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3337 | u8 old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3338 | u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3339 | |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3340 | if (!rdev->ops->set_wiphy_params) |
| 3341 | return -EOPNOTSUPP; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3342 | |
| 3343 | old_retry_short = rdev->wiphy.retry_short; |
| 3344 | old_retry_long = rdev->wiphy.retry_long; |
| 3345 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 3346 | old_rts_threshold = rdev->wiphy.rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3347 | old_coverage_class = rdev->wiphy.coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3348 | old_txq_limit = rdev->wiphy.txq_limit; |
| 3349 | old_txq_memory_limit = rdev->wiphy.txq_memory_limit; |
| 3350 | old_txq_quantum = rdev->wiphy.txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3351 | |
| 3352 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 3353 | rdev->wiphy.retry_short = retry_short; |
| 3354 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 3355 | rdev->wiphy.retry_long = retry_long; |
| 3356 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 3357 | rdev->wiphy.frag_threshold = frag_threshold; |
| 3358 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 3359 | rdev->wiphy.rts_threshold = rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3360 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
| 3361 | rdev->wiphy.coverage_class = coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3362 | if (changed & WIPHY_PARAM_TXQ_LIMIT) |
| 3363 | rdev->wiphy.txq_limit = txq_limit; |
| 3364 | if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT) |
| 3365 | rdev->wiphy.txq_memory_limit = txq_memory_limit; |
| 3366 | if (changed & WIPHY_PARAM_TXQ_QUANTUM) |
| 3367 | rdev->wiphy.txq_quantum = txq_quantum; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3368 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3369 | result = rdev_set_wiphy_params(rdev, changed); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3370 | if (result) { |
| 3371 | rdev->wiphy.retry_short = old_retry_short; |
| 3372 | rdev->wiphy.retry_long = old_retry_long; |
| 3373 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 3374 | rdev->wiphy.rts_threshold = old_rts_threshold; |
Lukáš Turek | 81077e8 | 2009-12-21 22:50:47 +0100 | [diff] [blame] | 3375 | rdev->wiphy.coverage_class = old_coverage_class; |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3376 | rdev->wiphy.txq_limit = old_txq_limit; |
| 3377 | rdev->wiphy.txq_memory_limit = old_txq_memory_limit; |
| 3378 | rdev->wiphy.txq_quantum = old_txq_quantum; |
Michal Kazior | 9189ee3 | 2015-08-03 10:55:24 +0200 | [diff] [blame] | 3379 | return result; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3380 | } |
| 3381 | } |
Ying Xue | 7f2b856 | 2014-01-15 10:23:45 +0800 | [diff] [blame] | 3382 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3383 | } |
| 3384 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3385 | static int nl80211_send_chandef(struct sk_buff *msg, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 3386 | const struct cfg80211_chan_def *chandef) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3387 | { |
Johannes Berg | 601555c | 2014-11-27 17:26:56 +0100 | [diff] [blame] | 3388 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 3389 | return -EINVAL; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3390 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3391 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 3392 | chandef->chan->center_freq)) |
| 3393 | return -ENOBUFS; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 3394 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 3395 | chandef->chan->freq_offset)) |
| 3396 | return -ENOBUFS; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 3397 | switch (chandef->width) { |
| 3398 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3399 | case NL80211_CHAN_WIDTH_20: |
| 3400 | case NL80211_CHAN_WIDTH_40: |
| 3401 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3402 | cfg80211_get_chandef_type(chandef))) |
| 3403 | return -ENOBUFS; |
| 3404 | break; |
| 3405 | default: |
| 3406 | break; |
| 3407 | } |
| 3408 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) |
| 3409 | return -ENOBUFS; |
| 3410 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) |
| 3411 | return -ENOBUFS; |
| 3412 | if (chandef->center_freq2 && |
| 3413 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3414 | return -ENOBUFS; |
| 3415 | return 0; |
| 3416 | } |
| 3417 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3418 | 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] | 3419 | struct cfg80211_registered_device *rdev, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3420 | struct wireless_dev *wdev, |
| 3421 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3422 | { |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3423 | struct net_device *dev = wdev->netdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3424 | void *hdr; |
| 3425 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3426 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && |
| 3427 | cmd != NL80211_CMD_DEL_INTERFACE && |
| 3428 | cmd != NL80211_CMD_SET_INTERFACE); |
Tomasz Bursztyka | 8f894be | 2014-11-12 16:26:45 +0200 | [diff] [blame] | 3429 | |
| 3430 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3431 | if (!hdr) |
| 3432 | return -1; |
| 3433 | |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3434 | if (dev && |
| 3435 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3436 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3437 | goto nla_put_failure; |
| 3438 | |
| 3439 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 3440 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 3441 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 3442 | NL80211_ATTR_PAD) || |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3443 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3444 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
| 3445 | rdev->devlist_generation ^ |
Antonio Quartulli | 446faa1 | 2018-06-14 09:43:06 +0800 | [diff] [blame] | 3446 | (cfg80211_rdev_list_generation << 2)) || |
| 3447 | nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3448 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3449 | |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3450 | if (rdev->ops->get_channel) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3451 | int ret; |
Johannes Berg | f43e521 | 2019-09-23 13:51:16 +0200 | [diff] [blame] | 3452 | struct cfg80211_chan_def chandef = {}; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3453 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3454 | ret = rdev_get_channel(rdev, wdev, &chandef); |
| 3455 | if (ret == 0) { |
| 3456 | if (nl80211_send_chandef(msg, &chandef)) |
| 3457 | goto nla_put_failure; |
| 3458 | } |
Pontus Fuchs | d91df0e | 2012-04-03 16:39:58 +0200 | [diff] [blame] | 3459 | } |
| 3460 | |
Rafał Miłecki | d55d0d5 | 2015-08-31 22:59:38 +0200 | [diff] [blame] | 3461 | if (rdev->ops->get_tx_power) { |
| 3462 | int dbm, ret; |
| 3463 | |
| 3464 | ret = rdev_get_tx_power(rdev, wdev, &dbm); |
| 3465 | if (ret == 0 && |
| 3466 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, |
| 3467 | DBM_TO_MBM(dbm))) |
| 3468 | goto nla_put_failure; |
| 3469 | } |
| 3470 | |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3471 | wdev_lock(wdev); |
| 3472 | switch (wdev->iftype) { |
| 3473 | case NL80211_IFTYPE_AP: |
| 3474 | if (wdev->ssid_len && |
| 3475 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3476 | goto nla_put_failure_locked; |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3477 | break; |
| 3478 | case NL80211_IFTYPE_STATION: |
| 3479 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3480 | case NL80211_IFTYPE_ADHOC: { |
| 3481 | const u8 *ssid_ie; |
| 3482 | if (!wdev->current_bss) |
| 3483 | break; |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3484 | rcu_read_lock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3485 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
| 3486 | WLAN_EID_SSID); |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3487 | if (ssid_ie && |
| 3488 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) |
| 3489 | goto nla_put_failure_rcu_locked; |
| 3490 | rcu_read_unlock(); |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3491 | break; |
| 3492 | } |
| 3493 | default: |
| 3494 | /* nothing */ |
| 3495 | break; |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3496 | } |
Johannes Berg | 4490526 | 2017-10-17 21:56:01 +0200 | [diff] [blame] | 3497 | wdev_unlock(wdev); |
Antonio Quartulli | b84e7a0 | 2012-11-07 12:52:20 +0100 | [diff] [blame] | 3498 | |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3499 | if (rdev->ops->get_txq_stats) { |
| 3500 | struct cfg80211_txq_stats txqstats = {}; |
| 3501 | int ret = rdev_get_txq_stats(rdev, wdev, &txqstats); |
| 3502 | |
| 3503 | if (ret == 0 && |
| 3504 | !nl80211_put_txq_stats(msg, &txqstats, |
| 3505 | NL80211_ATTR_TXQ_STATS)) |
| 3506 | goto nla_put_failure; |
| 3507 | } |
| 3508 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 3509 | genlmsg_end(msg, hdr); |
| 3510 | return 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3511 | |
Dominik Brodowski | 7a94b8c | 2018-01-15 08:12:15 +0100 | [diff] [blame] | 3512 | nla_put_failure_rcu_locked: |
| 3513 | rcu_read_unlock(); |
Johannes Berg | 4564b18 | 2017-12-11 12:33:47 +0100 | [diff] [blame] | 3514 | nla_put_failure_locked: |
| 3515 | wdev_unlock(wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3516 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 3517 | genlmsg_cancel(msg, hdr); |
| 3518 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 3522 | { |
| 3523 | int wp_idx = 0; |
| 3524 | int if_idx = 0; |
| 3525 | int wp_start = cb->args[0]; |
| 3526 | int if_start = cb->args[1]; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3527 | int filter_wiphy = -1; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3528 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3529 | struct wireless_dev *wdev; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3530 | int ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3531 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 3532 | rtnl_lock(); |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3533 | if (!cb->args[2]) { |
| 3534 | struct nl80211_dump_wiphy_state state = { |
| 3535 | .filter_wiphy = -1, |
| 3536 | }; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3537 | |
| 3538 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); |
| 3539 | if (ret) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3540 | goto out_unlock; |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3541 | |
| 3542 | filter_wiphy = state.filter_wiphy; |
| 3543 | |
| 3544 | /* |
| 3545 | * if filtering, set cb->args[2] to +1 since 0 is the default |
| 3546 | * value needed to determine that parsing is necessary. |
| 3547 | */ |
| 3548 | if (filter_wiphy >= 0) |
| 3549 | cb->args[2] = filter_wiphy + 1; |
| 3550 | else |
| 3551 | cb->args[2] = -1; |
| 3552 | } else if (cb->args[2] > 0) { |
| 3553 | filter_wiphy = cb->args[2] - 1; |
| 3554 | } |
| 3555 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3556 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 3557 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3558 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3559 | if (wp_idx < wp_start) { |
| 3560 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3561 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3562 | } |
Denis Kenzior | b7fb44d | 2016-08-03 17:02:15 -0500 | [diff] [blame] | 3563 | |
| 3564 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) |
| 3565 | continue; |
| 3566 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3567 | if_idx = 0; |
| 3568 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 3569 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3570 | if (if_idx < if_start) { |
| 3571 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3572 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3573 | } |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3574 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3575 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3576 | rdev, wdev, |
| 3577 | NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3578 | goto out; |
| 3579 | } |
| 3580 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3581 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3582 | |
| 3583 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3584 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 3585 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3586 | cb->args[0] = wp_idx; |
| 3587 | cb->args[1] = if_idx; |
| 3588 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 3589 | ret = skb->len; |
| 3590 | out_unlock: |
| 3591 | rtnl_unlock(); |
| 3592 | |
| 3593 | return ret; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 3597 | { |
| 3598 | struct sk_buff *msg; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 3599 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 72fb2ab | 2012-06-15 17:52:47 +0200 | [diff] [blame] | 3600 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3601 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3603 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3604 | return -ENOMEM; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3605 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3606 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3607 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3608 | nlmsg_free(msg); |
| 3609 | return -ENOBUFS; |
| 3610 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3611 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 3612 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3613 | } |
| 3614 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3615 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 3616 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 3617 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 3618 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 3619 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 3620 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3621 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3622 | }; |
| 3623 | |
| 3624 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 3625 | { |
| 3626 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 3627 | int flag; |
| 3628 | |
| 3629 | *mntrflags = 0; |
| 3630 | |
| 3631 | if (!nla) |
| 3632 | return -EINVAL; |
| 3633 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 3634 | 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] | 3635 | return -EINVAL; |
| 3636 | |
| 3637 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 3638 | if (flags[flag]) |
| 3639 | *mntrflags |= (1<<flag); |
| 3640 | |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3641 | *mntrflags |= MONITOR_FLAG_CHANGED; |
| 3642 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 3643 | return 0; |
| 3644 | } |
| 3645 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3646 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
| 3647 | enum nl80211_iftype type, |
| 3648 | struct genl_info *info, |
| 3649 | struct vif_params *params) |
| 3650 | { |
| 3651 | bool change = false; |
| 3652 | int err; |
| 3653 | |
| 3654 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 3655 | if (type != NL80211_IFTYPE_MONITOR) |
| 3656 | return -EINVAL; |
| 3657 | |
| 3658 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 3659 | ¶ms->flags); |
| 3660 | if (err) |
| 3661 | return err; |
| 3662 | |
| 3663 | change = true; |
| 3664 | } |
| 3665 | |
| 3666 | if (params->flags & MONITOR_FLAG_ACTIVE && |
| 3667 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
| 3668 | return -EOPNOTSUPP; |
| 3669 | |
| 3670 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
| 3671 | const u8 *mumimo_groups; |
| 3672 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3673 | |
| 3674 | if (type != NL80211_IFTYPE_MONITOR) |
| 3675 | return -EINVAL; |
| 3676 | |
| 3677 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3678 | return -EOPNOTSUPP; |
| 3679 | |
| 3680 | mumimo_groups = |
| 3681 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); |
| 3682 | |
| 3683 | /* bits 0 and 63 are reserved and must be zero */ |
Johannes Berg | 4954601 | 2017-04-27 09:13:38 +0200 | [diff] [blame] | 3684 | if ((mumimo_groups[0] & BIT(0)) || |
| 3685 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3686 | return -EINVAL; |
| 3687 | |
| 3688 | params->vht_mumimo_groups = mumimo_groups; |
| 3689 | change = true; |
| 3690 | } |
| 3691 | |
| 3692 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { |
| 3693 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; |
| 3694 | |
| 3695 | if (type != NL80211_IFTYPE_MONITOR) |
| 3696 | return -EINVAL; |
| 3697 | |
| 3698 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) |
| 3699 | return -EOPNOTSUPP; |
| 3700 | |
| 3701 | params->vht_mumimo_follow_addr = |
| 3702 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); |
| 3703 | change = true; |
| 3704 | } |
| 3705 | |
| 3706 | return change ? 1 : 0; |
| 3707 | } |
| 3708 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3709 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3710 | struct net_device *netdev, u8 use_4addr, |
| 3711 | enum nl80211_iftype iftype) |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3712 | { |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3713 | if (!use_4addr) { |
Julian Wiedmann | 2e92a2d | 2020-02-20 09:00:07 +0100 | [diff] [blame] | 3714 | if (netdev && netif_is_bridge_port(netdev)) |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3715 | return -EBUSY; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3716 | return 0; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3717 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3718 | |
| 3719 | switch (iftype) { |
| 3720 | case NL80211_IFTYPE_AP_VLAN: |
| 3721 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) |
| 3722 | return 0; |
| 3723 | break; |
| 3724 | case NL80211_IFTYPE_STATION: |
| 3725 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) |
| 3726 | return 0; |
| 3727 | break; |
| 3728 | default: |
| 3729 | break; |
| 3730 | } |
| 3731 | |
| 3732 | return -EOPNOTSUPP; |
| 3733 | } |
| 3734 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3735 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 3736 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3737 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3738 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 3739 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3740 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3741 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3742 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3743 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3744 | memset(¶ms, 0, sizeof(params)); |
| 3745 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3746 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3747 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3748 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3749 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3750 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3751 | change = true; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 3752 | } |
| 3753 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 3754 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3755 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3756 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3757 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
| 3758 | return -EINVAL; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3759 | if (netif_running(dev)) |
| 3760 | return -EBUSY; |
| 3761 | |
| 3762 | wdev_lock(wdev); |
| 3763 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3764 | IEEE80211_MAX_MESH_ID_LEN); |
| 3765 | wdev->mesh_id_up_len = |
| 3766 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3767 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3768 | wdev->mesh_id_up_len); |
| 3769 | wdev_unlock(wdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3770 | } |
| 3771 | |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3772 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
| 3773 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
| 3774 | change = true; |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3775 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3776 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3777 | return err; |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3778 | } else { |
| 3779 | params.use_4addr = -1; |
| 3780 | } |
| 3781 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3782 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
| 3783 | if (err < 0) |
| 3784 | return err; |
| 3785 | if (err > 0) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3786 | change = true; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3787 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3788 | if (change) |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3789 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 3790 | else |
| 3791 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 3792 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3793 | if (!err && params.use_4addr != -1) |
| 3794 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
| 3795 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3796 | if (change && !err) { |
| 3797 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 3798 | |
| 3799 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE); |
| 3800 | } |
| 3801 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3802 | return err; |
| 3803 | } |
| 3804 | |
| 3805 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 3806 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3808 | struct vif_params params; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3809 | struct wireless_dev *wdev; |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 3810 | struct sk_buff *msg; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3811 | int err; |
| 3812 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
| 3813 | |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3814 | /* to avoid failing a new interface creation due to pending removal */ |
| 3815 | cfg80211_destroy_ifaces(rdev); |
| 3816 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3817 | memset(¶ms, 0, sizeof(params)); |
| 3818 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3819 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 3820 | return -EINVAL; |
| 3821 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 3822 | if (info->attrs[NL80211_ATTR_IFTYPE]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3823 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3824 | |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3825 | if (!rdev->ops->add_virtual_intf) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3826 | return -EOPNOTSUPP; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3827 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3828 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
Ben Greear | e8f479b | 2014-10-22 12:23:05 -0700 | [diff] [blame] | 3829 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
| 3830 | info->attrs[NL80211_ATTR_MAC]) { |
Arend van Spriel | 1c18f14 | 2013-01-08 10:17:27 +0100 | [diff] [blame] | 3831 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
| 3832 | ETH_ALEN); |
| 3833 | if (!is_valid_ether_addr(params.macaddr)) |
| 3834 | return -EADDRNOTAVAIL; |
| 3835 | } |
| 3836 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3837 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3838 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
Johannes Berg | ad4bb6f | 2009-11-19 00:56:30 +0100 | [diff] [blame] | 3839 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3840 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3841 | return err; |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 3842 | } |
Felix Fietkau | 8b78764 | 2009-11-10 18:53:10 +0100 | [diff] [blame] | 3843 | |
Manikanta Pubbisetty | e6f4051 | 2019-07-22 12:44:50 +0530 | [diff] [blame] | 3844 | if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0)) |
Manikanta Pubbisetty | 33d915d | 2019-05-08 14:55:33 +0530 | [diff] [blame] | 3845 | return -EOPNOTSUPP; |
| 3846 | |
Johannes Berg | 1db7759 | 2017-04-12 11:36:31 +0200 | [diff] [blame] | 3847 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
| 3848 | if (err < 0) |
| 3849 | return err; |
Felix Fietkau | e057d3c | 2013-05-28 13:01:52 +0200 | [diff] [blame] | 3850 | |
Johannes Berg | a18c719 | 2015-02-24 10:56:42 +0100 | [diff] [blame] | 3851 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 3852 | if (!msg) |
| 3853 | return -ENOMEM; |
| 3854 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3855 | wdev = rdev_add_virtual_intf(rdev, |
| 3856 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 3857 | NET_NAME_USER, type, ¶ms); |
Rafał Miłecki | d687cbb | 2014-11-14 18:43:28 +0100 | [diff] [blame] | 3858 | if (WARN_ON(!wdev)) { |
| 3859 | nlmsg_free(msg); |
| 3860 | return -EPROTO; |
| 3861 | } else if (IS_ERR(wdev)) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3862 | nlmsg_free(msg); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3863 | return PTR_ERR(wdev); |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3864 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3865 | |
Jukka Rissanen | 18e5ca6 | 2014-11-13 17:25:14 +0200 | [diff] [blame] | 3866 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 3867 | wdev->owner_nlportid = info->snd_portid; |
| 3868 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3869 | switch (type) { |
| 3870 | case NL80211_IFTYPE_MESH_POINT: |
| 3871 | if (!info->attrs[NL80211_ATTR_MESH_ID]) |
| 3872 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3873 | wdev_lock(wdev); |
| 3874 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != |
| 3875 | IEEE80211_MAX_MESH_ID_LEN); |
| 3876 | wdev->mesh_id_up_len = |
| 3877 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 3878 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), |
| 3879 | wdev->mesh_id_up_len); |
| 3880 | wdev_unlock(wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3881 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3882 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3883 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3884 | /* |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 3885 | * 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] | 3886 | * through the netdev notifier and must be added here |
| 3887 | */ |
Johannes Berg | e4d4216 | 2018-09-13 14:12:03 +0200 | [diff] [blame] | 3888 | cfg80211_init_wdev(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 3889 | break; |
| 3890 | default: |
| 3891 | break; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3892 | } |
| 3893 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 3894 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 3895 | rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) { |
Johannes Berg | 1c90f9d | 2012-06-16 00:05:37 +0200 | [diff] [blame] | 3896 | nlmsg_free(msg); |
| 3897 | return -ENOBUFS; |
| 3898 | } |
| 3899 | |
| 3900 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 3904 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3905 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3906 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3907 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3908 | if (!rdev->ops->del_virtual_intf) |
| 3909 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3910 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 3911 | /* |
| 3912 | * If we remove a wireless device without a netdev then clear |
| 3913 | * user_ptr[1] so that nl80211_post_doit won't dereference it |
| 3914 | * to check if it needs to do dev_put(). Otherwise it crashes |
| 3915 | * since the wdev has been freed, unlike with a netdev where |
| 3916 | * we need the dev_put() for the netdev to really be freed. |
| 3917 | */ |
| 3918 | if (!wdev->netdev) |
| 3919 | info->user_ptr[1] = NULL; |
| 3920 | |
Denis Kenzior | 7f8ed01 | 2016-08-03 16:58:35 -0500 | [diff] [blame] | 3921 | return rdev_del_virtual_intf(rdev, wdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3922 | } |
| 3923 | |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3924 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
| 3925 | { |
| 3926 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 3927 | struct net_device *dev = info->user_ptr[1]; |
| 3928 | u16 noack_map; |
| 3929 | |
| 3930 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) |
| 3931 | return -EINVAL; |
| 3932 | |
| 3933 | if (!rdev->ops->set_noack_map) |
| 3934 | return -EOPNOTSUPP; |
| 3935 | |
| 3936 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); |
| 3937 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 3938 | return rdev_set_noack_map(rdev, dev, noack_map); |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 3939 | } |
| 3940 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3941 | struct get_key_cookie { |
| 3942 | struct sk_buff *msg; |
| 3943 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3944 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3945 | }; |
| 3946 | |
| 3947 | static void get_key_callback(void *c, struct key_params *params) |
| 3948 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3949 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3950 | struct get_key_cookie *cookie = c; |
| 3951 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3952 | if ((params->key && |
| 3953 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 3954 | params->key_len, params->key)) || |
| 3955 | (params->seq && |
| 3956 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 3957 | params->seq_len, params->seq)) || |
| 3958 | (params->cipher && |
| 3959 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 3960 | params->cipher))) |
| 3961 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3962 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 3963 | key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY); |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3964 | if (!key) |
| 3965 | goto nla_put_failure; |
| 3966 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3967 | if ((params->key && |
| 3968 | nla_put(cookie->msg, NL80211_KEY_DATA, |
| 3969 | params->key_len, params->key)) || |
| 3970 | (params->seq && |
| 3971 | nla_put(cookie->msg, NL80211_KEY_SEQ, |
| 3972 | params->seq_len, params->seq)) || |
| 3973 | (params->cipher && |
| 3974 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, |
| 3975 | params->cipher))) |
| 3976 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3977 | |
Andrew Zaborowski | efdfce7 | 2018-09-24 18:10:22 +0200 | [diff] [blame] | 3978 | if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 3979 | goto nla_put_failure; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 3980 | |
| 3981 | nla_nest_end(cookie->msg, key); |
| 3982 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3983 | return; |
| 3984 | nla_put_failure: |
| 3985 | cookie->error = 1; |
| 3986 | } |
| 3987 | |
| 3988 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 3989 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3991 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 3992 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3993 | u8 key_idx = 0; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 3994 | const u8 *mac_addr = NULL; |
| 3995 | bool pairwise; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3996 | struct get_key_cookie cookie = { |
| 3997 | .error = 0, |
| 3998 | }; |
| 3999 | void *hdr; |
| 4000 | struct sk_buff *msg; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 4001 | bool bigtk_support = false; |
| 4002 | |
| 4003 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 4004 | NL80211_EXT_FEATURE_BEACON_PROTECTION)) |
| 4005 | bigtk_support = true; |
| 4006 | |
| 4007 | if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION || |
| 4008 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) && |
| 4009 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4010 | NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT)) |
| 4011 | bigtk_support = true; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4012 | |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4013 | if (info->attrs[NL80211_ATTR_KEY_IDX]) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4014 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 4015 | |
| 4016 | if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) { |
| 4017 | GENL_SET_ERR_MSG(info, "BIGTK not supported"); |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4018 | return -EINVAL; |
Johannes Berg | 155d7c7 | 2020-04-20 14:06:00 +0200 | [diff] [blame] | 4019 | } |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4020 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4021 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4022 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4023 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4024 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4025 | pairwise = !!mac_addr; |
| 4026 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
| 4027 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 4028 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4029 | if (kt != NL80211_KEYTYPE_GROUP && |
| 4030 | kt != NL80211_KEYTYPE_PAIRWISE) |
| 4031 | return -EINVAL; |
| 4032 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
| 4033 | } |
| 4034 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4035 | if (!rdev->ops->get_key) |
| 4036 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4037 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4038 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4039 | return -ENOENT; |
| 4040 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4041 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4042 | if (!msg) |
| 4043 | return -ENOMEM; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4044 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 4045 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4046 | NL80211_CMD_NEW_KEY); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 4047 | if (!hdr) |
Johannes Berg | 9fe271a | 2013-10-25 11:15:12 +0200 | [diff] [blame] | 4048 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4049 | |
| 4050 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4051 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4052 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 4053 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 4054 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 4055 | goto nla_put_failure; |
| 4056 | if (mac_addr && |
| 4057 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) |
| 4058 | goto nla_put_failure; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4059 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4060 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
| 4061 | get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4062 | |
| 4063 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 4064 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4065 | |
| 4066 | if (cookie.error) |
| 4067 | goto nla_put_failure; |
| 4068 | |
| 4069 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4070 | return genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4071 | |
| 4072 | nla_put_failure: |
| 4073 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 4074 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4075 | nlmsg_free(msg); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4076 | return err; |
| 4077 | } |
| 4078 | |
| 4079 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 4080 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4082 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4083 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4084 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4085 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4086 | err = nl80211_parse_key(info, &key); |
| 4087 | if (err) |
| 4088 | return err; |
| 4089 | |
| 4090 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4091 | return -EINVAL; |
| 4092 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4093 | /* Only support setting default key and |
| 4094 | * Extended Key ID action NL80211_KEY_SET_TX. |
| 4095 | */ |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4096 | if (!key.def && !key.defmgmt && !key.defbeacon && |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4097 | !(key.p.mode == NL80211_KEY_SET_TX)) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4098 | return -EINVAL; |
| 4099 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4100 | wdev_lock(dev->ieee80211_ptr); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4101 | |
| 4102 | if (key.def) { |
| 4103 | if (!rdev->ops->set_default_key) { |
| 4104 | err = -EOPNOTSUPP; |
| 4105 | goto out; |
| 4106 | } |
| 4107 | |
| 4108 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4109 | if (err) |
| 4110 | goto out; |
| 4111 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4112 | err = rdev_set_default_key(rdev, dev, key.idx, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4113 | key.def_uni, key.def_multi); |
| 4114 | |
| 4115 | if (err) |
| 4116 | goto out; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4117 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4118 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4119 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4120 | #endif |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4121 | } else if (key.defmgmt) { |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4122 | if (key.def_uni || !key.def_multi) { |
| 4123 | err = -EINVAL; |
| 4124 | goto out; |
| 4125 | } |
| 4126 | |
| 4127 | if (!rdev->ops->set_default_mgmt_key) { |
| 4128 | err = -EOPNOTSUPP; |
| 4129 | goto out; |
| 4130 | } |
| 4131 | |
| 4132 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4133 | if (err) |
| 4134 | goto out; |
| 4135 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4136 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4137 | if (err) |
| 4138 | goto out; |
| 4139 | |
| 4140 | #ifdef CONFIG_CFG80211_WEXT |
| 4141 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
| 4142 | #endif |
Jouni Malinen | 56be393 | 2020-02-22 15:25:43 +0200 | [diff] [blame] | 4143 | } else if (key.defbeacon) { |
| 4144 | if (key.def_uni || !key.def_multi) { |
| 4145 | err = -EINVAL; |
| 4146 | goto out; |
| 4147 | } |
| 4148 | |
| 4149 | if (!rdev->ops->set_default_beacon_key) { |
| 4150 | err = -EOPNOTSUPP; |
| 4151 | goto out; |
| 4152 | } |
| 4153 | |
| 4154 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 4155 | if (err) |
| 4156 | goto out; |
| 4157 | |
| 4158 | err = rdev_set_default_beacon_key(rdev, dev, key.idx); |
| 4159 | if (err) |
| 4160 | goto out; |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4161 | } else if (key.p.mode == NL80211_KEY_SET_TX && |
| 4162 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4163 | NL80211_EXT_FEATURE_EXT_KEY_ID)) { |
| 4164 | u8 *mac_addr = NULL; |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4165 | |
Alexander Wetzel | 6cdd397 | 2019-03-19 21:34:07 +0100 | [diff] [blame] | 4166 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4167 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4168 | |
| 4169 | if (!mac_addr || key.idx < 0 || key.idx > 1) { |
| 4170 | err = -EINVAL; |
| 4171 | goto out; |
| 4172 | } |
| 4173 | |
| 4174 | err = rdev_add_key(rdev, dev, key.idx, |
| 4175 | NL80211_KEYTYPE_PAIRWISE, |
| 4176 | mac_addr, &key.p); |
| 4177 | } else { |
| 4178 | err = -EINVAL; |
| 4179 | } |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 4180 | out: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4181 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4182 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4183 | return err; |
| 4184 | } |
| 4185 | |
| 4186 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 4187 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4189 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4190 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4191 | struct key_parse key; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4192 | const u8 *mac_addr = NULL; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4193 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4194 | err = nl80211_parse_key(info, &key); |
| 4195 | if (err) |
| 4196 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4197 | |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4198 | if (!key.p.key) { |
| 4199 | GENL_SET_ERR_MSG(info, "no key"); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4200 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4201 | } |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4202 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4203 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4204 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4205 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4206 | if (key.type == -1) { |
| 4207 | if (mac_addr) |
| 4208 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4209 | else |
| 4210 | key.type = NL80211_KEYTYPE_GROUP; |
| 4211 | } |
| 4212 | |
| 4213 | /* for now */ |
| 4214 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4215 | key.type != NL80211_KEYTYPE_GROUP) { |
| 4216 | GENL_SET_ERR_MSG(info, "key type not pairwise or group"); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4217 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4218 | } |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4219 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 4220 | if (key.type == NL80211_KEYTYPE_GROUP && |
| 4221 | info->attrs[NL80211_ATTR_VLAN_ID]) |
| 4222 | key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 4223 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4224 | if (!rdev->ops->add_key) |
| 4225 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 4226 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4227 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
| 4228 | key.type == NL80211_KEYTYPE_PAIRWISE, |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4229 | mac_addr)) { |
| 4230 | GENL_SET_ERR_MSG(info, "key setting validation failed"); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4231 | return -EINVAL; |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4232 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4233 | |
| 4234 | wdev_lock(dev->ieee80211_ptr); |
| 4235 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4236 | if (err) |
| 4237 | GENL_SET_ERR_MSG(info, "key not allowed"); |
| 4238 | if (!err) { |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4239 | err = rdev_add_key(rdev, dev, key.idx, |
| 4240 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4241 | mac_addr, &key.p); |
Jouni Malinen | f8af764 | 2020-02-22 15:25:42 +0200 | [diff] [blame] | 4242 | if (err) |
| 4243 | GENL_SET_ERR_MSG(info, "key addition failed"); |
| 4244 | } |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4245 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4246 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4247 | return err; |
| 4248 | } |
| 4249 | |
| 4250 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 4251 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4252 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4253 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4254 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4255 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4256 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4257 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4258 | err = nl80211_parse_key(info, &key); |
| 4259 | if (err) |
| 4260 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4261 | |
Anant Thazhemadam | 3dc289f | 2020-10-07 09:24:01 +0530 | [diff] [blame] | 4262 | if (key.idx < 0) |
| 4263 | return -EINVAL; |
| 4264 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4265 | if (info->attrs[NL80211_ATTR_MAC]) |
| 4266 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 4267 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4268 | if (key.type == -1) { |
| 4269 | if (mac_addr) |
| 4270 | key.type = NL80211_KEYTYPE_PAIRWISE; |
| 4271 | else |
| 4272 | key.type = NL80211_KEYTYPE_GROUP; |
| 4273 | } |
| 4274 | |
| 4275 | /* for now */ |
| 4276 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
| 4277 | key.type != NL80211_KEYTYPE_GROUP) |
| 4278 | return -EINVAL; |
| 4279 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4280 | if (!rdev->ops->del_key) |
| 4281 | return -EOPNOTSUPP; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4282 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4283 | wdev_lock(dev->ieee80211_ptr); |
| 4284 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4285 | |
Johannes Berg | 0fa7b39 | 2015-01-23 11:10:12 +0100 | [diff] [blame] | 4286 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 4287 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
| 4288 | err = -ENOENT; |
| 4289 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4290 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 4291 | err = rdev_del_key(rdev, dev, key.idx, |
| 4292 | key.type == NL80211_KEYTYPE_PAIRWISE, |
| 4293 | mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4294 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 4295 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4296 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4297 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4298 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 4299 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4300 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 4301 | } |
| 4302 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 4303 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4304 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4305 | return err; |
| 4306 | } |
| 4307 | |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4308 | /* This function returns an error or the number of nested attributes */ |
| 4309 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) |
| 4310 | { |
| 4311 | struct nlattr *attr; |
| 4312 | int n_entries = 0, tmp; |
| 4313 | |
| 4314 | nla_for_each_nested(attr, nl_attr, tmp) { |
| 4315 | if (nla_len(attr) != ETH_ALEN) |
| 4316 | return -EINVAL; |
| 4317 | |
| 4318 | n_entries++; |
| 4319 | } |
| 4320 | |
| 4321 | return n_entries; |
| 4322 | } |
| 4323 | |
| 4324 | /* |
| 4325 | * This function parses ACL information and allocates memory for ACL data. |
| 4326 | * On successful return, the calling function is responsible to free the |
| 4327 | * ACL buffer returned by this function. |
| 4328 | */ |
| 4329 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, |
| 4330 | struct genl_info *info) |
| 4331 | { |
| 4332 | enum nl80211_acl_policy acl_policy; |
| 4333 | struct nlattr *attr; |
| 4334 | struct cfg80211_acl_data *acl; |
| 4335 | int i = 0, n_entries, tmp; |
| 4336 | |
| 4337 | if (!wiphy->max_acl_mac_addrs) |
| 4338 | return ERR_PTR(-EOPNOTSUPP); |
| 4339 | |
| 4340 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) |
| 4341 | return ERR_PTR(-EINVAL); |
| 4342 | |
| 4343 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); |
| 4344 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && |
| 4345 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) |
| 4346 | return ERR_PTR(-EINVAL); |
| 4347 | |
| 4348 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) |
| 4349 | return ERR_PTR(-EINVAL); |
| 4350 | |
| 4351 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); |
| 4352 | if (n_entries < 0) |
| 4353 | return ERR_PTR(n_entries); |
| 4354 | |
| 4355 | if (n_entries > wiphy->max_acl_mac_addrs) |
| 4356 | return ERR_PTR(-ENOTSUPP); |
| 4357 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 4358 | acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 4359 | if (!acl) |
| 4360 | return ERR_PTR(-ENOMEM); |
| 4361 | |
| 4362 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { |
| 4363 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); |
| 4364 | i++; |
| 4365 | } |
| 4366 | |
| 4367 | acl->n_acl_entries = n_entries; |
| 4368 | acl->acl_policy = acl_policy; |
| 4369 | |
| 4370 | return acl; |
| 4371 | } |
| 4372 | |
| 4373 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) |
| 4374 | { |
| 4375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 4376 | struct net_device *dev = info->user_ptr[1]; |
| 4377 | struct cfg80211_acl_data *acl; |
| 4378 | int err; |
| 4379 | |
| 4380 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 4381 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 4382 | return -EOPNOTSUPP; |
| 4383 | |
| 4384 | if (!dev->ieee80211_ptr->beacon_interval) |
| 4385 | return -EINVAL; |
| 4386 | |
| 4387 | acl = parse_acl_data(&rdev->wiphy, info); |
| 4388 | if (IS_ERR(acl)) |
| 4389 | return PTR_ERR(acl); |
| 4390 | |
| 4391 | err = rdev_set_mac_acl(rdev, dev, acl); |
| 4392 | |
| 4393 | kfree(acl); |
| 4394 | |
| 4395 | return err; |
| 4396 | } |
| 4397 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4398 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4399 | u8 *rates, u8 rates_len) |
| 4400 | { |
| 4401 | u8 i; |
| 4402 | u32 mask = 0; |
| 4403 | |
| 4404 | for (i = 0; i < rates_len; i++) { |
| 4405 | int rate = (rates[i] & 0x7f) * 5; |
| 4406 | int ridx; |
| 4407 | |
| 4408 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { |
| 4409 | struct ieee80211_rate *srate = |
| 4410 | &sband->bitrates[ridx]; |
| 4411 | if (rate == srate->bitrate) { |
| 4412 | mask |= 1 << ridx; |
| 4413 | break; |
| 4414 | } |
| 4415 | } |
| 4416 | if (ridx == sband->n_bitrates) |
| 4417 | return 0; /* rate not found */ |
| 4418 | } |
| 4419 | |
| 4420 | return mask; |
| 4421 | } |
| 4422 | |
| 4423 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
| 4424 | u8 *rates, u8 rates_len, |
| 4425 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) |
| 4426 | { |
| 4427 | u8 i; |
| 4428 | |
| 4429 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 4430 | |
| 4431 | for (i = 0; i < rates_len; i++) { |
| 4432 | int ridx, rbit; |
| 4433 | |
| 4434 | ridx = rates[i] / 8; |
| 4435 | rbit = BIT(rates[i] % 8); |
| 4436 | |
| 4437 | /* check validity */ |
| 4438 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
| 4439 | return false; |
| 4440 | |
| 4441 | /* check availability */ |
Masashi Honma | 30fe6d5 | 2018-09-25 11:15:00 +0900 | [diff] [blame] | 4442 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4443 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
| 4444 | mcs[ridx] |= rbit; |
| 4445 | else |
| 4446 | return false; |
| 4447 | } |
| 4448 | |
| 4449 | return true; |
| 4450 | } |
| 4451 | |
| 4452 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
| 4453 | { |
| 4454 | u16 mcs_mask = 0; |
| 4455 | |
| 4456 | switch (vht_mcs_map) { |
| 4457 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: |
| 4458 | break; |
| 4459 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 4460 | mcs_mask = 0x00FF; |
| 4461 | break; |
| 4462 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 4463 | mcs_mask = 0x01FF; |
| 4464 | break; |
| 4465 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 4466 | mcs_mask = 0x03FF; |
| 4467 | break; |
| 4468 | default: |
| 4469 | break; |
| 4470 | } |
| 4471 | |
| 4472 | return mcs_mask; |
| 4473 | } |
| 4474 | |
| 4475 | static void vht_build_mcs_mask(u16 vht_mcs_map, |
| 4476 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) |
| 4477 | { |
| 4478 | u8 nss; |
| 4479 | |
| 4480 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { |
| 4481 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); |
| 4482 | vht_mcs_map >>= 2; |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, |
| 4487 | struct nl80211_txrate_vht *txrate, |
| 4488 | u16 mcs[NL80211_VHT_NSS_MAX]) |
| 4489 | { |
| 4490 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4491 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; |
| 4492 | u8 i; |
| 4493 | |
| 4494 | if (!sband->vht_cap.vht_supported) |
| 4495 | return false; |
| 4496 | |
| 4497 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); |
| 4498 | |
| 4499 | /* Build vht_mcs_mask from VHT capabilities */ |
| 4500 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4501 | |
| 4502 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
| 4503 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4504 | mcs[i] = txrate->mcs[i]; |
| 4505 | else |
| 4506 | return false; |
| 4507 | } |
| 4508 | |
| 4509 | return true; |
| 4510 | } |
| 4511 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4512 | static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map) |
| 4513 | { |
| 4514 | switch (he_mcs_map) { |
| 4515 | case IEEE80211_HE_MCS_NOT_SUPPORTED: |
| 4516 | return 0; |
| 4517 | case IEEE80211_HE_MCS_SUPPORT_0_7: |
| 4518 | return 0x00FF; |
| 4519 | case IEEE80211_HE_MCS_SUPPORT_0_9: |
| 4520 | return 0x03FF; |
| 4521 | case IEEE80211_HE_MCS_SUPPORT_0_11: |
| 4522 | return 0xFFF; |
| 4523 | default: |
| 4524 | break; |
| 4525 | } |
| 4526 | return 0; |
| 4527 | } |
| 4528 | |
| 4529 | static void he_build_mcs_mask(u16 he_mcs_map, |
| 4530 | u16 he_mcs_mask[NL80211_HE_NSS_MAX]) |
| 4531 | { |
| 4532 | u8 nss; |
| 4533 | |
| 4534 | for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) { |
| 4535 | he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03); |
| 4536 | he_mcs_map >>= 2; |
| 4537 | } |
| 4538 | } |
| 4539 | |
| 4540 | static u16 he_get_txmcsmap(struct genl_info *info, |
| 4541 | const struct ieee80211_sta_he_cap *he_cap) |
| 4542 | { |
| 4543 | struct net_device *dev = info->user_ptr[1]; |
| 4544 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 4545 | __le16 tx_mcs; |
| 4546 | |
| 4547 | switch (wdev->chandef.width) { |
| 4548 | case NL80211_CHAN_WIDTH_80P80: |
| 4549 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80; |
| 4550 | break; |
| 4551 | case NL80211_CHAN_WIDTH_160: |
| 4552 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160; |
| 4553 | break; |
| 4554 | default: |
| 4555 | tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80; |
| 4556 | break; |
| 4557 | } |
| 4558 | return le16_to_cpu(tx_mcs); |
| 4559 | } |
| 4560 | |
| 4561 | static bool he_set_mcs_mask(struct genl_info *info, |
| 4562 | struct wireless_dev *wdev, |
| 4563 | struct ieee80211_supported_band *sband, |
| 4564 | struct nl80211_txrate_he *txrate, |
| 4565 | u16 mcs[NL80211_HE_NSS_MAX]) |
| 4566 | { |
| 4567 | const struct ieee80211_sta_he_cap *he_cap; |
| 4568 | u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {}; |
| 4569 | u16 tx_mcs_map = 0; |
| 4570 | u8 i; |
| 4571 | |
| 4572 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4573 | if (!he_cap) |
| 4574 | return false; |
| 4575 | |
| 4576 | memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX); |
| 4577 | |
| 4578 | tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4579 | |
| 4580 | /* Build he_mcs_mask from HE capabilities */ |
| 4581 | he_build_mcs_mask(tx_mcs_map, tx_mcs_mask); |
| 4582 | |
| 4583 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) { |
| 4584 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) |
| 4585 | mcs[i] = txrate->mcs[i]; |
| 4586 | else |
| 4587 | return false; |
| 4588 | } |
| 4589 | |
| 4590 | return true; |
| 4591 | } |
| 4592 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4593 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4594 | struct nlattr *attrs[], |
| 4595 | enum nl80211_attrs attr, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4596 | struct cfg80211_bitrate_mask *mask, |
| 4597 | struct net_device *dev) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4598 | { |
| 4599 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
| 4600 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4601 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4602 | int rem, i; |
| 4603 | struct nlattr *tx_rates; |
| 4604 | struct ieee80211_supported_band *sband; |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4605 | u16 vht_tx_mcs_map, he_tx_mcs_map; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4606 | |
| 4607 | memset(mask, 0, sizeof(*mask)); |
| 4608 | /* Default to all rates enabled */ |
| 4609 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4610 | const struct ieee80211_sta_he_cap *he_cap; |
| 4611 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4612 | sband = rdev->wiphy.bands[i]; |
| 4613 | |
| 4614 | if (!sband) |
| 4615 | continue; |
| 4616 | |
| 4617 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; |
| 4618 | memcpy(mask->control[i].ht_mcs, |
| 4619 | sband->ht_cap.mcs.rx_mask, |
| 4620 | sizeof(mask->control[i].ht_mcs)); |
| 4621 | |
| 4622 | if (!sband->vht_cap.vht_supported) |
| 4623 | continue; |
| 4624 | |
| 4625 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); |
| 4626 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4627 | |
| 4628 | he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype); |
| 4629 | if (!he_cap) |
| 4630 | continue; |
| 4631 | |
| 4632 | he_tx_mcs_map = he_get_txmcsmap(info, he_cap); |
| 4633 | he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs); |
| 4634 | |
| 4635 | mask->control[i].he_gi = 0xFF; |
| 4636 | mask->control[i].he_ltf = 0xFF; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | /* if no rates are given set it back to the defaults */ |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 4640 | if (!attrs[attr]) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4641 | goto out; |
| 4642 | |
| 4643 | /* The nested attribute uses enum nl80211_band as the index. This maps |
| 4644 | * directly to the enum nl80211_band values used in cfg80211. |
| 4645 | */ |
| 4646 | 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] | 4647 | nla_for_each_nested(tx_rates, attrs[attr], rem) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4648 | enum nl80211_band band = nla_type(tx_rates); |
| 4649 | int err; |
| 4650 | |
| 4651 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 4652 | return -EINVAL; |
| 4653 | sband = rdev->wiphy.bands[band]; |
| 4654 | if (sband == NULL) |
| 4655 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4656 | err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX, |
| 4657 | tx_rates, |
| 4658 | nl80211_txattr_policy, |
| 4659 | info->extack); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4660 | if (err) |
| 4661 | return err; |
| 4662 | if (tb[NL80211_TXRATE_LEGACY]) { |
| 4663 | mask->control[band].legacy = rateset_to_mask( |
| 4664 | sband, |
| 4665 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
| 4666 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
| 4667 | if ((mask->control[band].legacy == 0) && |
| 4668 | nla_len(tb[NL80211_TXRATE_LEGACY])) |
| 4669 | return -EINVAL; |
| 4670 | } |
| 4671 | if (tb[NL80211_TXRATE_HT]) { |
| 4672 | if (!ht_rateset_to_mask( |
| 4673 | sband, |
| 4674 | nla_data(tb[NL80211_TXRATE_HT]), |
| 4675 | nla_len(tb[NL80211_TXRATE_HT]), |
| 4676 | mask->control[band].ht_mcs)) |
| 4677 | return -EINVAL; |
| 4678 | } |
| 4679 | if (tb[NL80211_TXRATE_VHT]) { |
| 4680 | if (!vht_set_mcs_mask( |
| 4681 | sband, |
| 4682 | nla_data(tb[NL80211_TXRATE_VHT]), |
| 4683 | mask->control[band].vht_mcs)) |
| 4684 | return -EINVAL; |
| 4685 | } |
| 4686 | if (tb[NL80211_TXRATE_GI]) { |
| 4687 | mask->control[band].gi = |
| 4688 | nla_get_u8(tb[NL80211_TXRATE_GI]); |
| 4689 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) |
| 4690 | return -EINVAL; |
| 4691 | } |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4692 | if (tb[NL80211_TXRATE_HE] && |
| 4693 | !he_set_mcs_mask(info, wdev, sband, |
| 4694 | nla_data(tb[NL80211_TXRATE_HE]), |
| 4695 | mask->control[band].he_mcs)) |
| 4696 | return -EINVAL; |
| 4697 | if (tb[NL80211_TXRATE_HE_GI]) |
| 4698 | mask->control[band].he_gi = |
| 4699 | nla_get_u8(tb[NL80211_TXRATE_HE_GI]); |
| 4700 | if (tb[NL80211_TXRATE_HE_LTF]) |
| 4701 | mask->control[band].he_ltf = |
| 4702 | nla_get_u8(tb[NL80211_TXRATE_HE_LTF]); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4703 | |
| 4704 | if (mask->control[band].legacy == 0) { |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4705 | /* don't allow empty legacy rates if HT, VHT or HE |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4706 | * are not even supported. |
| 4707 | */ |
| 4708 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4709 | rdev->wiphy.bands[band]->vht_cap.vht_supported || |
| 4710 | ieee80211_get_he_iftype_cap(sband, wdev->iftype))) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4711 | return -EINVAL; |
| 4712 | |
| 4713 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 4714 | if (mask->control[band].ht_mcs[i]) |
| 4715 | goto out; |
| 4716 | |
| 4717 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) |
| 4718 | if (mask->control[band].vht_mcs[i]) |
| 4719 | goto out; |
| 4720 | |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 4721 | for (i = 0; i < NL80211_HE_NSS_MAX; i++) |
| 4722 | if (mask->control[band].he_mcs[i]) |
| 4723 | goto out; |
| 4724 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4725 | /* legacy and mcs rates may not be both empty */ |
| 4726 | return -EINVAL; |
| 4727 | } |
| 4728 | } |
| 4729 | |
| 4730 | out: |
| 4731 | return 0; |
| 4732 | } |
| 4733 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4734 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
| 4735 | enum nl80211_band band, |
| 4736 | struct cfg80211_bitrate_mask *beacon_rate) |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4737 | { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4738 | u32 count_ht, count_vht, i; |
| 4739 | u32 rate = beacon_rate->control[band].legacy; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4740 | |
| 4741 | /* Allow only one rate */ |
| 4742 | if (hweight32(rate) > 1) |
| 4743 | return -EINVAL; |
| 4744 | |
| 4745 | count_ht = 0; |
| 4746 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4747 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4748 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4749 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4750 | count_ht++; |
| 4751 | if (count_ht > 1) |
| 4752 | return -EINVAL; |
| 4753 | } |
| 4754 | if (count_ht && rate) |
| 4755 | return -EINVAL; |
| 4756 | } |
| 4757 | |
| 4758 | count_vht = 0; |
| 4759 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4760 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4761 | return -EINVAL; |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4762 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4763 | count_vht++; |
| 4764 | if (count_vht > 1) |
| 4765 | return -EINVAL; |
| 4766 | } |
| 4767 | if (count_vht && rate) |
| 4768 | return -EINVAL; |
| 4769 | } |
| 4770 | |
| 4771 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) |
| 4772 | return -EINVAL; |
| 4773 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 4774 | if (rate && |
| 4775 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4776 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) |
| 4777 | return -EINVAL; |
| 4778 | if (count_ht && |
| 4779 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4780 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) |
| 4781 | return -EINVAL; |
| 4782 | if (count_vht && |
| 4783 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 4784 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) |
| 4785 | return -EINVAL; |
| 4786 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 4787 | return 0; |
| 4788 | } |
| 4789 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4790 | static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev, |
| 4791 | struct nlattr *attrs[], |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4792 | struct cfg80211_beacon_data *bcn) |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4793 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4794 | bool haveinfo = false; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4795 | int err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4796 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4797 | memset(bcn, 0, sizeof(*bcn)); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4798 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4799 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 4800 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); |
| 4801 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4802 | if (!bcn->head_len) |
| 4803 | return -EINVAL; |
| 4804 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4807 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 4808 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); |
| 4809 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4810 | haveinfo = true; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4811 | } |
| 4812 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 4813 | if (!haveinfo) |
| 4814 | return -EINVAL; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4815 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4816 | if (attrs[NL80211_ATTR_IE]) { |
| 4817 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); |
| 4818 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4819 | } |
| 4820 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4821 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4822 | bcn->proberesp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4823 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4824 | bcn->proberesp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4825 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4826 | } |
| 4827 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4828 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4829 | bcn->assocresp_ies = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4830 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4831 | bcn->assocresp_ies_len = |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4832 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
Jouni Malinen | 9946ecf | 2011-08-10 23:55:56 +0300 | [diff] [blame] | 4833 | } |
| 4834 | |
Simon Wunderlich | a1193be | 2013-06-14 14:15:19 +0200 | [diff] [blame] | 4835 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
| 4836 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); |
| 4837 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); |
Arik Nemtsov | 00f740e | 2011-11-10 11:28:56 +0200 | [diff] [blame] | 4838 | } |
| 4839 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4840 | if (attrs[NL80211_ATTR_FTM_RESPONDER]) { |
| 4841 | struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1]; |
| 4842 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 4843 | err = nla_parse_nested_deprecated(tb, |
| 4844 | NL80211_FTM_RESP_ATTR_MAX, |
| 4845 | attrs[NL80211_ATTR_FTM_RESPONDER], |
| 4846 | NULL, NULL); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 4847 | if (err) |
| 4848 | return err; |
| 4849 | |
| 4850 | if (tb[NL80211_FTM_RESP_ATTR_ENABLED] && |
| 4851 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 4852 | NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER)) |
| 4853 | bcn->ftm_responder = 1; |
| 4854 | else |
| 4855 | return -EOPNOTSUPP; |
| 4856 | |
| 4857 | if (tb[NL80211_FTM_RESP_ATTR_LCI]) { |
| 4858 | bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4859 | bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]); |
| 4860 | } |
| 4861 | |
| 4862 | if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) { |
| 4863 | bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4864 | bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]); |
| 4865 | } |
| 4866 | } else { |
| 4867 | bcn->ftm_responder = -1; |
| 4868 | } |
| 4869 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4870 | return 0; |
| 4871 | } |
| 4872 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4873 | static int nl80211_parse_he_obss_pd(struct nlattr *attrs, |
| 4874 | struct ieee80211_he_obss_pd *he_obss_pd) |
| 4875 | { |
| 4876 | struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1]; |
| 4877 | int err; |
| 4878 | |
| 4879 | err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs, |
| 4880 | he_obss_pd_policy, NULL); |
| 4881 | if (err) |
| 4882 | return err; |
| 4883 | |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 4884 | if (!tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]) |
| 4885 | return -EINVAL; |
| 4886 | |
| 4887 | he_obss_pd->sr_ctrl = nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_SR_CTRL]); |
| 4888 | |
Rajkumar Manoharan | 6c8b6e4 | 2020-09-28 00:28:10 -0700 | [diff] [blame] | 4889 | if (tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]) |
| 4890 | he_obss_pd->min_offset = |
| 4891 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]); |
| 4892 | if (tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]) |
| 4893 | he_obss_pd->max_offset = |
| 4894 | nla_get_u8(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]); |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 4895 | if (tb[NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET]) |
| 4896 | he_obss_pd->non_srg_max_offset = |
| 4897 | 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] | 4898 | |
Rajkumar Manoharan | 6c8b6e4 | 2020-09-28 00:28:10 -0700 | [diff] [blame] | 4899 | if (he_obss_pd->min_offset > he_obss_pd->max_offset) |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4900 | return -EINVAL; |
| 4901 | |
Rajkumar Manoharan | f5bec33 | 2020-09-28 00:28:11 -0700 | [diff] [blame] | 4902 | if (tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]) |
| 4903 | memcpy(he_obss_pd->bss_color_bitmap, |
| 4904 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP]), |
| 4905 | sizeof(he_obss_pd->bss_color_bitmap)); |
| 4906 | |
| 4907 | if (tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]) |
| 4908 | memcpy(he_obss_pd->partial_bssid_bitmap, |
| 4909 | nla_data(tb[NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP]), |
| 4910 | sizeof(he_obss_pd->partial_bssid_bitmap)); |
| 4911 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 4912 | he_obss_pd->enable = true; |
| 4913 | |
| 4914 | return 0; |
| 4915 | } |
| 4916 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4917 | static int nl80211_parse_he_bss_color(struct nlattr *attrs, |
| 4918 | struct cfg80211_he_bss_color *he_bss_color) |
| 4919 | { |
| 4920 | struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1]; |
| 4921 | int err; |
| 4922 | |
| 4923 | err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs, |
| 4924 | he_bss_color_policy, NULL); |
| 4925 | if (err) |
| 4926 | return err; |
| 4927 | |
| 4928 | if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]) |
| 4929 | return -EINVAL; |
| 4930 | |
| 4931 | he_bss_color->color = |
| 4932 | nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]); |
Johannes Berg | 75e6b59 | 2020-07-30 13:00:52 +0200 | [diff] [blame] | 4933 | he_bss_color->enabled = |
| 4934 | !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]); |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 4935 | he_bss_color->partial = |
| 4936 | nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]); |
| 4937 | |
| 4938 | return 0; |
| 4939 | } |
| 4940 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 4941 | static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev, |
| 4942 | struct nlattr *attrs, |
| 4943 | struct cfg80211_ap_settings *params) |
| 4944 | { |
| 4945 | struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1]; |
| 4946 | int ret; |
| 4947 | struct cfg80211_fils_discovery *fd = ¶ms->fils_discovery; |
| 4948 | |
| 4949 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4950 | NL80211_EXT_FEATURE_FILS_DISCOVERY)) |
| 4951 | return -EINVAL; |
| 4952 | |
| 4953 | ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs, |
| 4954 | NULL, NULL); |
| 4955 | if (ret) |
| 4956 | return ret; |
| 4957 | |
| 4958 | if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] || |
| 4959 | !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] || |
| 4960 | !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]) |
| 4961 | return -EINVAL; |
| 4962 | |
| 4963 | fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 4964 | fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]); |
| 4965 | fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]); |
| 4966 | fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]); |
| 4967 | |
| 4968 | return 0; |
| 4969 | } |
| 4970 | |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 4971 | static int |
| 4972 | nl80211_parse_unsol_bcast_probe_resp(struct cfg80211_registered_device *rdev, |
| 4973 | struct nlattr *attrs, |
| 4974 | struct cfg80211_ap_settings *params) |
| 4975 | { |
| 4976 | struct nlattr *tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX + 1]; |
| 4977 | int ret; |
| 4978 | struct cfg80211_unsol_bcast_probe_resp *presp = |
| 4979 | ¶ms->unsol_bcast_probe_resp; |
| 4980 | |
| 4981 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 4982 | NL80211_EXT_FEATURE_UNSOL_BCAST_PROBE_RESP)) |
| 4983 | return -EINVAL; |
| 4984 | |
| 4985 | ret = nla_parse_nested(tb, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_MAX, |
| 4986 | attrs, NULL, NULL); |
| 4987 | if (ret) |
| 4988 | return ret; |
| 4989 | |
| 4990 | if (!tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT] || |
| 4991 | !tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]) |
| 4992 | return -EINVAL; |
| 4993 | |
| 4994 | presp->tmpl = nla_data(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); |
| 4995 | presp->tmpl_len = nla_len(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL]); |
| 4996 | presp->interval = nla_get_u32(tb[NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT]); |
| 4997 | return 0; |
| 4998 | } |
| 4999 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5000 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
| 5001 | const u8 *rates) |
| 5002 | { |
| 5003 | int i; |
| 5004 | |
| 5005 | if (!rates) |
| 5006 | return; |
| 5007 | |
| 5008 | for (i = 0; i < rates[1]; i++) { |
| 5009 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 5010 | params->ht_required = true; |
| 5011 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) |
| 5012 | params->vht_required = true; |
Ilan Peer | 2a39259 | 2020-03-26 15:09:35 +0200 | [diff] [blame] | 5013 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY) |
| 5014 | params->he_required = true; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5015 | } |
| 5016 | } |
| 5017 | |
| 5018 | /* |
| 5019 | * Since the nl80211 API didn't include, from the beginning, attributes about |
| 5020 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the |
| 5021 | * benefit of drivers that rebuild IEs in the firmware. |
| 5022 | */ |
| 5023 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) |
| 5024 | { |
| 5025 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; |
Igor Mitsyanko | ba83bfb | 2017-08-30 13:52:25 -0700 | [diff] [blame] | 5026 | size_t ies_len = bcn->tail_len; |
| 5027 | const u8 *ies = bcn->tail; |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5028 | const u8 *rates; |
| 5029 | const u8 *cap; |
| 5030 | |
| 5031 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); |
| 5032 | nl80211_check_ap_rate_selectors(params, rates); |
| 5033 | |
| 5034 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); |
| 5035 | nl80211_check_ap_rate_selectors(params, rates); |
| 5036 | |
| 5037 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); |
| 5038 | if (cap && cap[1] >= sizeof(*params->ht_cap)) |
| 5039 | params->ht_cap = (void *)(cap + 2); |
| 5040 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); |
| 5041 | if (cap && cap[1] >= sizeof(*params->vht_cap)) |
| 5042 | params->vht_cap = (void *)(cap + 2); |
Shaul Triebitz | 244eb9a | 2018-08-31 11:31:14 +0300 | [diff] [blame] | 5043 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len); |
| 5044 | if (cap && cap[1] >= sizeof(*params->he_cap) + 1) |
| 5045 | params->he_cap = (void *)(cap + 3); |
Shaul Triebitz | 7e8d6f1 | 2020-01-31 13:12:54 +0200 | [diff] [blame] | 5046 | cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len); |
| 5047 | if (cap && cap[1] >= sizeof(*params->he_oper) + 1) |
| 5048 | params->he_oper = (void *)(cap + 3); |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5049 | } |
| 5050 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5051 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
| 5052 | struct cfg80211_ap_settings *params) |
| 5053 | { |
| 5054 | struct wireless_dev *wdev; |
| 5055 | bool ret = false; |
| 5056 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 5057 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5058 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 5059 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 5060 | continue; |
| 5061 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5062 | if (!wdev->preset_chandef.chan) |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5063 | continue; |
| 5064 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5065 | params->chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5066 | ret = true; |
| 5067 | break; |
| 5068 | } |
| 5069 | |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5070 | return ret; |
| 5071 | } |
| 5072 | |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5073 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
| 5074 | enum nl80211_auth_type auth_type, |
| 5075 | enum nl80211_commands cmd) |
| 5076 | { |
| 5077 | if (auth_type > NL80211_AUTHTYPE_MAX) |
| 5078 | return false; |
| 5079 | |
| 5080 | switch (cmd) { |
| 5081 | case NL80211_CMD_AUTHENTICATE: |
| 5082 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
| 5083 | auth_type == NL80211_AUTHTYPE_SAE) |
| 5084 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 5085 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5086 | NL80211_EXT_FEATURE_FILS_STA) && |
| 5087 | (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5088 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5089 | auth_type == NL80211_AUTHTYPE_FILS_PK)) |
| 5090 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5091 | return true; |
| 5092 | case NL80211_CMD_CONNECT: |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5093 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 5094 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 5095 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5096 | auth_type == NL80211_AUTHTYPE_SAE) |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 5097 | return false; |
Srinivas Dasari | 10773a7 | 2018-01-25 17:13:39 +0200 | [diff] [blame] | 5098 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 5099 | /* FILS with SK PFS or PK not supported yet */ |
| 5100 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5101 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5102 | return false; |
| 5103 | if (!wiphy_ext_feature_isset( |
| 5104 | &rdev->wiphy, |
| 5105 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 5106 | auth_type == NL80211_AUTHTYPE_FILS_SK) |
| 5107 | return false; |
| 5108 | return true; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5109 | case NL80211_CMD_START_AP: |
Chung-Hsien Hsu | 2831a63 | 2020-08-17 02:33:15 -0500 | [diff] [blame] | 5110 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 5111 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) && |
| 5112 | auth_type == NL80211_AUTHTYPE_SAE) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5113 | return false; |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 5114 | /* FILS not supported yet */ |
| 5115 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 5116 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 5117 | auth_type == NL80211_AUTHTYPE_FILS_PK) |
| 5118 | return false; |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5119 | return true; |
| 5120 | default: |
| 5121 | return false; |
| 5122 | } |
| 5123 | } |
| 5124 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5125 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
| 5126 | { |
| 5127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5128 | struct net_device *dev = info->user_ptr[1]; |
| 5129 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5130 | struct cfg80211_ap_settings params; |
| 5131 | int err; |
| 5132 | |
| 5133 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5134 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5135 | return -EOPNOTSUPP; |
| 5136 | |
| 5137 | if (!rdev->ops->start_ap) |
| 5138 | return -EOPNOTSUPP; |
| 5139 | |
| 5140 | if (wdev->beacon_interval) |
| 5141 | return -EALREADY; |
| 5142 | |
| 5143 | memset(¶ms, 0, sizeof(params)); |
| 5144 | |
| 5145 | /* these are required for START_AP */ |
| 5146 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 5147 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 5148 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
| 5149 | return -EINVAL; |
| 5150 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5151 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5152 | if (err) |
| 5153 | return err; |
| 5154 | |
| 5155 | params.beacon_interval = |
| 5156 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 5157 | params.dtim_period = |
| 5158 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 5159 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 5160 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
| 5161 | params.beacon_interval); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5162 | if (err) |
| 5163 | return err; |
| 5164 | |
| 5165 | /* |
| 5166 | * In theory, some of these attributes should be required here |
| 5167 | * but since they were not used when the command was originally |
| 5168 | * added, keep them optional for old user space programs to let |
| 5169 | * them continue to work with drivers that do not need the |
| 5170 | * additional information -- drivers must check! |
| 5171 | */ |
| 5172 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 5173 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 5174 | params.ssid_len = |
| 5175 | nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 5176 | if (params.ssid_len == 0) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5177 | return -EINVAL; |
| 5178 | } |
| 5179 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 5180 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5181 | params.hidden_ssid = nla_get_u32( |
| 5182 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5183 | |
| 5184 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
| 5185 | |
| 5186 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 5187 | params.auth_type = nla_get_u32( |
| 5188 | info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 5189 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
| 5190 | NL80211_CMD_START_AP)) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5191 | return -EINVAL; |
| 5192 | } else |
| 5193 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 5194 | |
| 5195 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, |
| 5196 | NL80211_MAX_NR_CIPHER_SUITES); |
| 5197 | if (err) |
| 5198 | return err; |
| 5199 | |
Vasanthakumar Thiagarajan | 1b658f1 | 2012-03-02 15:50:02 +0530 | [diff] [blame] | 5200 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
| 5201 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) |
| 5202 | return -EOPNOTSUPP; |
| 5203 | params.inactivity_timeout = nla_get_u16( |
| 5204 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); |
| 5205 | } |
| 5206 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5207 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 5208 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5209 | return -EINVAL; |
| 5210 | params.p2p_ctwindow = |
| 5211 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5212 | if (params.p2p_ctwindow != 0 && |
| 5213 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 5214 | return -EINVAL; |
| 5215 | } |
| 5216 | |
| 5217 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 5218 | u8 tmp; |
| 5219 | |
| 5220 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5221 | return -EINVAL; |
| 5222 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 5223 | params.p2p_opp_ps = tmp; |
| 5224 | if (params.p2p_opp_ps != 0 && |
| 5225 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 5226 | return -EINVAL; |
| 5227 | } |
| 5228 | |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5229 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5230 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 5231 | if (err) |
| 5232 | return err; |
| 5233 | } else if (wdev->preset_chandef.chan) { |
| 5234 | params.chandef = wdev->preset_chandef; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5235 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5236 | return -EINVAL; |
| 5237 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 5238 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 5239 | wdev->iftype)) |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 5240 | return -EINVAL; |
| 5241 | |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5242 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 5243 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 5244 | NL80211_ATTR_TX_RATES, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 5245 | ¶ms.beacon_rate, |
| 5246 | dev); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5247 | if (err) |
| 5248 | return err; |
| 5249 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 5250 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
| 5251 | ¶ms.beacon_rate); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 5252 | if (err) |
| 5253 | return err; |
| 5254 | } |
| 5255 | |
Eliad Peller | 18998c3 | 2014-09-10 14:07:34 +0300 | [diff] [blame] | 5256 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
| 5257 | params.smps_mode = |
| 5258 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); |
| 5259 | switch (params.smps_mode) { |
| 5260 | case NL80211_SMPS_OFF: |
| 5261 | break; |
| 5262 | case NL80211_SMPS_STATIC: |
| 5263 | if (!(rdev->wiphy.features & |
| 5264 | NL80211_FEATURE_STATIC_SMPS)) |
| 5265 | return -EINVAL; |
| 5266 | break; |
| 5267 | case NL80211_SMPS_DYNAMIC: |
| 5268 | if (!(rdev->wiphy.features & |
| 5269 | NL80211_FEATURE_DYNAMIC_SMPS)) |
| 5270 | return -EINVAL; |
| 5271 | break; |
| 5272 | default: |
| 5273 | return -EINVAL; |
| 5274 | } |
| 5275 | } else { |
| 5276 | params.smps_mode = NL80211_SMPS_OFF; |
| 5277 | } |
| 5278 | |
Purushottam Kushwaha | 6e8ef84 | 2016-07-05 13:44:51 +0530 | [diff] [blame] | 5279 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
| 5280 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) |
| 5281 | return -EOPNOTSUPP; |
| 5282 | |
Ola Olsson | 4baf6be | 2015-10-29 07:04:58 +0100 | [diff] [blame] | 5283 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
| 5284 | params.acl = parse_acl_data(&rdev->wiphy, info); |
| 5285 | if (IS_ERR(params.acl)) |
| 5286 | return PTR_ERR(params.acl); |
| 5287 | } |
| 5288 | |
John Crispin | a0de1ca3 | 2019-05-28 13:49:48 +0200 | [diff] [blame] | 5289 | params.twt_responder = |
| 5290 | nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]); |
| 5291 | |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5292 | if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) { |
| 5293 | err = nl80211_parse_he_obss_pd( |
| 5294 | info->attrs[NL80211_ATTR_HE_OBSS_PD], |
| 5295 | ¶ms.he_obss_pd); |
Luca Coelho | bc7a39b | 2020-06-26 12:49:39 +0300 | [diff] [blame] | 5296 | if (err) |
| 5297 | goto out; |
John Crispin | 796e90f | 2019-07-30 18:37:00 +0200 | [diff] [blame] | 5298 | } |
| 5299 | |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5300 | if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) { |
| 5301 | err = nl80211_parse_he_bss_color( |
| 5302 | info->attrs[NL80211_ATTR_HE_BSS_COLOR], |
| 5303 | ¶ms.he_bss_color); |
| 5304 | if (err) |
Luca Coelho | 60a0121 | 2020-06-26 12:49:40 +0300 | [diff] [blame] | 5305 | goto out; |
John Crispin | 5c5e52d | 2019-12-17 15:19:18 +0100 | [diff] [blame] | 5306 | } |
| 5307 | |
Aloka Dixit | 291c49d | 2020-09-11 00:05:29 +0000 | [diff] [blame] | 5308 | if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) { |
| 5309 | err = nl80211_parse_fils_discovery(rdev, |
| 5310 | info->attrs[NL80211_ATTR_FILS_DISCOVERY], |
| 5311 | ¶ms); |
| 5312 | if (err) |
| 5313 | goto out; |
| 5314 | } |
| 5315 | |
Aloka Dixit | 7443dcd | 2020-09-11 00:33:00 +0000 | [diff] [blame] | 5316 | if (info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP]) { |
| 5317 | err = nl80211_parse_unsol_bcast_probe_resp( |
| 5318 | rdev, info->attrs[NL80211_ATTR_UNSOL_BCAST_PROBE_RESP], |
| 5319 | ¶ms); |
| 5320 | if (err) |
| 5321 | return err; |
| 5322 | } |
| 5323 | |
Johannes Berg | 66cd794 | 2017-02-07 22:40:44 +0200 | [diff] [blame] | 5324 | nl80211_calculate_ap_params(¶ms); |
| 5325 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 5326 | if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT]) |
| 5327 | params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT; |
| 5328 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5329 | wdev_lock(wdev); |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 5330 | err = rdev_start_ap(rdev, dev, ¶ms); |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5331 | if (!err) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 5332 | wdev->preset_chandef = params.chandef; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5333 | wdev->beacon_interval = params.beacon_interval; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 5334 | wdev->chandef = params.chandef; |
Antonio Quartulli | 06e191e | 2012-11-07 12:52:19 +0100 | [diff] [blame] | 5335 | wdev->ssid_len = params.ssid_len; |
| 5336 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); |
Denis Kenzior | 466a306 | 2018-03-26 12:52:47 -0500 | [diff] [blame] | 5337 | |
| 5338 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 5339 | wdev->conn_owner_nlportid = info->snd_portid; |
Felix Fietkau | 46c1dd0 | 2012-06-19 02:50:57 +0200 | [diff] [blame] | 5340 | } |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5341 | wdev_unlock(wdev); |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5342 | |
Johannes Berg | 9951ebf | 2020-02-21 10:41:43 +0100 | [diff] [blame] | 5343 | out: |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 5344 | kfree(params.acl); |
| 5345 | |
Johannes Berg | 56d1893 | 2011-05-09 18:41:15 +0200 | [diff] [blame] | 5346 | return err; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5347 | } |
| 5348 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5349 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
| 5350 | { |
| 5351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5352 | struct net_device *dev = info->user_ptr[1]; |
| 5353 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 5354 | struct cfg80211_beacon_data params; |
| 5355 | int err; |
| 5356 | |
| 5357 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 5358 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 5359 | return -EOPNOTSUPP; |
| 5360 | |
| 5361 | if (!rdev->ops->change_beacon) |
| 5362 | return -EOPNOTSUPP; |
| 5363 | |
| 5364 | if (!wdev->beacon_interval) |
| 5365 | return -EINVAL; |
| 5366 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 5367 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5368 | if (err) |
| 5369 | return err; |
| 5370 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 5371 | wdev_lock(wdev); |
| 5372 | err = rdev_change_beacon(rdev, dev, ¶ms); |
| 5373 | wdev_unlock(wdev); |
| 5374 | |
| 5375 | return err; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 5376 | } |
| 5377 | |
| 5378 | 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] | 5379 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5381 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5382 | |
Ilan Peer | 7c8d5e0 | 2014-02-25 15:33:38 +0200 | [diff] [blame] | 5383 | return cfg80211_stop_ap(rdev, dev, false); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 5384 | } |
| 5385 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5386 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 5387 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 5388 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 5389 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 5390 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 5391 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
Johannes Berg | d83023d | 2011-12-14 09:29:15 +0100 | [diff] [blame] | 5392 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5393 | }; |
| 5394 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5395 | static int parse_station_flags(struct genl_info *info, |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5396 | enum nl80211_iftype iftype, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5397 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5398 | { |
| 5399 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5400 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5401 | int flag; |
| 5402 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5403 | /* |
| 5404 | * Try parsing the new attribute first so userspace |
| 5405 | * can specify both for older kernels. |
| 5406 | */ |
| 5407 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 5408 | if (nla) { |
| 5409 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5410 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5411 | sta_flags = nla_data(nla); |
| 5412 | params->sta_flags_mask = sta_flags->mask; |
| 5413 | params->sta_flags_set = sta_flags->set; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5414 | params->sta_flags_set &= params->sta_flags_mask; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5415 | if ((params->sta_flags_mask | |
| 5416 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 5417 | return -EINVAL; |
| 5418 | return 0; |
| 5419 | } |
| 5420 | |
| 5421 | /* if present, parse the old attribute */ |
| 5422 | |
| 5423 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5424 | if (!nla) |
| 5425 | return 0; |
| 5426 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 5427 | 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] | 5428 | return -EINVAL; |
| 5429 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5430 | /* |
| 5431 | * Only allow certain flags for interface types so that |
| 5432 | * other attributes are silently ignored. Remember that |
| 5433 | * this is backward compatibility code with old userspace |
| 5434 | * and shouldn't be hit in other cases anyway. |
| 5435 | */ |
| 5436 | switch (iftype) { |
| 5437 | case NL80211_IFTYPE_AP: |
| 5438 | case NL80211_IFTYPE_AP_VLAN: |
| 5439 | case NL80211_IFTYPE_P2P_GO: |
| 5440 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5441 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5442 | BIT(NL80211_STA_FLAG_WME) | |
| 5443 | BIT(NL80211_STA_FLAG_MFP); |
| 5444 | break; |
| 5445 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5446 | case NL80211_IFTYPE_STATION: |
| 5447 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5448 | BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5449 | break; |
| 5450 | case NL80211_IFTYPE_MESH_POINT: |
| 5451 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5452 | BIT(NL80211_STA_FLAG_MFP) | |
| 5453 | BIT(NL80211_STA_FLAG_AUTHORIZED); |
Bernd Edlinger | 5cf3006 | 2018-07-08 09:57:22 +0000 | [diff] [blame] | 5454 | break; |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 5455 | default: |
| 5456 | return -EINVAL; |
| 5457 | } |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5458 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5459 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
| 5460 | if (flags[flag]) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 5461 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5462 | |
Johannes Berg | 3383b5a | 2012-05-10 20:14:43 +0200 | [diff] [blame] | 5463 | /* no longer support new API additions in old API */ |
| 5464 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) |
| 5465 | return -EINVAL; |
| 5466 | } |
| 5467 | } |
| 5468 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5469 | return 0; |
| 5470 | } |
| 5471 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 5472 | 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] | 5473 | { |
| 5474 | struct nlattr *rate; |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5475 | u32 bitrate; |
| 5476 | u16 bitrate_compat; |
Matthias Kaehlcke | bbf67e4 | 2017-04-17 15:59:52 -0700 | [diff] [blame] | 5477 | enum nl80211_rate_info rate_flg; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5478 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5479 | rate = nla_nest_start_noflag(msg, attr); |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5480 | if (!rate) |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5481 | return false; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5482 | |
| 5483 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 5484 | bitrate = cfg80211_calculate_bitrate(info); |
Vladimir Kondratiev | 8eb41c8 | 2012-07-05 14:25:49 +0300 | [diff] [blame] | 5485 | /* report 16-bit bitrate only if we can */ |
| 5486 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5487 | if (bitrate > 0 && |
| 5488 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) |
| 5489 | return false; |
| 5490 | if (bitrate_compat > 0 && |
| 5491 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) |
| 5492 | return false; |
| 5493 | |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5494 | switch (info->bw) { |
| 5495 | case RATE_INFO_BW_5: |
| 5496 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; |
| 5497 | break; |
| 5498 | case RATE_INFO_BW_10: |
| 5499 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; |
| 5500 | break; |
| 5501 | default: |
| 5502 | WARN_ON(1); |
Miaohe Lin | 7b506ff | 2020-08-22 04:23:23 -0400 | [diff] [blame] | 5503 | fallthrough; |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5504 | case RATE_INFO_BW_20: |
| 5505 | rate_flg = 0; |
| 5506 | break; |
| 5507 | case RATE_INFO_BW_40: |
| 5508 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; |
| 5509 | break; |
| 5510 | case RATE_INFO_BW_80: |
| 5511 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; |
| 5512 | break; |
| 5513 | case RATE_INFO_BW_160: |
| 5514 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; |
| 5515 | break; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5516 | case RATE_INFO_BW_HE_RU: |
| 5517 | rate_flg = 0; |
| 5518 | WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS)); |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | if (rate_flg && nla_put_flag(msg, rate_flg)) |
| 5522 | return false; |
| 5523 | |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5524 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
| 5525 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) |
| 5526 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5527 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5528 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5529 | return false; |
| 5530 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { |
| 5531 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) |
| 5532 | return false; |
| 5533 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) |
| 5534 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5535 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
| 5536 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) |
| 5537 | return false; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5538 | } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) { |
| 5539 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs)) |
| 5540 | return false; |
| 5541 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss)) |
| 5542 | return false; |
| 5543 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi)) |
| 5544 | return false; |
| 5545 | if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm)) |
| 5546 | return false; |
| 5547 | if (info->bw == RATE_INFO_BW_HE_RU && |
| 5548 | nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC, |
| 5549 | info->he_ru_alloc)) |
| 5550 | return false; |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 5551 | } |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5552 | |
| 5553 | nla_nest_end(msg, rate); |
| 5554 | return true; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5555 | } |
| 5556 | |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5557 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
| 5558 | int id) |
| 5559 | { |
| 5560 | void *attr; |
| 5561 | int i = 0; |
| 5562 | |
| 5563 | if (!mask) |
| 5564 | return true; |
| 5565 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5566 | attr = nla_nest_start_noflag(msg, id); |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5567 | if (!attr) |
| 5568 | return false; |
| 5569 | |
| 5570 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { |
| 5571 | if (!(mask & BIT(i))) |
| 5572 | continue; |
| 5573 | |
| 5574 | if (nla_put_u8(msg, i, signal[i])) |
| 5575 | return false; |
| 5576 | } |
| 5577 | |
| 5578 | nla_nest_end(msg, attr); |
| 5579 | |
| 5580 | return true; |
| 5581 | } |
| 5582 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5583 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
| 5584 | u32 seq, int flags, |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5585 | struct cfg80211_registered_device *rdev, |
| 5586 | struct net_device *dev, |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 5587 | const u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5588 | { |
| 5589 | void *hdr; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5590 | struct nlattr *sinfoattr, *bss_param; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5591 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5592 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5593 | if (!hdr) { |
| 5594 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5595 | return -1; |
Andy Strohman | f77bf48 | 2019-05-24 23:27:29 -0700 | [diff] [blame] | 5596 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5597 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5598 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 5599 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 5600 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) |
| 5601 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 5602 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5603 | sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5604 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5605 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5606 | |
| 5607 | #define PUT_SINFO(attr, memb, type) do { \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5608 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5609 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5610 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
| 5611 | sinfo->memb)) \ |
| 5612 | goto nla_put_failure; \ |
| 5613 | } while (0) |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5614 | #define PUT_SINFO_U64(attr, memb) do { \ |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5615 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5616 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ |
| 5617 | sinfo->memb, NL80211_STA_INFO_PAD)) \ |
| 5618 | goto nla_put_failure; \ |
| 5619 | } while (0) |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5620 | |
| 5621 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); |
| 5622 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); |
Ben Greear | 6c7a003 | 2019-08-09 11:00:00 -0700 | [diff] [blame] | 5623 | PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5624 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5625 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) | |
| 5626 | BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5627 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5628 | (u32)sinfo->rx_bytes)) |
| 5629 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5630 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5631 | if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) | |
| 5632 | BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) && |
Vladimir Kondratiev | 42745e0 | 2013-02-04 13:53:11 +0200 | [diff] [blame] | 5633 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
| 5634 | (u32)sinfo->tx_bytes)) |
| 5635 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5636 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5637 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
| 5638 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5639 | PUT_SINFO(LLID, llid, u16); |
| 5640 | PUT_SINFO(PLID, plid, u16); |
| 5641 | PUT_SINFO(PLINK_STATE, plink_state, u8); |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5642 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 5643 | PUT_SINFO_U64(TX_DURATION, tx_duration); |
| 5644 | |
| 5645 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 5646 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 5647 | PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5648 | |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5649 | switch (rdev->wiphy.signal_type) { |
| 5650 | case CFG80211_SIGNAL_TYPE_MBM: |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5651 | PUT_SINFO(SIGNAL, signal, u8); |
| 5652 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); |
John W. Linville | 66266b3 | 2012-03-15 13:25:41 -0400 | [diff] [blame] | 5653 | break; |
| 5654 | default: |
| 5655 | break; |
| 5656 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5657 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5658 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5659 | sinfo->chain_signal, |
| 5660 | NL80211_STA_INFO_CHAIN_SIGNAL)) |
| 5661 | goto nla_put_failure; |
| 5662 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5663 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
Felix Fietkau | 119363c | 2013-04-22 16:29:30 +0200 | [diff] [blame] | 5664 | if (!nl80211_put_signal(msg, sinfo->chains, |
| 5665 | sinfo->chain_signal_avg, |
| 5666 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) |
| 5667 | goto nla_put_failure; |
| 5668 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5669 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5670 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
| 5671 | NL80211_STA_INFO_TX_BITRATE)) |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5672 | goto nla_put_failure; |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5673 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5674 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) { |
Felix Fietkau | c8dcfd8 | 2011-02-27 22:08:00 +0100 | [diff] [blame] | 5675 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
| 5676 | NL80211_STA_INFO_RX_BITRATE)) |
| 5677 | goto nla_put_failure; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 5678 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5679 | |
| 5680 | PUT_SINFO(RX_PACKETS, rx_packets, u32); |
| 5681 | PUT_SINFO(TX_PACKETS, tx_packets, u32); |
| 5682 | PUT_SINFO(TX_RETRIES, tx_retries, u32); |
| 5683 | PUT_SINFO(TX_FAILED, tx_failed, u32); |
| 5684 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); |
Narayanraddi Masti | ab60633 | 2019-02-07 12:16:05 -0800 | [diff] [blame] | 5685 | PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5686 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); |
| 5687 | PUT_SINFO(LOCAL_PM, local_pm, u32); |
| 5688 | PUT_SINFO(PEER_PM, peer_pm, u32); |
| 5689 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); |
Bob Copeland | dbdaee7 | 2018-10-25 15:48:53 -0400 | [diff] [blame] | 5690 | PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8); |
Markus Theil | 1303a51 | 2020-06-11 16:02:38 +0200 | [diff] [blame] | 5691 | PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8); |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5692 | |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5693 | if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5694 | bss_param = nla_nest_start_noflag(msg, |
| 5695 | NL80211_STA_INFO_BSS_PARAM); |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5696 | if (!bss_param) |
| 5697 | goto nla_put_failure; |
| 5698 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5699 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
| 5700 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || |
| 5701 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && |
| 5702 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || |
| 5703 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && |
| 5704 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || |
| 5705 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, |
| 5706 | sinfo->bss_param.dtim_period) || |
| 5707 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, |
| 5708 | sinfo->bss_param.beacon_interval)) |
| 5709 | goto nla_put_failure; |
Paul Stewart | f4263c9 | 2011-03-31 09:25:41 -0700 | [diff] [blame] | 5710 | |
| 5711 | nla_nest_end(msg, bss_param); |
| 5712 | } |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 5713 | if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5714 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
| 5715 | sizeof(struct nl80211_sta_flag_update), |
| 5716 | &sinfo->sta_flags)) |
| 5717 | goto nla_put_failure; |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5718 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5719 | PUT_SINFO_U64(T_OFFSET, t_offset); |
| 5720 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); |
| 5721 | PUT_SINFO_U64(BEACON_RX, rx_beacon); |
Johannes Berg | a76b194 | 2014-11-17 14:12:22 +0100 | [diff] [blame] | 5722 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
Ankita Bajaj | 0d4e14a | 2018-09-27 18:01:57 +0300 | [diff] [blame] | 5723 | PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32); |
| 5724 | PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32); |
Balaji Pothunoori | 81d5439 | 2018-04-16 20:18:40 +0530 | [diff] [blame] | 5725 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
Balaji Pothunoori | 9c06602 | 2018-07-19 18:56:27 +0530 | [diff] [blame] | 5726 | NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) { |
| 5727 | PUT_SINFO(ACK_SIGNAL, ack_signal, u8); |
| 5728 | PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8); |
| 5729 | } |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5730 | |
| 5731 | #undef PUT_SINFO |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5732 | #undef PUT_SINFO_U64 |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5733 | |
Arend van Spriel | 8689c05 | 2018-05-10 13:50:12 +0200 | [diff] [blame] | 5734 | if (sinfo->pertid) { |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5735 | struct nlattr *tidsattr; |
| 5736 | int tid; |
| 5737 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5738 | tidsattr = nla_nest_start_noflag(msg, |
| 5739 | NL80211_STA_INFO_TID_STATS); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5740 | if (!tidsattr) |
| 5741 | goto nla_put_failure; |
| 5742 | |
| 5743 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { |
| 5744 | struct cfg80211_tid_stats *tidstats; |
| 5745 | struct nlattr *tidattr; |
| 5746 | |
| 5747 | tidstats = &sinfo->pertid[tid]; |
| 5748 | |
| 5749 | if (!tidstats->filled) |
| 5750 | continue; |
| 5751 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 5752 | tidattr = nla_nest_start_noflag(msg, tid + 1); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5753 | if (!tidattr) |
| 5754 | goto nla_put_failure; |
| 5755 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5756 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5757 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5758 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
| 5759 | tidstats->memb, NL80211_TID_STATS_PAD)) \ |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5760 | goto nla_put_failure; \ |
| 5761 | } while (0) |
| 5762 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5763 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
| 5764 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); |
| 5765 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); |
| 5766 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5767 | |
Johannes Berg | d686b92 | 2016-04-26 09:54:11 +0200 | [diff] [blame] | 5768 | #undef PUT_TIDVAL_U64 |
Toke Høiland-Jørgensen | 52539ca | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 5769 | if ((tidstats->filled & |
| 5770 | BIT(NL80211_TID_STATS_TXQ_STATS)) && |
| 5771 | !nl80211_put_txq_stats(msg, &tidstats->txq_stats, |
| 5772 | NL80211_TID_STATS_TXQ_STATS)) |
| 5773 | goto nla_put_failure; |
| 5774 | |
Johannes Berg | 6de3980 | 2014-12-19 12:34:00 +0100 | [diff] [blame] | 5775 | nla_nest_end(msg, tidattr); |
| 5776 | } |
| 5777 | |
| 5778 | nla_nest_end(msg, tidsattr); |
| 5779 | } |
| 5780 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5781 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5782 | |
Johannes Berg | 319090b | 2014-11-17 14:08:11 +0100 | [diff] [blame] | 5783 | if (sinfo->assoc_req_ies_len && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 5784 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
| 5785 | sinfo->assoc_req_ies)) |
| 5786 | goto nla_put_failure; |
Jouni Malinen | 50d3dfb | 2011-08-08 12:11:52 +0300 | [diff] [blame] | 5787 | |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5788 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 5789 | genlmsg_end(msg, hdr); |
| 5790 | return 0; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5791 | |
| 5792 | nla_put_failure: |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5793 | cfg80211_sinfo_release_content(sinfo); |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 5794 | genlmsg_cancel(msg, hdr); |
| 5795 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5796 | } |
| 5797 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5798 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5799 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5800 | { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5801 | struct station_info sinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5802 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5803 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5804 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5805 | int sta_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5806 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5807 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5808 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 5809 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 5810 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5811 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5812 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5813 | if (!wdev->netdev) { |
| 5814 | err = -EINVAL; |
| 5815 | goto out_err; |
| 5816 | } |
| 5817 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5818 | if (!rdev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 5819 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5820 | goto out_err; |
| 5821 | } |
| 5822 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5823 | while (1) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5824 | memset(&sinfo, 0, sizeof(sinfo)); |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5825 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5826 | mac_addr, &sinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5827 | if (err == -ENOENT) |
| 5828 | break; |
| 5829 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 5830 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5831 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5832 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 5833 | NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5834 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 5835 | rdev, wdev->netdev, mac_addr, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5836 | &sinfo) < 0) |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5837 | goto out; |
| 5838 | |
| 5839 | sta_idx++; |
| 5840 | } |
| 5841 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5842 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 5843 | cb->args[2] = sta_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5844 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5845 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 5846 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 5847 | |
| 5848 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5849 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5850 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5851 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 5852 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5853 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 5854 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5855 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5856 | struct sk_buff *msg; |
| 5857 | u8 *mac_addr = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5858 | int err; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5859 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5860 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5861 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5862 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 5863 | return -EINVAL; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5864 | |
| 5865 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 5866 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5867 | if (!rdev->ops->get_station) |
| 5868 | return -EOPNOTSUPP; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5869 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5870 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5871 | if (err) |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5872 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 5873 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 5874 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5875 | if (!msg) { |
Denis Kenzior | ba8f566 | 2018-05-21 19:21:42 -0500 | [diff] [blame] | 5876 | cfg80211_sinfo_release_content(&sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5877 | return -ENOMEM; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 5878 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5879 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 5880 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
| 5881 | info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5882 | rdev, dev, mac_addr, &sinfo) < 0) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5883 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5884 | return -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 5885 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 5886 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 5887 | return genlmsg_reply(msg, info); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 5888 | } |
| 5889 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5890 | int cfg80211_check_station_change(struct wiphy *wiphy, |
| 5891 | struct station_parameters *params, |
| 5892 | enum cfg80211_station_type statype) |
| 5893 | { |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5894 | if (params->listen_interval != -1 && |
| 5895 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5896 | return -EINVAL; |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5897 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 5898 | if (params->support_p2p_ps != -1 && |
| 5899 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
| 5900 | return -EINVAL; |
| 5901 | |
Arik Nemtsov | c72e114 | 2014-07-17 17:14:29 +0300 | [diff] [blame] | 5902 | if (params->aid && |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 5903 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
| 5904 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5905 | return -EINVAL; |
| 5906 | |
| 5907 | /* When you run into this, adjust the code below for the new flag */ |
| 5908 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 5909 | |
| 5910 | switch (statype) { |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 5911 | case CFG80211_STA_MESH_PEER_KERNEL: |
| 5912 | case CFG80211_STA_MESH_PEER_USER: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5913 | /* |
| 5914 | * No ignoring the TDLS flag here -- the userspace mesh |
| 5915 | * code doesn't have the bug of including TDLS in the |
| 5916 | * mask everywhere. |
| 5917 | */ |
| 5918 | if (params->sta_flags_mask & |
| 5919 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5920 | BIT(NL80211_STA_FLAG_MFP) | |
| 5921 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5922 | return -EINVAL; |
| 5923 | break; |
| 5924 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 5925 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 5926 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 5927 | return -EINVAL; |
| 5928 | /* ignore since it can't change */ |
| 5929 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5930 | break; |
| 5931 | default: |
| 5932 | /* disallow mesh-specific things */ |
| 5933 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
| 5934 | return -EINVAL; |
| 5935 | if (params->local_pm) |
| 5936 | return -EINVAL; |
| 5937 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 5938 | return -EINVAL; |
| 5939 | } |
| 5940 | |
| 5941 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5942 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { |
| 5943 | /* TDLS can't be set, ... */ |
| 5944 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 5945 | return -EINVAL; |
| 5946 | /* |
| 5947 | * ... but don't bother the driver with it. This works around |
| 5948 | * a hostapd/wpa_supplicant issue -- it always includes the |
| 5949 | * TLDS_PEER flag in the mask even for AP mode. |
| 5950 | */ |
| 5951 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
| 5952 | } |
| 5953 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5954 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
| 5955 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5956 | /* reject other things that can't change */ |
| 5957 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) |
| 5958 | return -EINVAL; |
| 5959 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) |
| 5960 | return -EINVAL; |
| 5961 | if (params->supported_rates) |
| 5962 | return -EINVAL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 5963 | if (params->ext_capab || params->ht_capa || params->vht_capa || |
| 5964 | params->he_capa) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5965 | return -EINVAL; |
| 5966 | } |
| 5967 | |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5968 | if (statype != CFG80211_STA_AP_CLIENT && |
| 5969 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5970 | if (params->vlan) |
| 5971 | return -EINVAL; |
| 5972 | } |
| 5973 | |
| 5974 | switch (statype) { |
| 5975 | case CFG80211_STA_AP_MLME_CLIENT: |
| 5976 | /* Use this only for authorizing/unauthorizing a station */ |
| 5977 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) |
| 5978 | return -EOPNOTSUPP; |
| 5979 | break; |
| 5980 | case CFG80211_STA_AP_CLIENT: |
Ayala Beker | 47edb11 | 2015-09-21 15:49:53 +0300 | [diff] [blame] | 5981 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 5982 | /* accept only the listed bits */ |
| 5983 | if (params->sta_flags_mask & |
| 5984 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 5985 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5986 | BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5987 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | |
| 5988 | BIT(NL80211_STA_FLAG_WME) | |
| 5989 | BIT(NL80211_STA_FLAG_MFP))) |
| 5990 | return -EINVAL; |
| 5991 | |
| 5992 | /* but authenticated/associated only if driver handles it */ |
| 5993 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
| 5994 | params->sta_flags_mask & |
| 5995 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 5996 | BIT(NL80211_STA_FLAG_ASSOCIATED))) |
| 5997 | return -EINVAL; |
| 5998 | break; |
| 5999 | case CFG80211_STA_IBSS: |
| 6000 | case CFG80211_STA_AP_STA: |
| 6001 | /* reject any changes other than AUTHORIZED */ |
| 6002 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 6003 | return -EINVAL; |
| 6004 | break; |
| 6005 | case CFG80211_STA_TDLS_PEER_SETUP: |
| 6006 | /* reject any changes other than AUTHORIZED or WME */ |
| 6007 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | |
| 6008 | BIT(NL80211_STA_FLAG_WME))) |
| 6009 | return -EINVAL; |
| 6010 | /* force (at least) rates when authorizing */ |
| 6011 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && |
| 6012 | !params->supported_rates) |
| 6013 | return -EINVAL; |
| 6014 | break; |
| 6015 | case CFG80211_STA_TDLS_PEER_ACTIVE: |
| 6016 | /* reject any changes */ |
| 6017 | return -EINVAL; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 6018 | case CFG80211_STA_MESH_PEER_KERNEL: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6019 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
| 6020 | return -EINVAL; |
| 6021 | break; |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 6022 | case CFG80211_STA_MESH_PEER_USER: |
Chun-Yeow Yeoh | 4292504 | 2015-04-18 01:30:02 +0800 | [diff] [blame] | 6023 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
| 6024 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6025 | return -EINVAL; |
| 6026 | break; |
| 6027 | } |
| 6028 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 6029 | /* |
| 6030 | * Older kernel versions ignored this attribute entirely, so don't |
| 6031 | * reject attempts to update it but mark it as unused instead so the |
| 6032 | * driver won't look at the data. |
| 6033 | */ |
| 6034 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && |
| 6035 | statype != CFG80211_STA_TDLS_PEER_SETUP) |
| 6036 | params->opmode_notif_used = false; |
| 6037 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6038 | return 0; |
| 6039 | } |
| 6040 | EXPORT_SYMBOL(cfg80211_check_station_change); |
| 6041 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6042 | /* |
Felix Fietkau | c258d2d | 2009-11-11 17:23:31 +0100 | [diff] [blame] | 6043 | * 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] | 6044 | */ |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6045 | static struct net_device *get_vlan(struct genl_info *info, |
| 6046 | struct cfg80211_registered_device *rdev) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6047 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 6048 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6049 | struct net_device *v; |
| 6050 | int ret; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6051 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6052 | if (!vlanattr) |
| 6053 | return NULL; |
| 6054 | |
| 6055 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); |
| 6056 | if (!v) |
| 6057 | return ERR_PTR(-ENODEV); |
| 6058 | |
| 6059 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { |
| 6060 | ret = -EINVAL; |
| 6061 | goto error; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6062 | } |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6063 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6064 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 6065 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 6066 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { |
| 6067 | ret = -EINVAL; |
| 6068 | goto error; |
| 6069 | } |
| 6070 | |
Johannes Berg | 80b9989 | 2011-11-18 16:23:01 +0100 | [diff] [blame] | 6071 | if (!netif_running(v)) { |
| 6072 | ret = -ENETDOWN; |
| 6073 | goto error; |
| 6074 | } |
| 6075 | |
| 6076 | return v; |
| 6077 | error: |
| 6078 | dev_put(v); |
| 6079 | return ERR_PTR(ret); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6080 | } |
| 6081 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 6082 | static const struct nla_policy |
| 6083 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6084 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
| 6085 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, |
| 6086 | }; |
| 6087 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6088 | static int nl80211_parse_sta_wme(struct genl_info *info, |
| 6089 | struct station_parameters *params) |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6090 | { |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6091 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
| 6092 | struct nlattr *nla; |
| 6093 | int err; |
| 6094 | |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6095 | /* parse WME attributes if present */ |
| 6096 | if (!info->attrs[NL80211_ATTR_STA_WME]) |
| 6097 | return 0; |
| 6098 | |
| 6099 | nla = info->attrs[NL80211_ATTR_STA_WME]; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 6100 | err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla, |
| 6101 | nl80211_sta_wme_policy, |
| 6102 | info->extack); |
Jouni Malinen | df88129 | 2013-02-14 21:10:54 +0200 | [diff] [blame] | 6103 | if (err) |
| 6104 | return err; |
| 6105 | |
| 6106 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) |
| 6107 | params->uapsd_queues = nla_get_u8( |
| 6108 | tb[NL80211_STA_WME_UAPSD_QUEUES]); |
| 6109 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 6110 | return -EINVAL; |
| 6111 | |
| 6112 | if (tb[NL80211_STA_WME_MAX_SP]) |
| 6113 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); |
| 6114 | |
| 6115 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 6116 | return -EINVAL; |
| 6117 | |
| 6118 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
| 6119 | |
| 6120 | return 0; |
| 6121 | } |
| 6122 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6123 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
| 6124 | struct station_parameters *params) |
| 6125 | { |
| 6126 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { |
| 6127 | params->supported_channels = |
| 6128 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6129 | params->supported_channels_len = |
| 6130 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); |
| 6131 | /* |
| 6132 | * Need to include at least one (first channel, number of |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 6133 | * channels) tuple for each subband (checked in policy), |
| 6134 | * 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] | 6135 | */ |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6136 | if (params->supported_channels_len % 2) |
| 6137 | return -EINVAL; |
| 6138 | } |
| 6139 | |
| 6140 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { |
| 6141 | params->supported_oper_classes = |
| 6142 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
| 6143 | params->supported_oper_classes_len = |
| 6144 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6145 | } |
| 6146 | return 0; |
| 6147 | } |
| 6148 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6149 | static int nl80211_set_station_tdls(struct genl_info *info, |
| 6150 | struct station_parameters *params) |
| 6151 | { |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6152 | int err; |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6153 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6154 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
| 6155 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6156 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6157 | params->ht_capa = |
| 6158 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 6159 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6160 | params->vht_capa = |
| 6161 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6162 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6163 | params->he_capa = |
| 6164 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6165 | params->he_capa_len = |
| 6166 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6167 | } |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6168 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6169 | err = nl80211_parse_sta_channel_info(info, params); |
| 6170 | if (err) |
| 6171 | return err; |
| 6172 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6173 | return nl80211_parse_sta_wme(info, params); |
| 6174 | } |
| 6175 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6176 | static int nl80211_parse_sta_txpower_setting(struct genl_info *info, |
| 6177 | struct station_parameters *params) |
| 6178 | { |
| 6179 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6180 | int idx; |
| 6181 | |
| 6182 | if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) { |
| 6183 | if (!rdev->ops->set_tx_power || |
| 6184 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6185 | NL80211_EXT_FEATURE_STA_TX_PWR)) |
| 6186 | return -EOPNOTSUPP; |
| 6187 | |
| 6188 | idx = NL80211_ATTR_STA_TX_POWER_SETTING; |
| 6189 | params->txpwr.type = nla_get_u8(info->attrs[idx]); |
| 6190 | |
| 6191 | if (params->txpwr.type == NL80211_TX_POWER_LIMITED) { |
| 6192 | idx = NL80211_ATTR_STA_TX_POWER; |
| 6193 | |
| 6194 | if (info->attrs[idx]) |
| 6195 | params->txpwr.power = |
| 6196 | nla_get_s16(info->attrs[idx]); |
| 6197 | else |
| 6198 | return -EINVAL; |
| 6199 | } |
| 6200 | params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER; |
| 6201 | } |
| 6202 | |
| 6203 | return 0; |
| 6204 | } |
| 6205 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6206 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 6207 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6208 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6209 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6210 | struct station_parameters params; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6211 | u8 *mac_addr; |
| 6212 | int err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6213 | |
| 6214 | memset(¶ms, 0, sizeof(params)); |
| 6215 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6216 | if (!rdev->ops->change_station) |
| 6217 | return -EOPNOTSUPP; |
| 6218 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6219 | /* |
| 6220 | * AID and listen_interval properties can be set only for unassociated |
| 6221 | * station. Include these parameters here and will check them in |
| 6222 | * cfg80211_check_station_change(). |
| 6223 | */ |
Ayala Beker | a9bc31e | 2015-11-26 16:26:12 +0100 | [diff] [blame] | 6224 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 6225 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6226 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6227 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6228 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6229 | |
Ayala Beker | e420842 | 2015-10-23 11:20:06 +0300 | [diff] [blame] | 6230 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6231 | params.listen_interval = |
| 6232 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 6233 | else |
| 6234 | params.listen_interval = -1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6235 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6236 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) |
| 6237 | params.support_p2p_ps = |
| 6238 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
| 6239 | else |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6240 | params.support_p2p_ps = -1; |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6241 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6242 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6243 | return -EINVAL; |
| 6244 | |
| 6245 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6246 | |
| 6247 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 6248 | params.supported_rates = |
| 6249 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6250 | params.supported_rates_len = |
| 6251 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6252 | } |
| 6253 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6254 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6255 | params.capability = |
| 6256 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6257 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6258 | } |
| 6259 | |
| 6260 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6261 | params.ext_capab = |
| 6262 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6263 | params.ext_capab_len = |
| 6264 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6265 | } |
| 6266 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6267 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6268 | return -EINVAL; |
| 6269 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6270 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6271 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6272 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6273 | |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6274 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 6275 | params.plink_state = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6276 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6277 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 6278 | params.peer_aid = nla_get_u16( |
| 6279 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6280 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
| 6281 | } |
Javier Cardona | 9c3990a | 2011-05-03 16:57:11 -0700 | [diff] [blame] | 6282 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6283 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) |
| 6284 | params.local_pm = nla_get_u32( |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 6285 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); |
| 6286 | |
Beni Lev | 06f7c88 | 2016-07-19 19:28:56 +0300 | [diff] [blame] | 6287 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6288 | params.opmode_notif_used = true; |
| 6289 | params.opmode_notif = |
| 6290 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6291 | } |
| 6292 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6293 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6294 | params.he_6ghz_capa = |
Johannes Berg | fce2ff7 | 2020-08-05 15:35:18 +0200 | [diff] [blame] | 6295 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6296 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6297 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6298 | params.airtime_weight = |
| 6299 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6300 | |
| 6301 | if (params.airtime_weight && |
| 6302 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6303 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6304 | return -EOPNOTSUPP; |
| 6305 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6306 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6307 | if (err) |
| 6308 | return err; |
| 6309 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6310 | /* Include parameters for TDLS peer (will check later) */ |
| 6311 | err = nl80211_set_station_tdls(info, ¶ms); |
| 6312 | if (err) |
| 6313 | return err; |
| 6314 | |
| 6315 | params.vlan = get_vlan(info, rdev); |
| 6316 | if (IS_ERR(params.vlan)) |
| 6317 | return PTR_ERR(params.vlan); |
| 6318 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6319 | switch (dev->ieee80211_ptr->iftype) { |
| 6320 | case NL80211_IFTYPE_AP: |
| 6321 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6322 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 6323 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6324 | case NL80211_IFTYPE_STATION: |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 6325 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6326 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 6327 | break; |
| 6328 | default: |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6329 | err = -EOPNOTSUPP; |
| 6330 | goto out_put_vlan; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 6331 | } |
| 6332 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6333 | /* driver will call cfg80211_check_station_change() */ |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6334 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6335 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6336 | out_put_vlan: |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6337 | if (params.vlan) |
| 6338 | dev_put(params.vlan); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6339 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6340 | return err; |
| 6341 | } |
| 6342 | |
| 6343 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 6344 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6345 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6346 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6347 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6348 | struct station_parameters params; |
| 6349 | u8 *mac_addr = NULL; |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6350 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 6351 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6352 | |
| 6353 | memset(¶ms, 0, sizeof(params)); |
| 6354 | |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6355 | if (!rdev->ops->add_station) |
| 6356 | return -EOPNOTSUPP; |
| 6357 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6358 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6359 | return -EINVAL; |
| 6360 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6361 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 6362 | return -EINVAL; |
| 6363 | |
| 6364 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 6365 | return -EINVAL; |
| 6366 | |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6367 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
| 6368 | !info->attrs[NL80211_ATTR_PEER_AID]) |
Thadeu Lima de Souza Cascardo | 0e956c1 | 2010-02-12 12:34:50 -0200 | [diff] [blame] | 6369 | return -EINVAL; |
| 6370 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6371 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6372 | params.supported_rates = |
| 6373 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6374 | params.supported_rates_len = |
| 6375 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 6376 | params.listen_interval = |
| 6377 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6378 | |
Gurumoorthi Gnanasambandhan | 14f34e36 | 2019-10-31 23:46:40 +0200 | [diff] [blame] | 6379 | if (info->attrs[NL80211_ATTR_VLAN_ID]) |
| 6380 | params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]); |
| 6381 | |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6382 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6383 | params.support_p2p_ps = |
| 6384 | nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); |
Ayala Beker | 17b9424 | 2016-03-17 15:41:38 +0200 | [diff] [blame] | 6385 | } else { |
| 6386 | /* |
| 6387 | * if not specified, assume it's supported for P2P GO interface, |
| 6388 | * and is NOT supported for AP interface |
| 6389 | */ |
| 6390 | params.support_p2p_ps = |
| 6391 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; |
| 6392 | } |
| 6393 | |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6394 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
Jouni Malinen | 5e4b6f5 | 2013-05-16 20:11:08 +0300 | [diff] [blame] | 6395 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6396 | else |
| 6397 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 6398 | |
Jouni Malinen | 9d62a98 | 2013-02-14 21:10:13 +0200 | [diff] [blame] | 6399 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
| 6400 | params.capability = |
| 6401 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); |
| 6402 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; |
| 6403 | } |
| 6404 | |
| 6405 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { |
| 6406 | params.ext_capab = |
| 6407 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6408 | params.ext_capab_len = |
| 6409 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); |
| 6410 | } |
| 6411 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 6412 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 6413 | params.ht_capa = |
| 6414 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6415 | |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 6416 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
| 6417 | params.vht_capa = |
| 6418 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); |
| 6419 | |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6420 | if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) { |
| 6421 | params.he_capa = |
| 6422 | nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
| 6423 | params.he_capa_len = |
| 6424 | nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]); |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6425 | } |
| 6426 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6427 | if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]) |
| 6428 | params.he_6ghz_capa = |
| 6429 | nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]); |
| 6430 | |
Marek Kwaczynski | 60f4a7b | 2013-12-03 10:04:59 +0100 | [diff] [blame] | 6431 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
| 6432 | params.opmode_notif_used = true; |
| 6433 | params.opmode_notif = |
| 6434 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); |
| 6435 | } |
| 6436 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6437 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6438 | params.plink_action = |
Johannes Berg | f8bacc2 | 2013-02-14 23:27:01 +0100 | [diff] [blame] | 6439 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
Javier Cardona | 96b78df | 2011-04-07 15:08:33 -0700 | [diff] [blame] | 6440 | |
Toke Høiland-Jørgensen | 3664705 | 2018-12-18 17:02:07 -0800 | [diff] [blame] | 6441 | if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]) |
| 6442 | params.airtime_weight = |
| 6443 | nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]); |
| 6444 | |
| 6445 | if (params.airtime_weight && |
| 6446 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 6447 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 6448 | return -EOPNOTSUPP; |
| 6449 | |
Ashok Raj Nagarajan | e96d1cd | 2019-03-29 16:18:21 +0530 | [diff] [blame] | 6450 | err = nl80211_parse_sta_txpower_setting(info, ¶ms); |
| 6451 | if (err) |
| 6452 | return err; |
| 6453 | |
Sunil Dutt | c01fc9a | 2013-10-09 20:45:21 +0530 | [diff] [blame] | 6454 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
| 6455 | if (err) |
| 6456 | return err; |
| 6457 | |
Johannes Berg | ff27669 | 2013-02-15 00:09:01 +0100 | [diff] [blame] | 6458 | err = nl80211_parse_sta_wme(info, ¶ms); |
| 6459 | if (err) |
| 6460 | return err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6461 | |
Johannes Berg | bdd3ae3 | 2012-01-02 13:30:03 +0100 | [diff] [blame] | 6462 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6463 | return -EINVAL; |
| 6464 | |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6465 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
| 6466 | * as userspace might just pass through the capabilities from the IEs |
| 6467 | * directly, rather than enforcing this restriction and returning an |
| 6468 | * error in this case. |
| 6469 | */ |
| 6470 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { |
| 6471 | params.ht_capa = NULL; |
| 6472 | params.vht_capa = NULL; |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6473 | |
| 6474 | /* HE requires WME */ |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6475 | if (params.he_capa_len || params.he_6ghz_capa) |
Luca Coelho | c4cbaf7 | 2018-06-09 09:14:42 +0300 | [diff] [blame] | 6476 | return -EINVAL; |
Johannes Berg | 496fcc2 | 2015-03-12 08:53:27 +0200 | [diff] [blame] | 6477 | } |
| 6478 | |
Rajkumar Manoharan | 43e64bf | 2020-05-28 21:34:29 +0200 | [diff] [blame] | 6479 | /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */ |
| 6480 | if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa)) |
| 6481 | return -EINVAL; |
| 6482 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6483 | /* When you run into this, adjust the code below for the new flag */ |
| 6484 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); |
| 6485 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6486 | switch (dev->ieee80211_ptr->iftype) { |
| 6487 | case NL80211_IFTYPE_AP: |
| 6488 | case NL80211_IFTYPE_AP_VLAN: |
| 6489 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6490 | /* ignore WME attributes if iface/sta is not capable */ |
| 6491 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || |
| 6492 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) |
| 6493 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6494 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6495 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6496 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6497 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6498 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6499 | /* but don't bother the driver with it */ |
| 6500 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6501 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6502 | /* allow authenticated/associated only if driver handles it */ |
| 6503 | if (!(rdev->wiphy.features & |
| 6504 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6505 | params.sta_flags_mask & auth_assoc) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6506 | return -EINVAL; |
| 6507 | |
Johannes Berg | bda95eb | 2015-11-26 16:26:13 +0100 | [diff] [blame] | 6508 | /* Older userspace, or userspace wanting to be compatible with |
| 6509 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth |
| 6510 | * and assoc flags in the mask, but assumes the station will be |
| 6511 | * added as associated anyway since this was the required driver |
| 6512 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was |
| 6513 | * introduced. |
| 6514 | * In order to not bother drivers with this quirk in the API |
| 6515 | * set the flags in both the mask and set for new stations in |
| 6516 | * this case. |
| 6517 | */ |
| 6518 | if (!(params.sta_flags_mask & auth_assoc)) { |
| 6519 | params.sta_flags_mask |= auth_assoc; |
| 6520 | params.sta_flags_set |= auth_assoc; |
| 6521 | } |
| 6522 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6523 | /* must be last in here for error handling */ |
| 6524 | params.vlan = get_vlan(info, rdev); |
| 6525 | if (IS_ERR(params.vlan)) |
| 6526 | return PTR_ERR(params.vlan); |
| 6527 | break; |
| 6528 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6529 | /* ignore uAPSD data */ |
| 6530 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6531 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6532 | /* associated is disallowed */ |
| 6533 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) |
| 6534 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6535 | /* TDLS peers cannot be added */ |
Jouni Malinen | 3d124ea | 2013-05-27 18:24:02 +0300 | [diff] [blame] | 6536 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
| 6537 | info->attrs[NL80211_ATTR_PEER_AID]) |
Johannes Berg | 4319e19 | 2011-09-07 11:50:48 +0200 | [diff] [blame] | 6538 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6539 | break; |
| 6540 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 93d08f0 | 2013-03-04 09:29:46 +0100 | [diff] [blame] | 6541 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 984c311 | 2013-02-14 23:43:25 +0100 | [diff] [blame] | 6542 | /* ignore uAPSD data */ |
| 6543 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; |
| 6544 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6545 | /* these are disallowed */ |
| 6546 | if (params.sta_flags_mask & |
| 6547 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 6548 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 6549 | return -EINVAL; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6550 | /* Only TDLS peers can be added */ |
| 6551 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) |
| 6552 | return -EINVAL; |
| 6553 | /* Can only add if TDLS ... */ |
| 6554 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) |
| 6555 | return -EOPNOTSUPP; |
| 6556 | /* ... with external setup is supported */ |
| 6557 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) |
| 6558 | return -EOPNOTSUPP; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 6559 | /* |
| 6560 | * Older wpa_supplicant versions always mark the TDLS peer |
| 6561 | * as authorized, but it shouldn't yet be. |
| 6562 | */ |
| 6563 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6564 | break; |
| 6565 | default: |
| 6566 | return -EOPNOTSUPP; |
Eliad Peller | c75786c | 2011-08-23 14:37:46 +0300 | [diff] [blame] | 6567 | } |
| 6568 | |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 6569 | /* be aware of params.vlan when changing code here */ |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6570 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6571 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6572 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6573 | if (params.vlan) |
| 6574 | dev_put(params.vlan); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6575 | return err; |
| 6576 | } |
| 6577 | |
| 6578 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 6579 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6581 | struct net_device *dev = info->user_ptr[1]; |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6582 | struct station_del_parameters params; |
| 6583 | |
| 6584 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6585 | |
| 6586 | if (info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6587 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6588 | |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6589 | switch (dev->ieee80211_ptr->iftype) { |
| 6590 | case NL80211_IFTYPE_AP: |
| 6591 | case NL80211_IFTYPE_AP_VLAN: |
| 6592 | case NL80211_IFTYPE_MESH_POINT: |
| 6593 | case NL80211_IFTYPE_P2P_GO: |
| 6594 | /* always accept these */ |
| 6595 | break; |
| 6596 | case NL80211_IFTYPE_ADHOC: |
| 6597 | /* conditionally accept */ |
| 6598 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 6599 | NL80211_EXT_FEATURE_DEL_IBSS_STA)) |
| 6600 | break; |
Nicolas Cavallari | edafcf4 | 2020-03-05 14:57:53 +0100 | [diff] [blame] | 6601 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6602 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6603 | return -EINVAL; |
Johannes Berg | 306b79e | 2020-03-20 11:38:35 +0100 | [diff] [blame] | 6604 | } |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 6605 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6606 | if (!rdev->ops->del_station) |
| 6607 | return -EOPNOTSUPP; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6608 | |
Jouni Malinen | 9885686 | 2014-10-20 13:20:45 +0300 | [diff] [blame] | 6609 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
| 6610 | params.subtype = |
| 6611 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); |
| 6612 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && |
| 6613 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) |
| 6614 | return -EINVAL; |
| 6615 | } else { |
| 6616 | /* Default to Deauthentication frame */ |
| 6617 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; |
| 6618 | } |
| 6619 | |
| 6620 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { |
| 6621 | params.reason_code = |
| 6622 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 6623 | if (params.reason_code == 0) |
| 6624 | return -EINVAL; /* 0 is reserved */ |
| 6625 | } else { |
| 6626 | /* Default to reason code 2 */ |
| 6627 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 6628 | } |
| 6629 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 6630 | return rdev_del_station(rdev, dev, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 6631 | } |
| 6632 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6633 | 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] | 6634 | int flags, struct net_device *dev, |
| 6635 | u8 *dst, u8 *next_hop, |
| 6636 | struct mpath_info *pinfo) |
| 6637 | { |
| 6638 | void *hdr; |
| 6639 | struct nlattr *pinfoattr; |
| 6640 | |
Henning Rogge | 1ef4c85 | 2014-11-04 16:14:58 +0100 | [diff] [blame] | 6641 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6642 | if (!hdr) |
| 6643 | return -1; |
| 6644 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6645 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 6646 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 6647 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || |
| 6648 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) |
| 6649 | goto nla_put_failure; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 6650 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 6651 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6652 | if (!pinfoattr) |
| 6653 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6654 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
| 6655 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 6656 | pinfo->frame_qlen)) |
| 6657 | goto nla_put_failure; |
| 6658 | if (((pinfo->filled & MPATH_INFO_SN) && |
| 6659 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || |
| 6660 | ((pinfo->filled & MPATH_INFO_METRIC) && |
| 6661 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, |
| 6662 | pinfo->metric)) || |
| 6663 | ((pinfo->filled & MPATH_INFO_EXPTIME) && |
| 6664 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 6665 | pinfo->exptime)) || |
| 6666 | ((pinfo->filled & MPATH_INFO_FLAGS) && |
| 6667 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, |
| 6668 | pinfo->flags)) || |
| 6669 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && |
| 6670 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 6671 | pinfo->discovery_timeout)) || |
| 6672 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && |
| 6673 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
Julan Hsu | cc24163 | 2019-01-15 15:28:42 -0800 | [diff] [blame] | 6674 | pinfo->discovery_retries)) || |
| 6675 | ((pinfo->filled & MPATH_INFO_HOP_COUNT) && |
| 6676 | nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT, |
Julan Hsu | 540bbcb | 2019-01-15 15:28:43 -0800 | [diff] [blame] | 6677 | pinfo->hop_count)) || |
| 6678 | ((pinfo->filled & MPATH_INFO_PATH_CHANGE) && |
| 6679 | nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE, |
| 6680 | pinfo->path_change_count))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 6681 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6682 | |
| 6683 | nla_nest_end(msg, pinfoattr); |
| 6684 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 6685 | genlmsg_end(msg, hdr); |
| 6686 | return 0; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6687 | |
| 6688 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 6689 | genlmsg_cancel(msg, hdr); |
| 6690 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6694 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6695 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6696 | struct mpath_info pinfo; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6697 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6698 | struct wireless_dev *wdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6699 | u8 dst[ETH_ALEN]; |
| 6700 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6701 | int path_idx = cb->args[2]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6702 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6703 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6704 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6705 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 6706 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6707 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6708 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6709 | if (!rdev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6710 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6711 | goto out_err; |
| 6712 | } |
| 6713 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6714 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6715 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 6716 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6717 | } |
| 6718 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6719 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 6720 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6721 | next_hop, &pinfo); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6722 | if (err == -ENOENT) |
| 6723 | break; |
| 6724 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6725 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6726 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6727 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6728 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6729 | wdev->netdev, dst, next_hop, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6730 | &pinfo) < 0) |
| 6731 | goto out; |
| 6732 | |
| 6733 | path_idx++; |
| 6734 | } |
| 6735 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6736 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 6737 | cb->args[2] = path_idx; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6738 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6739 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6740 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 6741 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6742 | } |
| 6743 | |
| 6744 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6745 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6746 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6747 | int err; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6748 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6749 | struct mpath_info pinfo; |
| 6750 | struct sk_buff *msg; |
| 6751 | u8 *dst = NULL; |
| 6752 | u8 next_hop[ETH_ALEN]; |
| 6753 | |
| 6754 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6755 | |
| 6756 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6757 | return -EINVAL; |
| 6758 | |
| 6759 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6760 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6761 | if (!rdev->ops->get_mpath) |
| 6762 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6763 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6764 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6765 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 6766 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6767 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6768 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6769 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6770 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 6771 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6772 | if (!msg) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6773 | return -ENOMEM; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6774 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 6775 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6776 | dev, dst, next_hop, &pinfo) < 0) { |
| 6777 | nlmsg_free(msg); |
| 6778 | return -ENOBUFS; |
| 6779 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6780 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6781 | return genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6782 | } |
| 6783 | |
| 6784 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6785 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6786 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6787 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6788 | u8 *dst = NULL; |
| 6789 | u8 *next_hop = NULL; |
| 6790 | |
| 6791 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6792 | return -EINVAL; |
| 6793 | |
| 6794 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6795 | return -EINVAL; |
| 6796 | |
| 6797 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6798 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6799 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6800 | if (!rdev->ops->change_mpath) |
| 6801 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6802 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6803 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6804 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6805 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6806 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6807 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6808 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6809 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6810 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6812 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6813 | u8 *dst = NULL; |
| 6814 | u8 *next_hop = NULL; |
| 6815 | |
| 6816 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6817 | return -EINVAL; |
| 6818 | |
| 6819 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 6820 | return -EINVAL; |
| 6821 | |
| 6822 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6823 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 6824 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6825 | if (!rdev->ops->add_mpath) |
| 6826 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6827 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6828 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6829 | return -EOPNOTSUPP; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6830 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6831 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6832 | } |
| 6833 | |
| 6834 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 6835 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6837 | struct net_device *dev = info->user_ptr[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6838 | u8 *dst = NULL; |
| 6839 | |
| 6840 | if (info->attrs[NL80211_ATTR_MAC]) |
| 6841 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6842 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6843 | if (!rdev->ops->del_mpath) |
| 6844 | return -EOPNOTSUPP; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 6845 | |
Miaoqing Pan | b501426 | 2019-09-26 16:16:50 +0800 | [diff] [blame] | 6846 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6847 | return -EOPNOTSUPP; |
| 6848 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 6849 | return rdev_del_mpath(rdev, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 6850 | } |
| 6851 | |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6852 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
| 6853 | { |
| 6854 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6855 | int err; |
| 6856 | struct net_device *dev = info->user_ptr[1]; |
| 6857 | struct mpath_info pinfo; |
| 6858 | struct sk_buff *msg; |
| 6859 | u8 *dst = NULL; |
| 6860 | u8 mpp[ETH_ALEN]; |
| 6861 | |
| 6862 | memset(&pinfo, 0, sizeof(pinfo)); |
| 6863 | |
| 6864 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 6865 | return -EINVAL; |
| 6866 | |
| 6867 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 6868 | |
| 6869 | if (!rdev->ops->get_mpp) |
| 6870 | return -EOPNOTSUPP; |
| 6871 | |
| 6872 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
| 6873 | return -EOPNOTSUPP; |
| 6874 | |
| 6875 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); |
| 6876 | if (err) |
| 6877 | return err; |
| 6878 | |
| 6879 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 6880 | if (!msg) |
| 6881 | return -ENOMEM; |
| 6882 | |
| 6883 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
| 6884 | dev, dst, mpp, &pinfo) < 0) { |
| 6885 | nlmsg_free(msg); |
| 6886 | return -ENOBUFS; |
| 6887 | } |
| 6888 | |
| 6889 | return genlmsg_reply(msg, info); |
| 6890 | } |
| 6891 | |
| 6892 | static int nl80211_dump_mpp(struct sk_buff *skb, |
| 6893 | struct netlink_callback *cb) |
| 6894 | { |
| 6895 | struct mpath_info pinfo; |
| 6896 | struct cfg80211_registered_device *rdev; |
| 6897 | struct wireless_dev *wdev; |
| 6898 | u8 dst[ETH_ALEN]; |
| 6899 | u8 mpp[ETH_ALEN]; |
| 6900 | int path_idx = cb->args[2]; |
| 6901 | int err; |
| 6902 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6903 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 6904 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6905 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6906 | goto out_err; |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6907 | |
| 6908 | if (!rdev->ops->dump_mpp) { |
| 6909 | err = -EOPNOTSUPP; |
| 6910 | goto out_err; |
| 6911 | } |
| 6912 | |
| 6913 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 6914 | err = -EOPNOTSUPP; |
| 6915 | goto out_err; |
| 6916 | } |
| 6917 | |
| 6918 | while (1) { |
| 6919 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, |
| 6920 | mpp, &pinfo); |
| 6921 | if (err == -ENOENT) |
| 6922 | break; |
| 6923 | if (err) |
| 6924 | goto out_err; |
| 6925 | |
| 6926 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
| 6927 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 6928 | wdev->netdev, dst, mpp, |
| 6929 | &pinfo) < 0) |
| 6930 | goto out; |
| 6931 | |
| 6932 | path_idx++; |
| 6933 | } |
| 6934 | |
| 6935 | out: |
| 6936 | cb->args[2] = path_idx; |
| 6937 | err = skb->len; |
| 6938 | out_err: |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 6939 | rtnl_unlock(); |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 6940 | return err; |
| 6941 | } |
| 6942 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6943 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 6944 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 6945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 6946 | struct net_device *dev = info->user_ptr[1]; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6947 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6948 | struct bss_parameters params; |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 6949 | int err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6950 | |
| 6951 | memset(¶ms, 0, sizeof(params)); |
| 6952 | /* default to not changing parameters */ |
| 6953 | params.use_cts_prot = -1; |
| 6954 | params.use_short_preamble = -1; |
| 6955 | params.use_short_slot_time = -1; |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6956 | params.ap_isolate = -1; |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6957 | params.ht_opmode = -1; |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6958 | params.p2p_ctwindow = -1; |
| 6959 | params.p2p_opp_ps = -1; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6960 | |
| 6961 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 6962 | params.use_cts_prot = |
| 6963 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 6964 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 6965 | params.use_short_preamble = |
| 6966 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 6967 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 6968 | params.use_short_slot_time = |
| 6969 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 6970 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 6971 | params.basic_rates = |
| 6972 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6973 | params.basic_rates_len = |
| 6974 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 6975 | } |
Felix Fietkau | fd8aaaf | 2010-04-27 01:23:35 +0200 | [diff] [blame] | 6976 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
| 6977 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
Helmut Schaa | 50b12f5 | 2010-11-19 12:40:25 +0100 | [diff] [blame] | 6978 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
| 6979 | params.ht_opmode = |
| 6980 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 6981 | |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6982 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
| 6983 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6984 | return -EINVAL; |
| 6985 | params.p2p_ctwindow = |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 6986 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6987 | if (params.p2p_ctwindow != 0 && |
| 6988 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) |
| 6989 | return -EINVAL; |
| 6990 | } |
| 6991 | |
| 6992 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { |
| 6993 | u8 tmp; |
| 6994 | |
| 6995 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 6996 | return -EINVAL; |
| 6997 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); |
Johannes Berg | 53cabad | 2012-11-14 15:17:28 +0100 | [diff] [blame] | 6998 | params.p2p_opp_ps = tmp; |
| 6999 | if (params.p2p_opp_ps && |
| 7000 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) |
| 7001 | return -EINVAL; |
| 7002 | } |
| 7003 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7004 | if (!rdev->ops->change_bss) |
| 7005 | return -EOPNOTSUPP; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7006 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 7007 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7008 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
| 7009 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 7010 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 7011 | wdev_lock(wdev); |
| 7012 | err = rdev_change_bss(rdev, dev, ¶ms); |
| 7013 | wdev_unlock(wdev); |
| 7014 | |
| 7015 | return err; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 7016 | } |
| 7017 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7018 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7019 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7020 | char *data = NULL; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 7021 | bool is_indoor; |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 7022 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 7023 | u32 owner_nlportid; |
| 7024 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 7025 | /* |
| 7026 | * You should only get this when cfg80211 hasn't yet initialized |
| 7027 | * completely when built-in to the kernel right between the time |
| 7028 | * window between nl80211_init() and regulatory_init(), if that is |
| 7029 | * even possible. |
| 7030 | */ |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7031 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 7032 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 7033 | |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 7034 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
| 7035 | user_reg_hint_type = |
| 7036 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); |
| 7037 | else |
| 7038 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; |
| 7039 | |
| 7040 | switch (user_reg_hint_type) { |
| 7041 | case NL80211_USER_REG_HINT_USER: |
| 7042 | case NL80211_USER_REG_HINT_CELL_BASE: |
Ilan Peer | 52616f2 | 2014-02-25 16:26:00 +0200 | [diff] [blame] | 7043 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7044 | return -EINVAL; |
| 7045 | |
| 7046 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7047 | return regulatory_hint_user(data, user_reg_hint_type); |
| 7048 | case NL80211_USER_REG_HINT_INDOOR: |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 7049 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 7050 | owner_nlportid = info->snd_portid; |
| 7051 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; |
| 7052 | } else { |
| 7053 | owner_nlportid = 0; |
| 7054 | is_indoor = true; |
| 7055 | } |
| 7056 | |
| 7057 | return regulatory_hint_indoor(is_indoor, owner_nlportid); |
Luis R. Rodriguez | 57b5ce0 | 2012-07-12 11:49:18 -0700 | [diff] [blame] | 7058 | default: |
| 7059 | return -EINVAL; |
| 7060 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7061 | } |
| 7062 | |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 7063 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
| 7064 | { |
| 7065 | return reg_reload_regdb(); |
| 7066 | } |
| 7067 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7068 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7069 | struct genl_info *info) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7070 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7071 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7072 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7073 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 7074 | struct mesh_config cur_params; |
| 7075 | int err = 0; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7076 | void *hdr; |
| 7077 | struct nlattr *pinfoattr; |
| 7078 | struct sk_buff *msg; |
| 7079 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7080 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7081 | return -EOPNOTSUPP; |
| 7082 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7083 | if (!rdev->ops->get_mesh_config) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7084 | return -EOPNOTSUPP; |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 7085 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7086 | wdev_lock(wdev); |
| 7087 | /* If not connected, get default parameters */ |
| 7088 | if (!wdev->mesh_id_len) |
| 7089 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
| 7090 | else |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7091 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7092 | wdev_unlock(wdev); |
| 7093 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7094 | if (err) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7095 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7096 | |
| 7097 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 7098 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7099 | if (!msg) |
| 7100 | return -ENOMEM; |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 7101 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7102 | NL80211_CMD_GET_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7103 | if (!hdr) |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7104 | goto out; |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7105 | pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7106 | if (!pinfoattr) |
| 7107 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7108 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 7109 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 7110 | cur_params.dot11MeshRetryTimeout) || |
| 7111 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7112 | cur_params.dot11MeshConfirmTimeout) || |
| 7113 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7114 | cur_params.dot11MeshHoldingTimeout) || |
| 7115 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7116 | cur_params.dot11MeshMaxPeerLinks) || |
| 7117 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 7118 | cur_params.dot11MeshMaxRetries) || |
| 7119 | nla_put_u8(msg, NL80211_MESHCONF_TTL, |
| 7120 | cur_params.dot11MeshTTL) || |
| 7121 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, |
| 7122 | cur_params.element_ttl) || |
| 7123 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7124 | cur_params.auto_open_plinks) || |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 7125 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
| 7126 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7127 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7128 | cur_params.dot11MeshHWMPmaxPREQretries) || |
| 7129 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7130 | cur_params.path_refresh_time) || |
| 7131 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7132 | cur_params.min_discovery_timeout) || |
| 7133 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 7134 | cur_params.dot11MeshHWMPactivePathTimeout) || |
| 7135 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 7136 | cur_params.dot11MeshHWMPpreqMinInterval) || |
| 7137 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
| 7138 | cur_params.dot11MeshHWMPperrMinInterval) || |
| 7139 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 7140 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || |
| 7141 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
| 7142 | cur_params.dot11MeshHWMPRootMode) || |
| 7143 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7144 | cur_params.dot11MeshHWMPRannInterval) || |
| 7145 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
| 7146 | cur_params.dot11MeshGateAnnouncementProtocol) || |
| 7147 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 7148 | cur_params.dot11MeshForwarding) || |
Masashi Honma | 335d534 | 2017-03-16 10:57:17 +0900 | [diff] [blame] | 7149 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 7150 | cur_params.rssi_threshold) || |
| 7151 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 7152 | cur_params.ht_opmode) || |
| 7153 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7154 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || |
| 7155 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7156 | cur_params.dot11MeshHWMProotInterval) || |
| 7157 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 7158 | cur_params.dot11MeshHWMPconfirmationInterval) || |
| 7159 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, |
| 7160 | cur_params.power_mode) || |
| 7161 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 7162 | cur_params.dot11MeshAwakeWindowDuration) || |
| 7163 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7164 | cur_params.plink_timeout) || |
| 7165 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE, |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7166 | cur_params.dot11MeshConnectedToMeshGate) || |
| 7167 | nla_put_u8(msg, NL80211_MESHCONF_NOLEARN, |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7168 | cur_params.dot11MeshNolearn) || |
| 7169 | nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7170 | cur_params.dot11MeshConnectedToAuthServer)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7171 | goto nla_put_failure; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7172 | nla_nest_end(msg, pinfoattr); |
| 7173 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7174 | return genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7175 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 7176 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7177 | out: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7178 | nlmsg_free(msg); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 7179 | return -ENOBUFS; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7180 | } |
| 7181 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7182 | static const struct nla_policy |
| 7183 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
| 7184 | [NL80211_MESHCONF_RETRY_TIMEOUT] = |
| 7185 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7186 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = |
| 7187 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7188 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = |
| 7189 | NLA_POLICY_RANGE(NLA_U16, 1, 255), |
| 7190 | [NL80211_MESHCONF_MAX_PEER_LINKS] = |
| 7191 | NLA_POLICY_RANGE(NLA_U16, 0, 255), |
| 7192 | [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16), |
| 7193 | [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7194 | [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1), |
| 7195 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7196 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = |
| 7197 | NLA_POLICY_RANGE(NLA_U32, 1, 255), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7198 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 7199 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7200 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1), |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7201 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7202 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = |
| 7203 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7204 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = |
| 7205 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7206 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = |
| 7207 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7208 | [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4), |
| 7209 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = |
| 7210 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7211 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7212 | [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1), |
| 7213 | [NL80211_MESHCONF_RSSI_THRESHOLD] = |
| 7214 | NLA_POLICY_RANGE(NLA_S32, -255, 0), |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7215 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 7216 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7217 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = |
| 7218 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7219 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = |
| 7220 | NLA_POLICY_MIN(NLA_U16, 1), |
| 7221 | [NL80211_MESHCONF_POWER_MODE] = |
| 7222 | NLA_POLICY_RANGE(NLA_U32, |
| 7223 | NL80211_MESH_POWER_ACTIVE, |
| 7224 | NL80211_MESH_POWER_MAX), |
Marco Porsch | 3b1c5a5 | 2013-01-07 16:04:52 +0100 | [diff] [blame] | 7225 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, |
Colleen Twitty | 8e7c053 | 2013-06-03 09:53:39 -0700 | [diff] [blame] | 7226 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7227 | [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] | 7228 | [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1), |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7229 | [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] | 7230 | }; |
| 7231 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7232 | static const struct nla_policy |
| 7233 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7234 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7235 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
| 7236 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, |
Javier Cardona | 15d5dda | 2011-04-07 15:08:28 -0700 | [diff] [blame] | 7237 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7238 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7239 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 7240 | [NL80211_MESH_SETUP_IE] = |
| 7241 | NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr, |
| 7242 | IEEE80211_MAX_DATA_LEN), |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7243 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7244 | }; |
| 7245 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7246 | static int nl80211_parse_mesh_config(struct genl_info *info, |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7247 | struct mesh_config *cfg, |
| 7248 | u32 *mask_out) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7249 | { |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7250 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7251 | u32 mask = 0; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7252 | u16 ht_opmode; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7253 | |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7254 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \ |
| 7255 | do { \ |
| 7256 | if (tb[attr]) { \ |
| 7257 | cfg->param = fn(tb[attr]); \ |
| 7258 | mask |= BIT((attr) - 1); \ |
| 7259 | } \ |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7260 | } while (0) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7261 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7262 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7263 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7264 | 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] | 7265 | return -EINVAL; |
| 7266 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7267 | /* This makes sure that there aren't more than 32 mesh config |
| 7268 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 7269 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 7270 | |
| 7271 | /* Fill in the params struct */ |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7272 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask, |
| 7273 | NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 7274 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask, |
| 7275 | NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 7276 | nla_get_u16); |
| 7277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask, |
| 7278 | NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 7279 | nla_get_u16); |
| 7280 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask, |
| 7281 | NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7282 | nla_get_u16); |
| 7283 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask, |
| 7284 | NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 7285 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask, |
| 7286 | NL80211_MESHCONF_TTL, nla_get_u8); |
| 7287 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask, |
| 7288 | NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); |
| 7289 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask, |
| 7290 | NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 7291 | nla_get_u8); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7292 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7293 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7294 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7295 | nla_get_u32); |
| 7296 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask, |
| 7297 | NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 7298 | nla_get_u8); |
| 7299 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask, |
| 7300 | NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 7301 | nla_get_u32); |
| 7302 | if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) && |
| 7303 | (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535)) |
| 7304 | return -EINVAL; |
| 7305 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask, |
| 7306 | NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 7307 | nla_get_u16); |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7308 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7309 | mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7310 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7311 | nla_get_u32); |
| 7312 | if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) && |
| 7313 | (cfg->dot11MeshHWMPactivePathTimeout < 1 || |
| 7314 | cfg->dot11MeshHWMPactivePathTimeout > 65535)) |
| 7315 | return -EINVAL; |
| 7316 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7317 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7318 | nla_get_u16); |
| 7319 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7320 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7321 | nla_get_u16); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7322 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7323 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 7324 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7325 | nla_get_u16); |
| 7326 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, |
| 7327 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); |
| 7328 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, |
| 7329 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, |
| 7330 | nla_get_u16); |
| 7331 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol, |
Marco Porsch | ea54fba | 2013-01-07 16:04:48 +0100 | [diff] [blame] | 7332 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7333 | nla_get_u8); |
| 7334 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask, |
| 7335 | NL80211_MESHCONF_FORWARDING, nla_get_u8); |
| 7336 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask, |
| 7337 | NL80211_MESHCONF_RSSI_THRESHOLD, |
| 7338 | nla_get_s32); |
Bob Copeland | 01d66fb | 2018-10-25 17:36:34 -0400 | [diff] [blame] | 7339 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask, |
| 7340 | NL80211_MESHCONF_CONNECTED_TO_GATE, |
| 7341 | nla_get_u8); |
Markus Theil | 184eebe | 2020-06-11 16:02:37 +0200 | [diff] [blame] | 7342 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask, |
| 7343 | NL80211_MESHCONF_CONNECTED_TO_AS, |
| 7344 | nla_get_u8); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7345 | /* |
| 7346 | * Check HT operation mode based on |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7347 | * IEEE 802.11-2016 9.4.2.57 HT Operation element. |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7348 | */ |
| 7349 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { |
| 7350 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); |
| 7351 | |
| 7352 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | |
| 7353 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | |
| 7354 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) |
| 7355 | return -EINVAL; |
| 7356 | |
Bob Copeland | 188f60a | 2018-06-24 21:10:49 -0400 | [diff] [blame] | 7357 | /* NON_HT_STA bit is reserved, but some programs set it */ |
| 7358 | ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT; |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7359 | |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7360 | cfg->ht_opmode = ht_opmode; |
Masashi Honma | fd551ba | 2017-01-26 08:56:13 +0900 | [diff] [blame] | 7361 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
Masashi Honma | 9757235 | 2016-08-03 10:07:44 +0900 | [diff] [blame] | 7362 | } |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7363 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7364 | dot11MeshHWMPactivePathToRootTimeout, mask, |
| 7365 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
| 7366 | nla_get_u32); |
| 7367 | if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) && |
| 7368 | (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 || |
| 7369 | cfg->dot11MeshHWMPactivePathToRootTimeout > 65535)) |
| 7370 | return -EINVAL; |
| 7371 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask, |
| 7372 | NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
| 7373 | nla_get_u16); |
| 7374 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval, |
| 7375 | mask, |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 7376 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
Johannes Berg | ab0d76f | 2018-10-02 10:00:07 +0200 | [diff] [blame] | 7377 | nla_get_u16); |
| 7378 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask, |
| 7379 | NL80211_MESHCONF_POWER_MODE, nla_get_u32); |
| 7380 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask, |
| 7381 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); |
| 7382 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask, |
| 7383 | NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32); |
Linus Lüssing | e3718a6 | 2020-06-17 09:30:33 +0200 | [diff] [blame] | 7384 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask, |
| 7385 | NL80211_MESHCONF_NOLEARN, nla_get_u8); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7386 | if (mask_out) |
| 7387 | *mask_out = mask; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7388 | |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7389 | return 0; |
| 7390 | |
| 7391 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 7392 | } |
| 7393 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7394 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
| 7395 | struct mesh_setup *setup) |
| 7396 | { |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7398 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
| 7399 | |
| 7400 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) |
| 7401 | return -EINVAL; |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7402 | 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] | 7403 | return -EINVAL; |
| 7404 | |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 7405 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
| 7406 | setup->sync_method = |
| 7407 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? |
| 7408 | IEEE80211_SYNC_METHOD_VENDOR : |
| 7409 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; |
| 7410 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7411 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
| 7412 | setup->path_sel_proto = |
| 7413 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? |
| 7414 | IEEE80211_PATH_PROTOCOL_VENDOR : |
| 7415 | IEEE80211_PATH_PROTOCOL_HWMP; |
| 7416 | |
| 7417 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) |
| 7418 | setup->path_metric = |
| 7419 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? |
| 7420 | IEEE80211_PATH_METRIC_VENDOR : |
| 7421 | IEEE80211_PATH_METRIC_AIRTIME; |
| 7422 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7423 | if (tb[NL80211_MESH_SETUP_IE]) { |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7424 | struct nlattr *ieattr = |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7425 | tb[NL80211_MESH_SETUP_IE]; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 7426 | setup->ie = nla_data(ieattr); |
| 7427 | setup->ie_len = nla_len(ieattr); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7428 | } |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7429 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
| 7430 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) |
| 7431 | return -EINVAL; |
| 7432 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 7433 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
| 7434 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); |
Thomas Pedersen | bb2798d | 2013-03-04 13:06:10 -0800 | [diff] [blame] | 7435 | if (setup->is_secure) |
| 7436 | setup->user_mpm = true; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7437 | |
Colleen Twitty | 6e16d90 | 2013-05-08 11:45:59 -0700 | [diff] [blame] | 7438 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
| 7439 | if (!setup->user_mpm) |
| 7440 | return -EINVAL; |
| 7441 | setup->auth_id = |
| 7442 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); |
| 7443 | } |
| 7444 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 7445 | return 0; |
| 7446 | } |
| 7447 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7448 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7449 | struct genl_info *info) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7450 | { |
| 7451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7452 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7453 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7454 | struct mesh_config cfg; |
| 7455 | u32 mask; |
| 7456 | int err; |
| 7457 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7458 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 7459 | return -EOPNOTSUPP; |
| 7460 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7461 | if (!rdev->ops->update_mesh_config) |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7462 | return -EOPNOTSUPP; |
| 7463 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 7464 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
Johannes Berg | bd90fdc | 2010-12-03 09:20:43 +0100 | [diff] [blame] | 7465 | if (err) |
| 7466 | return err; |
| 7467 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7468 | wdev_lock(wdev); |
| 7469 | if (!wdev->mesh_id_len) |
| 7470 | err = -ENOLINK; |
| 7471 | |
| 7472 | if (!err) |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 7473 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 7474 | |
| 7475 | wdev_unlock(wdev); |
| 7476 | |
| 7477 | return err; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 7478 | } |
| 7479 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7480 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
| 7481 | struct sk_buff *msg) |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7482 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7483 | struct nlattr *nl_reg_rules; |
| 7484 | unsigned int i; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7485 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7486 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
| 7487 | (regdom->dfs_region && |
| 7488 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7489 | goto nla_put_failure; |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7490 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7491 | 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] | 7492 | if (!nl_reg_rules) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7493 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7494 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7495 | for (i = 0; i < regdom->n_reg_rules; i++) { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7496 | struct nlattr *nl_reg_rule; |
| 7497 | const struct ieee80211_reg_rule *reg_rule; |
| 7498 | const struct ieee80211_freq_range *freq_range; |
| 7499 | const struct ieee80211_power_rule *power_rule; |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7500 | unsigned int max_bandwidth_khz; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7501 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7502 | reg_rule = ®dom->reg_rules[i]; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7503 | freq_range = ®_rule->freq_range; |
| 7504 | power_rule = ®_rule->power_rule; |
| 7505 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 7506 | nl_reg_rule = nla_nest_start_noflag(msg, i); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7507 | if (!nl_reg_rule) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7508 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7509 | |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7510 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
| 7511 | if (!max_bandwidth_khz) |
| 7512 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, |
| 7513 | reg_rule); |
| 7514 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7515 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 7516 | reg_rule->flags) || |
| 7517 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 7518 | freq_range->start_freq_khz) || |
| 7519 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 7520 | freq_range->end_freq_khz) || |
| 7521 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
Janusz Dziedzic | 9752482 | 2014-01-30 09:52:20 +0100 | [diff] [blame] | 7522 | max_bandwidth_khz) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 7523 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 7524 | power_rule->max_antenna_gain) || |
| 7525 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
Janusz Dziedzic | 089027e | 2014-02-21 19:46:12 +0100 | [diff] [blame] | 7526 | power_rule->max_eirp) || |
| 7527 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, |
| 7528 | reg_rule->dfs_cac_ms)) |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7529 | goto nla_put_failure; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7530 | |
| 7531 | nla_nest_end(msg, nl_reg_rule); |
| 7532 | } |
| 7533 | |
| 7534 | nla_nest_end(msg, nl_reg_rules); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7535 | return 0; |
| 7536 | |
| 7537 | nla_put_failure: |
| 7538 | return -EMSGSIZE; |
| 7539 | } |
| 7540 | |
| 7541 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) |
| 7542 | { |
| 7543 | const struct ieee80211_regdomain *regdom = NULL; |
| 7544 | struct cfg80211_registered_device *rdev; |
| 7545 | struct wiphy *wiphy = NULL; |
| 7546 | struct sk_buff *msg; |
| 7547 | void *hdr; |
| 7548 | |
| 7549 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 7550 | if (!msg) |
| 7551 | return -ENOBUFS; |
| 7552 | |
| 7553 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 7554 | NL80211_CMD_GET_REG); |
| 7555 | if (!hdr) |
| 7556 | goto put_failure; |
| 7557 | |
| 7558 | if (info->attrs[NL80211_ATTR_WIPHY]) { |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7559 | bool self_managed; |
| 7560 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7561 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
| 7562 | if (IS_ERR(rdev)) { |
| 7563 | nlmsg_free(msg); |
| 7564 | return PTR_ERR(rdev); |
| 7565 | } |
| 7566 | |
| 7567 | wiphy = &rdev->wiphy; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7568 | self_managed = wiphy->regulatory_flags & |
| 7569 | REGULATORY_WIPHY_SELF_MANAGED; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7570 | regdom = get_wiphy_regdom(wiphy); |
| 7571 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7572 | /* a self-managed-reg device must have a private regdom */ |
| 7573 | if (WARN_ON(!regdom && self_managed)) { |
| 7574 | nlmsg_free(msg); |
| 7575 | return -EINVAL; |
| 7576 | } |
| 7577 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7578 | if (regdom && |
| 7579 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7580 | goto nla_put_failure; |
| 7581 | } |
| 7582 | |
| 7583 | if (!wiphy && reg_last_request_cell_base() && |
| 7584 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7585 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7586 | goto nla_put_failure; |
| 7587 | |
| 7588 | rcu_read_lock(); |
| 7589 | |
| 7590 | if (!regdom) |
| 7591 | regdom = rcu_dereference(cfg80211_regdomain); |
| 7592 | |
| 7593 | if (nl80211_put_regdom(regdom, msg)) |
| 7594 | goto nla_put_failure_rcu; |
| 7595 | |
| 7596 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7597 | |
| 7598 | genlmsg_end(msg, hdr); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7599 | return genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7600 | |
Johannes Berg | 458f4f9 | 2012-12-06 15:47:38 +0100 | [diff] [blame] | 7601 | nla_put_failure_rcu: |
| 7602 | rcu_read_unlock(); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7603 | nla_put_failure: |
Julia Lawall | efe1cf0 | 2011-01-28 15:17:11 +0100 | [diff] [blame] | 7604 | put_failure: |
Yuri Ershov | d080e27 | 2010-06-29 15:08:07 +0400 | [diff] [blame] | 7605 | nlmsg_free(msg); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 7606 | return -EMSGSIZE; |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 7607 | } |
| 7608 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7609 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
| 7610 | u32 seq, int flags, struct wiphy *wiphy, |
| 7611 | const struct ieee80211_regdomain *regdom) |
| 7612 | { |
| 7613 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
| 7614 | NL80211_CMD_GET_REG); |
| 7615 | |
| 7616 | if (!hdr) |
| 7617 | return -1; |
| 7618 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 7619 | genl_dump_check_consistent(cb, hdr); |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7620 | |
| 7621 | if (nl80211_put_regdom(regdom, msg)) |
| 7622 | goto nla_put_failure; |
| 7623 | |
| 7624 | if (!wiphy && reg_last_request_cell_base() && |
| 7625 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, |
| 7626 | NL80211_USER_REG_HINT_CELL_BASE)) |
| 7627 | goto nla_put_failure; |
| 7628 | |
| 7629 | if (wiphy && |
| 7630 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 7631 | goto nla_put_failure; |
| 7632 | |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 7633 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 7634 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 7635 | goto nla_put_failure; |
| 7636 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 7637 | genlmsg_end(msg, hdr); |
| 7638 | return 0; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 7639 | |
| 7640 | nla_put_failure: |
| 7641 | genlmsg_cancel(msg, hdr); |
| 7642 | return -EMSGSIZE; |
| 7643 | } |
| 7644 | |
| 7645 | static int nl80211_get_reg_dump(struct sk_buff *skb, |
| 7646 | struct netlink_callback *cb) |
| 7647 | { |
| 7648 | const struct ieee80211_regdomain *regdom = NULL; |
| 7649 | struct cfg80211_registered_device *rdev; |
| 7650 | int err, reg_idx, start = cb->args[2]; |
| 7651 | |
| 7652 | rtnl_lock(); |
| 7653 | |
| 7654 | if (cfg80211_regdomain && start == 0) { |
| 7655 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7656 | NLM_F_MULTI, NULL, |
| 7657 | rtnl_dereference(cfg80211_regdomain)); |
| 7658 | if (err < 0) |
| 7659 | goto out_err; |
| 7660 | } |
| 7661 | |
| 7662 | /* the global regdom is idx 0 */ |
| 7663 | reg_idx = 1; |
| 7664 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 7665 | regdom = get_wiphy_regdom(&rdev->wiphy); |
| 7666 | if (!regdom) |
| 7667 | continue; |
| 7668 | |
| 7669 | if (++reg_idx <= start) |
| 7670 | continue; |
| 7671 | |
| 7672 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, |
| 7673 | NLM_F_MULTI, &rdev->wiphy, regdom); |
| 7674 | if (err < 0) { |
| 7675 | reg_idx--; |
| 7676 | break; |
| 7677 | } |
| 7678 | } |
| 7679 | |
| 7680 | cb->args[2] = reg_idx; |
| 7681 | err = skb->len; |
| 7682 | out_err: |
| 7683 | rtnl_unlock(); |
| 7684 | return err; |
| 7685 | } |
| 7686 | |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7687 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
| 7688 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 7689 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 7690 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 7691 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 7692 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 7693 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 7694 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 7695 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
| 7696 | }; |
| 7697 | |
| 7698 | static int parse_reg_rule(struct nlattr *tb[], |
| 7699 | struct ieee80211_reg_rule *reg_rule) |
| 7700 | { |
| 7701 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 7702 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 7703 | |
| 7704 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 7705 | return -EINVAL; |
| 7706 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 7707 | return -EINVAL; |
| 7708 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 7709 | return -EINVAL; |
| 7710 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 7711 | return -EINVAL; |
| 7712 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 7713 | return -EINVAL; |
| 7714 | |
| 7715 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 7716 | |
| 7717 | freq_range->start_freq_khz = |
| 7718 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 7719 | freq_range->end_freq_khz = |
| 7720 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 7721 | freq_range->max_bandwidth_khz = |
| 7722 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 7723 | |
| 7724 | power_rule->max_eirp = |
| 7725 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 7726 | |
| 7727 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 7728 | power_rule->max_antenna_gain = |
| 7729 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 7730 | |
| 7731 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
| 7732 | reg_rule->dfs_cac_ms = |
| 7733 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); |
| 7734 | |
| 7735 | return 0; |
| 7736 | } |
| 7737 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7738 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 7739 | { |
| 7740 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 7741 | struct nlattr *nl_reg_rule; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7742 | char *alpha2; |
| 7743 | int rem_reg_rules, r; |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7744 | u32 num_rules = 0, rule_idx = 0; |
Luis R. Rodriguez | 4c7d398 | 2013-11-13 18:54:02 +0100 | [diff] [blame] | 7745 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
Johannes Berg | ea372c5 | 2014-11-28 14:54:31 +0100 | [diff] [blame] | 7746 | struct ieee80211_regdomain *rd; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7747 | |
| 7748 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 7749 | return -EINVAL; |
| 7750 | |
| 7751 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 7752 | return -EINVAL; |
| 7753 | |
| 7754 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 7755 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7756 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
| 7757 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); |
| 7758 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7759 | 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] | 7760 | rem_reg_rules) { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7761 | num_rules++; |
| 7762 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 7763 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7764 | } |
| 7765 | |
Luis R. Rodriguez | e438768 | 2013-11-05 09:18:01 -0800 | [diff] [blame] | 7766 | if (!reg_is_valid_request(alpha2)) |
| 7767 | return -EINVAL; |
| 7768 | |
Gustavo A. R. Silva | 391d132 | 2019-04-03 10:37:44 -0500 | [diff] [blame] | 7769 | rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL); |
Johannes Berg | 6913b49 | 2012-12-04 00:48:59 +0100 | [diff] [blame] | 7770 | if (!rd) |
| 7771 | return -ENOMEM; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7772 | |
| 7773 | rd->n_reg_rules = num_rules; |
| 7774 | rd->alpha2[0] = alpha2[0]; |
| 7775 | rd->alpha2[1] = alpha2[1]; |
| 7776 | |
Luis R. Rodriguez | 8b60b07 | 2011-10-11 10:59:02 -0700 | [diff] [blame] | 7777 | /* |
| 7778 | * Disable DFS master mode if the DFS region was |
| 7779 | * not supported or known on this kernel. |
| 7780 | */ |
| 7781 | if (reg_supported_dfs_region(dfs_region)) |
| 7782 | rd->dfs_region = dfs_region; |
| 7783 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7784 | 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] | 7785 | rem_reg_rules) { |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7786 | r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX, |
| 7787 | nl_reg_rule, reg_rule_policy, |
| 7788 | info->extack); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 7789 | if (r) |
| 7790 | goto bad_reg; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7791 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 7792 | if (r) |
| 7793 | goto bad_reg; |
| 7794 | |
| 7795 | rule_idx++; |
| 7796 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7797 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 7798 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7799 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7800 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7801 | } |
| 7802 | |
Johannes Berg | 0662799 | 2016-06-09 10:40:09 +0200 | [diff] [blame] | 7803 | /* set_regdom takes ownership of rd */ |
| 7804 | return set_regdom(rd, REGD_SOURCE_CRDA); |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 7805 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7806 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 7807 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7808 | } |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 7809 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 7810 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7811 | static int validate_scan_freqs(struct nlattr *freqs) |
| 7812 | { |
| 7813 | struct nlattr *attr1, *attr2; |
| 7814 | int n_channels = 0, tmp1, tmp2; |
| 7815 | |
Srinivas Dasari | d7f13f7 | 2017-07-07 01:43:42 +0300 | [diff] [blame] | 7816 | nla_for_each_nested(attr1, freqs, tmp1) |
| 7817 | if (nla_len(attr1) != sizeof(u32)) |
| 7818 | return 0; |
| 7819 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 7820 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 7821 | n_channels++; |
| 7822 | /* |
| 7823 | * Some hardware has a limited channel list for |
| 7824 | * scanning, and it is pretty much nonsensical |
| 7825 | * to scan for a channel twice, so disallow that |
| 7826 | * and don't require drivers to check that the |
| 7827 | * channel list they get isn't longer than what |
| 7828 | * they can scan, as long as they can scan all |
| 7829 | * the channels they registered at once. |
| 7830 | */ |
| 7831 | nla_for_each_nested(attr2, freqs, tmp2) |
| 7832 | if (attr1 != attr2 && |
| 7833 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 7834 | return 0; |
| 7835 | } |
| 7836 | |
| 7837 | return n_channels; |
| 7838 | } |
| 7839 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7840 | 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] | 7841 | { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 7842 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7843 | } |
| 7844 | |
| 7845 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, |
| 7846 | struct cfg80211_bss_selection *bss_select) |
| 7847 | { |
| 7848 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; |
| 7849 | struct nlattr *nest; |
| 7850 | int err; |
| 7851 | bool found = false; |
| 7852 | int i; |
| 7853 | |
| 7854 | /* only process one nested attribute */ |
| 7855 | nest = nla_data(nla); |
| 7856 | if (!nla_ok(nest, nla_len(nest))) |
| 7857 | return -EINVAL; |
| 7858 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 7859 | err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX, |
| 7860 | nest, nl80211_bss_select_policy, |
| 7861 | NULL); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 7862 | if (err) |
| 7863 | return err; |
| 7864 | |
| 7865 | /* only one attribute may be given */ |
| 7866 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { |
| 7867 | if (attr[i]) { |
| 7868 | if (found) |
| 7869 | return -EINVAL; |
| 7870 | found = true; |
| 7871 | } |
| 7872 | } |
| 7873 | |
| 7874 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; |
| 7875 | |
| 7876 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) |
| 7877 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; |
| 7878 | |
| 7879 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { |
| 7880 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; |
| 7881 | bss_select->param.band_pref = |
| 7882 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); |
| 7883 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) |
| 7884 | return -EINVAL; |
| 7885 | } |
| 7886 | |
| 7887 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { |
| 7888 | struct nl80211_bss_select_rssi_adjust *adj_param; |
| 7889 | |
| 7890 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); |
| 7891 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; |
| 7892 | bss_select->param.adjust.band = adj_param->band; |
| 7893 | bss_select->param.adjust.delta = adj_param->delta; |
| 7894 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) |
| 7895 | return -EINVAL; |
| 7896 | } |
| 7897 | |
| 7898 | /* user-space did not provide behaviour attribute */ |
| 7899 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) |
| 7900 | return -EINVAL; |
| 7901 | |
| 7902 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) |
| 7903 | return -EINVAL; |
| 7904 | |
| 7905 | return 0; |
| 7906 | } |
| 7907 | |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 7908 | int nl80211_parse_random_mac(struct nlattr **attrs, |
| 7909 | u8 *mac_addr, u8 *mac_addr_mask) |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7910 | { |
| 7911 | int i; |
| 7912 | |
| 7913 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { |
Joe Perches | d2beae1 | 2015-03-02 19:54:58 -0800 | [diff] [blame] | 7914 | eth_zero_addr(mac_addr); |
| 7915 | eth_zero_addr(mac_addr_mask); |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 7916 | mac_addr[0] = 0x2; |
| 7917 | mac_addr_mask[0] = 0x3; |
| 7918 | |
| 7919 | return 0; |
| 7920 | } |
| 7921 | |
| 7922 | /* need both or none */ |
| 7923 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) |
| 7924 | return -EINVAL; |
| 7925 | |
| 7926 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); |
| 7927 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); |
| 7928 | |
| 7929 | /* don't allow or configure an mcast address */ |
| 7930 | if (!is_multicast_ether_addr(mac_addr_mask) || |
| 7931 | is_multicast_ether_addr(mac_addr)) |
| 7932 | return -EINVAL; |
| 7933 | |
| 7934 | /* |
| 7935 | * allow users to pass a MAC address that has bits set outside |
| 7936 | * of the mask, but don't bother drivers with having to deal |
| 7937 | * with such bits |
| 7938 | */ |
| 7939 | for (i = 0; i < ETH_ALEN; i++) |
| 7940 | mac_addr[i] &= mac_addr_mask[i]; |
| 7941 | |
| 7942 | return 0; |
| 7943 | } |
| 7944 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 7945 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
| 7946 | { |
| 7947 | ASSERT_WDEV_LOCK(wdev); |
| 7948 | |
| 7949 | if (!cfg80211_beaconing_iface_active(wdev)) |
| 7950 | return true; |
| 7951 | |
| 7952 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 7953 | return true; |
| 7954 | |
| 7955 | return regulatory_pre_cac_allowed(wdev->wiphy); |
| 7956 | } |
| 7957 | |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 7958 | static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag, |
| 7959 | enum nl80211_ext_feature_index feat) |
| 7960 | { |
| 7961 | if (!(flags & flag)) |
| 7962 | return true; |
| 7963 | if (wiphy_ext_feature_isset(wiphy, feat)) |
| 7964 | return true; |
| 7965 | return false; |
| 7966 | } |
| 7967 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 7968 | static int |
| 7969 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 7970 | void *request, struct nlattr **attrs, |
| 7971 | bool is_sched_scan) |
| 7972 | { |
| 7973 | u8 *mac_addr, *mac_addr_mask; |
| 7974 | u32 *flags; |
| 7975 | enum nl80211_feature_flags randomness_flag; |
| 7976 | |
| 7977 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) |
| 7978 | return 0; |
| 7979 | |
| 7980 | if (is_sched_scan) { |
| 7981 | struct cfg80211_sched_scan_request *req = request; |
| 7982 | |
| 7983 | randomness_flag = wdev ? |
| 7984 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : |
| 7985 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; |
| 7986 | flags = &req->flags; |
| 7987 | mac_addr = req->mac_addr; |
| 7988 | mac_addr_mask = req->mac_addr_mask; |
| 7989 | } else { |
| 7990 | struct cfg80211_scan_request *req = request; |
| 7991 | |
| 7992 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; |
| 7993 | flags = &req->flags; |
| 7994 | mac_addr = req->mac_addr; |
| 7995 | mac_addr_mask = req->mac_addr_mask; |
| 7996 | } |
| 7997 | |
| 7998 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); |
| 7999 | |
Sunil Dutt | 5037a00 | 2018-01-25 17:13:37 +0200 | [diff] [blame] | 8000 | if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
| 8001 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) || |
Johannes Berg | db0a4ad | 2018-05-28 15:47:37 +0200 | [diff] [blame] | 8002 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8003 | NL80211_SCAN_FLAG_LOW_SPAN, |
| 8004 | NL80211_EXT_FEATURE_LOW_SPAN_SCAN) || |
| 8005 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8006 | NL80211_SCAN_FLAG_LOW_POWER, |
| 8007 | NL80211_EXT_FEATURE_LOW_POWER_SCAN) || |
| 8008 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8009 | NL80211_SCAN_FLAG_HIGH_ACCURACY, |
| 8010 | NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) || |
| 8011 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8012 | NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME, |
| 8013 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) || |
| 8014 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8015 | NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP, |
| 8016 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) || |
| 8017 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8018 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION, |
| 8019 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) || |
| 8020 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8021 | NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE, |
Johannes Berg | 2e076f1 | 2018-05-28 15:47:40 +0200 | [diff] [blame] | 8022 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) || |
| 8023 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8024 | NL80211_SCAN_FLAG_RANDOM_SN, |
| 8025 | NL80211_EXT_FEATURE_SCAN_RANDOM_SN) || |
| 8026 | !nl80211_check_scan_feat(wiphy, *flags, |
| 8027 | NL80211_SCAN_FLAG_MIN_PREQ_CONTENT, |
| 8028 | NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT)) |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8029 | return -EOPNOTSUPP; |
| 8030 | |
| 8031 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { |
| 8032 | int err; |
| 8033 | |
| 8034 | if (!(wiphy->features & randomness_flag) || |
| 8035 | (wdev && wdev->current_bss)) |
| 8036 | return -EOPNOTSUPP; |
| 8037 | |
| 8038 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); |
| 8039 | if (err) |
| 8040 | return err; |
| 8041 | } |
| 8042 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8043 | return 0; |
| 8044 | } |
| 8045 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8046 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 8047 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8048 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8049 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8050 | struct cfg80211_scan_request *request; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8051 | struct nlattr *scan_freqs = NULL; |
| 8052 | bool scan_freqs_khz = false; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8053 | struct nlattr *attr; |
| 8054 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 8055 | int err, tmp, n_ssids = 0, n_channels, i; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8056 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8057 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8058 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8059 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 8060 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
| 8061 | return -EOPNOTSUPP; |
| 8062 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 8063 | if (!rdev->ops->scan) |
| 8064 | return -EOPNOTSUPP; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8065 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8066 | if (rdev->scan_req || rdev->scan_msg) |
| 8067 | return -EBUSY; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8068 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8069 | if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) { |
| 8070 | if (!wiphy_ext_feature_isset(wiphy, |
| 8071 | NL80211_EXT_FEATURE_SCAN_FREQ_KHZ)) |
| 8072 | return -EOPNOTSUPP; |
| 8073 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]; |
| 8074 | scan_freqs_khz = true; |
| 8075 | } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) |
| 8076 | scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]; |
| 8077 | |
| 8078 | if (scan_freqs) { |
| 8079 | n_channels = validate_scan_freqs(scan_freqs); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8080 | if (!n_channels) |
| 8081 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8082 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8083 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8084 | } |
| 8085 | |
| 8086 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8087 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 8088 | n_ssids++; |
| 8089 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8090 | if (n_ssids > wiphy->max_scan_ssids) |
| 8091 | return -EINVAL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8092 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8093 | if (info->attrs[NL80211_ATTR_IE]) |
| 8094 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 8095 | else |
| 8096 | ie_len = 0; |
| 8097 | |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8098 | if (ie_len > wiphy->max_scan_ie_len) |
| 8099 | return -EINVAL; |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 8100 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8101 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8102 | + sizeof(*request->ssids) * n_ssids |
| 8103 | + sizeof(*request->channels) * n_channels |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8104 | + ie_len, GFP_KERNEL); |
Christophe JAILLET | 8328685 | 2020-07-12 19:35:39 +0200 | [diff] [blame] | 8105 | if (!request) |
| 8106 | return -ENOMEM; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8107 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8108 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 8109 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8110 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8111 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8112 | if (n_ssids) |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8113 | request->ie = (void *)(request->ssids + n_ssids); |
| 8114 | else |
| 8115 | request->ie = (void *)(request->channels + n_channels); |
| 8116 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8117 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8118 | i = 0; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8119 | if (scan_freqs) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8120 | /* user specified, bail out if channel not found */ |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8121 | nla_for_each_nested(attr, scan_freqs, tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8122 | struct ieee80211_channel *chan; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8123 | int freq = nla_get_u32(attr); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8124 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8125 | if (!scan_freqs_khz) |
| 8126 | freq = MHZ_TO_KHZ(freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8127 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 8128 | chan = ieee80211_get_channel_khz(wiphy, freq); |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8129 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8130 | err = -EINVAL; |
| 8131 | goto out_free; |
| 8132 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8133 | |
| 8134 | /* ignore disabled channels */ |
| 8135 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8136 | continue; |
| 8137 | |
| 8138 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8139 | i++; |
| 8140 | } |
| 8141 | } else { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8142 | enum nl80211_band band; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8143 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8144 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8145 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8146 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8147 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8148 | if (!wiphy->bands[band]) |
| 8149 | continue; |
| 8150 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8151 | struct ieee80211_channel *chan; |
| 8152 | |
| 8153 | chan = &wiphy->bands[band]->channels[j]; |
| 8154 | |
| 8155 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8156 | continue; |
| 8157 | |
| 8158 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8159 | i++; |
| 8160 | } |
| 8161 | } |
| 8162 | } |
| 8163 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame] | 8164 | if (!i) { |
| 8165 | err = -EINVAL; |
| 8166 | goto out_free; |
| 8167 | } |
| 8168 | |
| 8169 | request->n_channels = i; |
| 8170 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 8171 | wdev_lock(wdev); |
| 8172 | if (!cfg80211_off_channel_oper_allowed(wdev)) { |
| 8173 | struct ieee80211_channel *chan; |
| 8174 | |
| 8175 | if (request->n_channels != 1) { |
| 8176 | wdev_unlock(wdev); |
| 8177 | err = -EBUSY; |
| 8178 | goto out_free; |
| 8179 | } |
| 8180 | |
| 8181 | chan = request->channels[0]; |
| 8182 | if (chan->center_freq != wdev->chandef.chan->center_freq) { |
| 8183 | wdev_unlock(wdev); |
| 8184 | err = -EBUSY; |
| 8185 | goto out_free; |
| 8186 | } |
| 8187 | } |
| 8188 | wdev_unlock(wdev); |
| 8189 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8190 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8191 | if (n_ssids) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8192 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8193 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8194 | err = -EINVAL; |
| 8195 | goto out_free; |
| 8196 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8197 | request->ssids[i].ssid_len = nla_len(attr); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8198 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8199 | i++; |
| 8200 | } |
| 8201 | } |
| 8202 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8203 | if (info->attrs[NL80211_ATTR_IE]) { |
| 8204 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54b | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 8205 | memcpy((void *)request->ie, |
| 8206 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 8207 | request->ie_len); |
| 8208 | } |
| 8209 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8210 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
Johannes Berg | a401d2b | 2011-07-20 00:52:16 +0200 | [diff] [blame] | 8211 | if (wiphy->bands[i]) |
| 8212 | request->rates[i] = |
| 8213 | (1 << wiphy->bands[i]->n_bitrates) - 1; |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8214 | |
| 8215 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { |
| 8216 | nla_for_each_nested(attr, |
| 8217 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], |
| 8218 | tmp) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8219 | enum nl80211_band band = nla_type(attr); |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8220 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8221 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8222 | err = -EINVAL; |
| 8223 | goto out_free; |
| 8224 | } |
Felix Fietkau | 1b09cd8 | 2013-11-20 19:40:41 +0100 | [diff] [blame] | 8225 | |
| 8226 | if (!wiphy->bands[band]) |
| 8227 | continue; |
| 8228 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 8229 | err = ieee80211_get_ratemask(wiphy->bands[band], |
| 8230 | nla_data(attr), |
| 8231 | nla_len(attr), |
| 8232 | &request->rates[band]); |
| 8233 | if (err) |
| 8234 | goto out_free; |
| 8235 | } |
| 8236 | } |
| 8237 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 8238 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
| 8239 | if (!wiphy_ext_feature_isset(wiphy, |
| 8240 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { |
| 8241 | err = -EOPNOTSUPP; |
| 8242 | goto out_free; |
| 8243 | } |
| 8244 | |
| 8245 | request->duration = |
| 8246 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); |
| 8247 | request->duration_mandatory = |
| 8248 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); |
| 8249 | } |
| 8250 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8251 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
| 8252 | false); |
| 8253 | if (err) |
| 8254 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8255 | |
Rajkumar Manoharan | e9f935e | 2011-09-25 14:53:30 +0530 | [diff] [blame] | 8256 | request->no_cck = |
| 8257 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
| 8258 | |
Vamsi Krishna | 2fa436b | 2016-12-02 23:59:08 +0200 | [diff] [blame] | 8259 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
| 8260 | * BSSID to scan for. This was problematic because that same attribute |
| 8261 | * was already used for another purpose (local random MAC address). The |
| 8262 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards |
| 8263 | * compatibility with older userspace components, also use the |
| 8264 | * NL80211_ATTR_MAC value here if it can be determined to be used for |
| 8265 | * the specific BSSID use case instead of the random MAC address |
| 8266 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). |
| 8267 | */ |
| 8268 | if (info->attrs[NL80211_ATTR_BSSID]) |
| 8269 | memcpy(request->bssid, |
| 8270 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); |
| 8271 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && |
| 8272 | info->attrs[NL80211_ATTR_MAC]) |
Jouni Malinen | 818965d | 2016-02-26 22:12:47 +0200 | [diff] [blame] | 8273 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
| 8274 | ETH_ALEN); |
| 8275 | else |
| 8276 | eth_broadcast_addr(request->bssid); |
| 8277 | |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 8278 | request->wdev = wdev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8279 | request->wiphy = &rdev->wiphy; |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8280 | request->scan_start = jiffies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8281 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 8282 | rdev->scan_req = request; |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 8283 | err = cfg80211_scan(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8284 | |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8285 | if (err) |
| 8286 | goto out_free; |
| 8287 | |
| 8288 | nl80211_send_scan_start(rdev, wdev); |
| 8289 | if (wdev->netdev) |
| 8290 | dev_hold(wdev->netdev); |
| 8291 | |
| 8292 | return 0; |
| 8293 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8294 | out_free: |
Christophe JAILLET | 504776b | 2020-07-12 19:35:51 +0200 | [diff] [blame] | 8295 | rdev->scan_req = NULL; |
| 8296 | kfree(request); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 8297 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 8298 | return err; |
| 8299 | } |
| 8300 | |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 8301 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
| 8302 | { |
| 8303 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8304 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 8305 | |
| 8306 | if (!rdev->ops->abort_scan) |
| 8307 | return -EOPNOTSUPP; |
| 8308 | |
| 8309 | if (rdev->scan_msg) |
| 8310 | return 0; |
| 8311 | |
| 8312 | if (!rdev->scan_req) |
| 8313 | return -ENOENT; |
| 8314 | |
| 8315 | rdev_abort_scan(rdev, wdev); |
| 8316 | return 0; |
| 8317 | } |
| 8318 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8319 | static int |
| 8320 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, |
| 8321 | struct cfg80211_sched_scan_request *request, |
| 8322 | struct nlattr **attrs) |
| 8323 | { |
| 8324 | int tmp, err, i = 0; |
| 8325 | struct nlattr *attr; |
| 8326 | |
| 8327 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8328 | u32 interval; |
| 8329 | |
| 8330 | /* |
| 8331 | * If scan plans are not specified, |
Arend Van Spriel | 5a88de5 | 2016-11-17 09:02:40 +0000 | [diff] [blame] | 8332 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8333 | * case one scan plan will be set with the specified scan |
| 8334 | * interval and infinite number of iterations. |
| 8335 | */ |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8336 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
| 8337 | if (!interval) |
| 8338 | return -EINVAL; |
| 8339 | |
| 8340 | request->scan_plans[0].interval = |
| 8341 | DIV_ROUND_UP(interval, MSEC_PER_SEC); |
| 8342 | if (!request->scan_plans[0].interval) |
| 8343 | return -EINVAL; |
| 8344 | |
| 8345 | if (request->scan_plans[0].interval > |
| 8346 | wiphy->max_sched_scan_plan_interval) |
| 8347 | request->scan_plans[0].interval = |
| 8348 | wiphy->max_sched_scan_plan_interval; |
| 8349 | |
| 8350 | return 0; |
| 8351 | } |
| 8352 | |
| 8353 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { |
| 8354 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; |
| 8355 | |
| 8356 | if (WARN_ON(i >= n_plans)) |
| 8357 | return -EINVAL; |
| 8358 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8359 | err = nla_parse_nested_deprecated(plan, |
| 8360 | NL80211_SCHED_SCAN_PLAN_MAX, |
| 8361 | attr, nl80211_plan_policy, |
| 8362 | NULL); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8363 | if (err) |
| 8364 | return err; |
| 8365 | |
| 8366 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) |
| 8367 | return -EINVAL; |
| 8368 | |
| 8369 | request->scan_plans[i].interval = |
| 8370 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); |
| 8371 | if (!request->scan_plans[i].interval || |
| 8372 | request->scan_plans[i].interval > |
| 8373 | wiphy->max_sched_scan_plan_interval) |
| 8374 | return -EINVAL; |
| 8375 | |
| 8376 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { |
| 8377 | request->scan_plans[i].iterations = |
| 8378 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); |
| 8379 | if (!request->scan_plans[i].iterations || |
| 8380 | (request->scan_plans[i].iterations > |
| 8381 | wiphy->max_sched_scan_plan_iterations)) |
| 8382 | return -EINVAL; |
| 8383 | } else if (i < n_plans - 1) { |
| 8384 | /* |
| 8385 | * All scan plans but the last one must specify |
| 8386 | * a finite number of iterations |
| 8387 | */ |
| 8388 | return -EINVAL; |
| 8389 | } |
| 8390 | |
| 8391 | i++; |
| 8392 | } |
| 8393 | |
| 8394 | /* |
| 8395 | * The last scan plan must not specify the number of |
| 8396 | * iterations, it is supposed to run infinitely |
| 8397 | */ |
| 8398 | if (request->scan_plans[n_plans - 1].iterations) |
| 8399 | return -EINVAL; |
| 8400 | |
| 8401 | return 0; |
| 8402 | } |
| 8403 | |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8404 | static int |
| 8405 | nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy, |
| 8406 | struct cfg80211_match_set *match_sets, |
| 8407 | struct nlattr *tb_band_rssi, |
| 8408 | s32 rssi_thold) |
| 8409 | { |
| 8410 | struct nlattr *attr; |
| 8411 | int i, tmp, ret = 0; |
| 8412 | |
| 8413 | if (!wiphy_ext_feature_isset(wiphy, |
| 8414 | NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) { |
| 8415 | if (tb_band_rssi) |
| 8416 | ret = -EOPNOTSUPP; |
| 8417 | else |
| 8418 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8419 | match_sets->per_band_rssi_thold[i] = |
| 8420 | NL80211_SCAN_RSSI_THOLD_OFF; |
| 8421 | return ret; |
| 8422 | } |
| 8423 | |
| 8424 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
| 8425 | match_sets->per_band_rssi_thold[i] = rssi_thold; |
| 8426 | |
| 8427 | nla_for_each_nested(attr, tb_band_rssi, tmp) { |
| 8428 | enum nl80211_band band = nla_type(attr); |
| 8429 | |
| 8430 | if (band < 0 || band >= NUM_NL80211_BANDS) |
| 8431 | return -EINVAL; |
| 8432 | |
| 8433 | match_sets->per_band_rssi_thold[band] = nla_get_s32(attr); |
| 8434 | } |
| 8435 | |
| 8436 | return 0; |
| 8437 | } |
| 8438 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8439 | static struct cfg80211_sched_scan_request * |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8440 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8441 | struct nlattr **attrs, int max_match_sets) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8442 | { |
| 8443 | struct cfg80211_sched_scan_request *request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8444 | struct nlattr *attr; |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8445 | 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] | 8446 | enum nl80211_band band; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8447 | size_t ie_len; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8448 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8449 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8450 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8451 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8452 | n_channels = validate_scan_freqs( |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8453 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8454 | if (!n_channels) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8455 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8456 | } else { |
Ilan Peer | bdfbec2 | 2014-01-09 11:37:23 +0200 | [diff] [blame] | 8457 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8458 | } |
| 8459 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8460 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 8461 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8462 | tmp) |
| 8463 | n_ssids++; |
| 8464 | |
Luciano Coelho | 93b6aa6 | 2011-07-13 14:57:28 +0300 | [diff] [blame] | 8465 | if (n_ssids > wiphy->max_sched_scan_ssids) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8466 | return ERR_PTR(-EINVAL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8467 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8468 | /* |
| 8469 | * First, count the number of 'real' matchsets. Due to an issue with |
| 8470 | * the old implementation, matchsets containing only the RSSI attribute |
| 8471 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' |
| 8472 | * RSSI for all matchsets, rather than their own matchset for reporting |
| 8473 | * all APs with a strong RSSI. This is needed to be compatible with |
| 8474 | * older userspace that treated a matchset with only the RSSI as the |
| 8475 | * global RSSI for all other matchsets - if there are other matchsets. |
| 8476 | */ |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8477 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8478 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8479 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8480 | tmp) { |
| 8481 | struct nlattr *rssi; |
| 8482 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8483 | err = nla_parse_nested_deprecated(tb, |
| 8484 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8485 | attr, |
| 8486 | nl80211_match_policy, |
| 8487 | NULL); |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8488 | if (err) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8489 | return ERR_PTR(err); |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8490 | |
| 8491 | /* SSID and BSSID are mutually exclusive */ |
| 8492 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && |
| 8493 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) |
| 8494 | return ERR_PTR(-EINVAL); |
| 8495 | |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8496 | /* add other standalone attributes here */ |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8497 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
| 8498 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8499 | n_match_sets++; |
| 8500 | continue; |
| 8501 | } |
| 8502 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8503 | if (rssi) |
| 8504 | default_match_rssi = nla_get_s32(rssi); |
| 8505 | } |
| 8506 | } |
| 8507 | |
| 8508 | /* However, if there's no other matchset, add the RSSI one */ |
| 8509 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) |
| 8510 | n_match_sets = 1; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8511 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8512 | if (n_match_sets > max_match_sets) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8513 | return ERR_PTR(-EINVAL); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8514 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8515 | if (attrs[NL80211_ATTR_IE]) |
| 8516 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8517 | else |
| 8518 | ie_len = 0; |
| 8519 | |
Luciano Coelho | 5a865ba | 2011-07-13 14:57:29 +0300 | [diff] [blame] | 8520 | if (ie_len > wiphy->max_sched_scan_ie_len) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8521 | return ERR_PTR(-EINVAL); |
Luciano Coelho | c10841c | 2011-06-30 08:32:41 +0300 | [diff] [blame] | 8522 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8523 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
| 8524 | /* |
| 8525 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since |
| 8526 | * each scan plan already specifies its own interval |
| 8527 | */ |
| 8528 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8529 | return ERR_PTR(-EINVAL); |
| 8530 | |
| 8531 | nla_for_each_nested(attr, |
| 8532 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) |
| 8533 | n_plans++; |
| 8534 | } else { |
| 8535 | /* |
| 8536 | * The scan interval attribute is kept for backward |
| 8537 | * compatibility. If no scan plans are specified and sched scan |
| 8538 | * interval is specified, one scan plan will be set with this |
| 8539 | * scan interval and infinite number of iterations. |
| 8540 | */ |
| 8541 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
| 8542 | return ERR_PTR(-EINVAL); |
| 8543 | |
| 8544 | n_plans = 1; |
| 8545 | } |
| 8546 | |
| 8547 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) |
| 8548 | return ERR_PTR(-EINVAL); |
| 8549 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8550 | if (!wiphy_ext_feature_isset( |
| 8551 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && |
| 8552 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || |
| 8553 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) |
| 8554 | return ERR_PTR(-EINVAL); |
| 8555 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8556 | request = kzalloc(sizeof(*request) |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8557 | + sizeof(*request->ssids) * n_ssids |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8558 | + sizeof(*request->match_sets) * n_match_sets |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8559 | + sizeof(*request->scan_plans) * n_plans |
Luciano Coelho | a2cd43c | 2011-05-18 11:42:03 +0300 | [diff] [blame] | 8560 | + sizeof(*request->channels) * n_channels |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8561 | + ie_len, GFP_KERNEL); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8562 | if (!request) |
| 8563 | return ERR_PTR(-ENOMEM); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8564 | |
| 8565 | if (n_ssids) |
| 8566 | request->ssids = (void *)&request->channels[n_channels]; |
| 8567 | request->n_ssids = n_ssids; |
| 8568 | if (ie_len) { |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8569 | if (n_ssids) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8570 | request->ie = (void *)(request->ssids + n_ssids); |
| 8571 | else |
| 8572 | request->ie = (void *)(request->channels + n_channels); |
| 8573 | } |
| 8574 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8575 | if (n_match_sets) { |
| 8576 | if (request->ie) |
| 8577 | request->match_sets = (void *)(request->ie + ie_len); |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8578 | else if (n_ssids) |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8579 | request->match_sets = |
| 8580 | (void *)(request->ssids + n_ssids); |
| 8581 | else |
| 8582 | request->match_sets = |
| 8583 | (void *)(request->channels + n_channels); |
| 8584 | } |
| 8585 | request->n_match_sets = n_match_sets; |
| 8586 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8587 | if (n_match_sets) |
| 8588 | request->scan_plans = (void *)(request->match_sets + |
| 8589 | n_match_sets); |
| 8590 | else if (request->ie) |
| 8591 | request->scan_plans = (void *)(request->ie + ie_len); |
| 8592 | else if (n_ssids) |
| 8593 | request->scan_plans = (void *)(request->ssids + n_ssids); |
| 8594 | else |
| 8595 | request->scan_plans = (void *)(request->channels + n_channels); |
| 8596 | |
| 8597 | request->n_scan_plans = n_plans; |
| 8598 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8599 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8600 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8601 | /* user specified, bail out if channel not found */ |
| 8602 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8603 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8604 | tmp) { |
| 8605 | struct ieee80211_channel *chan; |
| 8606 | |
| 8607 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 8608 | |
| 8609 | if (!chan) { |
| 8610 | err = -EINVAL; |
| 8611 | goto out_free; |
| 8612 | } |
| 8613 | |
| 8614 | /* ignore disabled channels */ |
| 8615 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8616 | continue; |
| 8617 | |
| 8618 | request->channels[i] = chan; |
| 8619 | i++; |
| 8620 | } |
| 8621 | } else { |
| 8622 | /* all channels */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 8623 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8624 | int j; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 8625 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8626 | if (!wiphy->bands[band]) |
| 8627 | continue; |
| 8628 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 8629 | struct ieee80211_channel *chan; |
| 8630 | |
| 8631 | chan = &wiphy->bands[band]->channels[j]; |
| 8632 | |
| 8633 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 8634 | continue; |
| 8635 | |
| 8636 | request->channels[i] = chan; |
| 8637 | i++; |
| 8638 | } |
| 8639 | } |
| 8640 | } |
| 8641 | |
| 8642 | if (!i) { |
| 8643 | err = -EINVAL; |
| 8644 | goto out_free; |
| 8645 | } |
| 8646 | |
| 8647 | request->n_channels = i; |
| 8648 | |
| 8649 | i = 0; |
Johannes Berg | 13874e4 | 2015-01-23 11:25:20 +0100 | [diff] [blame] | 8650 | if (n_ssids) { |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8651 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8652 | tmp) { |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8653 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8654 | err = -EINVAL; |
| 8655 | goto out_free; |
| 8656 | } |
Luciano Coelho | 57a27e1 | 2011-06-07 20:42:26 +0300 | [diff] [blame] | 8657 | request->ssids[i].ssid_len = nla_len(attr); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8658 | memcpy(request->ssids[i].ssid, nla_data(attr), |
| 8659 | nla_len(attr)); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8660 | i++; |
| 8661 | } |
| 8662 | } |
| 8663 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8664 | i = 0; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8665 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8666 | nla_for_each_nested(attr, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8667 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8668 | tmp) { |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8669 | struct nlattr *ssid, *bssid, *rssi; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8670 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 8671 | err = nla_parse_nested_deprecated(tb, |
| 8672 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
| 8673 | attr, |
| 8674 | nl80211_match_policy, |
| 8675 | NULL); |
Johannes Berg | ae811e2 | 2014-01-24 10:17:47 +0100 | [diff] [blame] | 8676 | if (err) |
| 8677 | goto out_free; |
Johannes Berg | 4a4ab0d | 2012-06-13 11:17:11 +0200 | [diff] [blame] | 8678 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
Arend Van Spriel | 3007e35 | 2017-04-21 13:05:01 +0100 | [diff] [blame] | 8679 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8680 | |
| 8681 | if (!ssid && !bssid) { |
| 8682 | i++; |
| 8683 | continue; |
| 8684 | } |
| 8685 | |
| 8686 | if (WARN_ON(i >= n_match_sets)) { |
| 8687 | /* this indicates a programming error, |
| 8688 | * the loop above should have verified |
| 8689 | * things properly |
| 8690 | */ |
| 8691 | err = -EINVAL; |
| 8692 | goto out_free; |
| 8693 | } |
| 8694 | |
| 8695 | if (ssid) { |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8696 | memcpy(request->match_sets[i].ssid.ssid, |
| 8697 | nla_data(ssid), nla_len(ssid)); |
| 8698 | request->match_sets[i].ssid.ssid_len = |
| 8699 | nla_len(ssid); |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8700 | } |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 8701 | if (bssid) |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8702 | memcpy(request->match_sets[i].bssid, |
| 8703 | nla_data(bssid), ETH_ALEN); |
Johannes Berg | d39f3b4 | 2019-04-08 13:40:47 +0200 | [diff] [blame] | 8704 | |
| 8705 | /* special attribute - old implementation w/a */ |
| 8706 | request->match_sets[i].rssi_thold = default_match_rssi; |
| 8707 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
| 8708 | if (rssi) |
| 8709 | request->match_sets[i].rssi_thold = |
| 8710 | nla_get_s32(rssi); |
vamsi krishna | 1e1b11b | 2019-02-01 18:34:51 +0530 | [diff] [blame] | 8711 | |
| 8712 | /* Parse per band RSSI attribute */ |
| 8713 | err = nl80211_parse_sched_scan_per_band_rssi(wiphy, |
| 8714 | &request->match_sets[i], |
| 8715 | tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI], |
| 8716 | request->match_sets[i].rssi_thold); |
| 8717 | if (err) |
| 8718 | goto out_free; |
| 8719 | |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8720 | i++; |
| 8721 | } |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8722 | |
| 8723 | /* there was no other matchset, so the RSSI one is alone */ |
Luciano Coelho | f89f46c | 2014-12-01 11:32:09 +0200 | [diff] [blame] | 8724 | if (i == 0 && n_match_sets) |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 8725 | request->match_sets[0].rssi_thold = default_match_rssi; |
| 8726 | |
| 8727 | request->min_rssi_thold = INT_MAX; |
| 8728 | for (i = 0; i < n_match_sets; i++) |
| 8729 | request->min_rssi_thold = |
| 8730 | min(request->match_sets[i].rssi_thold, |
| 8731 | request->min_rssi_thold); |
| 8732 | } else { |
| 8733 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; |
Luciano Coelho | a1f1c21 | 2011-08-31 16:01:48 +0300 | [diff] [blame] | 8734 | } |
| 8735 | |
Johannes Berg | 9900e48 | 2014-02-04 21:01:25 +0100 | [diff] [blame] | 8736 | if (ie_len) { |
| 8737 | request->ie_len = ie_len; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8738 | memcpy((void *)request->ie, |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8739 | nla_data(attrs[NL80211_ATTR_IE]), |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8740 | request->ie_len); |
| 8741 | } |
| 8742 | |
Roee Zamir | 2d23d07 | 2017-08-06 11:38:22 +0300 | [diff] [blame] | 8743 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
| 8744 | if (err) |
| 8745 | goto out_free; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 8746 | |
Luciano Coelho | 9c74893 | 2015-01-16 16:04:09 +0200 | [diff] [blame] | 8747 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
| 8748 | request->delay = |
| 8749 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); |
| 8750 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 8751 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
| 8752 | request->relative_rssi = nla_get_s8( |
| 8753 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); |
| 8754 | request->relative_rssi_set = true; |
| 8755 | } |
| 8756 | |
| 8757 | if (request->relative_rssi_set && |
| 8758 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { |
| 8759 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; |
| 8760 | |
| 8761 | rssi_adjust = nla_data( |
| 8762 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); |
| 8763 | request->rssi_adjust.band = rssi_adjust->band; |
| 8764 | request->rssi_adjust.delta = rssi_adjust->delta; |
| 8765 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { |
| 8766 | err = -EINVAL; |
| 8767 | goto out_free; |
| 8768 | } |
| 8769 | } |
| 8770 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 8771 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
| 8772 | if (err) |
| 8773 | goto out_free; |
| 8774 | |
Sam Leffler | 15d6030 | 2012-10-11 21:03:34 -0700 | [diff] [blame] | 8775 | request->scan_start = jiffies; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8776 | |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8777 | return request; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8778 | |
| 8779 | out_free: |
| 8780 | kfree(request); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8781 | return ERR_PTR(err); |
| 8782 | } |
| 8783 | |
| 8784 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
| 8785 | struct genl_info *info) |
| 8786 | { |
| 8787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8788 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | ad2b26a | 2014-06-12 21:39:05 +0200 | [diff] [blame] | 8789 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8790 | struct cfg80211_sched_scan_request *sched_scan_req; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8791 | bool want_multi; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8792 | int err; |
| 8793 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8794 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8795 | return -EOPNOTSUPP; |
| 8796 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8797 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
| 8798 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); |
| 8799 | if (err) |
| 8800 | return err; |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8801 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8802 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 8803 | info->attrs, |
| 8804 | rdev->wiphy.max_match_sets); |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8805 | |
| 8806 | err = PTR_ERR_OR_ZERO(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8807 | if (err) |
| 8808 | goto out_err; |
| 8809 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8810 | /* leave request id zero for legacy request |
| 8811 | * or if driver does not support multi-scheduled scan |
| 8812 | */ |
Denis Kenzior | 2fd351a | 2019-10-08 11:43:50 -0500 | [diff] [blame] | 8813 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) |
| 8814 | sched_scan_req->reqid = cfg80211_assign_cookie(rdev); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8815 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8816 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8817 | if (err) |
| 8818 | goto out_free; |
| 8819 | |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8820 | sched_scan_req->dev = dev; |
| 8821 | sched_scan_req->wiphy = &rdev->wiphy; |
| 8822 | |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 8823 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 8824 | sched_scan_req->owner_nlportid = info->snd_portid; |
| 8825 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8826 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8827 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 8828 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8829 | return 0; |
| 8830 | |
| 8831 | out_free: |
Jukka Rissanen | 31a60ed | 2014-12-15 13:25:38 +0200 | [diff] [blame] | 8832 | kfree(sched_scan_req); |
Luciano Coelho | 256da02 | 2014-11-10 16:13:46 +0200 | [diff] [blame] | 8833 | out_err: |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8834 | return err; |
| 8835 | } |
| 8836 | |
| 8837 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
| 8838 | struct genl_info *info) |
| 8839 | { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8840 | struct cfg80211_sched_scan_request *req; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8841 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8842 | u64 cookie; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8843 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8844 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8845 | return -EOPNOTSUPP; |
| 8846 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 8847 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
| 8848 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 8849 | return __cfg80211_stop_sched_scan(rdev, cookie, false); |
| 8850 | } |
| 8851 | |
| 8852 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, |
| 8853 | struct cfg80211_sched_scan_request, |
| 8854 | list); |
| 8855 | if (!req || req->reqid || |
| 8856 | (req->owner_nlportid && |
| 8857 | req->owner_nlportid != info->snd_portid)) |
| 8858 | return -ENOENT; |
| 8859 | |
| 8860 | return cfg80211_stop_sched_scan_req(rdev, req, false); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 8861 | } |
| 8862 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8863 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
| 8864 | struct genl_info *info) |
| 8865 | { |
| 8866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8867 | struct net_device *dev = info->user_ptr[1]; |
| 8868 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8869 | struct wiphy *wiphy = wdev->wiphy; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8870 | struct cfg80211_chan_def chandef; |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8871 | enum nl80211_dfs_regions dfs_region; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8872 | unsigned int cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8873 | int err; |
| 8874 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8875 | dfs_region = reg_get_dfs_region(wiphy); |
Luis R. Rodriguez | 55f7435 | 2013-11-25 20:56:10 +0100 | [diff] [blame] | 8876 | if (dfs_region == NL80211_DFS_UNSET) |
| 8877 | return -EINVAL; |
| 8878 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8879 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8880 | if (err) |
| 8881 | return err; |
| 8882 | |
Simon Wunderlich | ff311bc | 2013-09-03 19:43:18 +0200 | [diff] [blame] | 8883 | if (netif_carrier_ok(dev)) |
| 8884 | return -EBUSY; |
| 8885 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8886 | if (wdev->cac_started) |
| 8887 | return -EBUSY; |
| 8888 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8889 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8890 | if (err < 0) |
| 8891 | return err; |
| 8892 | |
| 8893 | if (err == 0) |
| 8894 | return -EINVAL; |
| 8895 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8896 | if (!cfg80211_chandef_dfs_usable(wiphy, &chandef)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8897 | return -EINVAL; |
| 8898 | |
Dmitry Lebed | 13cf6de | 2018-03-01 12:39:15 +0300 | [diff] [blame] | 8899 | /* CAC start is offloaded to HW and can't be started manually */ |
| 8900 | if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD)) |
| 8901 | return -EOPNOTSUPP; |
| 8902 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8903 | if (!rdev->ops->start_radar_detection) |
| 8904 | return -EOPNOTSUPP; |
| 8905 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8906 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
| 8907 | if (WARN_ON(!cac_time_ms)) |
| 8908 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; |
| 8909 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 8910 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8911 | if (!err) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 8912 | wdev->chandef = chandef; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8913 | wdev->cac_started = true; |
| 8914 | wdev->cac_start_time = jiffies; |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 8915 | wdev->cac_time_ms = cac_time_ms; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8916 | } |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 8917 | return err; |
| 8918 | } |
| 8919 | |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8920 | static int nl80211_notify_radar_detection(struct sk_buff *skb, |
| 8921 | struct genl_info *info) |
| 8922 | { |
| 8923 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8924 | struct net_device *dev = info->user_ptr[1]; |
| 8925 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8926 | struct wiphy *wiphy = wdev->wiphy; |
| 8927 | struct cfg80211_chan_def chandef; |
| 8928 | enum nl80211_dfs_regions dfs_region; |
| 8929 | int err; |
| 8930 | |
| 8931 | dfs_region = reg_get_dfs_region(wiphy); |
| 8932 | if (dfs_region == NL80211_DFS_UNSET) { |
| 8933 | GENL_SET_ERR_MSG(info, |
| 8934 | "DFS Region is not set. Unexpected Radar indication"); |
| 8935 | return -EINVAL; |
| 8936 | } |
| 8937 | |
| 8938 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 8939 | if (err) { |
| 8940 | GENL_SET_ERR_MSG(info, "Unable to extract chandef info"); |
| 8941 | return err; |
| 8942 | } |
| 8943 | |
| 8944 | err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype); |
| 8945 | if (err < 0) { |
| 8946 | GENL_SET_ERR_MSG(info, "chandef is invalid"); |
| 8947 | return err; |
| 8948 | } |
| 8949 | |
| 8950 | if (err == 0) { |
| 8951 | GENL_SET_ERR_MSG(info, |
| 8952 | "Unexpected Radar indication for chandef/iftype"); |
| 8953 | return -EINVAL; |
| 8954 | } |
| 8955 | |
| 8956 | /* Do not process this notification if radar is already detected |
| 8957 | * by kernel on this channel, and return success. |
| 8958 | */ |
| 8959 | if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 8960 | return 0; |
| 8961 | |
| 8962 | cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE); |
| 8963 | |
| 8964 | cfg80211_sched_dfs_chan_update(rdev); |
| 8965 | |
Luca Coelho | a680fe4 | 2019-04-17 09:34:40 +0300 | [diff] [blame] | 8966 | rdev->radar_chandef = chandef; |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 8967 | |
| 8968 | /* Propagate this notification to other radios as well */ |
| 8969 | queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk); |
| 8970 | |
| 8971 | return 0; |
| 8972 | } |
| 8973 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8974 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
| 8975 | { |
| 8976 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 8977 | struct net_device *dev = info->user_ptr[1]; |
| 8978 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 8979 | struct cfg80211_csa_settings params; |
| 8980 | /* csa_attrs is defined static to avoid waste of stack size - this |
| 8981 | * function is called under RTNL lock, so this should not be a problem. |
| 8982 | */ |
| 8983 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8984 | int err; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8985 | bool need_new_beacon = false; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8986 | bool need_handle_dfs_flag = true; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 8987 | int len, i; |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 8988 | u32 cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 8989 | |
| 8990 | if (!rdev->ops->channel_switch || |
| 8991 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) |
| 8992 | return -EOPNOTSUPP; |
| 8993 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 8994 | switch (dev->ieee80211_ptr->iftype) { |
| 8995 | case NL80211_IFTYPE_AP: |
| 8996 | case NL80211_IFTYPE_P2P_GO: |
| 8997 | need_new_beacon = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 8998 | /* For all modes except AP the handle_dfs flag needs to be |
| 8999 | * supplied to tell the kernel that userspace will handle radar |
| 9000 | * events when they happen. Otherwise a switch to a channel |
| 9001 | * requiring DFS will be rejected. |
| 9002 | */ |
| 9003 | need_handle_dfs_flag = false; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9004 | |
| 9005 | /* useless if AP is not running */ |
| 9006 | if (!wdev->beacon_interval) |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 9007 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9008 | break; |
| 9009 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 9010 | if (!wdev->ssid_len) |
| 9011 | return -ENOTCONN; |
| 9012 | break; |
Chun-Yeow Yeoh | c6da674 | 2013-10-14 19:08:28 -0700 | [diff] [blame] | 9013 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | 1ff79df | 2014-01-22 10:05:27 +0100 | [diff] [blame] | 9014 | if (!wdev->mesh_id_len) |
| 9015 | return -ENOTCONN; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9016 | break; |
| 9017 | default: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9018 | return -EOPNOTSUPP; |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9019 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9020 | |
| 9021 | memset(¶ms, 0, sizeof(params)); |
Johannes Berg | c177db2 | 2018-10-30 09:17:44 +0100 | [diff] [blame] | 9022 | params.beacon_csa.ftm_responder = -1; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9023 | |
| 9024 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 9025 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) |
| 9026 | return -EINVAL; |
| 9027 | |
| 9028 | /* only important for AP, IBSS and mesh create IEs internally */ |
Andrei Otcheretianski | d0a361a | 2013-10-17 10:52:17 +0200 | [diff] [blame] | 9029 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9030 | return -EINVAL; |
| 9031 | |
Luciano Coelho | 252e07c | 2014-10-08 09:48:34 +0300 | [diff] [blame] | 9032 | /* Even though the attribute is u32, the specification says |
| 9033 | * u8, so let's make sure we don't overflow. |
| 9034 | */ |
| 9035 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); |
| 9036 | if (cs_count > 255) |
| 9037 | return -EINVAL; |
| 9038 | |
| 9039 | params.count = cs_count; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9040 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9041 | if (!need_new_beacon) |
| 9042 | goto skip_beacons; |
| 9043 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 9044 | err = nl80211_parse_beacon(rdev, info->attrs, ¶ms.beacon_after); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9045 | if (err) |
| 9046 | return err; |
| 9047 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 9048 | err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX, |
| 9049 | info->attrs[NL80211_ATTR_CSA_IES], |
| 9050 | nl80211_policy, info->extack); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9051 | if (err) |
| 9052 | return err; |
| 9053 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 9054 | err = nl80211_parse_beacon(rdev, csa_attrs, ¶ms.beacon_csa); |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9055 | if (err) |
| 9056 | return err; |
| 9057 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9058 | if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9059 | return -EINVAL; |
| 9060 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9061 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9062 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9063 | return -EINVAL; |
| 9064 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9065 | params.n_counter_offsets_beacon = len / sizeof(u16); |
| 9066 | if (rdev->wiphy.max_num_csa_counters && |
| 9067 | (params.n_counter_offsets_beacon > |
| 9068 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9069 | return -EINVAL; |
| 9070 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9071 | params.counter_offsets_beacon = |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9072 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9073 | |
| 9074 | /* sanity checks - counters should fit and be the same */ |
| 9075 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { |
| 9076 | u16 offset = params.counter_offsets_beacon[i]; |
| 9077 | |
| 9078 | if (offset >= params.beacon_csa.tail_len) |
| 9079 | return -EINVAL; |
| 9080 | |
| 9081 | if (params.beacon_csa.tail[offset] != params.count) |
| 9082 | return -EINVAL; |
| 9083 | } |
| 9084 | |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9085 | if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) { |
| 9086 | len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9087 | if (!len || (len % sizeof(u16))) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9088 | return -EINVAL; |
| 9089 | |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9090 | params.n_counter_offsets_presp = len / sizeof(u16); |
| 9091 | if (rdev->wiphy.max_num_csa_counters && |
Johannes Berg | ad5987b | 2016-09-13 15:53:55 +0200 | [diff] [blame] | 9092 | (params.n_counter_offsets_presp > |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9093 | rdev->wiphy.max_num_csa_counters)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9094 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9095 | |
| 9096 | params.counter_offsets_presp = |
John Crispin | 00c207e | 2020-08-11 10:01:03 +0200 | [diff] [blame] | 9097 | nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]); |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 9098 | |
| 9099 | /* sanity checks - counters should fit and be the same */ |
| 9100 | for (i = 0; i < params.n_counter_offsets_presp; i++) { |
| 9101 | u16 offset = params.counter_offsets_presp[i]; |
| 9102 | |
| 9103 | if (offset >= params.beacon_csa.probe_resp_len) |
| 9104 | return -EINVAL; |
| 9105 | |
| 9106 | if (params.beacon_csa.probe_resp[offset] != |
| 9107 | params.count) |
| 9108 | return -EINVAL; |
| 9109 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9110 | } |
| 9111 | |
Simon Wunderlich | ee4bc9e | 2013-08-28 13:41:33 +0200 | [diff] [blame] | 9112 | skip_beacons: |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9113 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
| 9114 | if (err) |
| 9115 | return err; |
| 9116 | |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 9117 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
| 9118 | wdev->iftype)) |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9119 | return -EINVAL; |
| 9120 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9121 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 9122 | ¶ms.chandef, |
| 9123 | wdev->iftype); |
| 9124 | if (err < 0) |
| 9125 | return err; |
| 9126 | |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9127 | if (err > 0) { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 9128 | params.radar_required = true; |
Benjamin Berg | 8d9de16 | 2017-05-16 11:23:12 +0200 | [diff] [blame] | 9129 | if (need_handle_dfs_flag && |
| 9130 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { |
| 9131 | return -EINVAL; |
| 9132 | } |
| 9133 | } |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9134 | |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9135 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
| 9136 | params.block_tx = true; |
| 9137 | |
Simon Wunderlich | c56589e | 2013-11-21 18:19:49 +0100 | [diff] [blame] | 9138 | wdev_lock(wdev); |
| 9139 | err = rdev_channel_switch(rdev, dev, ¶ms); |
| 9140 | wdev_unlock(wdev); |
| 9141 | |
| 9142 | return err; |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 9143 | } |
| 9144 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9145 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
| 9146 | u32 seq, int flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9147 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9148 | struct wireless_dev *wdev, |
| 9149 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9150 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9151 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9152 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9153 | void *hdr; |
| 9154 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9155 | |
| 9156 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9157 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9158 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9159 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 9160 | if (!hdr) |
| 9161 | return -1; |
| 9162 | |
Michal Kubecek | 0a833c2 | 2017-11-15 13:09:32 +0100 | [diff] [blame] | 9163 | genl_dump_check_consistent(cb, hdr); |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9164 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9165 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
| 9166 | goto nla_put_failure; |
| 9167 | if (wdev->netdev && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9168 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
| 9169 | goto nla_put_failure; |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9170 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 9171 | NL80211_ATTR_PAD)) |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9172 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9173 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9174 | bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9175 | if (!bss) |
| 9176 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9177 | if ((!is_zero_ether_addr(res->bssid) && |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9178 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9179 | goto nla_put_failure; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9180 | |
| 9181 | rcu_read_lock(); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9182 | /* indicate whether we have probe response data or not */ |
| 9183 | if (rcu_access_pointer(res->proberesp_ies) && |
| 9184 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) |
| 9185 | goto fail_unlock_rcu; |
| 9186 | |
| 9187 | /* this pointer prefers to be pointed to probe response data |
| 9188 | * but is always valid |
| 9189 | */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9190 | ies = rcu_dereference(res->ies); |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9191 | if (ies) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9192 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
| 9193 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9194 | goto fail_unlock_rcu; |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9195 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 9196 | ies->len, ies->data)) |
| 9197 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9198 | } |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9199 | |
| 9200 | /* and this pointer is always (unless driver didn't know) beacon data */ |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9201 | ies = rcu_dereference(res->beacon_ies); |
Johannes Berg | 0e22708 | 2014-08-12 20:34:30 +0200 | [diff] [blame] | 9202 | if (ies && ies->from_beacon) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9203 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
| 9204 | NL80211_BSS_PAD)) |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9205 | goto fail_unlock_rcu; |
| 9206 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, |
| 9207 | ies->len, ies->data)) |
| 9208 | goto fail_unlock_rcu; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame] | 9209 | } |
| 9210 | rcu_read_unlock(); |
| 9211 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9212 | if (res->beacon_interval && |
| 9213 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) |
| 9214 | goto nla_put_failure; |
| 9215 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || |
| 9216 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9217 | nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET, |
| 9218 | res->channel->freq_offset) || |
Simon Wunderlich | dcd6eac | 2013-07-08 16:55:49 +0200 | [diff] [blame] | 9219 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9220 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 9221 | jiffies_to_msecs(jiffies - intbss->ts))) |
| 9222 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9223 | |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 9224 | if (intbss->parent_tsf && |
| 9225 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, |
| 9226 | intbss->parent_tsf, NL80211_BSS_PAD) || |
| 9227 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, |
| 9228 | intbss->parent_bssid))) |
| 9229 | goto nla_put_failure; |
| 9230 | |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 9231 | if (intbss->ts_boottime && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9232 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
| 9233 | intbss->ts_boottime, NL80211_BSS_PAD)) |
Dmitry Shmidt | 6e19bc4 | 2015-10-07 11:32:53 +0200 | [diff] [blame] | 9234 | goto nla_put_failure; |
| 9235 | |
Sunil Dutt | 983dafa | 2017-12-13 19:51:36 +0200 | [diff] [blame] | 9236 | if (!nl80211_put_signal(msg, intbss->pub.chains, |
| 9237 | intbss->pub.chain_signal, |
| 9238 | NL80211_BSS_CHAIN_SIGNAL)) |
| 9239 | goto nla_put_failure; |
| 9240 | |
Johannes Berg | 77965c97 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 9241 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9242 | case CFG80211_SIGNAL_TYPE_MBM: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9243 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
| 9244 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9245 | break; |
| 9246 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9247 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
| 9248 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9249 | break; |
| 9250 | default: |
| 9251 | break; |
| 9252 | } |
| 9253 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9254 | switch (wdev->iftype) { |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9255 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9256 | case NL80211_IFTYPE_STATION: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9257 | if (intbss == wdev->current_bss && |
| 9258 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9259 | NL80211_BSS_STATUS_ASSOCIATED)) |
| 9260 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9261 | break; |
| 9262 | case NL80211_IFTYPE_ADHOC: |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9263 | if (intbss == wdev->current_bss && |
| 9264 | nla_put_u32(msg, NL80211_BSS_STATUS, |
| 9265 | NL80211_BSS_STATUS_IBSS_JOINED)) |
| 9266 | goto nla_put_failure; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9267 | break; |
| 9268 | default: |
| 9269 | break; |
| 9270 | } |
| 9271 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9272 | nla_nest_end(msg, bss); |
| 9273 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9274 | genlmsg_end(msg, hdr); |
| 9275 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9276 | |
Johannes Berg | 8cef2c9 | 2013-02-05 16:54:31 +0100 | [diff] [blame] | 9277 | fail_unlock_rcu: |
| 9278 | rcu_read_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9279 | nla_put_failure: |
| 9280 | genlmsg_cancel(msg, hdr); |
| 9281 | return -EMSGSIZE; |
| 9282 | } |
| 9283 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9284 | 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] | 9285 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9286 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9287 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9288 | struct wireless_dev *wdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9289 | int start = cb->args[2], idx = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9290 | int err; |
| 9291 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9292 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9293 | err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9294 | if (err) { |
| 9295 | rtnl_unlock(); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9296 | return err; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9297 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9298 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9299 | wdev_lock(wdev); |
| 9300 | spin_lock_bh(&rdev->bss_lock); |
Denis Kenzior | d1e23c9 | 2018-05-21 10:31:13 -0500 | [diff] [blame] | 9301 | |
| 9302 | /* |
| 9303 | * dump_scan will be called multiple times to break up the scan results |
| 9304 | * into multiple messages. It is unlikely that any more bss-es will be |
| 9305 | * expired after the first call, so only call only call this on the |
| 9306 | * first dump_scan invocation. |
| 9307 | */ |
| 9308 | if (start == 0) |
| 9309 | cfg80211_bss_expire(rdev); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9310 | |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9311 | cb->seq = rdev->bss_generation; |
| 9312 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9313 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9314 | if (++idx <= start) |
| 9315 | continue; |
Johannes Berg | 9720bb3 | 2011-06-21 09:45:33 +0200 | [diff] [blame] | 9316 | if (nl80211_send_bss(skb, cb, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9317 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9318 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9319 | idx--; |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9320 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9321 | } |
| 9322 | } |
| 9323 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 9324 | spin_unlock_bh(&rdev->bss_lock); |
| 9325 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9326 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9327 | cb->args[2] = idx; |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9328 | rtnl_unlock(); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9329 | |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9330 | return skb->len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 9331 | } |
| 9332 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9333 | 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] | 9334 | int flags, struct net_device *dev, |
| 9335 | bool allow_radio_stats, |
| 9336 | struct survey_info *survey) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9337 | { |
| 9338 | void *hdr; |
| 9339 | struct nlattr *infoattr; |
| 9340 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9341 | /* skip radio stats if userspace didn't request them */ |
| 9342 | if (!survey->channel && !allow_radio_stats) |
| 9343 | return 0; |
| 9344 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9345 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9346 | NL80211_CMD_NEW_SURVEY_RESULTS); |
| 9347 | if (!hdr) |
| 9348 | return -ENOMEM; |
| 9349 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9350 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 9351 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9352 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 9353 | infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9354 | if (!infoattr) |
| 9355 | goto nla_put_failure; |
| 9356 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9357 | if (survey->channel && |
| 9358 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9359 | survey->channel->center_freq)) |
| 9360 | goto nla_put_failure; |
| 9361 | |
Thomas Pedersen | 58ef7c1 | 2020-09-21 19:28:16 -0700 | [diff] [blame] | 9362 | if (survey->channel && survey->channel->freq_offset && |
| 9363 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY_OFFSET, |
| 9364 | survey->channel->freq_offset)) |
| 9365 | goto nla_put_failure; |
| 9366 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9367 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && |
| 9368 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) |
| 9369 | goto nla_put_failure; |
| 9370 | if ((survey->filled & SURVEY_INFO_IN_USE) && |
| 9371 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) |
| 9372 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9373 | if ((survey->filled & SURVEY_INFO_TIME) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9374 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
| 9375 | survey->time, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9376 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9377 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9378 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
| 9379 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9380 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9381 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9382 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
| 9383 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9384 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9385 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9386 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
| 9387 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9388 | goto nla_put_failure; |
Johannes Berg | 4ed20be | 2014-11-14 16:35:34 +0100 | [diff] [blame] | 9389 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9390 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
| 9391 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 9392 | goto nla_put_failure; |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9393 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 9394 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
| 9395 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) |
Johannes Berg | 052536a | 2014-11-14 16:44:11 +0100 | [diff] [blame] | 9396 | goto nla_put_failure; |
Felix Fietkau | c8cd6e7 | 2019-08-28 12:20:42 +0200 | [diff] [blame] | 9397 | if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) && |
| 9398 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX, |
| 9399 | survey->time_bss_rx, NL80211_SURVEY_INFO_PAD)) |
| 9400 | goto nla_put_failure; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9401 | |
| 9402 | nla_nest_end(msg, infoattr); |
| 9403 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 9404 | genlmsg_end(msg, hdr); |
| 9405 | return 0; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9406 | |
| 9407 | nla_put_failure: |
| 9408 | genlmsg_cancel(msg, hdr); |
| 9409 | return -EMSGSIZE; |
| 9410 | } |
| 9411 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9412 | 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] | 9413 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9414 | struct nlattr **attrbuf; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9415 | struct survey_info survey; |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9416 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9417 | struct wireless_dev *wdev; |
| 9418 | int survey_idx = cb->args[2]; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9419 | int res; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9420 | bool radio_stats; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9421 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9422 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 9423 | if (!attrbuf) |
| 9424 | return -ENOMEM; |
| 9425 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9426 | rtnl_lock(); |
Johannes Berg | 5297c65 | 2018-09-27 14:36:44 +0200 | [diff] [blame] | 9427 | res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev); |
Johannes Berg | 6774889 | 2010-10-04 21:14:06 +0200 | [diff] [blame] | 9428 | if (res) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9429 | goto out_err; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9430 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9431 | /* prepare_wdev_dump parsed the attributes */ |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 9432 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9433 | |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9434 | if (!wdev->netdev) { |
| 9435 | res = -EINVAL; |
| 9436 | goto out_err; |
| 9437 | } |
| 9438 | |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9439 | if (!rdev->ops->dump_survey) { |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9440 | res = -EOPNOTSUPP; |
| 9441 | goto out_err; |
| 9442 | } |
| 9443 | |
| 9444 | while (1) { |
Zhao, Gang | 1b8ec87 | 2014-04-21 12:53:02 +0800 | [diff] [blame] | 9445 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9446 | if (res == -ENOENT) |
| 9447 | break; |
| 9448 | if (res) |
| 9449 | goto out_err; |
| 9450 | |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9451 | /* don't send disabled channels, but do send non-channel data */ |
| 9452 | if (survey.channel && |
| 9453 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { |
Luis R. Rodriguez | 180cdc7 | 2011-05-27 07:24:02 -0700 | [diff] [blame] | 9454 | survey_idx++; |
| 9455 | continue; |
| 9456 | } |
| 9457 | |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9458 | if (nl80211_send_survey(skb, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 9459 | NETLINK_CB(cb->skb).portid, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9460 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 11f78ac | 2014-11-14 16:43:50 +0100 | [diff] [blame] | 9461 | wdev->netdev, radio_stats, &survey) < 0) |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9462 | goto out; |
| 9463 | survey_idx++; |
| 9464 | } |
| 9465 | |
| 9466 | out: |
Johannes Berg | 97990a0 | 2013-04-19 01:02:55 +0200 | [diff] [blame] | 9467 | cb->args[2] = survey_idx; |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9468 | res = skb->len; |
| 9469 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 9470 | kfree(attrbuf); |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 9471 | rtnl_unlock(); |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 9472 | return res; |
| 9473 | } |
| 9474 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9475 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 9476 | { |
| 9477 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
Chung-Hsien Hsu | cc3e14c | 2019-05-09 09:49:05 +0000 | [diff] [blame] | 9478 | NL80211_WPA_VERSION_2 | |
| 9479 | NL80211_WPA_VERSION_3)); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9480 | } |
| 9481 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9482 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 9483 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9484 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9485 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9486 | struct ieee80211_channel *chan; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9487 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
| 9488 | int err, ssid_len, ie_len = 0, auth_data_len = 0; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9489 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9490 | struct key_parse key; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9491 | bool local_state_change; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9492 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9493 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9494 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9495 | return -EINVAL; |
| 9496 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 9497 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 9498 | return -EINVAL; |
| 9499 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9500 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 9501 | return -EINVAL; |
| 9502 | |
| 9503 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 9504 | return -EINVAL; |
| 9505 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9506 | err = nl80211_parse_key(info, &key); |
| 9507 | if (err) |
| 9508 | return err; |
| 9509 | |
| 9510 | if (key.idx >= 0) { |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 9511 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
| 9512 | return -EINVAL; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9513 | if (!key.p.key || !key.p.key_len) |
| 9514 | return -EINVAL; |
| 9515 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 9516 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 9517 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 9518 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 9519 | return -EINVAL; |
Johannes Berg | b6b5555 | 2016-09-13 16:25:58 +0200 | [diff] [blame] | 9520 | if (key.idx > 3) |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 9521 | return -EINVAL; |
| 9522 | } else { |
| 9523 | key.p.key_len = 0; |
| 9524 | key.p.key = NULL; |
| 9525 | } |
| 9526 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9527 | if (key.idx >= 0) { |
| 9528 | int i; |
| 9529 | bool ok = false; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9530 | |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9531 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
| 9532 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
| 9533 | ok = true; |
| 9534 | break; |
| 9535 | } |
| 9536 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9537 | if (!ok) |
| 9538 | return -EINVAL; |
Johannes Berg | afea0b7 | 2010-08-10 09:46:42 +0200 | [diff] [blame] | 9539 | } |
| 9540 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9541 | if (!rdev->ops->auth) |
| 9542 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9543 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9544 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9545 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9546 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9547 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9548 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9549 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9550 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9551 | freq += |
| 9552 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9553 | |
| 9554 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9555 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9556 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9557 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9558 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9559 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 9560 | |
| 9561 | if (info->attrs[NL80211_ATTR_IE]) { |
| 9562 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9563 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 9564 | } |
| 9565 | |
| 9566 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9567 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9568 | return -EINVAL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9569 | |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9570 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
| 9571 | auth_type == NL80211_AUTHTYPE_FILS_SK || |
| 9572 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || |
| 9573 | auth_type == NL80211_AUTHTYPE_FILS_PK) && |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9574 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9575 | return -EINVAL; |
| 9576 | |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9577 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
Jouni Malinen | 6318106 | 2016-10-27 00:42:02 +0300 | [diff] [blame] | 9578 | if (auth_type != NL80211_AUTHTYPE_SAE && |
| 9579 | auth_type != NL80211_AUTHTYPE_FILS_SK && |
| 9580 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && |
| 9581 | auth_type != NL80211_AUTHTYPE_FILS_PK) |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9582 | return -EINVAL; |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9583 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
| 9584 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 9585 | } |
| 9586 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9587 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9588 | |
Johannes Berg | 95de817 | 2012-01-20 13:55:25 +0100 | [diff] [blame] | 9589 | /* |
| 9590 | * Since we no longer track auth state, ignore |
| 9591 | * requests to only change local state. |
| 9592 | */ |
| 9593 | if (local_state_change) |
| 9594 | return 0; |
| 9595 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9596 | wdev_lock(dev->ieee80211_ptr); |
| 9597 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
| 9598 | ssid, ssid_len, ie, ie_len, |
| 9599 | key.p.key, key.p.key_len, key.idx, |
Jouni Malinen | 11b6b5a | 2016-10-27 00:41:58 +0300 | [diff] [blame] | 9600 | auth_data, auth_data_len); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9601 | wdev_unlock(dev->ieee80211_ptr); |
| 9602 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9603 | } |
| 9604 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9605 | static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev, |
| 9606 | struct genl_info *info) |
| 9607 | { |
| 9608 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9609 | GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set"); |
| 9610 | return -EINVAL; |
| 9611 | } |
| 9612 | |
| 9613 | if (!rdev->ops->tx_control_port || |
| 9614 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9615 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 9616 | return -EOPNOTSUPP; |
| 9617 | |
| 9618 | return 0; |
| 9619 | } |
| 9620 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9621 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
| 9622 | struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9623 | struct cfg80211_crypto_settings *settings, |
| 9624 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9625 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 9626 | memset(settings, 0, sizeof(*settings)); |
| 9627 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9628 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 9629 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9630 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 9631 | u16 proto; |
Kirtika Ruchandani | 7a087e7 | 2016-05-29 19:51:23 -0700 | [diff] [blame] | 9632 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 9633 | proto = nla_get_u16( |
| 9634 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 9635 | settings->control_port_ethertype = cpu_to_be16(proto); |
| 9636 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
| 9637 | proto != ETH_P_PAE) |
| 9638 | return -EINVAL; |
| 9639 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) |
| 9640 | settings->control_port_no_encrypt = true; |
| 9641 | } else |
| 9642 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); |
| 9643 | |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9644 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 9645 | int r = validate_pae_over_nl80211(rdev, info); |
| 9646 | |
| 9647 | if (r < 0) |
| 9648 | return r; |
| 9649 | |
| 9650 | settings->control_port_over_nl80211 = true; |
Markus Theil | 7f3f96c | 2020-03-12 10:10:54 +0100 | [diff] [blame] | 9651 | |
| 9652 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH]) |
| 9653 | settings->control_port_no_preauth = true; |
Denis Kenzior | 64bf3d4 | 2018-03-26 12:52:43 -0500 | [diff] [blame] | 9654 | } |
| 9655 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9656 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 9657 | void *data; |
| 9658 | int len, i; |
| 9659 | |
| 9660 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9661 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 9662 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 9663 | |
| 9664 | if (len % sizeof(u32)) |
| 9665 | return -EINVAL; |
| 9666 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 9667 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9668 | return -EINVAL; |
| 9669 | |
| 9670 | memcpy(settings->ciphers_pairwise, data, len); |
| 9671 | |
| 9672 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9673 | if (!cfg80211_supported_cipher_suite( |
| 9674 | &rdev->wiphy, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9675 | settings->ciphers_pairwise[i])) |
| 9676 | return -EINVAL; |
| 9677 | } |
| 9678 | |
| 9679 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 9680 | settings->cipher_group = |
| 9681 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
Jouni Malinen | 38ba3c5 | 2011-09-21 18:14:56 +0300 | [diff] [blame] | 9682 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
| 9683 | settings->cipher_group)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9684 | return -EINVAL; |
| 9685 | } |
| 9686 | |
| 9687 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 9688 | settings->wpa_versions = |
| 9689 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 9690 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 9691 | return -EINVAL; |
| 9692 | } |
| 9693 | |
| 9694 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 9695 | void *data; |
Jouni Malinen | 6d30240 | 2011-09-21 18:11:33 +0300 | [diff] [blame] | 9696 | int len; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9697 | |
| 9698 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9699 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 9700 | settings->n_akm_suites = len / sizeof(u32); |
| 9701 | |
| 9702 | if (len % sizeof(u32)) |
| 9703 | return -EINVAL; |
| 9704 | |
Jouni Malinen | 1b9ca02 | 2011-09-21 16:13:07 +0300 | [diff] [blame] | 9705 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
| 9706 | return -EINVAL; |
| 9707 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9708 | memcpy(settings->akm_suites, data, len); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9709 | } |
| 9710 | |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9711 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 9712 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) |
| 9713 | return -EINVAL; |
| 9714 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | f966227 | 2020-06-23 08:49:35 -0500 | [diff] [blame] | 9715 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) && |
| 9716 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9717 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK)) |
Eliad Peller | 91b5ab6 | 2017-06-09 13:08:42 +0100 | [diff] [blame] | 9718 | return -EINVAL; |
| 9719 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 9720 | } |
| 9721 | |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 9722 | if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) { |
| 9723 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
Chung-Hsien Hsu | 2831a63 | 2020-08-17 02:33:15 -0500 | [diff] [blame] | 9724 | NL80211_EXT_FEATURE_SAE_OFFLOAD) && |
| 9725 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9726 | NL80211_EXT_FEATURE_SAE_OFFLOAD_AP)) |
Chung-Hsien Hsu | 26f7044 | 2019-05-09 09:49:06 +0000 | [diff] [blame] | 9727 | return -EINVAL; |
| 9728 | settings->sae_pwd = |
| 9729 | nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9730 | settings->sae_pwd_len = |
| 9731 | nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]); |
| 9732 | } |
| 9733 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 9734 | return 0; |
| 9735 | } |
| 9736 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9737 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 9738 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9740 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 9741 | struct ieee80211_channel *chan; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9742 | struct cfg80211_assoc_request req = {}; |
| 9743 | const u8 *bssid, *ssid; |
| 9744 | int err, ssid_len = 0; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9745 | u32 freq; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9746 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9747 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9748 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9749 | return -EPERM; |
| 9750 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9751 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9752 | !info->attrs[NL80211_ATTR_SSID] || |
| 9753 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9754 | return -EINVAL; |
| 9755 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9756 | if (!rdev->ops->assoc) |
| 9757 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9758 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9759 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9760 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9761 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9762 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9763 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9764 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 9765 | freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 9766 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 9767 | freq += |
| 9768 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 9769 | chan = nl80211_get_valid_chan(&rdev->wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 9770 | if (!chan) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9771 | return -EINVAL; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9772 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9773 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 9774 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9775 | |
| 9776 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9777 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9778 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9779 | } |
| 9780 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9781 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9782 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9783 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 9784 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9785 | req.use_mfp = true; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9786 | else if (mfp != NL80211_MFP_NO) |
| 9787 | return -EINVAL; |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 9788 | } |
| 9789 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9790 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9791 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 9792 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9793 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9794 | req.flags |= ASSOC_REQ_DISABLE_HT; |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9795 | |
| 9796 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9797 | memcpy(&req.ht_capa_mask, |
| 9798 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 9799 | sizeof(req.ht_capa_mask)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9800 | |
| 9801 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9802 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9803 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9804 | memcpy(&req.ht_capa, |
| 9805 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 9806 | sizeof(req.ht_capa)); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 9807 | } |
| 9808 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9809 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9810 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9811 | |
| 9812 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9813 | memcpy(&req.vht_capa_mask, |
| 9814 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 9815 | sizeof(req.vht_capa_mask)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9816 | |
| 9817 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9818 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9819 | return -EINVAL; |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9820 | memcpy(&req.vht_capa, |
| 9821 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 9822 | sizeof(req.vht_capa)); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 9823 | } |
| 9824 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9825 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 9826 | if (!((rdev->wiphy.features & |
| 9827 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 9828 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 9829 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 9830 | NL80211_EXT_FEATURE_RRM)) |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 9831 | return -EINVAL; |
| 9832 | req.flags |= ASSOC_REQ_USE_RRM; |
| 9833 | } |
| 9834 | |
Jouni Malinen | 348bd45 | 2016-10-27 00:42:03 +0300 | [diff] [blame] | 9835 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
| 9836 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9837 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); |
| 9838 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) |
| 9839 | return -EINVAL; |
| 9840 | req.fils_nonces = |
| 9841 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); |
| 9842 | } |
| 9843 | |
Thomas Pedersen | d2b7588 | 2020-09-21 19:28:04 -0700 | [diff] [blame] | 9844 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) { |
| 9845 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY]) |
| 9846 | return -EINVAL; |
| 9847 | memcpy(&req.s1g_capa_mask, |
| 9848 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]), |
| 9849 | sizeof(req.s1g_capa_mask)); |
| 9850 | } |
| 9851 | |
| 9852 | if (info->attrs[NL80211_ATTR_S1G_CAPABILITY]) { |
| 9853 | if (!info->attrs[NL80211_ATTR_S1G_CAPABILITY_MASK]) |
| 9854 | return -EINVAL; |
| 9855 | memcpy(&req.s1g_capa, |
| 9856 | nla_data(info->attrs[NL80211_ATTR_S1G_CAPABILITY]), |
| 9857 | sizeof(req.s1g_capa)); |
| 9858 | } |
| 9859 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9860 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9861 | if (!err) { |
| 9862 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9863 | |
Johannes Berg | f62fab7 | 2013-02-21 20:09:09 +0100 | [diff] [blame] | 9864 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
| 9865 | ssid, ssid_len, &req); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 9866 | |
| 9867 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 9868 | dev->ieee80211_ptr->conn_owner_nlportid = |
| 9869 | info->snd_portid; |
| 9870 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 9871 | bssid, ETH_ALEN); |
| 9872 | } |
| 9873 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9874 | wdev_unlock(dev->ieee80211_ptr); |
| 9875 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9876 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9877 | return err; |
| 9878 | } |
| 9879 | |
| 9880 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 9881 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9882 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9883 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9884 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9885 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9886 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9887 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9888 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9889 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9890 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9891 | return -EPERM; |
| 9892 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9893 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9894 | return -EINVAL; |
| 9895 | |
| 9896 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9897 | return -EINVAL; |
| 9898 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9899 | if (!rdev->ops->deauth) |
| 9900 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9901 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9902 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9903 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9904 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9905 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9906 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9907 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9908 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9909 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9910 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9911 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9912 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9913 | |
| 9914 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9915 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9916 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9917 | } |
| 9918 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9919 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9920 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9921 | wdev_lock(dev->ieee80211_ptr); |
| 9922 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9923 | local_state_change); |
| 9924 | wdev_unlock(dev->ieee80211_ptr); |
| 9925 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9926 | } |
| 9927 | |
| 9928 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 9929 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 9931 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9932 | const u8 *ie = NULL, *bssid; |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9933 | int ie_len = 0, err; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9934 | u16 reason_code; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9935 | bool local_state_change; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9936 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 9937 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 9938 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 9939 | return -EPERM; |
| 9940 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9941 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 9942 | return -EINVAL; |
| 9943 | |
| 9944 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 9945 | return -EINVAL; |
| 9946 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9947 | if (!rdev->ops->disassoc) |
| 9948 | return -EOPNOTSUPP; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9949 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 9950 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9951 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 9952 | return -EOPNOTSUPP; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 9953 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9954 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9955 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9956 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 9957 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 9958 | /* Reason Code 0 is reserved */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 9959 | return -EINVAL; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 9960 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9961 | |
| 9962 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 9963 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 9964 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9965 | } |
| 9966 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 9967 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
| 9968 | |
Johannes Berg | 91bf9b2 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 9969 | wdev_lock(dev->ieee80211_ptr); |
| 9970 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
| 9971 | local_state_change); |
| 9972 | wdev_unlock(dev->ieee80211_ptr); |
| 9973 | return err; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 9974 | } |
| 9975 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9976 | static bool |
| 9977 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9978 | int mcast_rate[NUM_NL80211_BANDS], |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9979 | int rateval) |
| 9980 | { |
| 9981 | struct wiphy *wiphy = &rdev->wiphy; |
| 9982 | bool found = false; |
| 9983 | int band, i; |
| 9984 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 9985 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 9986 | struct ieee80211_supported_band *sband; |
| 9987 | |
| 9988 | sband = wiphy->bands[band]; |
| 9989 | if (!sband) |
| 9990 | continue; |
| 9991 | |
| 9992 | for (i = 0; i < sband->n_bitrates; i++) { |
| 9993 | if (sband->bitrates[i].bitrate == rateval) { |
| 9994 | mcast_rate[band] = i + 1; |
| 9995 | found = true; |
| 9996 | break; |
| 9997 | } |
| 9998 | } |
| 9999 | } |
| 10000 | |
| 10001 | return found; |
| 10002 | } |
| 10003 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10004 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10005 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10006 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10007 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10008 | struct cfg80211_ibss_params ibss; |
| 10009 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10010 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10011 | int err; |
| 10012 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10013 | memset(&ibss, 0, sizeof(ibss)); |
| 10014 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10015 | if (!info->attrs[NL80211_ATTR_SSID] || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10016 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10017 | return -EINVAL; |
| 10018 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10019 | ibss.beacon_interval = 100; |
| 10020 | |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10021 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10022 | ibss.beacon_interval = |
| 10023 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10024 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 10025 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
| 10026 | ibss.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 10027 | if (err) |
| 10028 | return err; |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 10029 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10030 | if (!rdev->ops->join_ibss) |
| 10031 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10032 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10033 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10034 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10035 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10036 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10037 | |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 10038 | if (info->attrs[NL80211_ATTR_MAC]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10039 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 3919349 | 2011-09-16 13:45:25 +0200 | [diff] [blame] | 10040 | |
| 10041 | if (!is_valid_ether_addr(ibss.bssid)) |
| 10042 | return -EINVAL; |
| 10043 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10044 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10045 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10046 | |
| 10047 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10048 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10049 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10050 | } |
| 10051 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10052 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
| 10053 | if (err) |
| 10054 | return err; |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 10055 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 10056 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
| 10057 | NL80211_IFTYPE_ADHOC)) |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 10058 | return -EINVAL; |
| 10059 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10060 | switch (ibss.chandef.width) { |
Simon Wunderlich | bf37264 | 2013-07-08 16:55:58 +0200 | [diff] [blame] | 10061 | case NL80211_CHAN_WIDTH_5: |
| 10062 | case NL80211_CHAN_WIDTH_10: |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10063 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 10064 | break; |
| 10065 | case NL80211_CHAN_WIDTH_20: |
| 10066 | case NL80211_CHAN_WIDTH_40: |
Janusz.Dziedzic@tieto.com | ffc1199 | 2015-02-21 16:52:39 +0100 | [diff] [blame] | 10067 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 10068 | return -EINVAL; |
| 10069 | break; |
| 10070 | case NL80211_CHAN_WIDTH_80: |
| 10071 | case NL80211_CHAN_WIDTH_80P80: |
| 10072 | case NL80211_CHAN_WIDTH_160: |
| 10073 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
| 10074 | return -EINVAL; |
| 10075 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 10076 | NL80211_EXT_FEATURE_VHT_IBSS)) |
| 10077 | return -EINVAL; |
| 10078 | break; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10079 | default: |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 10080 | return -EINVAL; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 10081 | } |
Johannes Berg | db9c64c | 2012-11-09 14:56:41 +0100 | [diff] [blame] | 10082 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10083 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10084 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10085 | |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10086 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 10087 | u8 *rates = |
| 10088 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10089 | int n_rates = |
| 10090 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 10091 | struct ieee80211_supported_band *sband = |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10092 | wiphy->bands[ibss.chandef.chan->band]; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10093 | |
Johannes Berg | 34850ab | 2011-07-18 18:08:35 +0200 | [diff] [blame] | 10094 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 10095 | &ibss.basic_rates); |
| 10096 | if (err) |
| 10097 | return err; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10098 | } |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10099 | |
Simon Wunderlich | 803768f | 2013-06-28 10:39:58 +0200 | [diff] [blame] | 10100 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10101 | memcpy(&ibss.ht_capa_mask, |
| 10102 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10103 | sizeof(ibss.ht_capa_mask)); |
| 10104 | |
| 10105 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
| 10106 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10107 | return -EINVAL; |
| 10108 | memcpy(&ibss.ht_capa, |
| 10109 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10110 | sizeof(ibss.ht_capa)); |
| 10111 | } |
| 10112 | |
Felix Fietkau | dd5b4cc | 2010-11-22 20:58:24 +0100 | [diff] [blame] | 10113 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 10114 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, |
| 10115 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 10116 | return -EINVAL; |
Teemu Paasikivi | fbd2c8d | 2010-06-14 12:55:31 +0300 | [diff] [blame] | 10117 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10118 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10119 | bool no_ht = false; |
| 10120 | |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10121 | connkeys = nl80211_parse_connkeys(rdev, info, &no_ht); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10122 | if (IS_ERR(connkeys)) |
| 10123 | return PTR_ERR(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10124 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 10125 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
| 10126 | no_ht) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10127 | kfree_sensitive(connkeys); |
Sujith Manoharan | de7044e | 2012-10-18 10:19:28 +0530 | [diff] [blame] | 10128 | return -EINVAL; |
| 10129 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10130 | } |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10131 | |
Antonio Quartulli | 267335d | 2012-01-31 20:25:47 +0100 | [diff] [blame] | 10132 | ibss.control_port = |
| 10133 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); |
| 10134 | |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10135 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 10136 | int r = validate_pae_over_nl80211(rdev, info); |
| 10137 | |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 10138 | if (r < 0) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10139 | kfree_sensitive(connkeys); |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10140 | return r; |
Johannes Berg | d350a0f | 2018-12-15 11:03:22 +0200 | [diff] [blame] | 10141 | } |
Denis Kenzior | c3bfe1f | 2018-03-26 12:52:48 -0500 | [diff] [blame] | 10142 | |
| 10143 | ibss.control_port_over_nl80211 = true; |
| 10144 | } |
| 10145 | |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 10146 | ibss.userspace_handles_dfs = |
| 10147 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 10148 | |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 10149 | wdev_lock(dev->ieee80211_ptr); |
| 10150 | err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10151 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10152 | kfree_sensitive(connkeys); |
Denis Kenzior | f8d16d3 | 2018-03-26 12:52:45 -0500 | [diff] [blame] | 10153 | else if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 10154 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10155 | wdev_unlock(dev->ieee80211_ptr); |
| 10156 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10157 | return err; |
| 10158 | } |
| 10159 | |
| 10160 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 10161 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10163 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10164 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10165 | if (!rdev->ops->leave_ibss) |
| 10166 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10167 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10168 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
| 10169 | return -EOPNOTSUPP; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10170 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10171 | return cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 10172 | } |
| 10173 | |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10174 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
| 10175 | { |
| 10176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10177 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10178 | int mcast_rate[NUM_NL80211_BANDS]; |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10179 | u32 nla_rate; |
| 10180 | int err; |
| 10181 | |
| 10182 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
Bertold Van den Bergh | 876dc93 | 2015-08-05 16:02:21 +0200 | [diff] [blame] | 10183 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
| 10184 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10185 | return -EOPNOTSUPP; |
| 10186 | |
| 10187 | if (!rdev->ops->set_mcast_rate) |
| 10188 | return -EOPNOTSUPP; |
| 10189 | |
| 10190 | memset(mcast_rate, 0, sizeof(mcast_rate)); |
| 10191 | |
| 10192 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) |
| 10193 | return -EINVAL; |
| 10194 | |
| 10195 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); |
| 10196 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) |
| 10197 | return -EINVAL; |
| 10198 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 10199 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10200 | |
| 10201 | return err; |
| 10202 | } |
| 10203 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10204 | static struct sk_buff * |
| 10205 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10206 | struct wireless_dev *wdev, int approxlen, |
| 10207 | u32 portid, u32 seq, enum nl80211_commands cmd, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10208 | enum nl80211_attrs attr, |
| 10209 | const struct nl80211_vendor_cmd_info *info, |
| 10210 | gfp_t gfp) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10211 | { |
| 10212 | struct sk_buff *skb; |
| 10213 | void *hdr; |
| 10214 | struct nlattr *data; |
| 10215 | |
| 10216 | skb = nlmsg_new(approxlen + 100, gfp); |
| 10217 | if (!skb) |
| 10218 | return NULL; |
| 10219 | |
| 10220 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); |
| 10221 | if (!hdr) { |
| 10222 | kfree_skb(skb); |
| 10223 | return NULL; |
| 10224 | } |
| 10225 | |
| 10226 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 10227 | goto nla_put_failure; |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 10228 | |
| 10229 | if (info) { |
| 10230 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, |
| 10231 | info->vendor_id)) |
| 10232 | goto nla_put_failure; |
| 10233 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, |
| 10234 | info->subcmd)) |
| 10235 | goto nla_put_failure; |
| 10236 | } |
| 10237 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10238 | if (wdev) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 10239 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 10240 | wdev_id(wdev), NL80211_ATTR_PAD)) |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10241 | goto nla_put_failure; |
| 10242 | if (wdev->netdev && |
| 10243 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, |
| 10244 | wdev->netdev->ifindex)) |
| 10245 | goto nla_put_failure; |
| 10246 | } |
| 10247 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10248 | data = nla_nest_start_noflag(skb, attr); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 10249 | if (!data) |
| 10250 | goto nla_put_failure; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10251 | |
| 10252 | ((void **)skb->cb)[0] = rdev; |
| 10253 | ((void **)skb->cb)[1] = hdr; |
| 10254 | ((void **)skb->cb)[2] = data; |
| 10255 | |
| 10256 | return skb; |
| 10257 | |
| 10258 | nla_put_failure: |
| 10259 | kfree_skb(skb); |
| 10260 | return NULL; |
| 10261 | } |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 10262 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10263 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 10264 | struct wireless_dev *wdev, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10265 | enum nl80211_commands cmd, |
| 10266 | enum nl80211_attrs attr, |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10267 | unsigned int portid, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10268 | int vendor_event_idx, |
| 10269 | int approxlen, gfp_t gfp) |
| 10270 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 10271 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10272 | const struct nl80211_vendor_cmd_info *info; |
| 10273 | |
| 10274 | switch (cmd) { |
| 10275 | case NL80211_CMD_TESTMODE: |
| 10276 | if (WARN_ON(vendor_event_idx != -1)) |
| 10277 | return NULL; |
| 10278 | info = NULL; |
| 10279 | break; |
| 10280 | case NL80211_CMD_VENDOR: |
| 10281 | if (WARN_ON(vendor_event_idx < 0 || |
| 10282 | vendor_event_idx >= wiphy->n_vendor_events)) |
| 10283 | return NULL; |
| 10284 | info = &wiphy->vendor_events[vendor_event_idx]; |
| 10285 | break; |
| 10286 | default: |
| 10287 | WARN_ON(1); |
| 10288 | return NULL; |
| 10289 | } |
| 10290 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10291 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0, |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10292 | cmd, attr, info, gfp); |
| 10293 | } |
| 10294 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); |
| 10295 | |
| 10296 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) |
| 10297 | { |
| 10298 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 10299 | void *hdr = ((void **)skb->cb)[1]; |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10300 | struct nlmsghdr *nlhdr = nlmsg_hdr(skb); |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10301 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 10302 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; |
| 10303 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 10304 | /* clear CB data for netlink core to own from now on */ |
| 10305 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 10306 | |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10307 | nla_nest_end(skb, data); |
| 10308 | genlmsg_end(skb, hdr); |
| 10309 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10310 | if (nlhdr->nlmsg_pid) { |
| 10311 | genlmsg_unicast(wiphy_net(&rdev->wiphy), skb, |
| 10312 | nlhdr->nlmsg_pid); |
| 10313 | } else { |
| 10314 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) |
| 10315 | mcgrp = NL80211_MCGRP_VENDOR; |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10316 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 10317 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 10318 | skb, 0, mcgrp, gfp); |
| 10319 | } |
Johannes Berg | e03ad6e | 2014-01-01 17:22:30 +0100 | [diff] [blame] | 10320 | } |
| 10321 | EXPORT_SYMBOL(__cfg80211_send_event_skb); |
| 10322 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10323 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10324 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 10325 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10326 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10327 | struct wireless_dev *wdev = |
| 10328 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10329 | int err; |
| 10330 | |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10331 | if (!rdev->ops->testmode_cmd) |
| 10332 | return -EOPNOTSUPP; |
| 10333 | |
| 10334 | if (IS_ERR(wdev)) { |
| 10335 | err = PTR_ERR(wdev); |
| 10336 | if (err != -EINVAL) |
| 10337 | return err; |
| 10338 | wdev = NULL; |
| 10339 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 10340 | return -EINVAL; |
| 10341 | } |
| 10342 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10343 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 10344 | return -EINVAL; |
| 10345 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10346 | rdev->cur_cmd_info = info; |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 10347 | err = rdev_testmode_cmd(rdev, wdev, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10348 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 10349 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 10350 | rdev->cur_cmd_info = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10351 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10352 | return err; |
| 10353 | } |
| 10354 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10355 | static int nl80211_testmode_dump(struct sk_buff *skb, |
| 10356 | struct netlink_callback *cb) |
| 10357 | { |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10358 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10359 | struct nlattr **attrbuf = NULL; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10360 | int err; |
| 10361 | long phy_idx; |
| 10362 | void *data = NULL; |
| 10363 | int data_len = 0; |
| 10364 | |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10365 | rtnl_lock(); |
| 10366 | |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10367 | if (cb->args[0]) { |
| 10368 | /* |
| 10369 | * 0 is a valid index, but not valid for args[0], |
| 10370 | * so we need to offset by 1. |
| 10371 | */ |
| 10372 | phy_idx = cb->args[0] - 1; |
Luca Coelho | a4956dc | 2017-02-07 22:13:56 +0200 | [diff] [blame] | 10373 | |
| 10374 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
| 10375 | if (!rdev) { |
| 10376 | err = -ENOENT; |
| 10377 | goto out_err; |
| 10378 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10379 | } else { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10380 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), |
| 10381 | GFP_KERNEL); |
| 10382 | if (!attrbuf) { |
| 10383 | err = -ENOMEM; |
| 10384 | goto out_err; |
| 10385 | } |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10386 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 10387 | err = nlmsg_parse_deprecated(cb->nlh, |
| 10388 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 10389 | attrbuf, nl80211_fam.maxattr, |
| 10390 | nl80211_policy, NULL); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10391 | if (err) |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10392 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10393 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10394 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10395 | if (IS_ERR(rdev)) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10396 | err = PTR_ERR(rdev); |
| 10397 | goto out_err; |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10398 | } |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10399 | phy_idx = rdev->wiphy_idx; |
Johannes Berg | 2bd7e35 | 2012-06-15 14:23:16 +0200 | [diff] [blame] | 10400 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 10401 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
| 10402 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10403 | } |
| 10404 | |
| 10405 | if (cb->args[1]) { |
| 10406 | data = nla_data((void *)cb->args[1]); |
| 10407 | data_len = nla_len((void *)cb->args[1]); |
| 10408 | } |
| 10409 | |
Johannes Berg | 00918d3 | 2011-12-13 17:22:05 +0100 | [diff] [blame] | 10410 | if (!rdev->ops->testmode_dump) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10411 | err = -EOPNOTSUPP; |
| 10412 | goto out_err; |
| 10413 | } |
| 10414 | |
| 10415 | while (1) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 10416 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10417 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 10418 | NL80211_CMD_TESTMODE); |
| 10419 | struct nlattr *tmdata; |
| 10420 | |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 10421 | if (!hdr) |
| 10422 | break; |
| 10423 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 10424 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10425 | genlmsg_cancel(skb, hdr); |
| 10426 | break; |
| 10427 | } |
| 10428 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 10429 | tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10430 | if (!tmdata) { |
| 10431 | genlmsg_cancel(skb, hdr); |
| 10432 | break; |
| 10433 | } |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10434 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10435 | nla_nest_end(skb, tmdata); |
| 10436 | |
| 10437 | if (err == -ENOBUFS || err == -ENOENT) { |
| 10438 | genlmsg_cancel(skb, hdr); |
| 10439 | break; |
| 10440 | } else if (err) { |
| 10441 | genlmsg_cancel(skb, hdr); |
| 10442 | goto out_err; |
| 10443 | } |
| 10444 | |
| 10445 | genlmsg_end(skb, hdr); |
| 10446 | } |
| 10447 | |
| 10448 | err = skb->len; |
| 10449 | /* see above */ |
| 10450 | cb->args[0] = phy_idx + 1; |
| 10451 | out_err: |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 10452 | kfree(attrbuf); |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 10453 | rtnl_unlock(); |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 10454 | return err; |
| 10455 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 10456 | #endif |
| 10457 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10458 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 10459 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10460 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10461 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10462 | struct cfg80211_connect_params connect; |
| 10463 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10464 | struct cfg80211_cached_keys *connkeys = NULL; |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10465 | u32 freq = 0; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10466 | int err; |
| 10467 | |
| 10468 | memset(&connect, 0, sizeof(connect)); |
| 10469 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10470 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 10471 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 10472 | return -EINVAL; |
| 10473 | |
| 10474 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10475 | connect.auth_type = |
| 10476 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
Jouni Malinen | e39e5b5 | 2012-09-30 19:29:39 +0300 | [diff] [blame] | 10477 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
| 10478 | NL80211_CMD_CONNECT)) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10479 | return -EINVAL; |
| 10480 | } else |
| 10481 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 10482 | |
| 10483 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 10484 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 10485 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
| 10486 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10487 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 10488 | return -EINVAL; |
| 10489 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; |
| 10490 | |
Johannes Berg | c0692b8 | 2010-08-27 14:26:53 +0300 | [diff] [blame] | 10491 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 10492 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10493 | if (err) |
| 10494 | return err; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10495 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10496 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10497 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10498 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10499 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 10500 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10501 | |
Bala Shanmugam | 4486ea9 | 2012-03-07 17:27:12 +0530 | [diff] [blame] | 10502 | connect.bg_scan_period = -1; |
| 10503 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && |
| 10504 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { |
| 10505 | connect.bg_scan_period = |
| 10506 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); |
| 10507 | } |
| 10508 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10509 | if (info->attrs[NL80211_ATTR_MAC]) |
| 10510 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10511 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
| 10512 | connect.bssid_hint = |
| 10513 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10514 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10515 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10516 | |
| 10517 | if (info->attrs[NL80211_ATTR_IE]) { |
| 10518 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10519 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10520 | } |
| 10521 | |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10522 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 10523 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Emmanuel Grumbach | 6502600 | 2017-08-18 15:31:41 +0300 | [diff] [blame] | 10524 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
| 10525 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10526 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) |
| 10527 | return -EOPNOTSUPP; |
Jouni Malinen | cee00a9 | 2013-01-15 17:15:57 +0200 | [diff] [blame] | 10528 | } else { |
| 10529 | connect.mfp = NL80211_MFP_NO; |
| 10530 | } |
| 10531 | |
Jouni Malinen | ba6fbac | 2016-03-29 13:53:27 +0300 | [diff] [blame] | 10532 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 10533 | connect.prev_bssid = |
| 10534 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 10535 | |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10536 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 10537 | freq = MHZ_TO_KHZ(nla_get_u32( |
| 10538 | info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 10539 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]) |
| 10540 | freq += |
| 10541 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]); |
| 10542 | |
| 10543 | if (freq) { |
| 10544 | connect.channel = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10545 | if (!connect.channel) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10546 | return -EINVAL; |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10547 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 10548 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); |
| 10549 | freq = MHZ_TO_KHZ(freq); |
| 10550 | connect.channel_hint = nl80211_get_valid_chan(wiphy, freq); |
Jouni Malinen | 664834d | 2014-01-15 00:01:44 +0200 | [diff] [blame] | 10551 | if (!connect.channel_hint) |
Jouni Malinen | 1df4a51 | 2014-01-15 00:00:47 +0200 | [diff] [blame] | 10552 | return -EINVAL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10553 | } |
| 10554 | |
Alexei Avshalom Lazar | 2a38075 | 2019-08-18 17:35:17 +0300 | [diff] [blame] | 10555 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) { |
| 10556 | connect.edmg.channels = |
| 10557 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]); |
| 10558 | |
| 10559 | if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]) |
| 10560 | connect.edmg.bw_config = |
| 10561 | nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]); |
| 10562 | } |
| 10563 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10564 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
Johannes Berg | 768075e | 2017-11-13 15:35:06 +0100 | [diff] [blame] | 10565 | connkeys = nl80211_parse_connkeys(rdev, info, NULL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10566 | if (IS_ERR(connkeys)) |
| 10567 | return PTR_ERR(connkeys); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10568 | } |
| 10569 | |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10570 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
| 10571 | connect.flags |= ASSOC_REQ_DISABLE_HT; |
| 10572 | |
| 10573 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
| 10574 | memcpy(&connect.ht_capa_mask, |
| 10575 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), |
| 10576 | sizeof(connect.ht_capa_mask)); |
| 10577 | |
| 10578 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10579 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10580 | kfree_sensitive(connkeys); |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10581 | return -EINVAL; |
Wei Yongjun | b4e4f47 | 2012-09-02 21:41:04 +0800 | [diff] [blame] | 10582 | } |
Ben Greear | 7e7c892 | 2011-11-18 11:31:59 -0800 | [diff] [blame] | 10583 | memcpy(&connect.ht_capa, |
| 10584 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), |
| 10585 | sizeof(connect.ht_capa)); |
| 10586 | } |
| 10587 | |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10588 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
| 10589 | connect.flags |= ASSOC_REQ_DISABLE_VHT; |
| 10590 | |
| 10591 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
| 10592 | memcpy(&connect.vht_capa_mask, |
| 10593 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), |
| 10594 | sizeof(connect.vht_capa_mask)); |
| 10595 | |
| 10596 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { |
| 10597 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10598 | kfree_sensitive(connkeys); |
Johannes Berg | ee2aca3 | 2013-02-21 17:36:01 +0100 | [diff] [blame] | 10599 | return -EINVAL; |
| 10600 | } |
| 10601 | memcpy(&connect.vht_capa, |
| 10602 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), |
| 10603 | sizeof(connect.vht_capa)); |
| 10604 | } |
| 10605 | |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10606 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
Beni Lev | 0c9ca11 | 2016-02-17 20:30:00 +0200 | [diff] [blame] | 10607 | if (!((rdev->wiphy.features & |
| 10608 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && |
| 10609 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && |
| 10610 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 10611 | NL80211_EXT_FEATURE_RRM)) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10612 | kfree_sensitive(connkeys); |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10613 | return -EINVAL; |
Ola Olsson | 707554b | 2015-12-11 21:04:52 +0100 | [diff] [blame] | 10614 | } |
Assaf Krauss | bab5ab7 | 2014-09-03 15:25:01 +0300 | [diff] [blame] | 10615 | connect.flags |= ASSOC_REQ_USE_RRM; |
| 10616 | } |
| 10617 | |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10618 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 10619 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10620 | kfree_sensitive(connkeys); |
Lior David | 34d5051 | 2016-01-28 10:58:25 +0200 | [diff] [blame] | 10621 | return -EOPNOTSUPP; |
| 10622 | } |
| 10623 | |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10624 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
| 10625 | /* bss selection makes no sense if bssid is set */ |
| 10626 | if (connect.bssid) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10627 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10628 | return -EINVAL; |
| 10629 | } |
| 10630 | |
| 10631 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], |
| 10632 | wiphy, &connect.bss_select); |
| 10633 | if (err) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10634 | kfree_sensitive(connkeys); |
Arend van Spriel | 38de03d | 2016-03-02 20:37:18 +0100 | [diff] [blame] | 10635 | return err; |
| 10636 | } |
| 10637 | } |
| 10638 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10639 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
| 10640 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && |
| 10641 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10642 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10643 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10644 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10645 | connect.fils_erp_username = |
| 10646 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10647 | connect.fils_erp_username_len = |
| 10648 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10649 | connect.fils_erp_realm = |
| 10650 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10651 | connect.fils_erp_realm_len = |
| 10652 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10653 | connect.fils_erp_next_seq_num = |
| 10654 | nla_get_u16( |
| 10655 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10656 | connect.fils_erp_rrk = |
| 10657 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10658 | connect.fils_erp_rrk_len = |
| 10659 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10660 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10661 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10662 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10663 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10664 | kfree_sensitive(connkeys); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10665 | return -EINVAL; |
| 10666 | } |
| 10667 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10668 | if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) { |
| 10669 | if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10670 | kfree_sensitive(connkeys); |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 10671 | GENL_SET_ERR_MSG(info, |
| 10672 | "external auth requires connection ownership"); |
| 10673 | return -EINVAL; |
| 10674 | } |
| 10675 | connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT; |
| 10676 | } |
| 10677 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10678 | wdev_lock(dev->ieee80211_ptr); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10679 | |
Jouni Malinen | 4ce2bd9 | 2016-03-29 13:53:28 +0300 | [diff] [blame] | 10680 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
| 10681 | connect.prev_bssid); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 10682 | if (err) |
Waiman Long | 453431a | 2020-08-06 23:18:13 -0700 | [diff] [blame] | 10683 | kfree_sensitive(connkeys); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10684 | |
| 10685 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
| 10686 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 10687 | if (connect.bssid) |
| 10688 | memcpy(dev->ieee80211_ptr->disconnect_bssid, |
| 10689 | connect.bssid, ETH_ALEN); |
| 10690 | else |
Miaohe Lin | 3b1648f | 2020-08-01 17:15:49 +0800 | [diff] [blame] | 10691 | eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid); |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 10692 | } |
| 10693 | |
| 10694 | wdev_unlock(dev->ieee80211_ptr); |
| 10695 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10696 | return err; |
| 10697 | } |
| 10698 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10699 | static int nl80211_update_connect_params(struct sk_buff *skb, |
| 10700 | struct genl_info *info) |
| 10701 | { |
| 10702 | struct cfg80211_connect_params connect = {}; |
| 10703 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10704 | struct net_device *dev = info->user_ptr[1]; |
| 10705 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10706 | bool fils_sk_offload; |
| 10707 | u32 auth_type; |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10708 | u32 changed = 0; |
| 10709 | int ret; |
| 10710 | |
| 10711 | if (!rdev->ops->update_connect_params) |
| 10712 | return -EOPNOTSUPP; |
| 10713 | |
| 10714 | if (info->attrs[NL80211_ATTR_IE]) { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10715 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 10716 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 10717 | changed |= UPDATE_ASSOC_IES; |
| 10718 | } |
| 10719 | |
Vidyullatha Kanchanapally | 7f9a3e1 | 2018-05-22 10:19:08 +0200 | [diff] [blame] | 10720 | fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy, |
| 10721 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD); |
| 10722 | |
| 10723 | /* |
| 10724 | * when driver supports fils-sk offload all attributes must be |
| 10725 | * provided. So the else covers "fils-sk-not-all" and |
| 10726 | * "no-fils-sk-any". |
| 10727 | */ |
| 10728 | if (fils_sk_offload && |
| 10729 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && |
| 10730 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && |
| 10731 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && |
| 10732 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10733 | connect.fils_erp_username = |
| 10734 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10735 | connect.fils_erp_username_len = |
| 10736 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); |
| 10737 | connect.fils_erp_realm = |
| 10738 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10739 | connect.fils_erp_realm_len = |
| 10740 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); |
| 10741 | connect.fils_erp_next_seq_num = |
| 10742 | nla_get_u16( |
| 10743 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); |
| 10744 | connect.fils_erp_rrk = |
| 10745 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10746 | connect.fils_erp_rrk_len = |
| 10747 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); |
| 10748 | changed |= UPDATE_FILS_ERP_INFO; |
| 10749 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || |
| 10750 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || |
| 10751 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || |
| 10752 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { |
| 10753 | return -EINVAL; |
| 10754 | } |
| 10755 | |
| 10756 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 10757 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 10758 | if (!nl80211_valid_auth_type(rdev, auth_type, |
| 10759 | NL80211_CMD_CONNECT)) |
| 10760 | return -EINVAL; |
| 10761 | |
| 10762 | if (auth_type == NL80211_AUTHTYPE_FILS_SK && |
| 10763 | fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO)) |
| 10764 | return -EINVAL; |
| 10765 | |
| 10766 | connect.auth_type = auth_type; |
| 10767 | changed |= UPDATE_AUTH_TYPE; |
| 10768 | } |
| 10769 | |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 10770 | wdev_lock(dev->ieee80211_ptr); |
| 10771 | if (!wdev->current_bss) |
| 10772 | ret = -ENOLINK; |
| 10773 | else |
| 10774 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); |
| 10775 | wdev_unlock(dev->ieee80211_ptr); |
| 10776 | |
| 10777 | return ret; |
| 10778 | } |
| 10779 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10780 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 10781 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10783 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10784 | u16 reason; |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10785 | int ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10786 | |
Andrew Zaborowski | bad2929 | 2018-05-22 02:46:02 +0200 | [diff] [blame] | 10787 | if (dev->ieee80211_ptr->conn_owner_nlportid && |
| 10788 | dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid) |
| 10789 | return -EPERM; |
| 10790 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10791 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 10792 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 10793 | else |
| 10794 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 10795 | |
| 10796 | if (reason == 0) |
| 10797 | return -EINVAL; |
| 10798 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10799 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10800 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10801 | return -EOPNOTSUPP; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10802 | |
Johannes Berg | 83739b0 | 2013-05-15 17:44:01 +0200 | [diff] [blame] | 10803 | wdev_lock(dev->ieee80211_ptr); |
| 10804 | ret = cfg80211_disconnect(rdev, dev, reason, true); |
| 10805 | wdev_unlock(dev->ieee80211_ptr); |
| 10806 | return ret; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 10807 | } |
| 10808 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10809 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 10810 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10812 | struct net *net; |
| 10813 | int err; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10814 | |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10815 | if (info->attrs[NL80211_ATTR_PID]) { |
| 10816 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 10817 | |
| 10818 | net = get_net_ns_by_pid(pid); |
| 10819 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { |
| 10820 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); |
| 10821 | |
| 10822 | net = get_net_ns_by_fd(fd); |
| 10823 | } else { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10824 | return -EINVAL; |
Vadim Kochan | 4b681c8 | 2015-01-12 16:34:05 +0200 | [diff] [blame] | 10825 | } |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10826 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10827 | if (IS_ERR(net)) |
| 10828 | return PTR_ERR(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10829 | |
| 10830 | err = 0; |
| 10831 | |
| 10832 | /* check if anything to do */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10833 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
| 10834 | err = cfg80211_switch_netns(rdev, net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10835 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10836 | put_net(net); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 10837 | return err; |
| 10838 | } |
| 10839 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10840 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10841 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10843 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
| 10844 | struct cfg80211_pmksa *pmksa) = NULL; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10845 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10846 | struct cfg80211_pmksa pmksa; |
| 10847 | |
| 10848 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
| 10849 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10850 | if (!info->attrs[NL80211_ATTR_PMKID]) |
| 10851 | return -EINVAL; |
| 10852 | |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10853 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 10854 | |
| 10855 | if (info->attrs[NL80211_ATTR_MAC]) { |
| 10856 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10857 | } else if (info->attrs[NL80211_ATTR_SSID] && |
| 10858 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && |
| 10859 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || |
| 10860 | info->attrs[NL80211_ATTR_PMK])) { |
| 10861 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 10862 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 10863 | pmksa.cache_id = |
| 10864 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); |
| 10865 | } else { |
| 10866 | return -EINVAL; |
| 10867 | } |
| 10868 | if (info->attrs[NL80211_ATTR_PMK]) { |
| 10869 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 10870 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 10871 | } |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10872 | |
Veerendranath Jakkam | 7fc82af | 2020-03-13 01:59:03 +0200 | [diff] [blame] | 10873 | if (info->attrs[NL80211_ATTR_PMK_LIFETIME]) |
| 10874 | pmksa.pmk_lifetime = |
| 10875 | nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]); |
| 10876 | |
| 10877 | if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]) |
| 10878 | pmksa.pmk_reauth_threshold = |
| 10879 | nla_get_u8( |
| 10880 | info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]); |
| 10881 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Liangwei Dong | 6c90036 | 2019-01-18 16:54:38 +0530 | [diff] [blame] | 10883 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
| 10884 | !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP && |
| 10885 | wiphy_ext_feature_isset(&rdev->wiphy, |
| 10886 | NL80211_EXT_FEATURE_AP_PMKSA_CACHING))) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10887 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10888 | |
| 10889 | switch (info->genlhdr->cmd) { |
| 10890 | case NL80211_CMD_SET_PMKSA: |
| 10891 | rdev_ops = rdev->ops->set_pmksa; |
| 10892 | break; |
| 10893 | case NL80211_CMD_DEL_PMKSA: |
| 10894 | rdev_ops = rdev->ops->del_pmksa; |
| 10895 | break; |
| 10896 | default: |
| 10897 | WARN_ON(1); |
| 10898 | break; |
| 10899 | } |
| 10900 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10901 | if (!rdev_ops) |
| 10902 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10903 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10904 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10905 | } |
| 10906 | |
| 10907 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
| 10908 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10910 | struct net_device *dev = info->user_ptr[1]; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10911 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 10912 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10913 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 10914 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10915 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10916 | if (!rdev->ops->flush_pmksa) |
| 10917 | return -EOPNOTSUPP; |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10918 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10919 | return rdev_flush_pmksa(rdev, dev); |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 10920 | } |
| 10921 | |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10922 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
| 10923 | { |
| 10924 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10925 | struct net_device *dev = info->user_ptr[1]; |
| 10926 | u8 action_code, dialog_token; |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10927 | u32 peer_capability = 0; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10928 | u16 status_code; |
| 10929 | u8 *peer; |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10930 | bool initiator; |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10931 | |
| 10932 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10933 | !rdev->ops->tdls_mgmt) |
| 10934 | return -EOPNOTSUPP; |
| 10935 | |
| 10936 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || |
| 10937 | !info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 10938 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || |
| 10939 | !info->attrs[NL80211_ATTR_IE] || |
| 10940 | !info->attrs[NL80211_ATTR_MAC]) |
| 10941 | return -EINVAL; |
| 10942 | |
| 10943 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10944 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); |
| 10945 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 10946 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10947 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10948 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
| 10949 | peer_capability = |
| 10950 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10951 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10952 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
Sunil Dutt Undekari | df942e7 | 2014-02-20 16:22:09 +0530 | [diff] [blame] | 10953 | dialog_token, status_code, peer_capability, |
Arik Nemtsov | 31fa97c | 2014-06-11 17:18:21 +0300 | [diff] [blame] | 10954 | initiator, |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10955 | nla_data(info->attrs[NL80211_ATTR_IE]), |
| 10956 | nla_len(info->attrs[NL80211_ATTR_IE])); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10957 | } |
| 10958 | |
| 10959 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) |
| 10960 | { |
| 10961 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 10962 | struct net_device *dev = info->user_ptr[1]; |
| 10963 | enum nl80211_tdls_operation operation; |
| 10964 | u8 *peer; |
| 10965 | |
| 10966 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || |
| 10967 | !rdev->ops->tdls_oper) |
| 10968 | return -EOPNOTSUPP; |
| 10969 | |
| 10970 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || |
| 10971 | !info->attrs[NL80211_ATTR_MAC]) |
| 10972 | return -EINVAL; |
| 10973 | |
| 10974 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); |
| 10975 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 10976 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 10977 | return rdev_tdls_oper(rdev, dev, peer, operation); |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 10978 | } |
| 10979 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10980 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
| 10981 | struct genl_info *info) |
| 10982 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 10983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 10984 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10985 | struct cfg80211_chan_def chandef; |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 10986 | const struct cfg80211_chan_def *compat_chandef; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10987 | struct sk_buff *msg; |
| 10988 | void *hdr; |
| 10989 | u64 cookie; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 10990 | u32 duration; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 10991 | int err; |
| 10992 | |
| 10993 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 10994 | !info->attrs[NL80211_ATTR_DURATION]) |
| 10995 | return -EINVAL; |
| 10996 | |
| 10997 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
| 10998 | |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 10999 | if (!rdev->ops->remain_on_channel || |
| 11000 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11001 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11002 | |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11003 | /* |
| 11004 | * We should be on that channel for at least a minimum amount of |
| 11005 | * time (10ms) but no longer than the driver supports. |
| 11006 | */ |
| 11007 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11008 | duration > rdev->wiphy.max_remain_on_channel_duration) |
| 11009 | return -EINVAL; |
| 11010 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11011 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11012 | if (err) |
| 11013 | return err; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11014 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 11015 | wdev_lock(wdev); |
| 11016 | if (!cfg80211_off_channel_oper_allowed(wdev) && |
| 11017 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { |
| 11018 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, |
| 11019 | &chandef); |
| 11020 | if (compat_chandef != &chandef) { |
| 11021 | wdev_unlock(wdev); |
| 11022 | return -EBUSY; |
| 11023 | } |
| 11024 | } |
| 11025 | wdev_unlock(wdev); |
| 11026 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11027 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11028 | if (!msg) |
| 11029 | return -ENOMEM; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11030 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11031 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11032 | NL80211_CMD_REMAIN_ON_CHANNEL); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11033 | if (!hdr) { |
| 11034 | err = -ENOBUFS; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11035 | goto free_msg; |
| 11036 | } |
| 11037 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11038 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
| 11039 | duration, &cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11040 | |
| 11041 | if (err) |
| 11042 | goto free_msg; |
| 11043 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11044 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11045 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11046 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11047 | |
| 11048 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11049 | |
| 11050 | return genlmsg_reply(msg, info); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11051 | |
| 11052 | nla_put_failure: |
| 11053 | err = -ENOBUFS; |
| 11054 | free_msg: |
| 11055 | nlmsg_free(msg); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11056 | return err; |
| 11057 | } |
| 11058 | |
| 11059 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
| 11060 | struct genl_info *info) |
| 11061 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11062 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11063 | struct wireless_dev *wdev = info->user_ptr[1]; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11064 | u64 cookie; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11065 | |
| 11066 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11067 | return -EINVAL; |
| 11068 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11069 | if (!rdev->ops->cancel_remain_on_channel) |
| 11070 | return -EOPNOTSUPP; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11071 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11072 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11073 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11074 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 11075 | } |
| 11076 | |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11077 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
| 11078 | struct genl_info *info) |
| 11079 | { |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11080 | struct cfg80211_bitrate_mask mask; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 11081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11082 | struct net_device *dev = info->user_ptr[1]; |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 11083 | int err; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11084 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11085 | if (!rdev->ops->set_bitrate_mask) |
| 11086 | return -EOPNOTSUPP; |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11087 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 11088 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 11089 | NL80211_ATTR_TX_RATES, &mask, |
| 11090 | dev); |
Purushottam Kushwaha | a7c7fbf | 2016-09-14 17:38:44 +0530 | [diff] [blame] | 11091 | if (err) |
| 11092 | return err; |
Janusz Dziedzic | 7869303 | 2013-12-03 09:50:44 +0100 | [diff] [blame] | 11093 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11094 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 11095 | } |
| 11096 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11097 | 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] | 11098 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11099 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11100 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11101 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11102 | |
| 11103 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
| 11104 | return -EINVAL; |
| 11105 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11106 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
| 11107 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11108 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11109 | switch (wdev->iftype) { |
| 11110 | case NL80211_IFTYPE_STATION: |
| 11111 | case NL80211_IFTYPE_ADHOC: |
| 11112 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11113 | case NL80211_IFTYPE_AP: |
| 11114 | case NL80211_IFTYPE_AP_VLAN: |
| 11115 | case NL80211_IFTYPE_MESH_POINT: |
| 11116 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11117 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11118 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11119 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11120 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11121 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11122 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11123 | |
| 11124 | /* not much point in registering if we can't reply */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11125 | if (!rdev->ops->mgmt_tx) |
| 11126 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11127 | |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 11128 | if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] && |
| 11129 | !wiphy_ext_feature_isset(&rdev->wiphy, |
| 11130 | NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) { |
| 11131 | GENL_SET_ERR_MSG(info, |
| 11132 | "multicast RX registrations are not supported"); |
| 11133 | return -EOPNOTSUPP; |
| 11134 | } |
| 11135 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11136 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 11137 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
| 11138 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
Johannes Berg | 9dba48a | 2020-04-17 12:40:15 +0200 | [diff] [blame] | 11139 | info->attrs[NL80211_ATTR_RECEIVE_MULTICAST], |
Ilan Peer | ff74c51 | 2020-01-31 13:45:29 +0200 | [diff] [blame] | 11140 | info->extack); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11141 | } |
| 11142 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 11143 | 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] | 11144 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11145 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11146 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11147 | struct cfg80211_chan_def chandef; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11148 | int err; |
Johannes Berg | d64d373 | 2011-11-10 09:44:46 +0100 | [diff] [blame] | 11149 | void *hdr = NULL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11150 | u64 cookie; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11151 | struct sk_buff *msg = NULL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11152 | struct cfg80211_mgmt_tx_params params = { |
| 11153 | .dont_wait_for_ack = |
| 11154 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], |
| 11155 | }; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11156 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11157 | if (!info->attrs[NL80211_ATTR_FRAME]) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11158 | return -EINVAL; |
| 11159 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11160 | if (!rdev->ops->mgmt_tx) |
| 11161 | return -EOPNOTSUPP; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11162 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11163 | switch (wdev->iftype) { |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11164 | case NL80211_IFTYPE_P2P_DEVICE: |
| 11165 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 11166 | return -EINVAL; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11167 | case NL80211_IFTYPE_STATION: |
| 11168 | case NL80211_IFTYPE_ADHOC: |
| 11169 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11170 | case NL80211_IFTYPE_AP: |
| 11171 | case NL80211_IFTYPE_AP_VLAN: |
| 11172 | case NL80211_IFTYPE_MESH_POINT: |
| 11173 | case NL80211_IFTYPE_P2P_GO: |
| 11174 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11175 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11176 | default: |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11177 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11178 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11179 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11180 | if (info->attrs[NL80211_ATTR_DURATION]) { |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11181 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11182 | return -EINVAL; |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11183 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11184 | |
| 11185 | /* |
| 11186 | * We should wait on the channel for at least a minimum amount |
| 11187 | * of time (10ms) but no longer than the driver supports. |
| 11188 | */ |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11189 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
| 11190 | params.wait > rdev->wiphy.max_remain_on_channel_duration) |
Johannes Berg | ebf348f | 2012-06-01 12:50:54 +0200 | [diff] [blame] | 11191 | return -EINVAL; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11192 | } |
| 11193 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11194 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11195 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11196 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
Johannes Berg | 7c4ef71 | 2011-11-18 15:33:48 +0100 | [diff] [blame] | 11197 | return -EINVAL; |
| 11198 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11199 | 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] | 11200 | |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11201 | /* get the channel if any has been specified, otherwise pass NULL to |
| 11202 | * the driver. The latter will use the current one |
| 11203 | */ |
| 11204 | chandef.chan = NULL; |
| 11205 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 11206 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 11207 | if (err) |
| 11208 | return err; |
| 11209 | } |
| 11210 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11211 | if (!chandef.chan && params.offchan) |
Antonio Quartulli | ea141b75 | 2013-06-11 14:20:03 +0200 | [diff] [blame] | 11212 | return -EINVAL; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11213 | |
Vasanthakumar Thiagarajan | 34373d1 | 2017-02-27 17:04:34 +0530 | [diff] [blame] | 11214 | wdev_lock(wdev); |
| 11215 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { |
| 11216 | wdev_unlock(wdev); |
| 11217 | return -EBUSY; |
| 11218 | } |
| 11219 | wdev_unlock(wdev); |
| 11220 | |
Andrei Otcheretianski | 34d22ce | 2014-05-09 14:11:44 +0300 | [diff] [blame] | 11221 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 11222 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 11223 | |
| 11224 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { |
| 11225 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11226 | int i; |
| 11227 | |
| 11228 | if (len % sizeof(u16)) |
| 11229 | return -EINVAL; |
| 11230 | |
| 11231 | params.n_csa_offsets = len / sizeof(u16); |
| 11232 | params.csa_offsets = |
| 11233 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); |
| 11234 | |
| 11235 | /* check that all the offsets fit the frame */ |
| 11236 | for (i = 0; i < params.n_csa_offsets; i++) { |
| 11237 | if (params.csa_offsets[i] >= params.len) |
| 11238 | return -EINVAL; |
| 11239 | } |
| 11240 | } |
| 11241 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11242 | if (!params.dont_wait_for_ack) { |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11243 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 11244 | if (!msg) |
| 11245 | return -ENOMEM; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11246 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11247 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11248 | NL80211_CMD_FRAME); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 11249 | if (!hdr) { |
| 11250 | err = -ENOBUFS; |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11251 | goto free_msg; |
| 11252 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11253 | } |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11254 | |
Andrei Otcheretianski | b176e62 | 2013-11-18 19:06:49 +0200 | [diff] [blame] | 11255 | params.chan = chandef.chan; |
| 11256 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11257 | if (err) |
| 11258 | goto free_msg; |
| 11259 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11260 | if (msg) { |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 11261 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 11262 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11263 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11264 | |
Johannes Berg | e247bd90 | 2011-11-04 11:18:21 +0100 | [diff] [blame] | 11265 | genlmsg_end(msg, hdr); |
| 11266 | return genlmsg_reply(msg, info); |
| 11267 | } |
| 11268 | |
| 11269 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11270 | |
| 11271 | nla_put_failure: |
| 11272 | err = -ENOBUFS; |
| 11273 | free_msg: |
| 11274 | nlmsg_free(msg); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 11275 | return err; |
| 11276 | } |
| 11277 | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11278 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
| 11279 | { |
| 11280 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11281 | struct wireless_dev *wdev = info->user_ptr[1]; |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11282 | u64 cookie; |
| 11283 | |
| 11284 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 11285 | return -EINVAL; |
| 11286 | |
| 11287 | if (!rdev->ops->mgmt_tx_cancel_wait) |
| 11288 | return -EOPNOTSUPP; |
| 11289 | |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11290 | switch (wdev->iftype) { |
| 11291 | case NL80211_IFTYPE_STATION: |
| 11292 | case NL80211_IFTYPE_ADHOC: |
| 11293 | case NL80211_IFTYPE_P2P_CLIENT: |
| 11294 | case NL80211_IFTYPE_AP: |
| 11295 | case NL80211_IFTYPE_AP_VLAN: |
| 11296 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 11297 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11298 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 11299 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11300 | default: |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11301 | return -EOPNOTSUPP; |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 11302 | } |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11303 | |
| 11304 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 11305 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11306 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 11307 | } |
| 11308 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11309 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11310 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11311 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11312 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11313 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11314 | u8 ps_state; |
| 11315 | bool state; |
| 11316 | int err; |
| 11317 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11318 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
| 11319 | return -EINVAL; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11320 | |
| 11321 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
| 11322 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11323 | wdev = dev->ieee80211_ptr; |
| 11324 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11325 | if (!rdev->ops->set_power_mgmt) |
| 11326 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11327 | |
| 11328 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
| 11329 | |
| 11330 | if (state == wdev->ps) |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11331 | return 0; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11332 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11333 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11334 | if (!err) |
| 11335 | wdev->ps = state; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11336 | return err; |
| 11337 | } |
| 11338 | |
| 11339 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
| 11340 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11341 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11342 | enum nl80211_ps_state ps_state; |
| 11343 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11344 | struct net_device *dev = info->user_ptr[1]; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11345 | struct sk_buff *msg; |
| 11346 | void *hdr; |
| 11347 | int err; |
| 11348 | |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11349 | wdev = dev->ieee80211_ptr; |
| 11350 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11351 | if (!rdev->ops->set_power_mgmt) |
| 11352 | return -EOPNOTSUPP; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11353 | |
| 11354 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11355 | if (!msg) |
| 11356 | return -ENOMEM; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11357 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11358 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11359 | NL80211_CMD_GET_POWER_SAVE); |
| 11360 | if (!hdr) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11361 | err = -ENOBUFS; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11362 | goto free_msg; |
| 11363 | } |
| 11364 | |
| 11365 | if (wdev->ps) |
| 11366 | ps_state = NL80211_PS_ENABLED; |
| 11367 | else |
| 11368 | ps_state = NL80211_PS_DISABLED; |
| 11369 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11370 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
| 11371 | goto nla_put_failure; |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11372 | |
| 11373 | genlmsg_end(msg, hdr); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11374 | return genlmsg_reply(msg, info); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11375 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11376 | nla_put_failure: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11377 | err = -ENOBUFS; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11378 | free_msg: |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11379 | nlmsg_free(msg); |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 11380 | return err; |
| 11381 | } |
| 11382 | |
Johannes Berg | 94e860f | 2014-01-20 23:58:15 +0100 | [diff] [blame] | 11383 | static const struct nla_policy |
| 11384 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11385 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11386 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
| 11387 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11388 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
| 11389 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, |
| 11390 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 11391 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11392 | }; |
| 11393 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11394 | static int nl80211_set_cqm_txe(struct genl_info *info, |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11395 | u32 rate, u32 pkts, u32 intvl) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11396 | { |
| 11397 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11398 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11399 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11400 | |
Johannes Berg | d9d8b01 | 2012-11-26 12:51:52 +0100 | [diff] [blame] | 11401 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11402 | return -EINVAL; |
| 11403 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11404 | if (!rdev->ops->set_cqm_txe_config) |
| 11405 | return -EOPNOTSUPP; |
| 11406 | |
| 11407 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 11408 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11409 | return -EOPNOTSUPP; |
| 11410 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 11411 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 11412 | } |
| 11413 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11414 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
| 11415 | struct net_device *dev) |
| 11416 | { |
| 11417 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 11418 | s32 last, low, high; |
| 11419 | u32 hyst; |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11420 | int i, n, low_index; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11421 | int err; |
| 11422 | |
| 11423 | /* RSSI reporting disabled? */ |
| 11424 | if (!wdev->cqm_config) |
| 11425 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); |
| 11426 | |
| 11427 | /* |
| 11428 | * Obtain current RSSI value if possible, if not and no RSSI threshold |
| 11429 | * event has been received yet, we should receive an event after a |
| 11430 | * connection is established and enough beacons received to calculate |
| 11431 | * the average. |
| 11432 | */ |
| 11433 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && |
| 11434 | rdev->ops->get_station) { |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11435 | struct station_info sinfo = {}; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11436 | u8 *mac_addr; |
| 11437 | |
| 11438 | mac_addr = wdev->current_bss->pub.bssid; |
| 11439 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11440 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
| 11441 | if (err) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11442 | return err; |
| 11443 | |
Felix Fietkau | df16737 | 2020-01-08 18:06:30 +0100 | [diff] [blame] | 11444 | cfg80211_sinfo_release_content(&sinfo); |
Omer Efrat | 397c657 | 2018-06-17 13:06:14 +0300 | [diff] [blame] | 11445 | if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11446 | wdev->cqm_config->last_rssi_event_value = |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 11447 | (s8) sinfo.rx_beacon_signal_avg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11448 | } |
| 11449 | |
| 11450 | last = wdev->cqm_config->last_rssi_event_value; |
| 11451 | hyst = wdev->cqm_config->rssi_hyst; |
| 11452 | n = wdev->cqm_config->n_rssi_thresholds; |
| 11453 | |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11454 | for (i = 0; i < n; i++) { |
| 11455 | i = array_index_nospec(i, n); |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11456 | if (last < wdev->cqm_config->rssi_thresholds[i]) |
| 11457 | break; |
Masashi Honma | 4b2c5a1 | 2019-09-08 09:56:53 +0900 | [diff] [blame] | 11458 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11459 | |
Masashi Honma | 1222a16 | 2018-09-25 11:15:01 +0900 | [diff] [blame] | 11460 | low_index = i - 1; |
| 11461 | if (low_index >= 0) { |
| 11462 | low_index = array_index_nospec(low_index, n); |
| 11463 | low = wdev->cqm_config->rssi_thresholds[low_index] - hyst; |
| 11464 | } else { |
| 11465 | low = S32_MIN; |
| 11466 | } |
| 11467 | if (i < n) { |
| 11468 | i = array_index_nospec(i, n); |
| 11469 | high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1; |
| 11470 | } else { |
| 11471 | high = S32_MAX; |
| 11472 | } |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11473 | |
| 11474 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); |
| 11475 | } |
| 11476 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11477 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11478 | const s32 *thresholds, int n_thresholds, |
| 11479 | u32 hysteresis) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11480 | { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11481 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11482 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11483 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11484 | int i, err; |
| 11485 | s32 prev = S32_MIN; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11486 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11487 | /* Check all values negative and sorted */ |
| 11488 | for (i = 0; i < n_thresholds; i++) { |
| 11489 | if (thresholds[i] > 0 || thresholds[i] <= prev) |
| 11490 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11491 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11492 | prev = thresholds[i]; |
| 11493 | } |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11494 | |
Johannes Berg | 074ac8d | 2010-09-16 14:58:22 +0200 | [diff] [blame] | 11495 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 11496 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 11497 | return -EOPNOTSUPP; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11498 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11499 | wdev_lock(wdev); |
| 11500 | cfg80211_cqm_config_free(wdev); |
| 11501 | wdev_unlock(wdev); |
| 11502 | |
| 11503 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { |
| 11504 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ |
| 11505 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); |
| 11506 | |
| 11507 | return rdev_set_cqm_rssi_config(rdev, dev, |
| 11508 | thresholds[0], hysteresis); |
| 11509 | } |
| 11510 | |
| 11511 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 11512 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) |
| 11513 | return -EOPNOTSUPP; |
| 11514 | |
| 11515 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ |
| 11516 | n_thresholds = 0; |
| 11517 | |
| 11518 | wdev_lock(wdev); |
| 11519 | if (n_thresholds) { |
| 11520 | struct cfg80211_cqm_config *cqm_config; |
| 11521 | |
| 11522 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + |
| 11523 | n_thresholds * sizeof(s32), GFP_KERNEL); |
| 11524 | if (!cqm_config) { |
| 11525 | err = -ENOMEM; |
| 11526 | goto unlock; |
| 11527 | } |
| 11528 | |
| 11529 | cqm_config->rssi_hyst = hysteresis; |
| 11530 | cqm_config->n_rssi_thresholds = n_thresholds; |
| 11531 | memcpy(cqm_config->rssi_thresholds, thresholds, |
| 11532 | n_thresholds * sizeof(s32)); |
| 11533 | |
| 11534 | wdev->cqm_config = cqm_config; |
| 11535 | } |
| 11536 | |
| 11537 | err = cfg80211_cqm_rssi_update(rdev, dev); |
| 11538 | |
| 11539 | unlock: |
| 11540 | wdev_unlock(wdev); |
| 11541 | |
| 11542 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11543 | } |
| 11544 | |
| 11545 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
| 11546 | { |
| 11547 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; |
| 11548 | struct nlattr *cqm; |
| 11549 | int err; |
| 11550 | |
| 11551 | cqm = info->attrs[NL80211_ATTR_CQM]; |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11552 | if (!cqm) |
| 11553 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11554 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11555 | err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm, |
| 11556 | nl80211_attr_cqm_policy, |
| 11557 | info->extack); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11558 | if (err) |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11559 | return err; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11560 | |
| 11561 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && |
| 11562 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11563 | const s32 *thresholds = |
| 11564 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
| 11565 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11566 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11567 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 11568 | if (len % 4) |
| 11569 | return -EINVAL; |
| 11570 | |
| 11571 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, |
| 11572 | hysteresis); |
Johannes Berg | 1da5fcc | 2013-08-06 14:10:48 +0200 | [diff] [blame] | 11573 | } |
| 11574 | |
| 11575 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && |
| 11576 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && |
| 11577 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { |
| 11578 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); |
| 11579 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); |
| 11580 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); |
| 11581 | |
| 11582 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); |
| 11583 | } |
| 11584 | |
| 11585 | return -EINVAL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 11586 | } |
| 11587 | |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 11588 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11589 | { |
| 11590 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11591 | struct net_device *dev = info->user_ptr[1]; |
| 11592 | struct ocb_setup setup = {}; |
| 11593 | int err; |
| 11594 | |
| 11595 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11596 | if (err) |
| 11597 | return err; |
| 11598 | |
| 11599 | return cfg80211_join_ocb(rdev, dev, &setup); |
| 11600 | } |
| 11601 | |
| 11602 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) |
| 11603 | { |
| 11604 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11605 | struct net_device *dev = info->user_ptr[1]; |
| 11606 | |
| 11607 | return cfg80211_leave_ocb(rdev, dev); |
| 11608 | } |
| 11609 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11610 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11611 | { |
| 11612 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11613 | struct net_device *dev = info->user_ptr[1]; |
| 11614 | struct mesh_config cfg; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11615 | struct mesh_setup setup; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11616 | int err; |
| 11617 | |
| 11618 | /* start with default */ |
| 11619 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11620 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11621 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11622 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11623 | /* and parse parameters if given */ |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 11624 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11625 | if (err) |
| 11626 | return err; |
| 11627 | } |
| 11628 | |
| 11629 | if (!info->attrs[NL80211_ATTR_MESH_ID] || |
| 11630 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) |
| 11631 | return -EINVAL; |
| 11632 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11633 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11634 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 11635 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 11636 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
| 11637 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, |
| 11638 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) |
| 11639 | return -EINVAL; |
| 11640 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11641 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 11642 | setup.beacon_interval = |
| 11643 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11644 | |
Purushottam Kushwaha | 0c317a0 | 2016-10-12 18:26:51 +0530 | [diff] [blame] | 11645 | err = cfg80211_validate_beacon_int(rdev, |
| 11646 | NL80211_IFTYPE_MESH_POINT, |
| 11647 | setup.beacon_interval); |
Purushottam Kushwaha | 12d20fc9 | 2016-08-11 15:14:02 +0530 | [diff] [blame] | 11648 | if (err) |
| 11649 | return err; |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 11650 | } |
| 11651 | |
| 11652 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 11653 | setup.dtim_period = |
| 11654 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 11655 | if (setup.dtim_period < 1 || setup.dtim_period > 100) |
| 11656 | return -EINVAL; |
| 11657 | } |
| 11658 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 11659 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
| 11660 | /* parse additional setup parameters if given */ |
| 11661 | err = nl80211_parse_mesh_setup(info, &setup); |
| 11662 | if (err) |
| 11663 | return err; |
| 11664 | } |
| 11665 | |
Thomas Pedersen | d37bb18 | 2013-03-04 13:06:13 -0800 | [diff] [blame] | 11666 | if (setup.user_mpm) |
| 11667 | cfg.auto_open_plinks = false; |
| 11668 | |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11669 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11670 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
| 11671 | if (err) |
| 11672 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11673 | } else { |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11674 | /* __cfg80211_join_mesh() will sort it out */ |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 11675 | setup.chandef.chan = NULL; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 11676 | } |
| 11677 | |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 11678 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 11679 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11680 | int n_rates = |
| 11681 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 11682 | struct ieee80211_supported_band *sband; |
| 11683 | |
| 11684 | if (!setup.chandef.chan) |
| 11685 | return -EINVAL; |
| 11686 | |
| 11687 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; |
| 11688 | |
| 11689 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
| 11690 | &setup.basic_rates); |
| 11691 | if (err) |
| 11692 | return err; |
| 11693 | } |
| 11694 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11695 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 11696 | err = nl80211_parse_tx_bitrate_mask(info, info->attrs, |
| 11697 | NL80211_ATTR_TX_RATES, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 11698 | &setup.beacon_rate, |
| 11699 | dev); |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11700 | if (err) |
| 11701 | return err; |
| 11702 | |
Johannes Berg | 265698d | 2017-09-18 22:46:36 +0200 | [diff] [blame] | 11703 | if (!setup.chandef.chan) |
| 11704 | return -EINVAL; |
| 11705 | |
Johannes Berg | 8564e38 | 2016-09-19 09:44:44 +0200 | [diff] [blame] | 11706 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
| 11707 | &setup.beacon_rate); |
| 11708 | if (err) |
| 11709 | return err; |
| 11710 | } |
| 11711 | |
Benjamin Berg | d37d49c | 2017-05-16 11:23:11 +0200 | [diff] [blame] | 11712 | setup.userspace_handles_dfs = |
| 11713 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); |
| 11714 | |
Denis Kenzior | 1224f58 | 2018-03-26 12:52:49 -0500 | [diff] [blame] | 11715 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) { |
| 11716 | int r = validate_pae_over_nl80211(rdev, info); |
| 11717 | |
| 11718 | if (r < 0) |
| 11719 | return r; |
| 11720 | |
| 11721 | setup.control_port_over_nl80211 = true; |
| 11722 | } |
| 11723 | |
Denis Kenzior | 188c1b3 | 2018-03-26 12:52:46 -0500 | [diff] [blame] | 11724 | wdev_lock(dev->ieee80211_ptr); |
| 11725 | err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
| 11726 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
| 11727 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; |
| 11728 | wdev_unlock(dev->ieee80211_ptr); |
| 11729 | |
| 11730 | return err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 11731 | } |
| 11732 | |
| 11733 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) |
| 11734 | { |
| 11735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11736 | struct net_device *dev = info->user_ptr[1]; |
| 11737 | |
| 11738 | return cfg80211_leave_mesh(rdev, dev); |
| 11739 | } |
| 11740 | |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 11741 | #ifdef CONFIG_PM |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11742 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
| 11743 | struct cfg80211_registered_device *rdev) |
| 11744 | { |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11745 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11746 | struct nlattr *nl_pats, *nl_pat; |
| 11747 | int i, pat_len; |
| 11748 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11749 | if (!wowlan->n_patterns) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11750 | return 0; |
| 11751 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11752 | nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11753 | if (!nl_pats) |
| 11754 | return -ENOBUFS; |
| 11755 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11756 | for (i = 0; i < wowlan->n_patterns; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11757 | nl_pat = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11758 | if (!nl_pat) |
| 11759 | return -ENOBUFS; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11760 | pat_len = wowlan->patterns[i].pattern_len; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11761 | 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] | 11762 | wowlan->patterns[i].mask) || |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 11763 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 11764 | wowlan->patterns[i].pattern) || |
| 11765 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11766 | wowlan->patterns[i].pkt_offset)) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11767 | return -ENOBUFS; |
| 11768 | nla_nest_end(msg, nl_pat); |
| 11769 | } |
| 11770 | nla_nest_end(msg, nl_pats); |
| 11771 | |
| 11772 | return 0; |
| 11773 | } |
| 11774 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11775 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
| 11776 | struct cfg80211_wowlan_tcp *tcp) |
| 11777 | { |
| 11778 | struct nlattr *nl_tcp; |
| 11779 | |
| 11780 | if (!tcp) |
| 11781 | return 0; |
| 11782 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11783 | nl_tcp = nla_nest_start_noflag(msg, |
| 11784 | NL80211_WOWLAN_TRIG_TCP_CONNECTION); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11785 | if (!nl_tcp) |
| 11786 | return -ENOBUFS; |
| 11787 | |
Jiri Benc | 930345e | 2015-03-29 16:59:25 +0200 | [diff] [blame] | 11788 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
| 11789 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11790 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
| 11791 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || |
| 11792 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || |
| 11793 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, |
| 11794 | tcp->payload_len, tcp->payload) || |
| 11795 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, |
| 11796 | tcp->data_interval) || |
| 11797 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, |
| 11798 | tcp->wake_len, tcp->wake_data) || |
| 11799 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, |
| 11800 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) |
| 11801 | return -ENOBUFS; |
| 11802 | |
| 11803 | if (tcp->payload_seq.len && |
| 11804 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, |
| 11805 | sizeof(tcp->payload_seq), &tcp->payload_seq)) |
| 11806 | return -ENOBUFS; |
| 11807 | |
| 11808 | if (tcp->payload_tok.len && |
| 11809 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, |
| 11810 | sizeof(tcp->payload_tok) + tcp->tokens_size, |
| 11811 | &tcp->payload_tok)) |
| 11812 | return -ENOBUFS; |
| 11813 | |
Johannes Berg | e248ad3 | 2013-05-16 10:24:28 +0200 | [diff] [blame] | 11814 | nla_nest_end(msg, nl_tcp); |
| 11815 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11816 | return 0; |
| 11817 | } |
| 11818 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11819 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
| 11820 | struct cfg80211_sched_scan_request *req) |
| 11821 | { |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11822 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11823 | int i; |
| 11824 | |
| 11825 | if (!req) |
| 11826 | return 0; |
| 11827 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11828 | nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11829 | if (!nd) |
| 11830 | return -ENOBUFS; |
| 11831 | |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11832 | if (req->n_scan_plans == 1 && |
| 11833 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, |
| 11834 | req->scan_plans[0].interval * 1000)) |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11835 | return -ENOBUFS; |
| 11836 | |
Luciano Coelho | 21fea56 | 2015-03-17 16:36:01 +0200 | [diff] [blame] | 11837 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
| 11838 | return -ENOBUFS; |
| 11839 | |
vamsi krishna | bf95ecd | 2017-01-13 01:12:20 +0200 | [diff] [blame] | 11840 | if (req->relative_rssi_set) { |
| 11841 | struct nl80211_bss_select_rssi_adjust rssi_adjust; |
| 11842 | |
| 11843 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, |
| 11844 | req->relative_rssi)) |
| 11845 | return -ENOBUFS; |
| 11846 | |
| 11847 | rssi_adjust.band = req->rssi_adjust.band; |
| 11848 | rssi_adjust.delta = req->rssi_adjust.delta; |
| 11849 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, |
| 11850 | sizeof(rssi_adjust), &rssi_adjust)) |
| 11851 | return -ENOBUFS; |
| 11852 | } |
| 11853 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11854 | freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11855 | if (!freqs) |
| 11856 | return -ENOBUFS; |
| 11857 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11858 | for (i = 0; i < req->n_channels; i++) { |
| 11859 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 11860 | return -ENOBUFS; |
| 11861 | } |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11862 | |
| 11863 | nla_nest_end(msg, freqs); |
| 11864 | |
| 11865 | if (req->n_match_sets) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11866 | matches = nla_nest_start_noflag(msg, |
| 11867 | NL80211_ATTR_SCHED_SCAN_MATCH); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11868 | if (!matches) |
| 11869 | return -ENOBUFS; |
| 11870 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11871 | for (i = 0; i < req->n_match_sets; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11872 | match = nla_nest_start_noflag(msg, i); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11873 | if (!match) |
| 11874 | return -ENOBUFS; |
| 11875 | |
Johannes Berg | 53b1898 | 2016-09-14 09:59:21 +0200 | [diff] [blame] | 11876 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
| 11877 | req->match_sets[i].ssid.ssid_len, |
| 11878 | req->match_sets[i].ssid.ssid)) |
| 11879 | return -ENOBUFS; |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11880 | nla_nest_end(msg, match); |
| 11881 | } |
| 11882 | nla_nest_end(msg, matches); |
| 11883 | } |
| 11884 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11885 | scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11886 | if (!scan_plans) |
| 11887 | return -ENOBUFS; |
| 11888 | |
| 11889 | for (i = 0; i < req->n_scan_plans; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11890 | scan_plan = nla_nest_start_noflag(msg, i + 1); |
Johannes Berg | 76e1fb4 | 2016-09-14 09:55:57 +0200 | [diff] [blame] | 11891 | if (!scan_plan) |
| 11892 | return -ENOBUFS; |
| 11893 | |
Colin Ian King | 6762696 | 2018-09-06 10:58:44 +0100 | [diff] [blame] | 11894 | if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, |
Avraham Stern | 3b06d27 | 2015-10-12 09:51:34 +0300 | [diff] [blame] | 11895 | req->scan_plans[i].interval) || |
| 11896 | (req->scan_plans[i].iterations && |
| 11897 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, |
| 11898 | req->scan_plans[i].iterations))) |
| 11899 | return -ENOBUFS; |
| 11900 | nla_nest_end(msg, scan_plan); |
| 11901 | } |
| 11902 | nla_nest_end(msg, scan_plans); |
| 11903 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11904 | nla_nest_end(msg, nd); |
| 11905 | |
| 11906 | return 0; |
| 11907 | } |
| 11908 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11909 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 11910 | { |
| 11911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 11912 | struct sk_buff *msg; |
| 11913 | void *hdr; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11914 | u32 size = NLMSG_DEFAULT_SIZE; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11915 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11916 | if (!rdev->wiphy.wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11917 | return -EOPNOTSUPP; |
| 11918 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11919 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11920 | /* adjust size to have room for all the data */ |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11921 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
| 11922 | rdev->wiphy.wowlan_config->tcp->payload_len + |
| 11923 | rdev->wiphy.wowlan_config->tcp->wake_len + |
| 11924 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11925 | } |
| 11926 | |
| 11927 | msg = nlmsg_new(size, GFP_KERNEL); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11928 | if (!msg) |
| 11929 | return -ENOMEM; |
| 11930 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 11931 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11932 | NL80211_CMD_GET_WOWLAN); |
| 11933 | if (!hdr) |
| 11934 | goto nla_put_failure; |
| 11935 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11936 | if (rdev->wiphy.wowlan_config) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11937 | struct nlattr *nl_wowlan; |
| 11938 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 11939 | nl_wowlan = nla_nest_start_noflag(msg, |
| 11940 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11941 | if (!nl_wowlan) |
| 11942 | goto nla_put_failure; |
| 11943 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11944 | if ((rdev->wiphy.wowlan_config->any && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11945 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11946 | (rdev->wiphy.wowlan_config->disconnect && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11947 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11948 | (rdev->wiphy.wowlan_config->magic_pkt && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11949 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11950 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11951 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11952 | (rdev->wiphy.wowlan_config->eap_identity_req && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11953 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11954 | (rdev->wiphy.wowlan_config->four_way_handshake && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11955 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11956 | (rdev->wiphy.wowlan_config->rfkill_release && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 11957 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
| 11958 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11959 | |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 11960 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
| 11961 | goto nla_put_failure; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11962 | |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 11963 | if (nl80211_send_wowlan_tcp(msg, |
| 11964 | rdev->wiphy.wowlan_config->tcp)) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11965 | goto nla_put_failure; |
| 11966 | |
Luciano Coelho | 75453cc | 2015-01-09 14:06:37 +0200 | [diff] [blame] | 11967 | if (nl80211_send_wowlan_nd( |
| 11968 | msg, |
| 11969 | rdev->wiphy.wowlan_config->nd_config)) |
| 11970 | goto nla_put_failure; |
| 11971 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 11972 | nla_nest_end(msg, nl_wowlan); |
| 11973 | } |
| 11974 | |
| 11975 | genlmsg_end(msg, hdr); |
| 11976 | return genlmsg_reply(msg, info); |
| 11977 | |
| 11978 | nla_put_failure: |
| 11979 | nlmsg_free(msg); |
| 11980 | return -ENOBUFS; |
| 11981 | } |
| 11982 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11983 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
| 11984 | struct nlattr *attr, |
| 11985 | struct cfg80211_wowlan *trig) |
| 11986 | { |
| 11987 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; |
| 11988 | struct cfg80211_wowlan_tcp *cfg; |
| 11989 | struct nl80211_wowlan_tcp_data_token *tok = NULL; |
| 11990 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; |
| 11991 | u32 size; |
| 11992 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; |
| 11993 | int err, port; |
| 11994 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 11995 | if (!rdev->wiphy.wowlan->tcp) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 11996 | return -EINVAL; |
| 11997 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 11998 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr, |
| 11999 | nl80211_wowlan_tcp_policy, NULL); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12000 | if (err) |
| 12001 | return err; |
| 12002 | |
| 12003 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || |
| 12004 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || |
| 12005 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || |
| 12006 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || |
| 12007 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || |
| 12008 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || |
| 12009 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || |
| 12010 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) |
| 12011 | return -EINVAL; |
| 12012 | |
| 12013 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12014 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12015 | return -EINVAL; |
| 12016 | |
| 12017 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12018 | rdev->wiphy.wowlan->tcp->data_interval_max || |
Johannes Berg | 723d568 | 2013-02-26 13:56:40 +0100 | [diff] [blame] | 12019 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12020 | return -EINVAL; |
| 12021 | |
| 12022 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12023 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12024 | return -EINVAL; |
| 12025 | |
| 12026 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); |
| 12027 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) |
| 12028 | return -EINVAL; |
| 12029 | |
| 12030 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { |
| 12031 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 12032 | |
| 12033 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); |
| 12034 | tokens_size = tokln - sizeof(*tok); |
| 12035 | |
| 12036 | if (!tok->len || tokens_size % tok->len) |
| 12037 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12038 | if (!rdev->wiphy.wowlan->tcp->tok) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12039 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12040 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12041 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12042 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12043 | return -EINVAL; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12044 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12045 | return -EINVAL; |
| 12046 | if (tok->offset + tok->len > data_size) |
| 12047 | return -EINVAL; |
| 12048 | } |
| 12049 | |
| 12050 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { |
| 12051 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12052 | if (!rdev->wiphy.wowlan->tcp->seq) |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12053 | return -EINVAL; |
| 12054 | if (seq->len == 0 || seq->len > 4) |
| 12055 | return -EINVAL; |
| 12056 | if (seq->len + seq->offset > data_size) |
| 12057 | return -EINVAL; |
| 12058 | } |
| 12059 | |
| 12060 | size = sizeof(*cfg); |
| 12061 | size += data_size; |
| 12062 | size += wake_size + wake_mask_size; |
| 12063 | size += tokens_size; |
| 12064 | |
| 12065 | cfg = kzalloc(size, GFP_KERNEL); |
| 12066 | if (!cfg) |
| 12067 | return -ENOMEM; |
Jiri Benc | 67b61f6 | 2015-03-29 16:59:26 +0200 | [diff] [blame] | 12068 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
| 12069 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12070 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
| 12071 | ETH_ALEN); |
| 12072 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) |
| 12073 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); |
| 12074 | else |
| 12075 | port = 0; |
| 12076 | #ifdef CONFIG_INET |
| 12077 | /* allocate a socket and port for it and use it */ |
| 12078 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, |
| 12079 | IPPROTO_TCP, &cfg->sock, 1); |
| 12080 | if (err) { |
| 12081 | kfree(cfg); |
| 12082 | return err; |
| 12083 | } |
| 12084 | if (inet_csk_get_port(cfg->sock->sk, port)) { |
| 12085 | sock_release(cfg->sock); |
| 12086 | kfree(cfg); |
| 12087 | return -EADDRINUSE; |
| 12088 | } |
| 12089 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; |
| 12090 | #else |
| 12091 | if (!port) { |
| 12092 | kfree(cfg); |
| 12093 | return -EINVAL; |
| 12094 | } |
| 12095 | cfg->src_port = port; |
| 12096 | #endif |
| 12097 | |
| 12098 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); |
| 12099 | cfg->payload_len = data_size; |
| 12100 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; |
| 12101 | memcpy((void *)cfg->payload, |
| 12102 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), |
| 12103 | data_size); |
| 12104 | if (seq) |
| 12105 | cfg->payload_seq = *seq; |
| 12106 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); |
| 12107 | cfg->wake_len = wake_size; |
| 12108 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; |
| 12109 | memcpy((void *)cfg->wake_data, |
| 12110 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), |
| 12111 | wake_size); |
| 12112 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + |
| 12113 | data_size + wake_size; |
| 12114 | memcpy((void *)cfg->wake_mask, |
| 12115 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), |
| 12116 | wake_mask_size); |
| 12117 | if (tok) { |
| 12118 | cfg->tokens_size = tokens_size; |
| 12119 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); |
| 12120 | } |
| 12121 | |
| 12122 | trig->tcp = cfg; |
| 12123 | |
| 12124 | return 0; |
| 12125 | } |
| 12126 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12127 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
| 12128 | const struct wiphy_wowlan_support *wowlan, |
| 12129 | struct nlattr *attr, |
| 12130 | struct cfg80211_wowlan *trig) |
| 12131 | { |
| 12132 | struct nlattr **tb; |
| 12133 | int err; |
| 12134 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 12135 | tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12136 | if (!tb) |
| 12137 | return -ENOMEM; |
| 12138 | |
| 12139 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { |
| 12140 | err = -EOPNOTSUPP; |
| 12141 | goto out; |
| 12142 | } |
| 12143 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12144 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr, |
| 12145 | nl80211_policy, NULL); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12146 | if (err) |
| 12147 | goto out; |
| 12148 | |
Arend Van Spriel | aad1e81 | 2017-01-27 12:27:44 +0000 | [diff] [blame] | 12149 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
| 12150 | wowlan->max_nd_match_sets); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12151 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
| 12152 | if (err) |
| 12153 | trig->nd_config = NULL; |
| 12154 | |
| 12155 | out: |
| 12156 | kfree(tb); |
| 12157 | return err; |
| 12158 | } |
| 12159 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12160 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
| 12161 | { |
| 12162 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12163 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12164 | struct cfg80211_wowlan new_triggers = {}; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12165 | struct cfg80211_wowlan *ntrig; |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12166 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12167 | int err, i; |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12168 | bool prev_enabled = rdev->wiphy.wowlan_config; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12169 | bool regular = false; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12170 | |
Johannes Berg | 964dc9e | 2013-06-03 17:25:34 +0200 | [diff] [blame] | 12171 | if (!wowlan) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12172 | return -EOPNOTSUPP; |
| 12173 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12174 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
| 12175 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12176 | rdev->wiphy.wowlan_config = NULL; |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12177 | goto set_wakeup; |
| 12178 | } |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12179 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12180 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG, |
| 12181 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], |
| 12182 | nl80211_wowlan_policy, info->extack); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12183 | if (err) |
| 12184 | return err; |
| 12185 | |
| 12186 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { |
| 12187 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) |
| 12188 | return -EINVAL; |
| 12189 | new_triggers.any = true; |
| 12190 | } |
| 12191 | |
| 12192 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { |
| 12193 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) |
| 12194 | return -EINVAL; |
| 12195 | new_triggers.disconnect = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12196 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12197 | } |
| 12198 | |
| 12199 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { |
| 12200 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) |
| 12201 | return -EINVAL; |
| 12202 | new_triggers.magic_pkt = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12203 | regular = true; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12204 | } |
| 12205 | |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12206 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
| 12207 | return -EINVAL; |
| 12208 | |
| 12209 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { |
| 12210 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) |
| 12211 | return -EINVAL; |
| 12212 | new_triggers.gtk_rekey_failure = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12213 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12214 | } |
| 12215 | |
| 12216 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { |
| 12217 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) |
| 12218 | return -EINVAL; |
| 12219 | new_triggers.eap_identity_req = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12220 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12221 | } |
| 12222 | |
| 12223 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { |
| 12224 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) |
| 12225 | return -EINVAL; |
| 12226 | new_triggers.four_way_handshake = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12227 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12228 | } |
| 12229 | |
| 12230 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { |
| 12231 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) |
| 12232 | return -EINVAL; |
| 12233 | new_triggers.rfkill_release = true; |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12234 | regular = true; |
Johannes Berg | 77dbbb1 | 2011-07-13 10:48:55 +0200 | [diff] [blame] | 12235 | } |
| 12236 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12237 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
| 12238 | struct nlattr *pat; |
| 12239 | int n_patterns = 0; |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12240 | int rem, pat_len, mask_len, pkt_offset; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12241 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12242 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12243 | regular = true; |
| 12244 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12245 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12246 | rem) |
| 12247 | n_patterns++; |
| 12248 | if (n_patterns > wowlan->n_patterns) |
| 12249 | return -EINVAL; |
| 12250 | |
| 12251 | new_triggers.patterns = kcalloc(n_patterns, |
| 12252 | sizeof(new_triggers.patterns[0]), |
| 12253 | GFP_KERNEL); |
| 12254 | if (!new_triggers.patterns) |
| 12255 | return -ENOMEM; |
| 12256 | |
| 12257 | new_triggers.n_patterns = n_patterns; |
| 12258 | i = 0; |
| 12259 | |
| 12260 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
| 12261 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12262 | u8 *mask_pat; |
| 12263 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12264 | err = nla_parse_nested_deprecated(pat_tb, |
| 12265 | MAX_NL80211_PKTPAT, |
| 12266 | pat, |
| 12267 | nl80211_packet_pattern_policy, |
| 12268 | info->extack); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12269 | if (err) |
| 12270 | goto error; |
| 12271 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12272 | err = -EINVAL; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12273 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12274 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12275 | goto error; |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12276 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12277 | mask_len = DIV_ROUND_UP(pat_len, 8); |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12278 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12279 | goto error; |
| 12280 | if (pat_len > wowlan->pattern_max_len || |
| 12281 | pat_len < wowlan->pattern_min_len) |
| 12282 | goto error; |
| 12283 | |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12284 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12285 | pkt_offset = 0; |
| 12286 | else |
| 12287 | pkt_offset = nla_get_u32( |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12288 | pat_tb[NL80211_PKTPAT_OFFSET]); |
Amitkumar Karwar | bb92d19 | 2013-02-12 12:16:26 -0800 | [diff] [blame] | 12289 | if (pkt_offset > wowlan->max_pkt_offset) |
| 12290 | goto error; |
| 12291 | new_triggers.patterns[i].pkt_offset = pkt_offset; |
| 12292 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12293 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12294 | if (!mask_pat) { |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12295 | err = -ENOMEM; |
| 12296 | goto error; |
| 12297 | } |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12298 | new_triggers.patterns[i].mask = mask_pat; |
| 12299 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12300 | mask_len); |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12301 | mask_pat += mask_len; |
| 12302 | new_triggers.patterns[i].pattern = mask_pat; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12303 | new_triggers.patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12304 | memcpy(mask_pat, |
Amitkumar Karwar | 50ac660 | 2013-06-25 19:03:56 -0700 | [diff] [blame] | 12305 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12306 | pat_len); |
| 12307 | i++; |
| 12308 | } |
| 12309 | } |
| 12310 | |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12311 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12312 | regular = true; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12313 | err = nl80211_parse_wowlan_tcp( |
| 12314 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], |
| 12315 | &new_triggers); |
| 12316 | if (err) |
| 12317 | goto error; |
| 12318 | } |
| 12319 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12320 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12321 | regular = true; |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 12322 | err = nl80211_parse_wowlan_nd( |
| 12323 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], |
| 12324 | &new_triggers); |
| 12325 | if (err) |
| 12326 | goto error; |
| 12327 | } |
| 12328 | |
Johannes Berg | 98fc438 | 2015-03-01 09:10:13 +0200 | [diff] [blame] | 12329 | /* The 'any' trigger means the device continues operating more or less |
| 12330 | * as in its normal operation mode and wakes up the host on most of the |
| 12331 | * normal interrupts (like packet RX, ...) |
| 12332 | * It therefore makes little sense to combine with the more constrained |
| 12333 | * wakeup trigger modes. |
| 12334 | */ |
| 12335 | if (new_triggers.any && regular) { |
| 12336 | err = -EINVAL; |
| 12337 | goto error; |
| 12338 | } |
| 12339 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12340 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
| 12341 | if (!ntrig) { |
| 12342 | err = -ENOMEM; |
| 12343 | goto error; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12344 | } |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12345 | cfg80211_rdev_free_wowlan(rdev); |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12346 | rdev->wiphy.wowlan_config = ntrig; |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12347 | |
Johannes Berg | ae33bd8 | 2012-07-12 16:25:02 +0200 | [diff] [blame] | 12348 | set_wakeup: |
Johannes Berg | 6abb9cb | 2013-05-15 09:30:07 +0200 | [diff] [blame] | 12349 | if (rdev->ops->set_wakeup && |
| 12350 | prev_enabled != !!rdev->wiphy.wowlan_config) |
| 12351 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 12352 | |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12353 | return 0; |
| 12354 | error: |
| 12355 | for (i = 0; i < new_triggers.n_patterns; i++) |
| 12356 | kfree(new_triggers.patterns[i].mask); |
| 12357 | kfree(new_triggers.patterns); |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 12358 | if (new_triggers.tcp && new_triggers.tcp->sock) |
| 12359 | sock_release(new_triggers.tcp->sock); |
| 12360 | kfree(new_triggers.tcp); |
Ola Olsson | e5dbe07 | 2015-12-12 23:17:17 +0100 | [diff] [blame] | 12361 | kfree(new_triggers.nd_config); |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12362 | return err; |
| 12363 | } |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 12364 | #endif |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 12365 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12366 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
| 12367 | struct cfg80211_registered_device *rdev) |
| 12368 | { |
| 12369 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; |
| 12370 | int i, j, pat_len; |
| 12371 | struct cfg80211_coalesce_rules *rule; |
| 12372 | |
| 12373 | if (!rdev->coalesce->n_rules) |
| 12374 | return 0; |
| 12375 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12376 | nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12377 | if (!nl_rules) |
| 12378 | return -ENOBUFS; |
| 12379 | |
| 12380 | for (i = 0; i < rdev->coalesce->n_rules; i++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12381 | nl_rule = nla_nest_start_noflag(msg, i + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12382 | if (!nl_rule) |
| 12383 | return -ENOBUFS; |
| 12384 | |
| 12385 | rule = &rdev->coalesce->rules[i]; |
| 12386 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, |
| 12387 | rule->delay)) |
| 12388 | return -ENOBUFS; |
| 12389 | |
| 12390 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, |
| 12391 | rule->condition)) |
| 12392 | return -ENOBUFS; |
| 12393 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12394 | nl_pats = nla_nest_start_noflag(msg, |
| 12395 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12396 | if (!nl_pats) |
| 12397 | return -ENOBUFS; |
| 12398 | |
| 12399 | for (j = 0; j < rule->n_patterns; j++) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 12400 | nl_pat = nla_nest_start_noflag(msg, j + 1); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12401 | if (!nl_pat) |
| 12402 | return -ENOBUFS; |
| 12403 | pat_len = rule->patterns[j].pattern_len; |
| 12404 | if (nla_put(msg, NL80211_PKTPAT_MASK, |
| 12405 | DIV_ROUND_UP(pat_len, 8), |
| 12406 | rule->patterns[j].mask) || |
| 12407 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
| 12408 | rule->patterns[j].pattern) || |
| 12409 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, |
| 12410 | rule->patterns[j].pkt_offset)) |
| 12411 | return -ENOBUFS; |
| 12412 | nla_nest_end(msg, nl_pat); |
| 12413 | } |
| 12414 | nla_nest_end(msg, nl_pats); |
| 12415 | nla_nest_end(msg, nl_rule); |
| 12416 | } |
| 12417 | nla_nest_end(msg, nl_rules); |
| 12418 | |
| 12419 | return 0; |
| 12420 | } |
| 12421 | |
| 12422 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12423 | { |
| 12424 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12425 | struct sk_buff *msg; |
| 12426 | void *hdr; |
| 12427 | |
| 12428 | if (!rdev->wiphy.coalesce) |
| 12429 | return -EOPNOTSUPP; |
| 12430 | |
| 12431 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12432 | if (!msg) |
| 12433 | return -ENOMEM; |
| 12434 | |
| 12435 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 12436 | NL80211_CMD_GET_COALESCE); |
| 12437 | if (!hdr) |
| 12438 | goto nla_put_failure; |
| 12439 | |
| 12440 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) |
| 12441 | goto nla_put_failure; |
| 12442 | |
| 12443 | genlmsg_end(msg, hdr); |
| 12444 | return genlmsg_reply(msg, info); |
| 12445 | |
| 12446 | nla_put_failure: |
| 12447 | nlmsg_free(msg); |
| 12448 | return -ENOBUFS; |
| 12449 | } |
| 12450 | |
| 12451 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) |
| 12452 | { |
| 12453 | struct cfg80211_coalesce *coalesce = rdev->coalesce; |
| 12454 | int i, j; |
| 12455 | struct cfg80211_coalesce_rules *rule; |
| 12456 | |
| 12457 | if (!coalesce) |
| 12458 | return; |
| 12459 | |
| 12460 | for (i = 0; i < coalesce->n_rules; i++) { |
| 12461 | rule = &coalesce->rules[i]; |
| 12462 | for (j = 0; j < rule->n_patterns; j++) |
| 12463 | kfree(rule->patterns[j].mask); |
| 12464 | kfree(rule->patterns); |
| 12465 | } |
| 12466 | kfree(coalesce->rules); |
| 12467 | kfree(coalesce); |
| 12468 | rdev->coalesce = NULL; |
| 12469 | } |
| 12470 | |
| 12471 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, |
| 12472 | struct nlattr *rule, |
| 12473 | struct cfg80211_coalesce_rules *new_rule) |
| 12474 | { |
| 12475 | int err, i; |
| 12476 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12477 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; |
| 12478 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; |
| 12479 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
| 12480 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12481 | err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX, |
| 12482 | rule, nl80211_coalesce_policy, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12483 | if (err) |
| 12484 | return err; |
| 12485 | |
| 12486 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) |
| 12487 | new_rule->delay = |
| 12488 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); |
| 12489 | if (new_rule->delay > coalesce->max_delay) |
| 12490 | return -EINVAL; |
| 12491 | |
| 12492 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) |
| 12493 | new_rule->condition = |
| 12494 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12495 | |
| 12496 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) |
| 12497 | return -EINVAL; |
| 12498 | |
| 12499 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12500 | rem) |
| 12501 | n_patterns++; |
| 12502 | if (n_patterns > coalesce->n_patterns) |
| 12503 | return -EINVAL; |
| 12504 | |
| 12505 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), |
| 12506 | GFP_KERNEL); |
| 12507 | if (!new_rule->patterns) |
| 12508 | return -ENOMEM; |
| 12509 | |
| 12510 | new_rule->n_patterns = n_patterns; |
| 12511 | i = 0; |
| 12512 | |
| 12513 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], |
| 12514 | rem) { |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12515 | u8 *mask_pat; |
| 12516 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12517 | err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT, |
| 12518 | pat, |
| 12519 | nl80211_packet_pattern_policy, |
| 12520 | NULL); |
Johannes Berg | 95bca62 | 2018-06-29 09:33:39 +0200 | [diff] [blame] | 12521 | if (err) |
| 12522 | return err; |
| 12523 | |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12524 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
| 12525 | !pat_tb[NL80211_PKTPAT_PATTERN]) |
| 12526 | return -EINVAL; |
| 12527 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
| 12528 | mask_len = DIV_ROUND_UP(pat_len, 8); |
| 12529 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
| 12530 | return -EINVAL; |
| 12531 | if (pat_len > coalesce->pattern_max_len || |
| 12532 | pat_len < coalesce->pattern_min_len) |
| 12533 | return -EINVAL; |
| 12534 | |
| 12535 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
| 12536 | pkt_offset = 0; |
| 12537 | else |
| 12538 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); |
| 12539 | if (pkt_offset > coalesce->max_pkt_offset) |
| 12540 | return -EINVAL; |
| 12541 | new_rule->patterns[i].pkt_offset = pkt_offset; |
| 12542 | |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12543 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
| 12544 | if (!mask_pat) |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12545 | return -ENOMEM; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12546 | |
| 12547 | new_rule->patterns[i].mask = mask_pat; |
| 12548 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), |
| 12549 | mask_len); |
| 12550 | |
| 12551 | mask_pat += mask_len; |
| 12552 | new_rule->patterns[i].pattern = mask_pat; |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12553 | new_rule->patterns[i].pattern_len = pat_len; |
Johannes Berg | 922bd80 | 2014-05-19 17:59:50 +0200 | [diff] [blame] | 12554 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
| 12555 | pat_len); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12556 | i++; |
| 12557 | } |
| 12558 | |
| 12559 | return 0; |
| 12560 | } |
| 12561 | |
| 12562 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) |
| 12563 | { |
| 12564 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12565 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; |
| 12566 | struct cfg80211_coalesce new_coalesce = {}; |
| 12567 | struct cfg80211_coalesce *n_coalesce; |
| 12568 | int err, rem_rule, n_rules = 0, i, j; |
| 12569 | struct nlattr *rule; |
| 12570 | struct cfg80211_coalesce_rules *tmp_rule; |
| 12571 | |
| 12572 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) |
| 12573 | return -EOPNOTSUPP; |
| 12574 | |
| 12575 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { |
| 12576 | cfg80211_rdev_free_coalesce(rdev); |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12577 | rdev_set_coalesce(rdev, NULL); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12578 | return 0; |
| 12579 | } |
| 12580 | |
| 12581 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12582 | rem_rule) |
| 12583 | n_rules++; |
| 12584 | if (n_rules > coalesce->n_rules) |
| 12585 | return -EINVAL; |
| 12586 | |
| 12587 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), |
| 12588 | GFP_KERNEL); |
| 12589 | if (!new_coalesce.rules) |
| 12590 | return -ENOMEM; |
| 12591 | |
| 12592 | new_coalesce.n_rules = n_rules; |
| 12593 | i = 0; |
| 12594 | |
| 12595 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], |
| 12596 | rem_rule) { |
| 12597 | err = nl80211_parse_coalesce_rule(rdev, rule, |
| 12598 | &new_coalesce.rules[i]); |
| 12599 | if (err) |
| 12600 | goto error; |
| 12601 | |
| 12602 | i++; |
| 12603 | } |
| 12604 | |
Ilan Peer | a1056b1b | 2015-10-22 22:27:46 +0300 | [diff] [blame] | 12605 | err = rdev_set_coalesce(rdev, &new_coalesce); |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 12606 | if (err) |
| 12607 | goto error; |
| 12608 | |
| 12609 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); |
| 12610 | if (!n_coalesce) { |
| 12611 | err = -ENOMEM; |
| 12612 | goto error; |
| 12613 | } |
| 12614 | cfg80211_rdev_free_coalesce(rdev); |
| 12615 | rdev->coalesce = n_coalesce; |
| 12616 | |
| 12617 | return 0; |
| 12618 | error: |
| 12619 | for (i = 0; i < new_coalesce.n_rules; i++) { |
| 12620 | tmp_rule = &new_coalesce.rules[i]; |
| 12621 | for (j = 0; j < tmp_rule->n_patterns; j++) |
| 12622 | kfree(tmp_rule->patterns[j].mask); |
| 12623 | kfree(tmp_rule->patterns); |
| 12624 | } |
| 12625 | kfree(new_coalesce.rules); |
| 12626 | |
| 12627 | return err; |
| 12628 | } |
| 12629 | |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12630 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
| 12631 | { |
| 12632 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12633 | struct net_device *dev = info->user_ptr[1]; |
| 12634 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12635 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; |
| 12636 | struct cfg80211_gtk_rekey_data rekey_data; |
| 12637 | int err; |
| 12638 | |
| 12639 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) |
| 12640 | return -EINVAL; |
| 12641 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12642 | err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA, |
| 12643 | info->attrs[NL80211_ATTR_REKEY_DATA], |
| 12644 | nl80211_rekey_policy, info->extack); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12645 | if (err) |
| 12646 | return err; |
| 12647 | |
Vladis Dronov | e785fa0 | 2017-09-13 00:21:21 +0200 | [diff] [blame] | 12648 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
| 12649 | !tb[NL80211_REKEY_DATA_KCK]) |
| 12650 | return -EINVAL; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12651 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN && |
| 12652 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12653 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12654 | return -ERANGE; |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12655 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN && |
| 12656 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK && |
| 12657 | nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN)) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12658 | return -ERANGE; |
| 12659 | |
Johannes Berg | 78f686c | 2014-09-10 22:28:06 +0300 | [diff] [blame] | 12660 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
| 12661 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); |
| 12662 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); |
Nathan Errera | 093a48d | 2020-05-28 21:22:38 +0200 | [diff] [blame] | 12663 | rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]); |
| 12664 | rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]); |
| 12665 | if (tb[NL80211_REKEY_DATA_AKM]) |
| 12666 | rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12667 | |
| 12668 | wdev_lock(wdev); |
| 12669 | if (!wdev->current_bss) { |
| 12670 | err = -ENOTCONN; |
| 12671 | goto out; |
| 12672 | } |
| 12673 | |
| 12674 | if (!rdev->ops->set_rekey_data) { |
| 12675 | err = -EOPNOTSUPP; |
| 12676 | goto out; |
| 12677 | } |
| 12678 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12679 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 12680 | out: |
| 12681 | wdev_unlock(wdev); |
| 12682 | return err; |
| 12683 | } |
| 12684 | |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12685 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
| 12686 | struct genl_info *info) |
| 12687 | { |
| 12688 | struct net_device *dev = info->user_ptr[1]; |
| 12689 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12690 | |
| 12691 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12692 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12693 | return -EINVAL; |
| 12694 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12695 | if (wdev->ap_unexpected_nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12696 | return -EBUSY; |
| 12697 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12698 | wdev->ap_unexpected_nlportid = info->snd_portid; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 12699 | return 0; |
| 12700 | } |
| 12701 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12702 | static int nl80211_probe_client(struct sk_buff *skb, |
| 12703 | struct genl_info *info) |
| 12704 | { |
| 12705 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12706 | struct net_device *dev = info->user_ptr[1]; |
| 12707 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 12708 | struct sk_buff *msg; |
| 12709 | void *hdr; |
| 12710 | const u8 *addr; |
| 12711 | u64 cookie; |
| 12712 | int err; |
| 12713 | |
| 12714 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 12715 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 12716 | return -EOPNOTSUPP; |
| 12717 | |
| 12718 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 12719 | return -EINVAL; |
| 12720 | |
| 12721 | if (!rdev->ops->probe_client) |
| 12722 | return -EOPNOTSUPP; |
| 12723 | |
| 12724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 12725 | if (!msg) |
| 12726 | return -ENOMEM; |
| 12727 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 12728 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12729 | NL80211_CMD_PROBE_CLIENT); |
Dan Carpenter | cb35fba | 2013-08-14 14:50:01 +0300 | [diff] [blame] | 12730 | if (!hdr) { |
| 12731 | err = -ENOBUFS; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12732 | goto free_msg; |
| 12733 | } |
| 12734 | |
| 12735 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 12736 | |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12737 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12738 | if (err) |
| 12739 | goto free_msg; |
| 12740 | |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 12741 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 12742 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 12743 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 12744 | |
| 12745 | genlmsg_end(msg, hdr); |
| 12746 | |
| 12747 | return genlmsg_reply(msg, info); |
| 12748 | |
| 12749 | nla_put_failure: |
| 12750 | err = -ENOBUFS; |
| 12751 | free_msg: |
| 12752 | nlmsg_free(msg); |
| 12753 | return err; |
| 12754 | } |
| 12755 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12756 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
| 12757 | { |
| 12758 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12759 | struct cfg80211_beacon_registration *reg, *nreg; |
| 12760 | int rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12761 | |
| 12762 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) |
| 12763 | return -EOPNOTSUPP; |
| 12764 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12765 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
| 12766 | if (!nreg) |
| 12767 | return -ENOMEM; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12768 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12769 | /* First, check if already registered. */ |
| 12770 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 12771 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 12772 | if (reg->nlportid == info->snd_portid) { |
| 12773 | rv = -EALREADY; |
| 12774 | goto out_err; |
| 12775 | } |
| 12776 | } |
| 12777 | /* Add it to the list */ |
| 12778 | nreg->nlportid = info->snd_portid; |
| 12779 | list_add(&nreg->list, &rdev->beacon_registrations); |
| 12780 | |
| 12781 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12782 | |
| 12783 | return 0; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 12784 | out_err: |
| 12785 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 12786 | kfree(nreg); |
| 12787 | return rv; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 12788 | } |
| 12789 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12790 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12791 | { |
| 12792 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12793 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12794 | int err; |
| 12795 | |
| 12796 | if (!rdev->ops->start_p2p_device) |
| 12797 | return -EOPNOTSUPP; |
| 12798 | |
| 12799 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12800 | return -EOPNOTSUPP; |
| 12801 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12802 | if (wdev_running(wdev)) |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12803 | return 0; |
| 12804 | |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 12805 | if (rfkill_blocked(rdev->rfkill)) |
| 12806 | return -ERFKILL; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12807 | |
Johannes Berg | eeb126e | 2012-10-23 15:16:50 +0200 | [diff] [blame] | 12808 | err = rdev_start_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12809 | if (err) |
| 12810 | return err; |
| 12811 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12812 | wdev->is_running = true; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12813 | rdev->opencount++; |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12814 | |
| 12815 | return 0; |
| 12816 | } |
| 12817 | |
| 12818 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) |
| 12819 | { |
| 12820 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12821 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12822 | |
| 12823 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) |
| 12824 | return -EOPNOTSUPP; |
| 12825 | |
| 12826 | if (!rdev->ops->stop_p2p_device) |
| 12827 | return -EOPNOTSUPP; |
| 12828 | |
Johannes Berg | f9f4752 | 2013-03-19 15:04:07 +0100 | [diff] [blame] | 12829 | cfg80211_stop_p2p_device(rdev, wdev); |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 12830 | |
| 12831 | return 0; |
| 12832 | } |
| 12833 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12834 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
| 12835 | { |
| 12836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12837 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12838 | struct cfg80211_nan_conf conf = {}; |
| 12839 | int err; |
| 12840 | |
| 12841 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12842 | return -EOPNOTSUPP; |
| 12843 | |
Johannes Berg | eeb04a9 | 2016-11-21 13:55:48 +0100 | [diff] [blame] | 12844 | if (wdev_running(wdev)) |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12845 | return -EEXIST; |
| 12846 | |
| 12847 | if (rfkill_blocked(rdev->rfkill)) |
| 12848 | return -ERFKILL; |
| 12849 | |
| 12850 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) |
| 12851 | return -EINVAL; |
| 12852 | |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12853 | conf.master_pref = |
| 12854 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12855 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 12856 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 12857 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 12858 | |
| 12859 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 12860 | return -EOPNOTSUPP; |
| 12861 | |
| 12862 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 12863 | return -EINVAL; |
| 12864 | |
| 12865 | conf.bands = bands; |
| 12866 | } |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12867 | |
| 12868 | err = rdev_start_nan(rdev, wdev, &conf); |
| 12869 | if (err) |
| 12870 | return err; |
| 12871 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12872 | wdev->is_running = true; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 12873 | rdev->opencount++; |
| 12874 | |
| 12875 | return 0; |
| 12876 | } |
| 12877 | |
| 12878 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) |
| 12879 | { |
| 12880 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12881 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12882 | |
| 12883 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12884 | return -EOPNOTSUPP; |
| 12885 | |
| 12886 | cfg80211_stop_nan(rdev, wdev); |
| 12887 | |
| 12888 | return 0; |
| 12889 | } |
| 12890 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12891 | static int validate_nan_filter(struct nlattr *filter_attr) |
| 12892 | { |
| 12893 | struct nlattr *attr; |
| 12894 | int len = 0, n_entries = 0, rem; |
| 12895 | |
| 12896 | nla_for_each_nested(attr, filter_attr, rem) { |
| 12897 | len += nla_len(attr); |
| 12898 | n_entries++; |
| 12899 | } |
| 12900 | |
| 12901 | if (len >= U8_MAX) |
| 12902 | return -EINVAL; |
| 12903 | |
| 12904 | return n_entries; |
| 12905 | } |
| 12906 | |
| 12907 | static int handle_nan_filter(struct nlattr *attr_filter, |
| 12908 | struct cfg80211_nan_func *func, |
| 12909 | bool tx) |
| 12910 | { |
| 12911 | struct nlattr *attr; |
| 12912 | int n_entries, rem, i; |
| 12913 | struct cfg80211_nan_func_filter *filter; |
| 12914 | |
| 12915 | n_entries = validate_nan_filter(attr_filter); |
| 12916 | if (n_entries < 0) |
| 12917 | return n_entries; |
| 12918 | |
| 12919 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); |
| 12920 | |
| 12921 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); |
| 12922 | if (!filter) |
| 12923 | return -ENOMEM; |
| 12924 | |
| 12925 | i = 0; |
| 12926 | nla_for_each_nested(attr, attr_filter, rem) { |
Thomas Graf | b15ca18 | 2016-10-26 10:53:16 +0200 | [diff] [blame] | 12927 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12928 | filter[i].len = nla_len(attr); |
| 12929 | i++; |
| 12930 | } |
| 12931 | if (tx) { |
| 12932 | func->num_tx_filters = n_entries; |
| 12933 | func->tx_filters = filter; |
| 12934 | } else { |
| 12935 | func->num_rx_filters = n_entries; |
| 12936 | func->rx_filters = filter; |
| 12937 | } |
| 12938 | |
| 12939 | return 0; |
| 12940 | } |
| 12941 | |
| 12942 | static int nl80211_nan_add_func(struct sk_buff *skb, |
| 12943 | struct genl_info *info) |
| 12944 | { |
| 12945 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 12946 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 12947 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; |
| 12948 | struct cfg80211_nan_func *func; |
| 12949 | struct sk_buff *msg = NULL; |
| 12950 | void *hdr = NULL; |
| 12951 | int err = 0; |
| 12952 | |
| 12953 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 12954 | return -EOPNOTSUPP; |
| 12955 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 12956 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12957 | return -ENOTCONN; |
| 12958 | |
| 12959 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) |
| 12960 | return -EINVAL; |
| 12961 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 12962 | err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX, |
| 12963 | info->attrs[NL80211_ATTR_NAN_FUNC], |
| 12964 | nl80211_nan_func_policy, |
| 12965 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12966 | if (err) |
| 12967 | return err; |
| 12968 | |
| 12969 | func = kzalloc(sizeof(*func), GFP_KERNEL); |
| 12970 | if (!func) |
| 12971 | return -ENOMEM; |
| 12972 | |
Johannes Berg | b60ad34 | 2018-10-01 11:52:07 +0200 | [diff] [blame] | 12973 | func->cookie = cfg80211_assign_cookie(rdev); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12974 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 12975 | if (!tb[NL80211_NAN_FUNC_TYPE]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 12976 | err = -EINVAL; |
| 12977 | goto out; |
| 12978 | } |
| 12979 | |
| 12980 | |
| 12981 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); |
| 12982 | |
| 12983 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { |
| 12984 | err = -EINVAL; |
| 12985 | goto out; |
| 12986 | } |
| 12987 | |
| 12988 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), |
| 12989 | sizeof(func->service_id)); |
| 12990 | |
| 12991 | func->close_range = |
| 12992 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); |
| 12993 | |
| 12994 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { |
| 12995 | func->serv_spec_info_len = |
| 12996 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); |
| 12997 | func->serv_spec_info = |
| 12998 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), |
| 12999 | func->serv_spec_info_len, |
| 13000 | GFP_KERNEL); |
| 13001 | if (!func->serv_spec_info) { |
| 13002 | err = -ENOMEM; |
| 13003 | goto out; |
| 13004 | } |
| 13005 | } |
| 13006 | |
| 13007 | if (tb[NL80211_NAN_FUNC_TTL]) |
| 13008 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); |
| 13009 | |
| 13010 | switch (func->type) { |
| 13011 | case NL80211_NAN_FUNC_PUBLISH: |
| 13012 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { |
| 13013 | err = -EINVAL; |
| 13014 | goto out; |
| 13015 | } |
| 13016 | |
| 13017 | func->publish_type = |
| 13018 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); |
| 13019 | func->publish_bcast = |
| 13020 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); |
| 13021 | |
| 13022 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && |
| 13023 | func->publish_bcast) { |
| 13024 | err = -EINVAL; |
| 13025 | goto out; |
| 13026 | } |
| 13027 | break; |
| 13028 | case NL80211_NAN_FUNC_SUBSCRIBE: |
| 13029 | func->subscribe_active = |
| 13030 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); |
| 13031 | break; |
| 13032 | case NL80211_NAN_FUNC_FOLLOW_UP: |
| 13033 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || |
Hao Chen | 3ea1545 | 2018-01-03 11:00:31 +0800 | [diff] [blame] | 13034 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
| 13035 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13036 | err = -EINVAL; |
| 13037 | goto out; |
| 13038 | } |
| 13039 | |
| 13040 | func->followup_id = |
| 13041 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); |
| 13042 | func->followup_reqid = |
| 13043 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); |
| 13044 | memcpy(func->followup_dest.addr, |
| 13045 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), |
| 13046 | sizeof(func->followup_dest.addr)); |
| 13047 | if (func->ttl) { |
| 13048 | err = -EINVAL; |
| 13049 | goto out; |
| 13050 | } |
| 13051 | break; |
| 13052 | default: |
| 13053 | err = -EINVAL; |
| 13054 | goto out; |
| 13055 | } |
| 13056 | |
| 13057 | if (tb[NL80211_NAN_FUNC_SRF]) { |
| 13058 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; |
| 13059 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13060 | err = nla_parse_nested_deprecated(srf_tb, |
| 13061 | NL80211_NAN_SRF_ATTR_MAX, |
| 13062 | tb[NL80211_NAN_FUNC_SRF], |
| 13063 | nl80211_nan_srf_policy, |
| 13064 | info->extack); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13065 | if (err) |
| 13066 | goto out; |
| 13067 | |
| 13068 | func->srf_include = |
| 13069 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); |
| 13070 | |
| 13071 | if (srf_tb[NL80211_NAN_SRF_BF]) { |
| 13072 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || |
| 13073 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { |
| 13074 | err = -EINVAL; |
| 13075 | goto out; |
| 13076 | } |
| 13077 | |
| 13078 | func->srf_bf_len = |
| 13079 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); |
| 13080 | func->srf_bf = |
| 13081 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), |
| 13082 | func->srf_bf_len, GFP_KERNEL); |
| 13083 | if (!func->srf_bf) { |
| 13084 | err = -ENOMEM; |
| 13085 | goto out; |
| 13086 | } |
| 13087 | |
| 13088 | func->srf_bf_idx = |
| 13089 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); |
| 13090 | } else { |
| 13091 | struct nlattr *attr, *mac_attr = |
| 13092 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; |
| 13093 | int n_entries, rem, i = 0; |
| 13094 | |
| 13095 | if (!mac_attr) { |
| 13096 | err = -EINVAL; |
| 13097 | goto out; |
| 13098 | } |
| 13099 | |
| 13100 | n_entries = validate_acl_mac_addrs(mac_attr); |
| 13101 | if (n_entries <= 0) { |
| 13102 | err = -EINVAL; |
| 13103 | goto out; |
| 13104 | } |
| 13105 | |
| 13106 | func->srf_num_macs = n_entries; |
| 13107 | func->srf_macs = |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 13108 | kcalloc(n_entries, sizeof(*func->srf_macs), |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13109 | GFP_KERNEL); |
| 13110 | if (!func->srf_macs) { |
| 13111 | err = -ENOMEM; |
| 13112 | goto out; |
| 13113 | } |
| 13114 | |
| 13115 | nla_for_each_nested(attr, mac_attr, rem) |
| 13116 | memcpy(func->srf_macs[i++].addr, nla_data(attr), |
| 13117 | sizeof(*func->srf_macs)); |
| 13118 | } |
| 13119 | } |
| 13120 | |
| 13121 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { |
| 13122 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], |
| 13123 | func, true); |
| 13124 | if (err) |
| 13125 | goto out; |
| 13126 | } |
| 13127 | |
| 13128 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { |
| 13129 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], |
| 13130 | func, false); |
| 13131 | if (err) |
| 13132 | goto out; |
| 13133 | } |
| 13134 | |
| 13135 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13136 | if (!msg) { |
| 13137 | err = -ENOMEM; |
| 13138 | goto out; |
| 13139 | } |
| 13140 | |
| 13141 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13142 | NL80211_CMD_ADD_NAN_FUNCTION); |
| 13143 | /* This can't really happen - we just allocated 4KB */ |
| 13144 | if (WARN_ON(!hdr)) { |
| 13145 | err = -ENOMEM; |
| 13146 | goto out; |
| 13147 | } |
| 13148 | |
| 13149 | err = rdev_add_nan_func(rdev, wdev, func); |
| 13150 | out: |
| 13151 | if (err < 0) { |
| 13152 | cfg80211_free_nan_func(func); |
| 13153 | nlmsg_free(msg); |
| 13154 | return err; |
| 13155 | } |
| 13156 | |
| 13157 | /* propagate the instance id and cookie to userspace */ |
| 13158 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, |
| 13159 | NL80211_ATTR_PAD)) |
| 13160 | goto nla_put_failure; |
| 13161 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13162 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13163 | if (!func_attr) |
| 13164 | goto nla_put_failure; |
| 13165 | |
| 13166 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, |
| 13167 | func->instance_id)) |
| 13168 | goto nla_put_failure; |
| 13169 | |
| 13170 | nla_nest_end(msg, func_attr); |
| 13171 | |
| 13172 | genlmsg_end(msg, hdr); |
| 13173 | return genlmsg_reply(msg, info); |
| 13174 | |
| 13175 | nla_put_failure: |
| 13176 | nlmsg_free(msg); |
| 13177 | return -ENOBUFS; |
| 13178 | } |
| 13179 | |
| 13180 | static int nl80211_nan_del_func(struct sk_buff *skb, |
| 13181 | struct genl_info *info) |
| 13182 | { |
| 13183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13184 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13185 | u64 cookie; |
| 13186 | |
| 13187 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13188 | return -EOPNOTSUPP; |
| 13189 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13190 | if (!wdev_running(wdev)) |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13191 | return -ENOTCONN; |
| 13192 | |
| 13193 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
| 13194 | return -EINVAL; |
| 13195 | |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 13196 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
| 13197 | |
| 13198 | rdev_del_nan_func(rdev, wdev, cookie); |
| 13199 | |
| 13200 | return 0; |
| 13201 | } |
| 13202 | |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13203 | static int nl80211_nan_change_config(struct sk_buff *skb, |
| 13204 | struct genl_info *info) |
| 13205 | { |
| 13206 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13207 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13208 | struct cfg80211_nan_conf conf = {}; |
| 13209 | u32 changed = 0; |
| 13210 | |
| 13211 | if (wdev->iftype != NL80211_IFTYPE_NAN) |
| 13212 | return -EOPNOTSUPP; |
| 13213 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13214 | if (!wdev_running(wdev)) |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13215 | return -ENOTCONN; |
| 13216 | |
| 13217 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { |
| 13218 | conf.master_pref = |
| 13219 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); |
| 13220 | if (conf.master_pref <= 1 || conf.master_pref == 255) |
| 13221 | return -EINVAL; |
| 13222 | |
| 13223 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; |
| 13224 | } |
| 13225 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 13226 | if (info->attrs[NL80211_ATTR_BANDS]) { |
| 13227 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); |
| 13228 | |
| 13229 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) |
| 13230 | return -EOPNOTSUPP; |
| 13231 | |
| 13232 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) |
| 13233 | return -EINVAL; |
| 13234 | |
| 13235 | conf.bands = bands; |
| 13236 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 13237 | } |
| 13238 | |
| 13239 | if (!changed) |
| 13240 | return -EINVAL; |
| 13241 | |
| 13242 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); |
| 13243 | } |
| 13244 | |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13245 | void cfg80211_nan_match(struct wireless_dev *wdev, |
| 13246 | struct cfg80211_nan_match_params *match, gfp_t gfp) |
| 13247 | { |
| 13248 | struct wiphy *wiphy = wdev->wiphy; |
| 13249 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13250 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; |
| 13251 | struct sk_buff *msg; |
| 13252 | void *hdr; |
| 13253 | |
| 13254 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) |
| 13255 | return; |
| 13256 | |
| 13257 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13258 | if (!msg) |
| 13259 | return; |
| 13260 | |
| 13261 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); |
| 13262 | if (!hdr) { |
| 13263 | nlmsg_free(msg); |
| 13264 | return; |
| 13265 | } |
| 13266 | |
| 13267 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13268 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13269 | wdev->netdev->ifindex)) || |
| 13270 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13271 | NL80211_ATTR_PAD)) |
| 13272 | goto nla_put_failure; |
| 13273 | |
| 13274 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, |
| 13275 | NL80211_ATTR_PAD) || |
| 13276 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) |
| 13277 | goto nla_put_failure; |
| 13278 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13279 | match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13280 | if (!match_attr) |
| 13281 | goto nla_put_failure; |
| 13282 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13283 | local_func_attr = nla_nest_start_noflag(msg, |
| 13284 | NL80211_NAN_MATCH_FUNC_LOCAL); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13285 | if (!local_func_attr) |
| 13286 | goto nla_put_failure; |
| 13287 | |
| 13288 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) |
| 13289 | goto nla_put_failure; |
| 13290 | |
| 13291 | nla_nest_end(msg, local_func_attr); |
| 13292 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13293 | peer_func_attr = nla_nest_start_noflag(msg, |
| 13294 | NL80211_NAN_MATCH_FUNC_PEER); |
Ayala Beker | 50bcd31 | 2016-09-20 17:31:17 +0300 | [diff] [blame] | 13295 | if (!peer_func_attr) |
| 13296 | goto nla_put_failure; |
| 13297 | |
| 13298 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || |
| 13299 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) |
| 13300 | goto nla_put_failure; |
| 13301 | |
| 13302 | if (match->info && match->info_len && |
| 13303 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, |
| 13304 | match->info)) |
| 13305 | goto nla_put_failure; |
| 13306 | |
| 13307 | nla_nest_end(msg, peer_func_attr); |
| 13308 | nla_nest_end(msg, match_attr); |
| 13309 | genlmsg_end(msg, hdr); |
| 13310 | |
| 13311 | if (!wdev->owner_nlportid) |
| 13312 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13313 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13314 | else |
| 13315 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13316 | wdev->owner_nlportid); |
| 13317 | |
| 13318 | return; |
| 13319 | |
| 13320 | nla_put_failure: |
| 13321 | nlmsg_free(msg); |
| 13322 | } |
| 13323 | EXPORT_SYMBOL(cfg80211_nan_match); |
| 13324 | |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13325 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
| 13326 | u8 inst_id, |
| 13327 | enum nl80211_nan_func_term_reason reason, |
| 13328 | u64 cookie, gfp_t gfp) |
| 13329 | { |
| 13330 | struct wiphy *wiphy = wdev->wiphy; |
| 13331 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13332 | struct sk_buff *msg; |
| 13333 | struct nlattr *func_attr; |
| 13334 | void *hdr; |
| 13335 | |
| 13336 | if (WARN_ON(!inst_id)) |
| 13337 | return; |
| 13338 | |
| 13339 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 13340 | if (!msg) |
| 13341 | return; |
| 13342 | |
| 13343 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); |
| 13344 | if (!hdr) { |
| 13345 | nlmsg_free(msg); |
| 13346 | return; |
| 13347 | } |
| 13348 | |
| 13349 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 13350 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 13351 | wdev->netdev->ifindex)) || |
| 13352 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 13353 | NL80211_ATTR_PAD)) |
| 13354 | goto nla_put_failure; |
| 13355 | |
| 13356 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 13357 | NL80211_ATTR_PAD)) |
| 13358 | goto nla_put_failure; |
| 13359 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13360 | func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC); |
Ayala Beker | 368e5a7 | 2016-09-20 17:31:18 +0300 | [diff] [blame] | 13361 | if (!func_attr) |
| 13362 | goto nla_put_failure; |
| 13363 | |
| 13364 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || |
| 13365 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) |
| 13366 | goto nla_put_failure; |
| 13367 | |
| 13368 | nla_nest_end(msg, func_attr); |
| 13369 | genlmsg_end(msg, hdr); |
| 13370 | |
| 13371 | if (!wdev->owner_nlportid) |
| 13372 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), |
| 13373 | msg, 0, NL80211_MCGRP_NAN, gfp); |
| 13374 | else |
| 13375 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 13376 | wdev->owner_nlportid); |
| 13377 | |
| 13378 | return; |
| 13379 | |
| 13380 | nla_put_failure: |
| 13381 | nlmsg_free(msg); |
| 13382 | } |
| 13383 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); |
| 13384 | |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 13385 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
| 13386 | struct genl_info *info) |
| 13387 | { |
| 13388 | void *hdr; |
| 13389 | struct sk_buff *msg; |
| 13390 | |
| 13391 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 13392 | if (!msg) |
| 13393 | return -ENOMEM; |
| 13394 | |
| 13395 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 13396 | NL80211_CMD_GET_PROTOCOL_FEATURES); |
| 13397 | if (!hdr) |
| 13398 | goto nla_put_failure; |
| 13399 | |
| 13400 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, |
| 13401 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) |
| 13402 | goto nla_put_failure; |
| 13403 | |
| 13404 | genlmsg_end(msg, hdr); |
| 13405 | return genlmsg_reply(msg, info); |
| 13406 | |
| 13407 | nla_put_failure: |
| 13408 | kfree_skb(msg); |
| 13409 | return -ENOBUFS; |
| 13410 | } |
| 13411 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13412 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
| 13413 | { |
| 13414 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13415 | struct cfg80211_update_ft_ies_params ft_params; |
| 13416 | struct net_device *dev = info->user_ptr[1]; |
| 13417 | |
| 13418 | if (!rdev->ops->update_ft_ies) |
| 13419 | return -EOPNOTSUPP; |
| 13420 | |
| 13421 | if (!info->attrs[NL80211_ATTR_MDID] || |
Johannes Berg | 3d7af87 | 2018-10-02 10:00:08 +0200 | [diff] [blame] | 13422 | !info->attrs[NL80211_ATTR_IE]) |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 13423 | return -EINVAL; |
| 13424 | |
| 13425 | memset(&ft_params, 0, sizeof(ft_params)); |
| 13426 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); |
| 13427 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 13428 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 13429 | |
| 13430 | return rdev_update_ft_ies(rdev, dev, &ft_params); |
| 13431 | } |
| 13432 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13433 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
| 13434 | struct genl_info *info) |
| 13435 | { |
| 13436 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13437 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13438 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; |
| 13439 | u16 duration; |
| 13440 | int ret; |
| 13441 | |
| 13442 | if (!rdev->ops->crit_proto_start) |
| 13443 | return -EOPNOTSUPP; |
| 13444 | |
| 13445 | if (WARN_ON(!rdev->ops->crit_proto_stop)) |
| 13446 | return -EINVAL; |
| 13447 | |
| 13448 | if (rdev->crit_proto_nlportid) |
| 13449 | return -EBUSY; |
| 13450 | |
| 13451 | /* determine protocol if provided */ |
| 13452 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) |
| 13453 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); |
| 13454 | |
| 13455 | if (proto >= NUM_NL80211_CRIT_PROTO) |
| 13456 | return -EINVAL; |
| 13457 | |
| 13458 | /* timeout must be provided */ |
| 13459 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) |
| 13460 | return -EINVAL; |
| 13461 | |
| 13462 | duration = |
| 13463 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); |
| 13464 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 13465 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); |
| 13466 | if (!ret) |
| 13467 | rdev->crit_proto_nlportid = info->snd_portid; |
| 13468 | |
| 13469 | return ret; |
| 13470 | } |
| 13471 | |
| 13472 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, |
| 13473 | struct genl_info *info) |
| 13474 | { |
| 13475 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13476 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 13477 | |
| 13478 | if (!rdev->ops->crit_proto_stop) |
| 13479 | return -EOPNOTSUPP; |
| 13480 | |
| 13481 | if (rdev->crit_proto_nlportid) { |
| 13482 | rdev->crit_proto_nlportid = 0; |
| 13483 | rdev_crit_proto_stop(rdev, wdev); |
| 13484 | } |
| 13485 | return 0; |
| 13486 | } |
| 13487 | |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13488 | static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd, |
| 13489 | struct nlattr *attr, |
| 13490 | struct netlink_ext_ack *extack) |
| 13491 | { |
| 13492 | if (vcmd->policy == VENDOR_CMD_RAW_DATA) { |
| 13493 | if (attr->nla_type & NLA_F_NESTED) { |
| 13494 | NL_SET_ERR_MSG_ATTR(extack, attr, |
| 13495 | "unexpected nested data"); |
| 13496 | return -EINVAL; |
| 13497 | } |
| 13498 | |
| 13499 | return 0; |
| 13500 | } |
| 13501 | |
| 13502 | if (!(attr->nla_type & NLA_F_NESTED)) { |
| 13503 | NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data"); |
| 13504 | return -EINVAL; |
| 13505 | } |
| 13506 | |
Michal Kubecek | 32d5109 | 2019-12-11 10:58:19 +0100 | [diff] [blame] | 13507 | return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13508 | } |
| 13509 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13510 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
| 13511 | { |
| 13512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13513 | struct wireless_dev *wdev = |
| 13514 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); |
| 13515 | int i, err; |
| 13516 | u32 vid, subcmd; |
| 13517 | |
| 13518 | if (!rdev->wiphy.vendor_commands) |
| 13519 | return -EOPNOTSUPP; |
| 13520 | |
| 13521 | if (IS_ERR(wdev)) { |
| 13522 | err = PTR_ERR(wdev); |
| 13523 | if (err != -EINVAL) |
| 13524 | return err; |
| 13525 | wdev = NULL; |
| 13526 | } else if (wdev->wiphy != &rdev->wiphy) { |
| 13527 | return -EINVAL; |
| 13528 | } |
| 13529 | |
| 13530 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || |
| 13531 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) |
| 13532 | return -EINVAL; |
| 13533 | |
| 13534 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); |
| 13535 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); |
| 13536 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
| 13537 | const struct wiphy_vendor_command *vcmd; |
| 13538 | void *data = NULL; |
| 13539 | int len = 0; |
| 13540 | |
| 13541 | vcmd = &rdev->wiphy.vendor_commands[i]; |
| 13542 | |
| 13543 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13544 | continue; |
| 13545 | |
| 13546 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13547 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
| 13548 | if (!wdev) |
| 13549 | return -EINVAL; |
| 13550 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
| 13551 | !wdev->netdev) |
| 13552 | return -EINVAL; |
| 13553 | |
| 13554 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 13555 | if (!wdev_running(wdev)) |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13556 | return -ENETDOWN; |
| 13557 | } |
| 13558 | } else { |
| 13559 | wdev = NULL; |
| 13560 | } |
| 13561 | |
Julian Squires | 4052d3d | 2020-07-06 17:13:53 -0400 | [diff] [blame] | 13562 | if (!vcmd->doit) |
| 13563 | return -EOPNOTSUPP; |
| 13564 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13565 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { |
| 13566 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
| 13567 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13568 | |
| 13569 | err = nl80211_vendor_check_policy(vcmd, |
| 13570 | info->attrs[NL80211_ATTR_VENDOR_DATA], |
| 13571 | info->extack); |
| 13572 | if (err) |
| 13573 | return err; |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13574 | } |
| 13575 | |
| 13576 | rdev->cur_cmd_info = info; |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13577 | err = vcmd->doit(&rdev->wiphy, wdev, data, len); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13578 | rdev->cur_cmd_info = NULL; |
| 13579 | return err; |
| 13580 | } |
| 13581 | |
| 13582 | return -EOPNOTSUPP; |
| 13583 | } |
| 13584 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13585 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
| 13586 | struct netlink_callback *cb, |
| 13587 | struct cfg80211_registered_device **rdev, |
| 13588 | struct wireless_dev **wdev) |
| 13589 | { |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13590 | struct nlattr **attrbuf; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13591 | u32 vid, subcmd; |
| 13592 | unsigned int i; |
| 13593 | int vcmd_idx = -1; |
| 13594 | int err; |
| 13595 | void *data = NULL; |
| 13596 | unsigned int data_len = 0; |
| 13597 | |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13598 | if (cb->args[0]) { |
| 13599 | /* subtract the 1 again here */ |
| 13600 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); |
| 13601 | struct wireless_dev *tmp; |
| 13602 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13603 | if (!wiphy) |
| 13604 | return -ENODEV; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13605 | *rdev = wiphy_to_rdev(wiphy); |
| 13606 | *wdev = NULL; |
| 13607 | |
| 13608 | if (cb->args[1]) { |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 13609 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13610 | if (tmp->identifier == cb->args[1] - 1) { |
| 13611 | *wdev = tmp; |
| 13612 | break; |
| 13613 | } |
| 13614 | } |
| 13615 | } |
| 13616 | |
| 13617 | /* keep rtnl locked in successful case */ |
| 13618 | return 0; |
| 13619 | } |
| 13620 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13621 | attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL); |
| 13622 | if (!attrbuf) |
| 13623 | return -ENOMEM; |
| 13624 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 13625 | err = nlmsg_parse_deprecated(cb->nlh, |
| 13626 | GENL_HDRLEN + nl80211_fam.hdrsize, |
| 13627 | attrbuf, nl80211_fam.maxattr, |
| 13628 | nl80211_policy, NULL); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13629 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13630 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13631 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13632 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13633 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { |
| 13634 | err = -EINVAL; |
| 13635 | goto out; |
| 13636 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13637 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13638 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13639 | if (IS_ERR(*wdev)) |
| 13640 | *wdev = NULL; |
| 13641 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13642 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13643 | if (IS_ERR(*rdev)) { |
| 13644 | err = PTR_ERR(*rdev); |
| 13645 | goto out; |
| 13646 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13647 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13648 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
| 13649 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13650 | |
| 13651 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { |
| 13652 | const struct wiphy_vendor_command *vcmd; |
| 13653 | |
| 13654 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; |
| 13655 | |
| 13656 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) |
| 13657 | continue; |
| 13658 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13659 | if (!vcmd->dumpit) { |
| 13660 | err = -EOPNOTSUPP; |
| 13661 | goto out; |
| 13662 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13663 | |
| 13664 | vcmd_idx = i; |
| 13665 | break; |
| 13666 | } |
| 13667 | |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13668 | if (vcmd_idx < 0) { |
| 13669 | err = -EOPNOTSUPP; |
| 13670 | goto out; |
| 13671 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13672 | |
Johannes Berg | c90c39d | 2016-10-24 14:40:01 +0200 | [diff] [blame] | 13673 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
| 13674 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
| 13675 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); |
Johannes Berg | 901bb98 | 2019-05-28 10:56:03 +0200 | [diff] [blame] | 13676 | |
| 13677 | err = nl80211_vendor_check_policy( |
| 13678 | &(*rdev)->wiphy.vendor_commands[vcmd_idx], |
| 13679 | attrbuf[NL80211_ATTR_VENDOR_DATA], |
| 13680 | cb->extack); |
| 13681 | if (err) |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13682 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13683 | } |
| 13684 | |
| 13685 | /* 0 is the first index - add 1 to parse only once */ |
| 13686 | cb->args[0] = (*rdev)->wiphy_idx + 1; |
| 13687 | /* add 1 to know if it was NULL */ |
| 13688 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; |
| 13689 | cb->args[2] = vcmd_idx; |
| 13690 | cb->args[3] = (unsigned long)data; |
| 13691 | cb->args[4] = data_len; |
| 13692 | |
| 13693 | /* keep rtnl locked in successful case */ |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 13694 | err = 0; |
| 13695 | out: |
| 13696 | kfree(attrbuf); |
| 13697 | return err; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13698 | } |
| 13699 | |
| 13700 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, |
| 13701 | struct netlink_callback *cb) |
| 13702 | { |
| 13703 | struct cfg80211_registered_device *rdev; |
| 13704 | struct wireless_dev *wdev; |
| 13705 | unsigned int vcmd_idx; |
| 13706 | const struct wiphy_vendor_command *vcmd; |
| 13707 | void *data; |
| 13708 | int data_len; |
| 13709 | int err; |
| 13710 | struct nlattr *vendor_data; |
| 13711 | |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13712 | rtnl_lock(); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13713 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
| 13714 | if (err) |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13715 | goto out; |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13716 | |
| 13717 | vcmd_idx = cb->args[2]; |
| 13718 | data = (void *)cb->args[3]; |
| 13719 | data_len = cb->args[4]; |
| 13720 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; |
| 13721 | |
| 13722 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | |
| 13723 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13724 | if (!wdev) { |
| 13725 | err = -EINVAL; |
| 13726 | goto out; |
| 13727 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13728 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13729 | !wdev->netdev) { |
| 13730 | err = -EINVAL; |
| 13731 | goto out; |
| 13732 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13733 | |
| 13734 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { |
Johannes Berg | ea90e0d | 2017-03-15 14:26:04 +0100 | [diff] [blame] | 13735 | if (!wdev_running(wdev)) { |
| 13736 | err = -ENETDOWN; |
| 13737 | goto out; |
| 13738 | } |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13739 | } |
| 13740 | } |
| 13741 | |
| 13742 | while (1) { |
| 13743 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
| 13744 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 13745 | NL80211_CMD_VENDOR); |
| 13746 | if (!hdr) |
| 13747 | break; |
| 13748 | |
| 13749 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 13750 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
| 13751 | wdev_id(wdev), |
| 13752 | NL80211_ATTR_PAD))) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13753 | genlmsg_cancel(skb, hdr); |
| 13754 | break; |
| 13755 | } |
| 13756 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 13757 | vendor_data = nla_nest_start_noflag(skb, |
| 13758 | NL80211_ATTR_VENDOR_DATA); |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13759 | if (!vendor_data) { |
| 13760 | genlmsg_cancel(skb, hdr); |
| 13761 | break; |
| 13762 | } |
| 13763 | |
| 13764 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, |
| 13765 | (unsigned long *)&cb->args[5]); |
| 13766 | nla_nest_end(skb, vendor_data); |
| 13767 | |
| 13768 | if (err == -ENOBUFS || err == -ENOENT) { |
| 13769 | genlmsg_cancel(skb, hdr); |
| 13770 | break; |
Julian Squires | 9c167b2 | 2020-07-20 12:20:35 -0230 | [diff] [blame] | 13771 | } else if (err <= 0) { |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 13772 | genlmsg_cancel(skb, hdr); |
| 13773 | goto out; |
| 13774 | } |
| 13775 | |
| 13776 | genlmsg_end(skb, hdr); |
| 13777 | } |
| 13778 | |
| 13779 | err = skb->len; |
| 13780 | out: |
| 13781 | rtnl_unlock(); |
| 13782 | return err; |
| 13783 | } |
| 13784 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13785 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
| 13786 | enum nl80211_commands cmd, |
| 13787 | enum nl80211_attrs attr, |
| 13788 | int approxlen) |
| 13789 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 13790 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13791 | |
| 13792 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13793 | return NULL; |
| 13794 | |
Ahmad Kholaif | 6c09e79 | 2015-02-26 15:26:53 +0200 | [diff] [blame] | 13795 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13796 | rdev->cur_cmd_info->snd_portid, |
| 13797 | rdev->cur_cmd_info->snd_seq, |
Johannes Berg | 567ffc3 | 2013-12-18 14:43:31 +0100 | [diff] [blame] | 13798 | cmd, attr, NULL, GFP_KERNEL); |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13799 | } |
| 13800 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); |
| 13801 | |
| 13802 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) |
| 13803 | { |
| 13804 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 13805 | void *hdr = ((void **)skb->cb)[1]; |
| 13806 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 13807 | |
Johannes Berg | bd8c78e | 2014-07-30 14:55:26 +0200 | [diff] [blame] | 13808 | /* clear CB data for netlink core to own from now on */ |
| 13809 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 13810 | |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 13811 | if (WARN_ON(!rdev->cur_cmd_info)) { |
| 13812 | kfree_skb(skb); |
| 13813 | return -EINVAL; |
| 13814 | } |
| 13815 | |
| 13816 | nla_nest_end(skb, data); |
| 13817 | genlmsg_end(skb, hdr); |
| 13818 | return genlmsg_reply(skb, rdev->cur_cmd_info); |
| 13819 | } |
| 13820 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); |
| 13821 | |
Johannes Berg | 55c1fdf | 2019-02-06 13:17:19 +0200 | [diff] [blame] | 13822 | unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy) |
| 13823 | { |
| 13824 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 13825 | |
| 13826 | if (WARN_ON(!rdev->cur_cmd_info)) |
| 13827 | return 0; |
| 13828 | |
| 13829 | return rdev->cur_cmd_info->snd_portid; |
| 13830 | } |
| 13831 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender); |
| 13832 | |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13833 | static int nl80211_set_qos_map(struct sk_buff *skb, |
| 13834 | struct genl_info *info) |
| 13835 | { |
| 13836 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13837 | struct cfg80211_qos_map *qos_map = NULL; |
| 13838 | struct net_device *dev = info->user_ptr[1]; |
| 13839 | u8 *pos, len, num_des, des_len, des; |
| 13840 | int ret; |
| 13841 | |
| 13842 | if (!rdev->ops->set_qos_map) |
| 13843 | return -EOPNOTSUPP; |
| 13844 | |
| 13845 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { |
| 13846 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13847 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); |
| 13848 | |
Johannes Berg | c8b8280 | 2020-08-19 08:56:43 +0200 | [diff] [blame] | 13849 | if (len % 2) |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 13850 | return -EINVAL; |
| 13851 | |
| 13852 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); |
| 13853 | if (!qos_map) |
| 13854 | return -ENOMEM; |
| 13855 | |
| 13856 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; |
| 13857 | if (num_des) { |
| 13858 | des_len = num_des * |
| 13859 | sizeof(struct cfg80211_dscp_exception); |
| 13860 | memcpy(qos_map->dscp_exception, pos, des_len); |
| 13861 | qos_map->num_des = num_des; |
| 13862 | for (des = 0; des < num_des; des++) { |
| 13863 | if (qos_map->dscp_exception[des].up > 7) { |
| 13864 | kfree(qos_map); |
| 13865 | return -EINVAL; |
| 13866 | } |
| 13867 | } |
| 13868 | pos += des_len; |
| 13869 | } |
| 13870 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); |
| 13871 | } |
| 13872 | |
| 13873 | wdev_lock(dev->ieee80211_ptr); |
| 13874 | ret = nl80211_key_allowed(dev->ieee80211_ptr); |
| 13875 | if (!ret) |
| 13876 | ret = rdev_set_qos_map(rdev, dev, qos_map); |
| 13877 | wdev_unlock(dev->ieee80211_ptr); |
| 13878 | |
| 13879 | kfree(qos_map); |
| 13880 | return ret; |
| 13881 | } |
| 13882 | |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13883 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13884 | { |
| 13885 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13886 | struct net_device *dev = info->user_ptr[1]; |
| 13887 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13888 | const u8 *peer; |
| 13889 | u8 tsid, up; |
| 13890 | u16 admitted_time = 0; |
| 13891 | int err; |
| 13892 | |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13893 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13894 | return -EOPNOTSUPP; |
| 13895 | |
| 13896 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || |
| 13897 | !info->attrs[NL80211_ATTR_USER_PRIO]) |
| 13898 | return -EINVAL; |
| 13899 | |
| 13900 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13901 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13902 | |
| 13903 | /* WMM uses TIDs 0-7 even for TSPEC */ |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13904 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13905 | /* TODO: handle 802.11 TSPEC/admission control |
Johannes Berg | 723e73a | 2014-10-22 09:25:06 +0200 | [diff] [blame] | 13906 | * need more attributes for that (e.g. BA session requirement); |
| 13907 | * change the WMM adminssion test above to allow both then |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 13908 | */ |
| 13909 | return -EINVAL; |
| 13910 | } |
| 13911 | |
| 13912 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13913 | |
| 13914 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { |
| 13915 | admitted_time = |
| 13916 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); |
| 13917 | if (!admitted_time) |
| 13918 | return -EINVAL; |
| 13919 | } |
| 13920 | |
| 13921 | wdev_lock(wdev); |
| 13922 | switch (wdev->iftype) { |
| 13923 | case NL80211_IFTYPE_STATION: |
| 13924 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13925 | if (wdev->current_bss) |
| 13926 | break; |
| 13927 | err = -ENOTCONN; |
| 13928 | goto out; |
| 13929 | default: |
| 13930 | err = -EOPNOTSUPP; |
| 13931 | goto out; |
| 13932 | } |
| 13933 | |
| 13934 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); |
| 13935 | |
| 13936 | out: |
| 13937 | wdev_unlock(wdev); |
| 13938 | return err; |
| 13939 | } |
| 13940 | |
| 13941 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) |
| 13942 | { |
| 13943 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13944 | struct net_device *dev = info->user_ptr[1]; |
| 13945 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13946 | const u8 *peer; |
| 13947 | u8 tsid; |
| 13948 | int err; |
| 13949 | |
| 13950 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) |
| 13951 | return -EINVAL; |
| 13952 | |
| 13953 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); |
| 13954 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 13955 | |
| 13956 | wdev_lock(wdev); |
| 13957 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); |
| 13958 | wdev_unlock(wdev); |
| 13959 | |
| 13960 | return err; |
| 13961 | } |
| 13962 | |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 13963 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
| 13964 | struct genl_info *info) |
| 13965 | { |
| 13966 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 13967 | struct net_device *dev = info->user_ptr[1]; |
| 13968 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 13969 | struct cfg80211_chan_def chandef = {}; |
| 13970 | const u8 *addr; |
| 13971 | u8 oper_class; |
| 13972 | int err; |
| 13973 | |
| 13974 | if (!rdev->ops->tdls_channel_switch || |
| 13975 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 13976 | return -EOPNOTSUPP; |
| 13977 | |
| 13978 | switch (dev->ieee80211_ptr->iftype) { |
| 13979 | case NL80211_IFTYPE_STATION: |
| 13980 | case NL80211_IFTYPE_P2P_CLIENT: |
| 13981 | break; |
| 13982 | default: |
| 13983 | return -EOPNOTSUPP; |
| 13984 | } |
| 13985 | |
| 13986 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 13987 | !info->attrs[NL80211_ATTR_OPER_CLASS]) |
| 13988 | return -EINVAL; |
| 13989 | |
| 13990 | err = nl80211_parse_chandef(rdev, info, &chandef); |
| 13991 | if (err) |
| 13992 | return err; |
| 13993 | |
| 13994 | /* |
| 13995 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 |
| 13996 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the |
| 13997 | * specification is not defined for them. |
| 13998 | */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 13999 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14000 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
| 14001 | chandef.width != NL80211_CHAN_WIDTH_20) |
| 14002 | return -EINVAL; |
| 14003 | |
| 14004 | /* we will be active on the TDLS link */ |
Arik Nemtsov | 923b352 | 2015-07-08 15:41:44 +0300 | [diff] [blame] | 14005 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
| 14006 | wdev->iftype)) |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 14007 | return -EINVAL; |
| 14008 | |
| 14009 | /* don't allow switching to DFS channels */ |
| 14010 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) |
| 14011 | return -EINVAL; |
| 14012 | |
| 14013 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14014 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); |
| 14015 | |
| 14016 | wdev_lock(wdev); |
| 14017 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); |
| 14018 | wdev_unlock(wdev); |
| 14019 | |
| 14020 | return err; |
| 14021 | } |
| 14022 | |
| 14023 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, |
| 14024 | struct genl_info *info) |
| 14025 | { |
| 14026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14027 | struct net_device *dev = info->user_ptr[1]; |
| 14028 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14029 | const u8 *addr; |
| 14030 | |
| 14031 | if (!rdev->ops->tdls_channel_switch || |
| 14032 | !rdev->ops->tdls_cancel_channel_switch || |
| 14033 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) |
| 14034 | return -EOPNOTSUPP; |
| 14035 | |
| 14036 | switch (dev->ieee80211_ptr->iftype) { |
| 14037 | case NL80211_IFTYPE_STATION: |
| 14038 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14039 | break; |
| 14040 | default: |
| 14041 | return -EOPNOTSUPP; |
| 14042 | } |
| 14043 | |
| 14044 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14045 | return -EINVAL; |
| 14046 | |
| 14047 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14048 | |
| 14049 | wdev_lock(wdev); |
| 14050 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); |
| 14051 | wdev_unlock(wdev); |
| 14052 | |
| 14053 | return 0; |
| 14054 | } |
| 14055 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14056 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
| 14057 | struct genl_info *info) |
| 14058 | { |
| 14059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14060 | struct net_device *dev = info->user_ptr[1]; |
| 14061 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14062 | const struct nlattr *nla; |
| 14063 | bool enabled; |
| 14064 | |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 14065 | if (!rdev->ops->set_multicast_to_unicast) |
| 14066 | return -EOPNOTSUPP; |
| 14067 | |
| 14068 | if (wdev->iftype != NL80211_IFTYPE_AP && |
| 14069 | wdev->iftype != NL80211_IFTYPE_P2P_GO) |
| 14070 | return -EOPNOTSUPP; |
| 14071 | |
| 14072 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; |
| 14073 | enabled = nla_get_flag(nla); |
| 14074 | |
| 14075 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); |
| 14076 | } |
| 14077 | |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14078 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14079 | { |
| 14080 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14081 | struct net_device *dev = info->user_ptr[1]; |
| 14082 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14083 | struct cfg80211_pmk_conf pmk_conf = {}; |
| 14084 | int ret; |
| 14085 | |
| 14086 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14087 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14088 | return -EOPNOTSUPP; |
| 14089 | |
| 14090 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14091 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14092 | return -EOPNOTSUPP; |
| 14093 | |
| 14094 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) |
| 14095 | return -EINVAL; |
| 14096 | |
| 14097 | wdev_lock(wdev); |
| 14098 | if (!wdev->current_bss) { |
| 14099 | ret = -ENOTCONN; |
| 14100 | goto out; |
| 14101 | } |
| 14102 | |
| 14103 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14104 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { |
| 14105 | ret = -EINVAL; |
| 14106 | goto out; |
| 14107 | } |
| 14108 | |
| 14109 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); |
| 14110 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); |
| 14111 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && |
| 14112 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { |
| 14113 | ret = -EINVAL; |
| 14114 | goto out; |
| 14115 | } |
| 14116 | |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 14117 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14118 | pmk_conf.pmk_r0_name = |
| 14119 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 14120 | |
| 14121 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); |
| 14122 | out: |
| 14123 | wdev_unlock(wdev); |
| 14124 | return ret; |
| 14125 | } |
| 14126 | |
| 14127 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) |
| 14128 | { |
| 14129 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14130 | struct net_device *dev = info->user_ptr[1]; |
| 14131 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14132 | const u8 *aa; |
| 14133 | int ret; |
| 14134 | |
| 14135 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
| 14136 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
| 14137 | return -EOPNOTSUPP; |
| 14138 | |
| 14139 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14140 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) |
| 14141 | return -EOPNOTSUPP; |
| 14142 | |
| 14143 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 14144 | return -EINVAL; |
| 14145 | |
| 14146 | wdev_lock(wdev); |
| 14147 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14148 | ret = rdev_del_pmk(rdev, dev, aa); |
| 14149 | wdev_unlock(wdev); |
| 14150 | |
| 14151 | return ret; |
| 14152 | } |
| 14153 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14154 | static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info) |
| 14155 | { |
| 14156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14157 | struct net_device *dev = info->user_ptr[1]; |
| 14158 | struct cfg80211_external_auth_params params; |
| 14159 | |
Srinivas Dasari | db8d93a | 2018-02-02 11:15:27 +0200 | [diff] [blame] | 14160 | if (!rdev->ops->external_auth) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14161 | return -EOPNOTSUPP; |
| 14162 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14163 | if (!info->attrs[NL80211_ATTR_SSID] && |
| 14164 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 14165 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14166 | return -EINVAL; |
| 14167 | |
| 14168 | if (!info->attrs[NL80211_ATTR_BSSID]) |
| 14169 | return -EINVAL; |
| 14170 | |
| 14171 | if (!info->attrs[NL80211_ATTR_STATUS_CODE]) |
| 14172 | return -EINVAL; |
| 14173 | |
| 14174 | memset(¶ms, 0, sizeof(params)); |
| 14175 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14176 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 14177 | params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Johannes Berg | cb9abd4 | 2020-08-05 15:47:16 +0200 | [diff] [blame] | 14178 | if (params.ssid.ssid_len == 0) |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14179 | return -EINVAL; |
| 14180 | memcpy(params.ssid.ssid, |
| 14181 | nla_data(info->attrs[NL80211_ATTR_SSID]), |
| 14182 | params.ssid.ssid_len); |
| 14183 | } |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14184 | |
| 14185 | memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]), |
| 14186 | ETH_ALEN); |
| 14187 | |
| 14188 | params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14189 | |
Srinivas Dasari | fe49437 | 2019-01-23 18:06:56 +0530 | [diff] [blame] | 14190 | if (info->attrs[NL80211_ATTR_PMKID]) |
| 14191 | params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
| 14192 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 14193 | return rdev_external_auth(rdev, dev, ¶ms); |
| 14194 | } |
| 14195 | |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14196 | static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info) |
| 14197 | { |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14198 | 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] | 14199 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14200 | struct net_device *dev = info->user_ptr[1]; |
| 14201 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14202 | const u8 *buf; |
| 14203 | size_t len; |
| 14204 | u8 *dest; |
| 14205 | u16 proto; |
| 14206 | bool noencrypt; |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14207 | u64 cookie = 0; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14208 | int err; |
| 14209 | |
| 14210 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
| 14211 | NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211)) |
| 14212 | return -EOPNOTSUPP; |
| 14213 | |
| 14214 | if (!rdev->ops->tx_control_port) |
| 14215 | return -EOPNOTSUPP; |
| 14216 | |
| 14217 | if (!info->attrs[NL80211_ATTR_FRAME] || |
| 14218 | !info->attrs[NL80211_ATTR_MAC] || |
| 14219 | !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
| 14220 | GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing"); |
| 14221 | return -EINVAL; |
| 14222 | } |
| 14223 | |
| 14224 | wdev_lock(wdev); |
| 14225 | |
| 14226 | switch (wdev->iftype) { |
| 14227 | case NL80211_IFTYPE_AP: |
| 14228 | case NL80211_IFTYPE_P2P_GO: |
| 14229 | case NL80211_IFTYPE_MESH_POINT: |
| 14230 | break; |
| 14231 | case NL80211_IFTYPE_ADHOC: |
| 14232 | case NL80211_IFTYPE_STATION: |
| 14233 | case NL80211_IFTYPE_P2P_CLIENT: |
| 14234 | if (wdev->current_bss) |
| 14235 | break; |
| 14236 | err = -ENOTCONN; |
| 14237 | goto out; |
| 14238 | default: |
| 14239 | err = -EOPNOTSUPP; |
| 14240 | goto out; |
| 14241 | } |
| 14242 | |
| 14243 | wdev_unlock(wdev); |
| 14244 | |
| 14245 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14246 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14247 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14248 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); |
| 14249 | noencrypt = |
| 14250 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]); |
| 14251 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 14252 | err = rdev_tx_control_port(rdev, dev, buf, len, |
| 14253 | dest, cpu_to_be16(proto), noencrypt, |
| 14254 | dont_wait_for_ack ? NULL : &cookie); |
| 14255 | if (!err && !dont_wait_for_ack) |
| 14256 | nl_set_extack_cookie_u64(info->extack, cookie); |
| 14257 | return err; |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 14258 | out: |
| 14259 | wdev_unlock(wdev); |
| 14260 | return err; |
| 14261 | } |
| 14262 | |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14263 | static int nl80211_get_ftm_responder_stats(struct sk_buff *skb, |
| 14264 | struct genl_info *info) |
| 14265 | { |
| 14266 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14267 | struct net_device *dev = info->user_ptr[1]; |
| 14268 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14269 | struct cfg80211_ftm_responder_stats ftm_stats = {}; |
| 14270 | struct sk_buff *msg; |
| 14271 | void *hdr; |
| 14272 | struct nlattr *ftm_stats_attr; |
| 14273 | int err; |
| 14274 | |
| 14275 | if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval) |
| 14276 | return -EOPNOTSUPP; |
| 14277 | |
| 14278 | err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats); |
| 14279 | if (err) |
| 14280 | return err; |
| 14281 | |
| 14282 | if (!ftm_stats.filled) |
| 14283 | return -ENODATA; |
| 14284 | |
| 14285 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 14286 | if (!msg) |
| 14287 | return -ENOMEM; |
| 14288 | |
| 14289 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
| 14290 | NL80211_CMD_GET_FTM_RESPONDER_STATS); |
| 14291 | if (!hdr) |
Navid Emamdoost | 1399c59 | 2019-10-04 14:42:19 -0500 | [diff] [blame] | 14292 | goto nla_put_failure; |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14293 | |
| 14294 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 14295 | goto nla_put_failure; |
| 14296 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 14297 | ftm_stats_attr = nla_nest_start_noflag(msg, |
| 14298 | NL80211_ATTR_FTM_RESPONDER_STATS); |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 14299 | if (!ftm_stats_attr) |
| 14300 | goto nla_put_failure; |
| 14301 | |
| 14302 | #define SET_FTM(field, name, type) \ |
| 14303 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14304 | nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \ |
| 14305 | ftm_stats.field)) \ |
| 14306 | goto nla_put_failure; } while (0) |
| 14307 | #define SET_FTM_U64(field, name) \ |
| 14308 | do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \ |
| 14309 | nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \ |
| 14310 | ftm_stats.field, NL80211_FTM_STATS_PAD)) \ |
| 14311 | goto nla_put_failure; } while (0) |
| 14312 | |
| 14313 | SET_FTM(success_num, SUCCESS_NUM, u32); |
| 14314 | SET_FTM(partial_num, PARTIAL_NUM, u32); |
| 14315 | SET_FTM(failed_num, FAILED_NUM, u32); |
| 14316 | SET_FTM(asap_num, ASAP_NUM, u32); |
| 14317 | SET_FTM(non_asap_num, NON_ASAP_NUM, u32); |
| 14318 | SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC); |
| 14319 | SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32); |
| 14320 | SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32); |
| 14321 | SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32); |
| 14322 | #undef SET_FTM |
| 14323 | |
| 14324 | nla_nest_end(msg, ftm_stats_attr); |
| 14325 | |
| 14326 | genlmsg_end(msg, hdr); |
| 14327 | return genlmsg_reply(msg, info); |
| 14328 | |
| 14329 | nla_put_failure: |
| 14330 | nlmsg_free(msg); |
| 14331 | return -ENOBUFS; |
| 14332 | } |
| 14333 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 14334 | static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info) |
| 14335 | { |
| 14336 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14337 | struct cfg80211_update_owe_info owe_info; |
| 14338 | struct net_device *dev = info->user_ptr[1]; |
| 14339 | |
| 14340 | if (!rdev->ops->update_owe_info) |
| 14341 | return -EOPNOTSUPP; |
| 14342 | |
| 14343 | if (!info->attrs[NL80211_ATTR_STATUS_CODE] || |
| 14344 | !info->attrs[NL80211_ATTR_MAC]) |
| 14345 | return -EINVAL; |
| 14346 | |
| 14347 | memset(&owe_info, 0, sizeof(owe_info)); |
| 14348 | owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); |
| 14349 | nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN); |
| 14350 | |
| 14351 | if (info->attrs[NL80211_ATTR_IE]) { |
| 14352 | owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 14353 | owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 14354 | } |
| 14355 | |
| 14356 | return rdev_update_owe_info(rdev, dev, &owe_info); |
| 14357 | } |
| 14358 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14359 | static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info) |
| 14360 | { |
| 14361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14362 | struct net_device *dev = info->user_ptr[1]; |
| 14363 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 14364 | struct station_info sinfo = {}; |
| 14365 | const u8 *buf; |
| 14366 | size_t len; |
| 14367 | u8 *dest; |
| 14368 | int err; |
| 14369 | |
| 14370 | if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station) |
| 14371 | return -EOPNOTSUPP; |
| 14372 | |
| 14373 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 14374 | !info->attrs[NL80211_ATTR_FRAME]) { |
| 14375 | GENL_SET_ERR_MSG(info, "Frame or MAC missing"); |
| 14376 | return -EINVAL; |
| 14377 | } |
| 14378 | |
| 14379 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
| 14380 | return -EOPNOTSUPP; |
| 14381 | |
| 14382 | dest = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14383 | buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
| 14384 | len = nla_len(info->attrs[NL80211_ATTR_FRAME]); |
| 14385 | |
| 14386 | if (len < sizeof(struct ethhdr)) |
| 14387 | return -EINVAL; |
| 14388 | |
| 14389 | if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) || |
| 14390 | !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr)) |
| 14391 | return -EINVAL; |
| 14392 | |
| 14393 | err = rdev_get_station(rdev, dev, dest, &sinfo); |
| 14394 | if (err) |
| 14395 | return err; |
| 14396 | |
Felix Fietkau | 2a279b34 | 2020-01-08 18:06:29 +0100 | [diff] [blame] | 14397 | cfg80211_sinfo_release_content(&sinfo); |
| 14398 | |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 14399 | return rdev_probe_mesh_link(rdev, dev, dest, buf, len); |
| 14400 | } |
| 14401 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14402 | static int parse_tid_conf(struct cfg80211_registered_device *rdev, |
| 14403 | struct nlattr *attrs[], struct net_device *dev, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14404 | struct cfg80211_tid_cfg *tid_conf, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14405 | struct genl_info *info, const u8 *peer) |
| 14406 | { |
| 14407 | struct netlink_ext_ack *extack = info->extack; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14408 | u64 mask; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14409 | int err; |
| 14410 | |
| 14411 | if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS]) |
| 14412 | return -EINVAL; |
| 14413 | |
| 14414 | tid_conf->config_override = |
| 14415 | nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]); |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14416 | tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14417 | |
| 14418 | if (tid_conf->config_override) { |
| 14419 | if (rdev->ops->reset_tid_config) { |
| 14420 | err = rdev_reset_tid_config(rdev, dev, peer, |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14421 | tid_conf->tids); |
Sergey Matyukevich | c033695 | 2020-04-24 14:29:04 +0300 | [diff] [blame] | 14422 | if (err) |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14423 | return err; |
| 14424 | } else { |
| 14425 | return -EINVAL; |
| 14426 | } |
| 14427 | } |
| 14428 | |
| 14429 | if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) { |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14430 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK); |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14431 | tid_conf->noack = |
| 14432 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]); |
| 14433 | } |
| 14434 | |
Tamizh chelvam | 6a21d16 | 2020-01-20 13:21:23 +0530 | [diff] [blame] | 14435 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) { |
| 14436 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT); |
| 14437 | tid_conf->retry_short = |
| 14438 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]); |
| 14439 | |
| 14440 | if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count) |
| 14441 | return -EINVAL; |
| 14442 | } |
| 14443 | |
| 14444 | if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) { |
| 14445 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG); |
| 14446 | tid_conf->retry_long = |
| 14447 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]); |
| 14448 | |
| 14449 | if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count) |
| 14450 | return -EINVAL; |
| 14451 | } |
| 14452 | |
Tamizh chelvam | ade274b | 2020-01-20 13:21:24 +0530 | [diff] [blame] | 14453 | if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) { |
| 14454 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL); |
| 14455 | tid_conf->ampdu = |
| 14456 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]); |
| 14457 | } |
| 14458 | |
Tamizh chelvam | 04f7d14 | 2020-01-20 13:21:25 +0530 | [diff] [blame] | 14459 | if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) { |
| 14460 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL); |
| 14461 | tid_conf->rtscts = |
| 14462 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]); |
| 14463 | } |
| 14464 | |
Sergey Matyukevich | 33462e6 | 2020-04-24 14:29:03 +0300 | [diff] [blame] | 14465 | if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) { |
| 14466 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL); |
| 14467 | tid_conf->amsdu = |
| 14468 | nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]); |
| 14469 | } |
| 14470 | |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14471 | if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) { |
| 14472 | u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr; |
| 14473 | |
| 14474 | tid_conf->txrate_type = nla_get_u8(attrs[idx]); |
| 14475 | |
| 14476 | if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) { |
| 14477 | attr = NL80211_TID_CONFIG_ATTR_TX_RATE; |
| 14478 | err = nl80211_parse_tx_bitrate_mask(info, attrs, attr, |
Miles Hu | eb89a6a | 2020-08-04 10:16:29 +0200 | [diff] [blame] | 14479 | &tid_conf->txrate_mask, dev); |
Tamizh Chelvam | 9a5f648 | 2020-05-13 13:41:44 +0530 | [diff] [blame] | 14480 | if (err) |
| 14481 | return err; |
| 14482 | |
| 14483 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE); |
| 14484 | } |
| 14485 | tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE); |
| 14486 | } |
| 14487 | |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14488 | if (peer) |
| 14489 | mask = rdev->wiphy.tid_config_support.peer; |
| 14490 | else |
| 14491 | mask = rdev->wiphy.tid_config_support.vif; |
| 14492 | |
| 14493 | if (tid_conf->mask & ~mask) { |
| 14494 | NL_SET_ERR_MSG(extack, "unsupported TID configuration"); |
| 14495 | return -ENOTSUPP; |
| 14496 | } |
| 14497 | |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14498 | return 0; |
| 14499 | } |
| 14500 | |
| 14501 | static int nl80211_set_tid_config(struct sk_buff *skb, |
| 14502 | struct genl_info *info) |
| 14503 | { |
| 14504 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 14505 | struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1]; |
| 14506 | struct net_device *dev = info->user_ptr[1]; |
Johannes Berg | 3710a8a | 2020-02-24 11:34:25 +0100 | [diff] [blame] | 14507 | struct cfg80211_tid_config *tid_config; |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 14508 | struct nlattr *tid; |
| 14509 | int conf_idx = 0, rem_conf; |
| 14510 | int ret = -EINVAL; |
| 14511 | u32 num_conf = 0; |
| 14512 | |
| 14513 | if (!info->attrs[NL80211_ATTR_TID_CONFIG]) |
| 14514 | return -EINVAL; |
| 14515 | |
| 14516 | if (!rdev->ops->set_tid_config) |
| 14517 | return -EOPNOTSUPP; |
| 14518 | |
| 14519 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14520 | rem_conf) |
| 14521 | num_conf++; |
| 14522 | |
| 14523 | tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf), |
| 14524 | GFP_KERNEL); |
| 14525 | if (!tid_config) |
| 14526 | return -ENOMEM; |
| 14527 | |
| 14528 | tid_config->n_tid_conf = num_conf; |
| 14529 | |
| 14530 | if (info->attrs[NL80211_ATTR_MAC]) |
| 14531 | tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 14532 | |
| 14533 | nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG], |
| 14534 | rem_conf) { |
| 14535 | ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX, |
| 14536 | tid, NULL, NULL); |
| 14537 | |
| 14538 | if (ret) |
| 14539 | goto bad_tid_conf; |
| 14540 | |
| 14541 | ret = parse_tid_conf(rdev, attrs, dev, |
| 14542 | &tid_config->tid_conf[conf_idx], |
| 14543 | info, tid_config->peer); |
| 14544 | if (ret) |
| 14545 | goto bad_tid_conf; |
| 14546 | |
| 14547 | conf_idx++; |
| 14548 | } |
| 14549 | |
| 14550 | ret = rdev_set_tid_config(rdev, dev, tid_config); |
| 14551 | |
| 14552 | bad_tid_conf: |
| 14553 | kfree(tid_config); |
| 14554 | return ret; |
| 14555 | } |
| 14556 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14557 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
| 14558 | #define NL80211_FLAG_NEED_NETDEV 0x02 |
| 14559 | #define NL80211_FLAG_NEED_RTNL 0x04 |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14560 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
| 14561 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ |
| 14562 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14563 | #define NL80211_FLAG_NEED_WDEV 0x10 |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 14564 | /* 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] | 14565 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
| 14566 | NL80211_FLAG_CHECK_NETDEV_UP) |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14567 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14568 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14569 | 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] | 14570 | struct genl_info *info) |
| 14571 | { |
| 14572 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14573 | struct wireless_dev *wdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14574 | struct net_device *dev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14575 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
| 14576 | |
| 14577 | if (rtnl) |
| 14578 | rtnl_lock(); |
| 14579 | |
| 14580 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { |
Johannes Berg | 4f7eff1 | 2012-06-15 14:14:22 +0200 | [diff] [blame] | 14581 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14582 | if (IS_ERR(rdev)) { |
| 14583 | if (rtnl) |
| 14584 | rtnl_unlock(); |
| 14585 | return PTR_ERR(rdev); |
| 14586 | } |
| 14587 | info->user_ptr[0] = rdev; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14588 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
| 14589 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14590 | ASSERT_RTNL(); |
| 14591 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14592 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
| 14593 | info->attrs); |
| 14594 | if (IS_ERR(wdev)) { |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14595 | if (rtnl) |
| 14596 | rtnl_unlock(); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14597 | return PTR_ERR(wdev); |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14598 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14599 | |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14600 | dev = wdev->netdev; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 14601 | rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14602 | |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14603 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
| 14604 | if (!dev) { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14605 | if (rtnl) |
| 14606 | rtnl_unlock(); |
| 14607 | return -EINVAL; |
| 14608 | } |
| 14609 | |
| 14610 | info->user_ptr[1] = dev; |
| 14611 | } else { |
| 14612 | info->user_ptr[1] = wdev; |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14613 | } |
Johannes Berg | 89a54e4 | 2012-06-15 14:33:17 +0200 | [diff] [blame] | 14614 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14615 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
| 14616 | !wdev_running(wdev)) { |
| 14617 | if (rtnl) |
| 14618 | rtnl_unlock(); |
| 14619 | return -ENETDOWN; |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14620 | } |
| 14621 | |
Arend Van Spriel | 73c7da3 | 2016-10-20 20:08:22 +0100 | [diff] [blame] | 14622 | if (dev) |
| 14623 | dev_hold(dev); |
| 14624 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14625 | info->user_ptr[0] = rdev; |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14626 | } |
| 14627 | |
| 14628 | return 0; |
| 14629 | } |
| 14630 | |
Johannes Berg | f84f771 | 2013-11-14 17:14:45 +0100 | [diff] [blame] | 14631 | 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] | 14632 | struct genl_info *info) |
| 14633 | { |
Johannes Berg | 1bf614e | 2012-06-15 15:23:36 +0200 | [diff] [blame] | 14634 | if (info->user_ptr[1]) { |
| 14635 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { |
| 14636 | struct wireless_dev *wdev = info->user_ptr[1]; |
| 14637 | |
| 14638 | if (wdev->netdev) |
| 14639 | dev_put(wdev->netdev); |
| 14640 | } else { |
| 14641 | dev_put(info->user_ptr[1]); |
| 14642 | } |
| 14643 | } |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14644 | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14645 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
| 14646 | rtnl_unlock(); |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14647 | |
| 14648 | /* If needed, clear the netlink message payload from the SKB |
| 14649 | * as it might contain key data that shouldn't stick around on |
| 14650 | * the heap after the SKB is freed. The netlink message header |
| 14651 | * is still needed for further processing, so leave it intact. |
| 14652 | */ |
| 14653 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { |
| 14654 | struct nlmsghdr *nlh = nlmsg_hdr(skb); |
| 14655 | |
| 14656 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); |
| 14657 | } |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14658 | } |
| 14659 | |
Johannes Berg | 4534de8 | 2013-11-14 17:14:46 +0100 | [diff] [blame] | 14660 | static const struct genl_ops nl80211_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14661 | { |
| 14662 | .cmd = NL80211_CMD_GET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14663 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14664 | .doit = nl80211_get_wiphy, |
| 14665 | .dumpit = nl80211_dump_wiphy, |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 14666 | .done = nl80211_dump_wiphy_done, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14667 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14668 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14669 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14670 | }, |
Jakub Kicinski | 66a9b92 | 2020-10-02 14:49:54 -0700 | [diff] [blame] | 14671 | }; |
| 14672 | |
| 14673 | static const struct genl_small_ops nl80211_small_ops[] = { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14674 | { |
| 14675 | .cmd = NL80211_CMD_SET_WIPHY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14676 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14677 | .doit = nl80211_set_wiphy, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14678 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14679 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14680 | }, |
| 14681 | { |
| 14682 | .cmd = NL80211_CMD_GET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14683 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14684 | .doit = nl80211_get_interface, |
| 14685 | .dumpit = nl80211_dump_interface, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14686 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14687 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 14688 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14689 | }, |
| 14690 | { |
| 14691 | .cmd = NL80211_CMD_SET_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14692 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14693 | .doit = nl80211_set_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14694 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14695 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14696 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14697 | }, |
| 14698 | { |
| 14699 | .cmd = NL80211_CMD_NEW_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14700 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14701 | .doit = nl80211_new_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14702 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14703 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14704 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14705 | }, |
| 14706 | { |
| 14707 | .cmd = NL80211_CMD_DEL_INTERFACE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14708 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14709 | .doit = nl80211_del_interface, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14710 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 14711 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14712 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 14713 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14714 | { |
| 14715 | .cmd = NL80211_CMD_GET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14716 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14717 | .doit = nl80211_get_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14718 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14719 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14720 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14721 | }, |
| 14722 | { |
| 14723 | .cmd = NL80211_CMD_SET_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14724 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14725 | .doit = nl80211_set_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14726 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14727 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14728 | NL80211_FLAG_NEED_RTNL | |
| 14729 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14730 | }, |
| 14731 | { |
| 14732 | .cmd = NL80211_CMD_NEW_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14733 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14734 | .doit = nl80211_new_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14735 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14737 | NL80211_FLAG_NEED_RTNL | |
| 14738 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14739 | }, |
| 14740 | { |
| 14741 | .cmd = NL80211_CMD_DEL_KEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14742 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14743 | .doit = nl80211_del_key, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14744 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14745 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14746 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 14747 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14748 | { |
| 14749 | .cmd = NL80211_CMD_SET_BEACON, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14750 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14751 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14752 | .doit = nl80211_set_beacon, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14753 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14754 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14755 | }, |
| 14756 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14757 | .cmd = NL80211_CMD_START_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14758 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14759 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14760 | .doit = nl80211_start_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14761 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14762 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14763 | }, |
| 14764 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14765 | .cmd = NL80211_CMD_STOP_AP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14766 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14767 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 14768 | .doit = nl80211_stop_ap, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14769 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14770 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 14771 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14772 | { |
| 14773 | .cmd = NL80211_CMD_GET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14774 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14775 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14776 | .dumpit = nl80211_dump_station, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14777 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 14778 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14779 | }, |
| 14780 | { |
| 14781 | .cmd = NL80211_CMD_SET_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14782 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14783 | .doit = nl80211_set_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14784 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14785 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14786 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14787 | }, |
| 14788 | { |
| 14789 | .cmd = NL80211_CMD_NEW_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14790 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14791 | .doit = nl80211_new_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14792 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14793 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14794 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14795 | }, |
| 14796 | { |
| 14797 | .cmd = NL80211_CMD_DEL_STATION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14798 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14799 | .doit = nl80211_del_station, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14800 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14801 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14802 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 14803 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14804 | { |
| 14805 | .cmd = NL80211_CMD_GET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14806 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14807 | .doit = nl80211_get_mpath, |
| 14808 | .dumpit = nl80211_dump_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14809 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14810 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14811 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14812 | }, |
| 14813 | { |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14814 | .cmd = NL80211_CMD_GET_MPP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14815 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14816 | .doit = nl80211_get_mpp, |
| 14817 | .dumpit = nl80211_dump_mpp, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14818 | .flags = GENL_UNS_ADMIN_PERM, |
Henning Rogge | 66be7d2 | 2014-09-12 08:58:49 +0200 | [diff] [blame] | 14819 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14820 | NL80211_FLAG_NEED_RTNL, |
| 14821 | }, |
| 14822 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14823 | .cmd = NL80211_CMD_SET_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14824 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14825 | .doit = nl80211_set_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14826 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14827 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14828 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14829 | }, |
| 14830 | { |
| 14831 | .cmd = NL80211_CMD_NEW_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14832 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14833 | .doit = nl80211_new_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14834 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14835 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14836 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14837 | }, |
| 14838 | { |
| 14839 | .cmd = NL80211_CMD_DEL_MPATH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14840 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14841 | .doit = nl80211_del_mpath, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14842 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14843 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14844 | NL80211_FLAG_NEED_RTNL, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 14845 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14846 | { |
| 14847 | .cmd = NL80211_CMD_SET_BSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14848 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14849 | .doit = nl80211_set_bss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14850 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14852 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 14853 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14854 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14855 | .cmd = NL80211_CMD_GET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14856 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 14857 | .doit = nl80211_get_reg_do, |
| 14858 | .dumpit = nl80211_get_reg_dump, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14859 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14860 | /* can be retrieved by unprivileged users */ |
| 14861 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14862 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 14863 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14864 | .cmd = NL80211_CMD_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14865 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14866 | .doit = nl80211_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14867 | .flags = GENL_ADMIN_PERM, |
Johannes Berg | 5fe231e | 2013-05-08 21:45:15 +0200 | [diff] [blame] | 14868 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14869 | }, |
Johannes Berg | b686303 | 2015-10-15 09:25:18 +0200 | [diff] [blame] | 14870 | #endif |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14871 | { |
| 14872 | .cmd = NL80211_CMD_REQ_SET_REG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14873 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14874 | .doit = nl80211_req_set_reg, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 14875 | .flags = GENL_ADMIN_PERM, |
| 14876 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14877 | { |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14878 | .cmd = NL80211_CMD_RELOAD_REGDB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14879 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14880 | .doit = nl80211_reload_regdb, |
Johannes Berg | 1ea4ff3e9 | 2017-09-13 16:07:22 +0200 | [diff] [blame] | 14881 | .flags = GENL_ADMIN_PERM, |
| 14882 | }, |
| 14883 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14884 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14885 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14886 | .doit = nl80211_get_mesh_config, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14887 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 14888 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14889 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14890 | }, |
| 14891 | { |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14892 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14893 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 14894 | .doit = nl80211_update_mesh_config, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14895 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 14896 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14897 | NL80211_FLAG_NEED_RTNL, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 14898 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 14899 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14900 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14901 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14902 | .doit = nl80211_trigger_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14903 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 14904 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14905 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14906 | }, |
| 14907 | { |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14908 | .cmd = NL80211_CMD_ABORT_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14909 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14910 | .doit = nl80211_abort_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14911 | .flags = GENL_UNS_ADMIN_PERM, |
Vidyullatha Kanchanapally | 91d3ab4 | 2015-10-30 19:14:49 +0530 | [diff] [blame] | 14912 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 14913 | NL80211_FLAG_NEED_RTNL, |
| 14914 | }, |
| 14915 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14916 | .cmd = NL80211_CMD_GET_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14917 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 14918 | .dumpit = nl80211_dump_scan, |
| 14919 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14920 | { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14921 | .cmd = NL80211_CMD_START_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14922 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14923 | .doit = nl80211_start_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14924 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14925 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14926 | NL80211_FLAG_NEED_RTNL, |
| 14927 | }, |
| 14928 | { |
| 14929 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14930 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14931 | .doit = nl80211_stop_sched_scan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14932 | .flags = GENL_UNS_ADMIN_PERM, |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 14933 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 14934 | NL80211_FLAG_NEED_RTNL, |
| 14935 | }, |
| 14936 | { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14937 | .cmd = NL80211_CMD_AUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14938 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14939 | .doit = nl80211_authenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14940 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14941 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 14942 | NL80211_FLAG_NEED_RTNL | |
| 14943 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14944 | }, |
| 14945 | { |
| 14946 | .cmd = NL80211_CMD_ASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14947 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14948 | .doit = nl80211_associate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14949 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14950 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 14951 | NL80211_FLAG_NEED_RTNL | |
| 14952 | NL80211_FLAG_CLEAR_SKB, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14953 | }, |
| 14954 | { |
| 14955 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14956 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14957 | .doit = nl80211_deauthenticate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14958 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14959 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14960 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14961 | }, |
| 14962 | { |
| 14963 | .cmd = NL80211_CMD_DISASSOCIATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14964 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14965 | .doit = nl80211_disassociate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14966 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14967 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14968 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 14969 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14970 | { |
| 14971 | .cmd = NL80211_CMD_JOIN_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14972 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14973 | .doit = nl80211_join_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14974 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14975 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14976 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14977 | }, |
| 14978 | { |
| 14979 | .cmd = NL80211_CMD_LEAVE_IBSS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14980 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14981 | .doit = nl80211_leave_ibss, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14982 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 14983 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14984 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 14985 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14986 | #ifdef CONFIG_NL80211_TESTMODE |
| 14987 | { |
| 14988 | .cmd = NL80211_CMD_TESTMODE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14989 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14990 | .doit = nl80211_testmode_do, |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 14991 | .dumpit = nl80211_testmode_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 14992 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 14993 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 14994 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 14995 | }, |
| 14996 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 14997 | { |
| 14998 | .cmd = NL80211_CMD_CONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 14999 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15000 | .doit = nl80211_connect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15001 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15002 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15003 | NL80211_FLAG_NEED_RTNL | |
| 15004 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15005 | }, |
| 15006 | { |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15007 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15008 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15009 | .doit = nl80211_update_connect_params, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15010 | .flags = GENL_ADMIN_PERM, |
| 15011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15012 | NL80211_FLAG_NEED_RTNL | |
| 15013 | NL80211_FLAG_CLEAR_SKB, |
vamsi krishna | 088e8df | 2016-10-27 16:51:11 +0300 | [diff] [blame] | 15014 | }, |
| 15015 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15016 | .cmd = NL80211_CMD_DISCONNECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15017 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15018 | .doit = nl80211_disconnect, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15019 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4126571 | 2010-10-04 21:14:05 +0200 | [diff] [blame] | 15020 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15021 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 15022 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15023 | { |
| 15024 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15025 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15026 | .doit = nl80211_wiphy_netns, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15027 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15028 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15029 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 15030 | }, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 15031 | { |
| 15032 | .cmd = NL80211_CMD_GET_SURVEY, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15033 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Holger Schurig | 61fa713 | 2009-11-11 12:25:40 +0100 | [diff] [blame] | 15034 | .dumpit = nl80211_dump_survey, |
| 15035 | }, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15036 | { |
| 15037 | .cmd = NL80211_CMD_SET_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15038 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15039 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15040 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 15041 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15042 | NL80211_FLAG_NEED_RTNL | |
| 15043 | NL80211_FLAG_CLEAR_SKB, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15044 | }, |
| 15045 | { |
| 15046 | .cmd = NL80211_CMD_DEL_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15047 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15048 | .doit = nl80211_setdel_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15049 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 15050 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15051 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15052 | }, |
| 15053 | { |
| 15054 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15055 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15056 | .doit = nl80211_flush_pmksa, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15057 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 15058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15059 | NL80211_FLAG_NEED_RTNL, |
Samuel Ortiz | 67fbb16 | 2009-11-24 23:59:15 +0100 | [diff] [blame] | 15060 | }, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15061 | { |
| 15062 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15063 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15064 | .doit = nl80211_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15065 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15066 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15067 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15068 | }, |
| 15069 | { |
| 15070 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15071 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15072 | .doit = nl80211_cancel_remain_on_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15073 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15074 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15075 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15076 | }, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 15077 | { |
| 15078 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15079 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 15080 | .doit = nl80211_set_tx_bitrate_mask, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15081 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15082 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15083 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 13ae75b | 2009-12-29 12:59:45 +0200 | [diff] [blame] | 15084 | }, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15085 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15086 | .cmd = NL80211_CMD_REGISTER_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15087 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15088 | .doit = nl80211_register_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15089 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15090 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15091 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15092 | }, |
| 15093 | { |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15094 | .cmd = NL80211_CMD_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15095 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 15096 | .doit = nl80211_tx_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15097 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15098 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15099 | NL80211_FLAG_NEED_RTNL, |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 15100 | }, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15101 | { |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 15102 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15103 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 15104 | .doit = nl80211_tx_mgmt_cancel_wait, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15105 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 15106 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
Johannes Berg | f7ca38d | 2010-11-25 10:02:29 +0100 | [diff] [blame] | 15107 | NL80211_FLAG_NEED_RTNL, |
| 15108 | }, |
| 15109 | { |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15110 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15111 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15112 | .doit = nl80211_set_power_save, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15113 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15114 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15115 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15116 | }, |
| 15117 | { |
| 15118 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15119 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15120 | .doit = nl80211_get_power_save, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15121 | /* can be retrieved by unprivileged users */ |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15122 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15123 | NL80211_FLAG_NEED_RTNL, |
Kalle Valo | ffb9eb3 | 2010-02-17 17:58:10 +0200 | [diff] [blame] | 15124 | }, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15125 | { |
| 15126 | .cmd = NL80211_CMD_SET_CQM, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15127 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15128 | .doit = nl80211_set_cqm, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15129 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15130 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15131 | NL80211_FLAG_NEED_RTNL, |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 15132 | }, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15133 | { |
| 15134 | .cmd = NL80211_CMD_SET_CHANNEL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15135 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15136 | .doit = nl80211_set_channel, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15137 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 4c47699 | 2010-10-04 21:36:35 +0200 | [diff] [blame] | 15138 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15139 | NL80211_FLAG_NEED_RTNL, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 15140 | }, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15141 | { |
| 15142 | .cmd = NL80211_CMD_SET_WDS_PEER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15143 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15144 | .doit = nl80211_set_wds_peer, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15145 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 43b1995 | 2010-10-07 13:10:30 +0200 | [diff] [blame] | 15146 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15147 | NL80211_FLAG_NEED_RTNL, |
Bill Jordan | e8347eb | 2010-10-01 13:54:28 -0400 | [diff] [blame] | 15148 | }, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15149 | { |
| 15150 | .cmd = NL80211_CMD_JOIN_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15151 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15152 | .doit = nl80211_join_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15153 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15154 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15155 | NL80211_FLAG_NEED_RTNL, |
| 15156 | }, |
| 15157 | { |
| 15158 | .cmd = NL80211_CMD_LEAVE_MESH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15159 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15160 | .doit = nl80211_leave_mesh, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15161 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 15162 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15163 | NL80211_FLAG_NEED_RTNL, |
| 15164 | }, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15165 | { |
| 15166 | .cmd = NL80211_CMD_JOIN_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15167 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15168 | .doit = nl80211_join_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15169 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15170 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15171 | NL80211_FLAG_NEED_RTNL, |
| 15172 | }, |
| 15173 | { |
| 15174 | .cmd = NL80211_CMD_LEAVE_OCB, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15175 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15176 | .doit = nl80211_leave_ocb, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15177 | .flags = GENL_UNS_ADMIN_PERM, |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 15178 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15179 | NL80211_FLAG_NEED_RTNL, |
| 15180 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 15181 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15182 | { |
| 15183 | .cmd = NL80211_CMD_GET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15184 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15185 | .doit = nl80211_get_wowlan, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15186 | /* can be retrieved by unprivileged users */ |
| 15187 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15188 | NL80211_FLAG_NEED_RTNL, |
| 15189 | }, |
| 15190 | { |
| 15191 | .cmd = NL80211_CMD_SET_WOWLAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15192 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15193 | .doit = nl80211_set_wowlan, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15194 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 15195 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15196 | NL80211_FLAG_NEED_RTNL, |
| 15197 | }, |
Johannes Berg | dfb89c5 | 2012-06-27 09:23:48 +0200 | [diff] [blame] | 15198 | #endif |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15199 | { |
| 15200 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15201 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15202 | .doit = nl80211_set_rekey_data, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15203 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15204 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 5393b91 | 2014-09-10 15:00:16 +0300 | [diff] [blame] | 15205 | NL80211_FLAG_NEED_RTNL | |
| 15206 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 15207 | }, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15208 | { |
| 15209 | .cmd = NL80211_CMD_TDLS_MGMT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15210 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15211 | .doit = nl80211_tdls_mgmt, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15212 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15213 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15214 | NL80211_FLAG_NEED_RTNL, |
| 15215 | }, |
| 15216 | { |
| 15217 | .cmd = NL80211_CMD_TDLS_OPER, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15218 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15219 | .doit = nl80211_tdls_oper, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15220 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 109086c | 2011-09-28 14:12:50 +0300 | [diff] [blame] | 15221 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15222 | NL80211_FLAG_NEED_RTNL, |
| 15223 | }, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15224 | { |
| 15225 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15226 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15227 | .doit = nl80211_register_unexpected_frame, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15228 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 15229 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15230 | NL80211_FLAG_NEED_RTNL, |
| 15231 | }, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15232 | { |
| 15233 | .cmd = NL80211_CMD_PROBE_CLIENT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15234 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15235 | .doit = nl80211_probe_client, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15236 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 2b5f8b0 | 2012-04-02 10:51:55 +0200 | [diff] [blame] | 15237 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 15238 | NL80211_FLAG_NEED_RTNL, |
| 15239 | }, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15240 | { |
| 15241 | .cmd = NL80211_CMD_REGISTER_BEACONS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15242 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15243 | .doit = nl80211_register_beacons, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15244 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 15245 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15246 | NL80211_FLAG_NEED_RTNL, |
| 15247 | }, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15248 | { |
| 15249 | .cmd = NL80211_CMD_SET_NOACK_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15250 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15251 | .doit = nl80211_set_noack_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15252 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 1d9d921 | 2011-11-18 14:20:43 +0100 | [diff] [blame] | 15253 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15254 | NL80211_FLAG_NEED_RTNL, |
| 15255 | }, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15256 | { |
| 15257 | .cmd = NL80211_CMD_START_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15258 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15259 | .doit = nl80211_start_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15260 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15261 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15262 | NL80211_FLAG_NEED_RTNL, |
| 15263 | }, |
| 15264 | { |
| 15265 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15266 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15267 | .doit = nl80211_stop_p2p_device, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15268 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 15269 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15270 | NL80211_FLAG_NEED_RTNL, |
| 15271 | }, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15272 | { |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15273 | .cmd = NL80211_CMD_START_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15274 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15275 | .doit = nl80211_start_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15276 | .flags = GENL_ADMIN_PERM, |
| 15277 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
| 15278 | NL80211_FLAG_NEED_RTNL, |
| 15279 | }, |
| 15280 | { |
| 15281 | .cmd = NL80211_CMD_STOP_NAN, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15282 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15283 | .doit = nl80211_stop_nan, |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 15284 | .flags = GENL_ADMIN_PERM, |
| 15285 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15286 | NL80211_FLAG_NEED_RTNL, |
| 15287 | }, |
| 15288 | { |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15289 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15290 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15291 | .doit = nl80211_nan_add_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15292 | .flags = GENL_ADMIN_PERM, |
| 15293 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15294 | NL80211_FLAG_NEED_RTNL, |
| 15295 | }, |
| 15296 | { |
| 15297 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15298 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15299 | .doit = nl80211_nan_del_func, |
Ayala Beker | a442b76 | 2016-09-20 17:31:15 +0300 | [diff] [blame] | 15300 | .flags = GENL_ADMIN_PERM, |
| 15301 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15302 | NL80211_FLAG_NEED_RTNL, |
| 15303 | }, |
| 15304 | { |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15305 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15306 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15307 | .doit = nl80211_nan_change_config, |
Ayala Beker | a5a9dcf | 2016-09-20 17:31:16 +0300 | [diff] [blame] | 15308 | .flags = GENL_ADMIN_PERM, |
| 15309 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15310 | NL80211_FLAG_NEED_RTNL, |
| 15311 | }, |
| 15312 | { |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15313 | .cmd = NL80211_CMD_SET_MCAST_RATE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15314 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15315 | .doit = nl80211_set_mcast_rate, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15316 | .flags = GENL_UNS_ADMIN_PERM, |
Antonio Quartulli | f4e583c | 2012-11-02 13:27:48 +0100 | [diff] [blame] | 15317 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15318 | NL80211_FLAG_NEED_RTNL, |
| 15319 | }, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15320 | { |
| 15321 | .cmd = NL80211_CMD_SET_MAC_ACL, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15322 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15323 | .doit = nl80211_set_mac_acl, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15324 | .flags = GENL_UNS_ADMIN_PERM, |
Vasanthakumar Thiagarajan | 77765ea | 2013-01-18 11:18:45 +0530 | [diff] [blame] | 15325 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15326 | NL80211_FLAG_NEED_RTNL, |
| 15327 | }, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15328 | { |
| 15329 | .cmd = NL80211_CMD_RADAR_DETECT, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15330 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15331 | .doit = nl80211_start_radar_detection, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15332 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 15333 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15334 | NL80211_FLAG_NEED_RTNL, |
| 15335 | }, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15336 | { |
| 15337 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15338 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15339 | .doit = nl80211_get_protocol_features, |
Johannes Berg | 3713b4e | 2013-02-14 16:19:38 +0100 | [diff] [blame] | 15340 | }, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15341 | { |
| 15342 | .cmd = NL80211_CMD_UPDATE_FT_IES, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15343 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15344 | .doit = nl80211_update_ft_ies, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15345 | .flags = GENL_UNS_ADMIN_PERM, |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 15346 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15347 | NL80211_FLAG_NEED_RTNL, |
| 15348 | }, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15349 | { |
| 15350 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15351 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15352 | .doit = nl80211_crit_protocol_start, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15353 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15354 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15355 | NL80211_FLAG_NEED_RTNL, |
| 15356 | }, |
| 15357 | { |
| 15358 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15359 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15360 | .doit = nl80211_crit_protocol_stop, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15361 | .flags = GENL_UNS_ADMIN_PERM, |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 15362 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15363 | NL80211_FLAG_NEED_RTNL, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15364 | }, |
| 15365 | { |
| 15366 | .cmd = NL80211_CMD_GET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15367 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15368 | .doit = nl80211_get_coalesce, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15369 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15370 | NL80211_FLAG_NEED_RTNL, |
| 15371 | }, |
| 15372 | { |
| 15373 | .cmd = NL80211_CMD_SET_COALESCE, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15374 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15375 | .doit = nl80211_set_coalesce, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15376 | .flags = GENL_UNS_ADMIN_PERM, |
Amitkumar Karwar | be29b99a | 2013-06-28 11:51:26 -0700 | [diff] [blame] | 15377 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
| 15378 | NL80211_FLAG_NEED_RTNL, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15379 | }, |
| 15380 | { |
| 15381 | .cmd = NL80211_CMD_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15382 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15383 | .doit = nl80211_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15384 | .flags = GENL_UNS_ADMIN_PERM, |
Simon Wunderlich | 16ef1fe | 2013-07-11 16:09:05 +0200 | [diff] [blame] | 15385 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15386 | NL80211_FLAG_NEED_RTNL, |
| 15387 | }, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15388 | { |
| 15389 | .cmd = NL80211_CMD_VENDOR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15390 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15391 | .doit = nl80211_vendor_cmd, |
Johannes Berg | 7bdbe40 | 2015-08-15 22:39:49 +0300 | [diff] [blame] | 15392 | .dumpit = nl80211_vendor_cmd_dump, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15393 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15394 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15395 | NL80211_FLAG_NEED_RTNL | |
| 15396 | NL80211_FLAG_CLEAR_SKB, |
Johannes Berg | ad7e718 | 2013-11-13 13:37:47 +0100 | [diff] [blame] | 15397 | }, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15398 | { |
| 15399 | .cmd = NL80211_CMD_SET_QOS_MAP, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15400 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15401 | .doit = nl80211_set_qos_map, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15402 | .flags = GENL_UNS_ADMIN_PERM, |
Kyeyoon Park | fa9ffc7 | 2013-12-16 23:01:30 -0800 | [diff] [blame] | 15403 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15404 | NL80211_FLAG_NEED_RTNL, |
| 15405 | }, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15406 | { |
| 15407 | .cmd = NL80211_CMD_ADD_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15408 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15409 | .doit = nl80211_add_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15410 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15411 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15412 | NL80211_FLAG_NEED_RTNL, |
| 15413 | }, |
| 15414 | { |
| 15415 | .cmd = NL80211_CMD_DEL_TX_TS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15416 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15417 | .doit = nl80211_del_tx_ts, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15418 | .flags = GENL_UNS_ADMIN_PERM, |
Johannes Berg | 960d01a | 2014-09-09 22:55:35 +0300 | [diff] [blame] | 15419 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15420 | NL80211_FLAG_NEED_RTNL, |
| 15421 | }, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15422 | { |
| 15423 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15424 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15425 | .doit = nl80211_tdls_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15426 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15427 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15428 | NL80211_FLAG_NEED_RTNL, |
| 15429 | }, |
| 15430 | { |
| 15431 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15432 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15433 | .doit = nl80211_tdls_cancel_channel_switch, |
Martin Willi | 5617c6c | 2016-05-09 18:33:58 +0200 | [diff] [blame] | 15434 | .flags = GENL_UNS_ADMIN_PERM, |
Arik Nemtsov | 1057d35 | 2014-11-19 12:54:26 +0200 | [diff] [blame] | 15435 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15436 | NL80211_FLAG_NEED_RTNL, |
| 15437 | }, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15438 | { |
| 15439 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15440 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15441 | .doit = nl80211_set_multicast_to_unicast, |
Michael Braun | ce0ce13 | 2016-10-10 19:12:22 +0200 | [diff] [blame] | 15442 | .flags = GENL_UNS_ADMIN_PERM, |
| 15443 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15444 | NL80211_FLAG_NEED_RTNL, |
| 15445 | }, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15446 | { |
| 15447 | .cmd = NL80211_CMD_SET_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15448 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15449 | .doit = nl80211_set_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
Sunil Dutt | d6db02a | 2019-02-25 15:37:20 +0530 | [diff] [blame] | 15451 | NL80211_FLAG_NEED_RTNL | |
| 15452 | NL80211_FLAG_CLEAR_SKB, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15453 | }, |
| 15454 | { |
| 15455 | .cmd = NL80211_CMD_DEL_PMK, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15456 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15457 | .doit = nl80211_del_pmk, |
Avraham Stern | 3a00df5 | 2017-06-09 13:08:43 +0100 | [diff] [blame] | 15458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15459 | NL80211_FLAG_NEED_RTNL, |
| 15460 | }, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15461 | { |
| 15462 | .cmd = NL80211_CMD_EXTERNAL_AUTH, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15463 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15464 | .doit = nl80211_external_auth, |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 15465 | .flags = GENL_ADMIN_PERM, |
| 15466 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15467 | NL80211_FLAG_NEED_RTNL, |
| 15468 | }, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15469 | { |
| 15470 | .cmd = NL80211_CMD_CONTROL_PORT_FRAME, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15471 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15472 | .doit = nl80211_tx_control_port, |
Denis Kenzior | 2576a9a | 2018-03-26 12:52:42 -0500 | [diff] [blame] | 15473 | .flags = GENL_UNS_ADMIN_PERM, |
| 15474 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15475 | NL80211_FLAG_NEED_RTNL, |
| 15476 | }, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15477 | { |
| 15478 | .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15479 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15480 | .doit = nl80211_get_ftm_responder_stats, |
Pradeep Kumar Chitrapu | 81e54d0 | 2018-09-20 17:30:09 -0700 | [diff] [blame] | 15481 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15482 | NL80211_FLAG_NEED_RTNL, |
| 15483 | }, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15484 | { |
| 15485 | .cmd = NL80211_CMD_PEER_MEASUREMENT_START, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15486 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15487 | .doit = nl80211_pmsr_start, |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 15488 | .flags = GENL_UNS_ADMIN_PERM, |
| 15489 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
| 15490 | NL80211_FLAG_NEED_RTNL, |
| 15491 | }, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15492 | { |
| 15493 | .cmd = NL80211_CMD_NOTIFY_RADAR, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 15494 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15495 | .doit = nl80211_notify_radar_detection, |
Sriram R | 30c6311 | 2018-12-04 17:46:52 +0530 | [diff] [blame] | 15496 | .flags = GENL_UNS_ADMIN_PERM, |
| 15497 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15498 | NL80211_FLAG_NEED_RTNL, |
| 15499 | }, |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 15500 | { |
| 15501 | .cmd = NL80211_CMD_UPDATE_OWE_INFO, |
| 15502 | .doit = nl80211_update_owe_info, |
| 15503 | .flags = GENL_ADMIN_PERM, |
| 15504 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15505 | NL80211_FLAG_NEED_RTNL, |
| 15506 | }, |
Rajkumar Manoharan | 5ab92e7 | 2019-04-11 13:47:24 -0700 | [diff] [blame] | 15507 | { |
| 15508 | .cmd = NL80211_CMD_PROBE_MESH_LINK, |
| 15509 | .doit = nl80211_probe_mesh_link, |
| 15510 | .flags = GENL_UNS_ADMIN_PERM, |
| 15511 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
| 15512 | NL80211_FLAG_NEED_RTNL, |
| 15513 | }, |
Tamizh chelvam | 77f576d | 2020-01-20 13:21:22 +0530 | [diff] [blame] | 15514 | { |
| 15515 | .cmd = NL80211_CMD_SET_TID_CONFIG, |
| 15516 | .doit = nl80211_set_tid_config, |
| 15517 | .flags = GENL_UNS_ADMIN_PERM, |
| 15518 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
| 15519 | NL80211_FLAG_NEED_RTNL, |
| 15520 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15521 | }; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 15522 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 15523 | static struct genl_family nl80211_fam __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15524 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
| 15525 | .hdrsize = 0, /* no private header */ |
| 15526 | .version = 1, /* no particular meaning now */ |
| 15527 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 3b0f31f | 2019-03-21 22:51:02 +0100 | [diff] [blame] | 15528 | .policy = nl80211_policy, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15529 | .netnsok = true, |
| 15530 | .pre_doit = nl80211_pre_doit, |
| 15531 | .post_doit = nl80211_post_doit, |
| 15532 | .module = THIS_MODULE, |
| 15533 | .ops = nl80211_ops, |
| 15534 | .n_ops = ARRAY_SIZE(nl80211_ops), |
Jakub Kicinski | 66a9b92 | 2020-10-02 14:49:54 -0700 | [diff] [blame] | 15535 | .small_ops = nl80211_small_ops, |
| 15536 | .n_small_ops = ARRAY_SIZE(nl80211_small_ops), |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15537 | .mcgrps = nl80211_mcgrps, |
| 15538 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), |
Johannes Berg | 50508d9 | 2019-07-29 16:31:09 +0200 | [diff] [blame] | 15539 | .parallel_ops = true, |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 15540 | }; |
| 15541 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15542 | /* notification functions */ |
| 15543 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15544 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
| 15545 | enum nl80211_commands cmd) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15546 | { |
| 15547 | struct sk_buff *msg; |
Johannes Berg | 86e8cf9 | 2013-06-19 10:57:22 +0200 | [diff] [blame] | 15548 | struct nl80211_dump_wiphy_state state = {}; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15549 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15550 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
| 15551 | cmd != NL80211_CMD_DEL_WIPHY); |
| 15552 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15553 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15554 | if (!msg) |
| 15555 | return; |
| 15556 | |
Johannes Berg | 3bb2055 | 2014-05-26 13:52:25 +0200 | [diff] [blame] | 15557 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15558 | nlmsg_free(msg); |
| 15559 | return; |
| 15560 | } |
| 15561 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15562 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15563 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 15564 | } |
| 15565 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15566 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
| 15567 | struct wireless_dev *wdev, |
| 15568 | enum nl80211_commands cmd) |
| 15569 | { |
| 15570 | struct sk_buff *msg; |
| 15571 | |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15572 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15573 | if (!msg) |
| 15574 | return; |
| 15575 | |
Andrew Zaborowski | 3d1a5bb | 2018-10-19 23:19:06 +0200 | [diff] [blame] | 15576 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) { |
Denis Kenzior | 896ff06 | 2016-08-03 16:58:33 -0500 | [diff] [blame] | 15577 | nlmsg_free(msg); |
| 15578 | return; |
| 15579 | } |
| 15580 | |
| 15581 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 15582 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
| 15583 | } |
| 15584 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15585 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 15586 | struct cfg80211_registered_device *rdev) |
| 15587 | { |
| 15588 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 15589 | struct nlattr *nest; |
| 15590 | int i; |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 15591 | struct cfg80211_scan_info *info; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15592 | |
| 15593 | if (WARN_ON(!req)) |
| 15594 | return 0; |
| 15595 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15596 | nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS); |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15597 | if (!nest) |
| 15598 | goto nla_put_failure; |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15599 | for (i = 0; i < req->n_ssids; i++) { |
| 15600 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) |
| 15601 | goto nla_put_failure; |
| 15602 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15603 | nla_nest_end(msg, nest); |
| 15604 | |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 15605 | if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) { |
| 15606 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ); |
| 15607 | if (!nest) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15608 | goto nla_put_failure; |
Thomas Pedersen | 2032f3b | 2020-04-30 10:25:52 -0700 | [diff] [blame] | 15609 | for (i = 0; i < req->n_channels; i++) { |
| 15610 | if (nla_put_u32(msg, i, |
| 15611 | ieee80211_channel_to_khz(req->channels[i]))) |
| 15612 | goto nla_put_failure; |
| 15613 | } |
| 15614 | nla_nest_end(msg, nest); |
| 15615 | } else { |
| 15616 | nest = nla_nest_start_noflag(msg, |
| 15617 | NL80211_ATTR_SCAN_FREQUENCIES); |
| 15618 | if (!nest) |
| 15619 | goto nla_put_failure; |
| 15620 | for (i = 0; i < req->n_channels; i++) { |
| 15621 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) |
| 15622 | goto nla_put_failure; |
| 15623 | } |
| 15624 | nla_nest_end(msg, nest); |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15625 | } |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15626 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15627 | if (req->ie && |
| 15628 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) |
| 15629 | goto nla_put_failure; |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15630 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 15631 | if (req->flags && |
| 15632 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) |
| 15633 | goto nla_put_failure; |
Sam Leffler | ed473771 | 2012-10-11 21:03:31 -0700 | [diff] [blame] | 15634 | |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 15635 | info = rdev->int_scan_req ? &rdev->int_scan_req->info : |
| 15636 | &rdev->scan_req->info; |
| 15637 | if (info->scan_start_tsf && |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 15638 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 15639 | info->scan_start_tsf, NL80211_BSS_PAD) || |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 15640 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, |
Tova Mussai | c8cb5b8 | 2020-09-18 11:33:13 +0200 | [diff] [blame] | 15641 | info->tsf_bssid))) |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 15642 | goto nla_put_failure; |
| 15643 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15644 | return 0; |
| 15645 | nla_put_failure: |
| 15646 | return -ENOBUFS; |
| 15647 | } |
| 15648 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15649 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15650 | struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15651 | struct wireless_dev *wdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15652 | u32 portid, u32 seq, int flags, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15653 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15654 | { |
| 15655 | void *hdr; |
| 15656 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 15657 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15658 | if (!hdr) |
| 15659 | return -1; |
| 15660 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15661 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15662 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 15663 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 15664 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 15665 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15666 | goto nla_put_failure; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15667 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 15668 | /* ignore errors and send incomplete event anyway */ |
| 15669 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15670 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15671 | genlmsg_end(msg, hdr); |
| 15672 | return 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15673 | |
| 15674 | nla_put_failure: |
| 15675 | genlmsg_cancel(msg, hdr); |
| 15676 | return -EMSGSIZE; |
| 15677 | } |
| 15678 | |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15679 | static int |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15680 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15681 | struct cfg80211_sched_scan_request *req, u32 cmd) |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15682 | { |
| 15683 | void *hdr; |
| 15684 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15685 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15686 | if (!hdr) |
| 15687 | return -1; |
| 15688 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15689 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
| 15690 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || |
| 15691 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || |
| 15692 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, |
| 15693 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15694 | goto nla_put_failure; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15695 | |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 15696 | genlmsg_end(msg, hdr); |
| 15697 | return 0; |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15698 | |
| 15699 | nla_put_failure: |
| 15700 | genlmsg_cancel(msg, hdr); |
| 15701 | return -EMSGSIZE; |
| 15702 | } |
| 15703 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15704 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 15705 | struct wireless_dev *wdev) |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15706 | { |
| 15707 | struct sk_buff *msg; |
| 15708 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15709 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15710 | if (!msg) |
| 15711 | return; |
| 15712 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15713 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15714 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 15715 | nlmsg_free(msg); |
| 15716 | return; |
| 15717 | } |
| 15718 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15719 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15720 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 15721 | } |
| 15722 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15723 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
| 15724 | struct wireless_dev *wdev, bool aborted) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15725 | { |
| 15726 | struct sk_buff *msg; |
| 15727 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 15728 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15729 | if (!msg) |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15730 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15731 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15732 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15733 | aborted ? NL80211_CMD_SCAN_ABORTED : |
| 15734 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15735 | nlmsg_free(msg); |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15736 | return NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15737 | } |
| 15738 | |
Johannes Berg | f9d15d1 | 2014-01-22 11:14:19 +0200 | [diff] [blame] | 15739 | return msg; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15740 | } |
| 15741 | |
Arend Van Spriel | 505a2e8 | 2016-12-16 11:21:54 +0000 | [diff] [blame] | 15742 | /* send message created by nl80211_build_scan_msg() */ |
| 15743 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, |
| 15744 | struct sk_buff *msg) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15745 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15746 | if (!msg) |
| 15747 | return; |
| 15748 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15749 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15750 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 15751 | } |
| 15752 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15753 | 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] | 15754 | { |
| 15755 | struct sk_buff *msg; |
| 15756 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 15757 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15758 | if (!msg) |
| 15759 | return; |
| 15760 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15761 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15762 | nlmsg_free(msg); |
| 15763 | return; |
| 15764 | } |
| 15765 | |
Arend Van Spriel | 96b08fd | 2017-04-13 13:06:27 +0100 | [diff] [blame] | 15766 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15767 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
Luciano Coelho | 807f8a8 | 2011-05-11 17:09:35 +0300 | [diff] [blame] | 15768 | } |
| 15769 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15770 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
| 15771 | struct regulatory_request *request) |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15772 | { |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15773 | /* Userspace can always count this one always being set */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15774 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
| 15775 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15776 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15777 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { |
| 15778 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15779 | NL80211_REGDOM_TYPE_WORLD)) |
| 15780 | goto nla_put_failure; |
| 15781 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { |
| 15782 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15783 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) |
| 15784 | goto nla_put_failure; |
| 15785 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 15786 | request->intersect) { |
| 15787 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15788 | NL80211_REGDOM_TYPE_INTERSECTION)) |
| 15789 | goto nla_put_failure; |
| 15790 | } else { |
| 15791 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, |
| 15792 | NL80211_REGDOM_TYPE_COUNTRY) || |
| 15793 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
| 15794 | request->alpha2)) |
| 15795 | goto nla_put_failure; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15796 | } |
| 15797 | |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15798 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
| 15799 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); |
| 15800 | |
| 15801 | if (wiphy && |
| 15802 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) |
| 15803 | goto nla_put_failure; |
Arik Nemtsov | 1bdd716 | 2014-12-15 19:26:01 +0200 | [diff] [blame] | 15804 | |
| 15805 | if (wiphy && |
| 15806 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
| 15807 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) |
| 15808 | goto nla_put_failure; |
Arik Nemtsov | ad30ca2 | 2014-12-15 19:25:59 +0200 | [diff] [blame] | 15809 | } |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15810 | |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15811 | return true; |
| 15812 | |
| 15813 | nla_put_failure: |
| 15814 | return false; |
| 15815 | } |
| 15816 | |
| 15817 | /* |
| 15818 | * This can happen on global regulatory changes or device specific settings |
| 15819 | * based on custom regulatory domains. |
| 15820 | */ |
| 15821 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, |
| 15822 | struct regulatory_request *request) |
| 15823 | { |
| 15824 | struct sk_buff *msg; |
| 15825 | void *hdr; |
| 15826 | |
| 15827 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 15828 | if (!msg) |
| 15829 | return; |
| 15830 | |
| 15831 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15832 | if (!hdr) |
| 15833 | goto nla_put_failure; |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15834 | |
zhong jiang | 24f6d76 | 2019-09-05 12:25:37 +0800 | [diff] [blame] | 15835 | if (!nl80211_reg_change_event_fill(msg, request)) |
Jonathan Doron | b0d7aa5 | 2014-12-15 19:26:00 +0200 | [diff] [blame] | 15836 | goto nla_put_failure; |
| 15837 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15838 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15839 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15840 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15841 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15842 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 15843 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15844 | |
| 15845 | return; |
| 15846 | |
| 15847 | nla_put_failure: |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 15848 | nlmsg_free(msg); |
| 15849 | } |
| 15850 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15851 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 15852 | struct net_device *netdev, |
| 15853 | const u8 *buf, size_t len, |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15854 | enum nl80211_commands cmd, gfp_t gfp, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15855 | int uapsd_queues, const u8 *req_ies, |
| 15856 | size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15857 | { |
| 15858 | struct sk_buff *msg; |
| 15859 | void *hdr; |
| 15860 | |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15861 | msg = nlmsg_new(100 + len + req_ies_len, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15862 | if (!msg) |
| 15863 | return; |
| 15864 | |
| 15865 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15866 | if (!hdr) { |
| 15867 | nlmsg_free(msg); |
| 15868 | return; |
| 15869 | } |
| 15870 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15871 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15872 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15873 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 15874 | (req_ies && |
| 15875 | 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] | 15876 | goto nla_put_failure; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15877 | |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15878 | if (uapsd_queues >= 0) { |
| 15879 | struct nlattr *nla_wmm = |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 15880 | nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME); |
Eliad Peller | b0b6aa2 | 2014-09-09 17:09:45 +0300 | [diff] [blame] | 15881 | if (!nla_wmm) |
| 15882 | goto nla_put_failure; |
| 15883 | |
| 15884 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 15885 | uapsd_queues)) |
| 15886 | goto nla_put_failure; |
| 15887 | |
| 15888 | nla_nest_end(msg, nla_wmm); |
| 15889 | } |
| 15890 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15891 | genlmsg_end(msg, hdr); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15892 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15893 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15894 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15895 | return; |
| 15896 | |
| 15897 | nla_put_failure: |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15898 | nlmsg_free(msg); |
| 15899 | } |
| 15900 | |
| 15901 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15902 | struct net_device *netdev, const u8 *buf, |
| 15903 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15904 | { |
| 15905 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15906 | NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15907 | } |
| 15908 | |
| 15909 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 15910 | struct net_device *netdev, const u8 *buf, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15911 | size_t len, gfp_t gfp, int uapsd_queues, |
| 15912 | const u8 *req_ies, size_t req_ies_len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15913 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15914 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15915 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues, |
| 15916 | req_ies, req_ies_len); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15917 | } |
| 15918 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15919 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15920 | struct net_device *netdev, const u8 *buf, |
| 15921 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15922 | { |
| 15923 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15924 | NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15925 | } |
| 15926 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 15927 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 15928 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15929 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15930 | { |
| 15931 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15932 | NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 15933 | } |
| 15934 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15935 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
| 15936 | size_t len) |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15937 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 15938 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 15939 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 15940 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15941 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 15942 | u32 cmd; |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15943 | |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15944 | if (WARN_ON(len < 2)) |
| 15945 | return; |
| 15946 | |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15947 | if (ieee80211_is_deauth(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15948 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15949 | } else if (ieee80211_is_disassoc(mgmt->frame_control)) { |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15950 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; |
Jouni Malinen | 4d797fc | 2020-04-01 17:25:47 +0300 | [diff] [blame] | 15951 | } else if (ieee80211_is_beacon(mgmt->frame_control)) { |
| 15952 | if (wdev->unprot_beacon_reported && |
| 15953 | elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000) |
| 15954 | return; |
| 15955 | cmd = NL80211_CMD_UNPROT_BEACON; |
| 15956 | wdev->unprot_beacon_reported = jiffies; |
| 15957 | } else { |
| 15958 | return; |
| 15959 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15960 | |
| 15961 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
Jouni Malinen | 4d9ec73 | 2019-02-15 02:14:33 +0200 | [diff] [blame] | 15962 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1, |
| 15963 | NULL, 0); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15964 | } |
Johannes Berg | 6ff57cf | 2013-05-16 00:55:00 +0200 | [diff] [blame] | 15965 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
Jouni Malinen | cf4e594 | 2010-12-16 00:52:40 +0200 | [diff] [blame] | 15966 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 15967 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 15968 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15969 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15970 | { |
| 15971 | struct sk_buff *msg; |
| 15972 | void *hdr; |
| 15973 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 15974 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15975 | if (!msg) |
| 15976 | return; |
| 15977 | |
| 15978 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 15979 | if (!hdr) { |
| 15980 | nlmsg_free(msg); |
| 15981 | return; |
| 15982 | } |
| 15983 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 15984 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 15985 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 15986 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
| 15987 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 15988 | goto nla_put_failure; |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15989 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 15990 | genlmsg_end(msg, hdr); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15991 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 15992 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 15993 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15994 | return; |
| 15995 | |
| 15996 | nla_put_failure: |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 15997 | nlmsg_free(msg); |
| 15998 | } |
| 15999 | |
| 16000 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16001 | struct net_device *netdev, const u8 *addr, |
| 16002 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16003 | { |
| 16004 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16005 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16006 | } |
| 16007 | |
| 16008 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16009 | struct net_device *netdev, const u8 *addr, |
| 16010 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16011 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16012 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 16013 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 16014 | } |
| 16015 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16016 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16017 | struct net_device *netdev, |
| 16018 | struct cfg80211_connect_resp_params *cr, |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 16019 | gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16020 | { |
| 16021 | struct sk_buff *msg; |
| 16022 | void *hdr; |
| 16023 | |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16024 | 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] | 16025 | cr->fils.kek_len + cr->fils.pmk_len + |
| 16026 | (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16027 | if (!msg) |
| 16028 | return; |
| 16029 | |
| 16030 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 16031 | if (!hdr) { |
| 16032 | nlmsg_free(msg); |
| 16033 | return; |
| 16034 | } |
| 16035 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16036 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16037 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16038 | (cr->bssid && |
| 16039 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || |
Jouni Malinen | bf1ecd2 | 2016-05-31 00:16:50 +0300 | [diff] [blame] | 16040 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16041 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
| 16042 | cr->status) || |
| 16043 | (cr->status < 0 && |
Purushottam Kushwaha | 3093ebbeab | 2017-01-13 01:12:21 +0200 | [diff] [blame] | 16044 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
Vidyullatha Kanchanapally | 5349a0f | 2017-03-31 00:22:33 +0300 | [diff] [blame] | 16045 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
| 16046 | cr->timeout_reason))) || |
| 16047 | (cr->req_ie && |
| 16048 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || |
| 16049 | (cr->resp_ie && |
| 16050 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16051 | cr->resp_ie)) || |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 16052 | (cr->fils.update_erp_next_seq_num && |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16053 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 16054 | cr->fils.erp_next_seq_num)) || |
Vidyullatha Kanchanapally | a3caf74 | 2017-03-31 00:22:34 +0300 | [diff] [blame] | 16055 | (cr->status == WLAN_STATUS_SUCCESS && |
Arend Van Spriel | 76804d2 | 2018-05-22 10:19:06 +0200 | [diff] [blame] | 16056 | ((cr->fils.kek && |
| 16057 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len, |
| 16058 | cr->fils.kek)) || |
| 16059 | (cr->fils.pmk && |
| 16060 | nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) || |
| 16061 | (cr->fils.pmkid && |
| 16062 | 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] | 16063 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16064 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16065 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16066 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16067 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16068 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16069 | return; |
| 16070 | |
| 16071 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16072 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16073 | } |
| 16074 | |
| 16075 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 16076 | struct net_device *netdev, |
| 16077 | struct cfg80211_roam_info *info, gfp_t gfp) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16078 | { |
| 16079 | struct sk_buff *msg; |
| 16080 | void *hdr; |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 16081 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16082 | |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 16083 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len + |
| 16084 | info->fils.kek_len + info->fils.pmk_len + |
| 16085 | (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16086 | if (!msg) |
| 16087 | return; |
| 16088 | |
| 16089 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 16090 | if (!hdr) { |
| 16091 | nlmsg_free(msg); |
| 16092 | return; |
| 16093 | } |
| 16094 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16095 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16096 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16097 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || |
Avraham Stern | 29ce6ec | 2017-04-26 10:58:49 +0300 | [diff] [blame] | 16098 | (info->req_ie && |
| 16099 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, |
| 16100 | info->req_ie)) || |
| 16101 | (info->resp_ie && |
| 16102 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, |
Arend Van Spriel | e841b7b | 2018-05-22 10:19:07 +0200 | [diff] [blame] | 16103 | info->resp_ie)) || |
| 16104 | (info->fils.update_erp_next_seq_num && |
| 16105 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 16106 | info->fils.erp_next_seq_num)) || |
| 16107 | (info->fils.kek && |
| 16108 | nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len, |
| 16109 | info->fils.kek)) || |
| 16110 | (info->fils.pmk && |
| 16111 | nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) || |
| 16112 | (info->fils.pmkid && |
| 16113 | 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] | 16114 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16115 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16116 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16117 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16118 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16119 | NL80211_MCGRP_MLME, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16120 | return; |
| 16121 | |
| 16122 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16123 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16124 | } |
| 16125 | |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16126 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, |
| 16127 | struct net_device *netdev, const u8 *bssid) |
| 16128 | { |
| 16129 | struct sk_buff *msg; |
| 16130 | void *hdr; |
| 16131 | |
| 16132 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 16133 | if (!msg) |
| 16134 | return; |
| 16135 | |
| 16136 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); |
| 16137 | if (!hdr) { |
| 16138 | nlmsg_free(msg); |
| 16139 | return; |
| 16140 | } |
| 16141 | |
Chung-Hsien Hsu | f4d7599 | 2019-05-09 09:48:25 +0000 | [diff] [blame] | 16142 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16143 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16144 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16145 | goto nla_put_failure; |
| 16146 | |
| 16147 | genlmsg_end(msg, hdr); |
| 16148 | |
| 16149 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16150 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 16151 | return; |
| 16152 | |
| 16153 | nla_put_failure: |
Avraham Stern | 503c1fb | 2017-09-29 14:21:49 +0200 | [diff] [blame] | 16154 | nlmsg_free(msg); |
| 16155 | } |
| 16156 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16157 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 16158 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 16159 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16160 | { |
| 16161 | struct sk_buff *msg; |
| 16162 | void *hdr; |
| 16163 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16164 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16165 | if (!msg) |
| 16166 | return; |
| 16167 | |
| 16168 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 16169 | if (!hdr) { |
| 16170 | nlmsg_free(msg); |
| 16171 | return; |
| 16172 | } |
| 16173 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16174 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16175 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
David Spinadel | 86b6c46 | 2017-12-18 12:14:05 +0200 | [diff] [blame] | 16176 | (reason && |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16177 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || |
| 16178 | (from_ap && |
| 16179 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || |
| 16180 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) |
| 16181 | goto nla_put_failure; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16182 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16183 | genlmsg_end(msg, hdr); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16184 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16185 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16186 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16187 | return; |
| 16188 | |
| 16189 | nla_put_failure: |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16190 | nlmsg_free(msg); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 16191 | } |
| 16192 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16193 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 16194 | struct net_device *netdev, const u8 *bssid, |
| 16195 | gfp_t gfp) |
| 16196 | { |
| 16197 | struct sk_buff *msg; |
| 16198 | void *hdr; |
| 16199 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16200 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16201 | if (!msg) |
| 16202 | return; |
| 16203 | |
| 16204 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 16205 | if (!hdr) { |
| 16206 | nlmsg_free(msg); |
| 16207 | return; |
| 16208 | } |
| 16209 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16210 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16211 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16212 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16213 | goto nla_put_failure; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16214 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16215 | genlmsg_end(msg, hdr); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16216 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16217 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16218 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16219 | return; |
| 16220 | |
| 16221 | nla_put_failure: |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 16222 | nlmsg_free(msg); |
| 16223 | } |
| 16224 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16225 | 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] | 16226 | const u8 *ie, u8 ie_len, |
| 16227 | int sig_dbm, gfp_t gfp) |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16228 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16229 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16230 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16231 | struct sk_buff *msg; |
| 16232 | void *hdr; |
| 16233 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16234 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
| 16235 | return; |
| 16236 | |
| 16237 | trace_cfg80211_notify_new_peer_candidate(dev, addr); |
| 16238 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16239 | msg = nlmsg_new(100 + ie_len, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16240 | if (!msg) |
| 16241 | return; |
| 16242 | |
| 16243 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); |
| 16244 | if (!hdr) { |
| 16245 | nlmsg_free(msg); |
| 16246 | return; |
| 16247 | } |
| 16248 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16249 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16250 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16251 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16252 | (ie_len && ie && |
Bob Copeland | ecbc12a | 2018-10-26 10:03:50 -0400 | [diff] [blame] | 16253 | nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) || |
| 16254 | (sig_dbm && |
| 16255 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16256 | goto nla_put_failure; |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16257 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16258 | genlmsg_end(msg, hdr); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16259 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16260 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16261 | NL80211_MCGRP_MLME, gfp); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16262 | return; |
| 16263 | |
| 16264 | nla_put_failure: |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16265 | nlmsg_free(msg); |
| 16266 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16267 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
Javier Cardona | c93b5e7 | 2011-04-07 15:08:34 -0700 | [diff] [blame] | 16268 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16269 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 16270 | struct net_device *netdev, const u8 *addr, |
| 16271 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16272 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16273 | { |
| 16274 | struct sk_buff *msg; |
| 16275 | void *hdr; |
| 16276 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 16277 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16278 | if (!msg) |
| 16279 | return; |
| 16280 | |
| 16281 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 16282 | if (!hdr) { |
| 16283 | nlmsg_free(msg); |
| 16284 | return; |
| 16285 | } |
| 16286 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16287 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16288 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16289 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 16290 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || |
| 16291 | (key_id != -1 && |
| 16292 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || |
| 16293 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) |
| 16294 | goto nla_put_failure; |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16295 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16296 | genlmsg_end(msg, hdr); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16297 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16298 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16299 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16300 | return; |
| 16301 | |
| 16302 | nla_put_failure: |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 16303 | nlmsg_free(msg); |
| 16304 | } |
| 16305 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16306 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 16307 | struct ieee80211_channel *channel_before, |
| 16308 | struct ieee80211_channel *channel_after) |
| 16309 | { |
| 16310 | struct sk_buff *msg; |
| 16311 | void *hdr; |
| 16312 | struct nlattr *nl_freq; |
| 16313 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 16314 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16315 | if (!msg) |
| 16316 | return; |
| 16317 | |
| 16318 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 16319 | if (!hdr) { |
| 16320 | nlmsg_free(msg); |
| 16321 | return; |
| 16322 | } |
| 16323 | |
| 16324 | /* |
| 16325 | * Since we are applying the beacon hint to a wiphy we know its |
| 16326 | * wiphy_idx is valid |
| 16327 | */ |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
| 16329 | goto nla_put_failure; |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16330 | |
| 16331 | /* Before */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16332 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16333 | if (!nl_freq) |
| 16334 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16335 | |
| 16336 | if (nl80211_msg_put_channel(msg, wiphy, channel_before, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16337 | goto nla_put_failure; |
| 16338 | nla_nest_end(msg, nl_freq); |
| 16339 | |
| 16340 | /* After */ |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16341 | nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16342 | if (!nl_freq) |
| 16343 | goto nla_put_failure; |
Haim Dreyfuss | 50f3271 | 2018-04-20 13:49:26 +0300 | [diff] [blame] | 16344 | |
| 16345 | if (nl80211_msg_put_channel(msg, wiphy, channel_after, false)) |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16346 | goto nla_put_failure; |
| 16347 | nla_nest_end(msg, nl_freq); |
| 16348 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16349 | genlmsg_end(msg, hdr); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16350 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16351 | rcu_read_lock(); |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16352 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16353 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 16354 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16355 | |
| 16356 | return; |
| 16357 | |
| 16358 | nla_put_failure: |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 16359 | nlmsg_free(msg); |
| 16360 | } |
| 16361 | |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16362 | static void nl80211_send_remain_on_chan_event( |
| 16363 | int cmd, struct cfg80211_registered_device *rdev, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16364 | struct wireless_dev *wdev, u64 cookie, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16365 | struct ieee80211_channel *chan, |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16366 | unsigned int duration, gfp_t gfp) |
| 16367 | { |
| 16368 | struct sk_buff *msg; |
| 16369 | void *hdr; |
| 16370 | |
| 16371 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16372 | if (!msg) |
| 16373 | return; |
| 16374 | |
| 16375 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 16376 | if (!hdr) { |
| 16377 | nlmsg_free(msg); |
| 16378 | return; |
| 16379 | } |
| 16380 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16381 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16382 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16383 | wdev->netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16384 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16385 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16386 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16387 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 16388 | NL80211_CHAN_NO_HT) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16389 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16390 | NL80211_ATTR_PAD)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16391 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16392 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16393 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
| 16394 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) |
| 16395 | goto nla_put_failure; |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16396 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16397 | genlmsg_end(msg, hdr); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16398 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16399 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16400 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16401 | return; |
| 16402 | |
| 16403 | nla_put_failure: |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16404 | nlmsg_free(msg); |
| 16405 | } |
| 16406 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16407 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
| 16408 | struct ieee80211_channel *chan, |
| 16409 | unsigned int duration, gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16410 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16411 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16412 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16413 | |
| 16414 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16415 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16416 | rdev, wdev, cookie, chan, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16417 | duration, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16418 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16419 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16420 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16421 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
| 16422 | struct ieee80211_channel *chan, |
| 16423 | gfp_t gfp) |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16424 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16425 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16426 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16427 | |
| 16428 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16429 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
Johannes Berg | 42d97a5 | 2012-11-08 18:31:02 +0100 | [diff] [blame] | 16430 | rdev, wdev, cookie, chan, 0, gfp); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16431 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16432 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
Jouni Malinen | 9588bbd | 2009-12-23 13:15:41 +0100 | [diff] [blame] | 16433 | |
James Prestwood | 1c38c7f | 2019-06-12 12:35:09 -0700 | [diff] [blame] | 16434 | void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie, |
| 16435 | struct ieee80211_channel *chan, |
| 16436 | gfp_t gfp) |
| 16437 | { |
| 16438 | struct wiphy *wiphy = wdev->wiphy; |
| 16439 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 16440 | |
| 16441 | trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan); |
| 16442 | nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL, |
| 16443 | rdev, wdev, cookie, chan, 0, gfp); |
| 16444 | } |
| 16445 | EXPORT_SYMBOL(cfg80211_tx_mgmt_expired); |
| 16446 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16447 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
| 16448 | struct station_info *sinfo, gfp_t gfp) |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16449 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16450 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16451 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16452 | struct sk_buff *msg; |
| 16453 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16454 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
| 16455 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16456 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16457 | if (!msg) |
| 16458 | return; |
| 16459 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16460 | 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] | 16461 | rdev, dev, mac_addr, sinfo) < 0) { |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16462 | nlmsg_free(msg); |
| 16463 | return; |
| 16464 | } |
| 16465 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16466 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16467 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16468 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16469 | EXPORT_SYMBOL(cfg80211_new_sta); |
Johannes Berg | 98b6218 | 2009-12-23 13:15:44 +0100 | [diff] [blame] | 16470 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16471 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
| 16472 | struct station_info *sinfo, gfp_t gfp) |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16473 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16474 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16475 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16476 | struct sk_buff *msg; |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16477 | struct station_info empty_sinfo = {}; |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16478 | |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16479 | if (!sinfo) |
| 16480 | sinfo = &empty_sinfo; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16481 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16482 | trace_cfg80211_del_sta(dev, mac_addr); |
| 16483 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16484 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 16485 | if (!msg) { |
| 16486 | cfg80211_sinfo_release_content(sinfo); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16487 | return; |
Johannes Berg | 7ea3e11 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 16488 | } |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16489 | |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16490 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
Johannes Berg | 5700712 | 2015-01-16 21:05:02 +0100 | [diff] [blame] | 16491 | rdev, dev, mac_addr, sinfo) < 0) { |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16492 | nlmsg_free(msg); |
Johannes Berg | 73887fd | 2018-05-18 09:57:55 +0200 | [diff] [blame] | 16493 | return; |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16494 | } |
| 16495 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16496 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16497 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16498 | } |
Johannes Berg | cf5ead8 | 2014-11-14 17:14:00 +0100 | [diff] [blame] | 16499 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
Jouni Malinen | ec15e68 | 2011-03-23 15:29:52 +0200 | [diff] [blame] | 16500 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16501 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
| 16502 | enum nl80211_connect_failed_reason reason, |
| 16503 | gfp_t gfp) |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16504 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16505 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16506 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16507 | struct sk_buff *msg; |
| 16508 | void *hdr; |
| 16509 | |
| 16510 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 16511 | if (!msg) |
| 16512 | return; |
| 16513 | |
| 16514 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); |
| 16515 | if (!hdr) { |
| 16516 | nlmsg_free(msg); |
| 16517 | return; |
| 16518 | } |
| 16519 | |
| 16520 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16521 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || |
| 16522 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) |
| 16523 | goto nla_put_failure; |
| 16524 | |
| 16525 | genlmsg_end(msg, hdr); |
| 16526 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16527 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16528 | NL80211_MCGRP_MLME, gfp); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16529 | return; |
| 16530 | |
| 16531 | nla_put_failure: |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16532 | nlmsg_free(msg); |
| 16533 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16534 | EXPORT_SYMBOL(cfg80211_conn_failed); |
Pandiyarajan Pitchaimuthu | ed44a95 | 2012-09-18 16:50:49 +0530 | [diff] [blame] | 16535 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16536 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
| 16537 | const u8 *addr, gfp_t gfp) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16538 | { |
| 16539 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16540 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16541 | struct sk_buff *msg; |
| 16542 | void *hdr; |
Mark Rutland | 6aa7de0 | 2017-10-23 14:07:29 -0700 | [diff] [blame] | 16543 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16544 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16545 | if (!nlportid) |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16546 | return false; |
| 16547 | |
| 16548 | msg = nlmsg_new(100, gfp); |
| 16549 | if (!msg) |
| 16550 | return true; |
| 16551 | |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16552 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16553 | if (!hdr) { |
| 16554 | nlmsg_free(msg); |
| 16555 | return true; |
| 16556 | } |
| 16557 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16558 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16559 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16560 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 16561 | goto nla_put_failure; |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16562 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 16563 | genlmsg_end(msg, hdr); |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16564 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16565 | return true; |
| 16566 | |
| 16567 | nla_put_failure: |
Johannes Berg | 28946da | 2011-11-04 11:18:12 +0100 | [diff] [blame] | 16568 | nlmsg_free(msg); |
| 16569 | return true; |
| 16570 | } |
| 16571 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16572 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
| 16573 | const u8 *addr, gfp_t gfp) |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16574 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16575 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16576 | bool ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16577 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16578 | trace_cfg80211_rx_spurious_frame(dev, addr); |
| 16579 | |
| 16580 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16581 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { |
| 16582 | trace_cfg80211_return_bool(false); |
| 16583 | return false; |
| 16584 | } |
| 16585 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, |
| 16586 | addr, gfp); |
| 16587 | trace_cfg80211_return_bool(ret); |
| 16588 | return ret; |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16589 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16590 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
| 16591 | |
| 16592 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
| 16593 | const u8 *addr, gfp_t gfp) |
| 16594 | { |
| 16595 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16596 | bool ret; |
| 16597 | |
| 16598 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); |
| 16599 | |
| 16600 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && |
| 16601 | wdev->iftype != NL80211_IFTYPE_P2P_GO && |
| 16602 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { |
| 16603 | trace_cfg80211_return_bool(false); |
| 16604 | return false; |
| 16605 | } |
| 16606 | ret = __nl80211_unexpected_frame(dev, |
| 16607 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, |
| 16608 | addr, gfp); |
| 16609 | trace_cfg80211_return_bool(ret); |
| 16610 | return ret; |
| 16611 | } |
| 16612 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
Johannes Berg | b92ab5d | 2011-11-04 11:18:19 +0100 | [diff] [blame] | 16613 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16614 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16615 | struct wireless_dev *wdev, u32 nlportid, |
Johannes Berg | 804483e | 2012-03-05 22:18:41 +0100 | [diff] [blame] | 16616 | int freq, int sig_dbm, |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16617 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16618 | { |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16619 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16620 | struct sk_buff *msg; |
| 16621 | void *hdr; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16622 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16623 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16624 | if (!msg) |
| 16625 | return -ENOMEM; |
| 16626 | |
Johannes Berg | 2e161f78 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 16627 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16628 | if (!hdr) { |
| 16629 | nlmsg_free(msg); |
| 16630 | return -ENOMEM; |
| 16631 | } |
| 16632 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16633 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16634 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16635 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16636 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16637 | NL80211_ATTR_PAD) || |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 16638 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) || |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 16639 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16640 | (sig_dbm && |
| 16641 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
Vladimir Kondratiev | 19504cf | 2013-08-15 14:51:28 +0300 | [diff] [blame] | 16642 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 16643 | (flags && |
| 16644 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16645 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16646 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16647 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16648 | |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 16649 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16650 | |
| 16651 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16652 | nlmsg_free(msg); |
| 16653 | return -ENOBUFS; |
| 16654 | } |
| 16655 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16656 | static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16657 | const u8 *buf, size_t len, bool ack, |
| 16658 | gfp_t gfp, enum nl80211_commands command) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16659 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16660 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16661 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16662 | struct net_device *netdev = wdev->netdev; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16663 | struct sk_buff *msg; |
| 16664 | void *hdr; |
| 16665 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16666 | if (command == NL80211_CMD_FRAME_TX_STATUS) |
| 16667 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
| 16668 | else |
| 16669 | trace_cfg80211_control_port_tx_status(wdev, cookie, ack); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16670 | |
Johannes Berg | 4ef8c1c | 2017-01-09 11:10:42 +0100 | [diff] [blame] | 16671 | msg = nlmsg_new(100 + len, gfp); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16672 | if (!msg) |
| 16673 | return; |
| 16674 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16675 | hdr = nl80211hdr_put(msg, 0, 0, 0, command); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16676 | if (!hdr) { |
| 16677 | nlmsg_free(msg); |
| 16678 | return; |
| 16679 | } |
| 16680 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16681 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 16682 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 16683 | netdev->ifindex)) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16684 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16685 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16686 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 16687 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 16688 | NL80211_ATTR_PAD) || |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16689 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
| 16690 | goto nla_put_failure; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16691 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16692 | genlmsg_end(msg, hdr); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +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); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16696 | return; |
| 16697 | |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16698 | nla_put_failure: |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16699 | nlmsg_free(msg); |
| 16700 | } |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 16701 | |
| 16702 | void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16703 | const u8 *buf, size_t len, bool ack, |
| 16704 | gfp_t gfp) |
| 16705 | { |
| 16706 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16707 | NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS); |
| 16708 | } |
| 16709 | EXPORT_SYMBOL(cfg80211_control_port_tx_status); |
| 16710 | |
| 16711 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
| 16712 | const u8 *buf, size_t len, bool ack, gfp_t gfp) |
| 16713 | { |
| 16714 | nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp, |
| 16715 | NL80211_CMD_FRAME_TX_STATUS); |
| 16716 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16717 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 16718 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16719 | static int __nl80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16720 | struct sk_buff *skb, |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16721 | bool unencrypted, gfp_t gfp) |
| 16722 | { |
| 16723 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16724 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16725 | struct ethhdr *ehdr = eth_hdr(skb); |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16726 | const u8 *addr = ehdr->h_source; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16727 | u16 proto = be16_to_cpu(skb->protocol); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16728 | struct sk_buff *msg; |
| 16729 | void *hdr; |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16730 | struct nlattr *frame; |
| 16731 | |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16732 | u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid); |
| 16733 | |
| 16734 | if (!nlportid) |
| 16735 | return -ENOENT; |
| 16736 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16737 | msg = nlmsg_new(100 + skb->len, gfp); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16738 | if (!msg) |
| 16739 | return -ENOMEM; |
| 16740 | |
| 16741 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 16742 | if (!hdr) { |
| 16743 | nlmsg_free(msg); |
| 16744 | return -ENOBUFS; |
| 16745 | } |
| 16746 | |
| 16747 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16748 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 16749 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 16750 | NL80211_ATTR_PAD) || |
Johannes Berg | 8d74a62 | 2020-02-24 10:19:12 +0100 | [diff] [blame] | 16751 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16752 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 16753 | (unencrypted && nla_put_flag(msg, |
| 16754 | NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 16755 | goto nla_put_failure; |
| 16756 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16757 | frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len); |
| 16758 | if (!frame) |
| 16759 | goto nla_put_failure; |
| 16760 | |
| 16761 | skb_copy_bits(skb, 0, nla_data(frame), skb->len); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16762 | genlmsg_end(msg, hdr); |
| 16763 | |
| 16764 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 16765 | |
| 16766 | nla_put_failure: |
| 16767 | nlmsg_free(msg); |
| 16768 | return -ENOBUFS; |
| 16769 | } |
| 16770 | |
| 16771 | bool cfg80211_rx_control_port(struct net_device *dev, |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16772 | struct sk_buff *skb, bool unencrypted) |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16773 | { |
| 16774 | int ret; |
| 16775 | |
Denis Kenzior | a948f71 | 2018-07-03 15:05:48 -0500 | [diff] [blame] | 16776 | trace_cfg80211_rx_control_port(dev, skb, unencrypted); |
| 16777 | ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC); |
Denis Kenzior | 6a671a5 | 2018-03-26 12:52:41 -0500 | [diff] [blame] | 16778 | trace_cfg80211_return_bool(ret == 0); |
| 16779 | return ret == 0; |
| 16780 | } |
| 16781 | EXPORT_SYMBOL(cfg80211_rx_control_port); |
| 16782 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16783 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
| 16784 | const char *mac, gfp_t gfp) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16785 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16786 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16787 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 16788 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 16789 | void **cb; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16790 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16791 | if (!msg) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16792 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16793 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16794 | cb = (void **)msg->cb; |
| 16795 | |
| 16796 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); |
| 16797 | if (!cb[0]) { |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16798 | nlmsg_free(msg); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16799 | return NULL; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16800 | } |
| 16801 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16802 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16803 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16804 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16805 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16806 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16807 | goto nla_put_failure; |
| 16808 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16809 | cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16810 | if (!cb[1]) |
| 16811 | goto nla_put_failure; |
| 16812 | |
| 16813 | cb[2] = rdev; |
| 16814 | |
| 16815 | return msg; |
| 16816 | nla_put_failure: |
| 16817 | nlmsg_free(msg); |
| 16818 | return NULL; |
| 16819 | } |
| 16820 | |
| 16821 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) |
| 16822 | { |
| 16823 | void **cb = (void **)msg->cb; |
| 16824 | struct cfg80211_registered_device *rdev = cb[2]; |
| 16825 | |
| 16826 | nla_nest_end(msg, cb[1]); |
| 16827 | genlmsg_end(msg, cb[0]); |
| 16828 | |
| 16829 | memset(msg->cb, 0, sizeof(msg->cb)); |
| 16830 | |
| 16831 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 16832 | NL80211_MCGRP_MLME, gfp); |
| 16833 | } |
| 16834 | |
| 16835 | void cfg80211_cqm_rssi_notify(struct net_device *dev, |
| 16836 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16837 | s32 rssi_level, gfp_t gfp) |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16838 | { |
| 16839 | struct sk_buff *msg; |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16840 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16841 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16842 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16843 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16844 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16845 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
| 16846 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) |
| 16847 | return; |
| 16848 | |
Andrew Zaborowski | 4a4b816 | 2017-02-10 10:02:31 +0100 | [diff] [blame] | 16849 | if (wdev->cqm_config) { |
| 16850 | wdev->cqm_config->last_rssi_event_value = rssi_level; |
| 16851 | |
| 16852 | cfg80211_cqm_rssi_update(rdev, dev); |
| 16853 | |
| 16854 | if (rssi_level == 0) |
| 16855 | rssi_level = wdev->cqm_config->last_rssi_event_value; |
| 16856 | } |
| 16857 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16858 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16859 | if (!msg) |
| 16860 | return; |
| 16861 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16862 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
| 16863 | rssi_event)) |
| 16864 | goto nla_put_failure; |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16865 | |
Andrzej Zaborowski | bee427b | 2017-01-25 12:43:41 +0100 | [diff] [blame] | 16866 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
| 16867 | rssi_level)) |
| 16868 | goto nla_put_failure; |
| 16869 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16870 | cfg80211_send_cqm(msg, gfp); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16871 | |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16872 | return; |
| 16873 | |
| 16874 | nla_put_failure: |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16875 | nlmsg_free(msg); |
| 16876 | } |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16877 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
Juuso Oikarinen | d6dc1a3 | 2010-03-23 09:02:33 +0200 | [diff] [blame] | 16878 | |
Johannes Berg | 5b97f49 | 2014-11-26 12:37:43 +0100 | [diff] [blame] | 16879 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
| 16880 | const u8 *peer, u32 num_packets, |
| 16881 | u32 rate, u32 intvl, gfp_t gfp) |
| 16882 | { |
| 16883 | struct sk_buff *msg; |
| 16884 | |
| 16885 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16886 | if (!msg) |
| 16887 | return; |
| 16888 | |
| 16889 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) |
| 16890 | goto nla_put_failure; |
| 16891 | |
| 16892 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) |
| 16893 | goto nla_put_failure; |
| 16894 | |
| 16895 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) |
| 16896 | goto nla_put_failure; |
| 16897 | |
| 16898 | cfg80211_send_cqm(msg, gfp); |
| 16899 | return; |
| 16900 | |
| 16901 | nla_put_failure: |
| 16902 | nlmsg_free(msg); |
| 16903 | } |
| 16904 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); |
| 16905 | |
| 16906 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, |
| 16907 | const u8 *peer, u32 num_packets, gfp_t gfp) |
| 16908 | { |
| 16909 | struct sk_buff *msg; |
| 16910 | |
| 16911 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); |
| 16912 | |
| 16913 | msg = cfg80211_prepare_cqm(dev, peer, gfp); |
| 16914 | if (!msg) |
| 16915 | return; |
| 16916 | |
| 16917 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
| 16918 | goto nla_put_failure; |
| 16919 | |
| 16920 | cfg80211_send_cqm(msg, gfp); |
| 16921 | return; |
| 16922 | |
| 16923 | nla_put_failure: |
| 16924 | nlmsg_free(msg); |
| 16925 | } |
| 16926 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); |
| 16927 | |
Johannes Berg | 98f0334 | 2014-11-26 12:42:02 +0100 | [diff] [blame] | 16928 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
| 16929 | { |
| 16930 | struct sk_buff *msg; |
| 16931 | |
| 16932 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
| 16933 | if (!msg) |
| 16934 | return; |
| 16935 | |
| 16936 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) |
| 16937 | goto nla_put_failure; |
| 16938 | |
| 16939 | cfg80211_send_cqm(msg, gfp); |
| 16940 | return; |
| 16941 | |
| 16942 | nla_put_failure: |
| 16943 | nlmsg_free(msg); |
| 16944 | } |
| 16945 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); |
| 16946 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16947 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
| 16948 | struct net_device *netdev, const u8 *bssid, |
| 16949 | const u8 *replay_ctr, gfp_t gfp) |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16950 | { |
| 16951 | struct sk_buff *msg; |
| 16952 | struct nlattr *rekey_attr; |
| 16953 | void *hdr; |
| 16954 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 16955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16956 | if (!msg) |
| 16957 | return; |
| 16958 | |
| 16959 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); |
| 16960 | if (!hdr) { |
| 16961 | nlmsg_free(msg); |
| 16962 | return; |
| 16963 | } |
| 16964 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16965 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 16966 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 16967 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) |
| 16968 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16969 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 16970 | rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16971 | if (!rekey_attr) |
| 16972 | goto nla_put_failure; |
| 16973 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 16974 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
| 16975 | NL80211_REPLAY_CTR_LEN, replay_ctr)) |
| 16976 | goto nla_put_failure; |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16977 | |
| 16978 | nla_nest_end(msg, rekey_attr); |
| 16979 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 16980 | genlmsg_end(msg, hdr); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16981 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 16982 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 16983 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16984 | return; |
| 16985 | |
| 16986 | nla_put_failure: |
Johannes Berg | e5497d7 | 2011-07-05 16:35:40 +0200 | [diff] [blame] | 16987 | nlmsg_free(msg); |
| 16988 | } |
| 16989 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16990 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
| 16991 | const u8 *replay_ctr, gfp_t gfp) |
| 16992 | { |
| 16993 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 16994 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 16995 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 16996 | |
| 16997 | trace_cfg80211_gtk_rekey_notify(dev, bssid); |
| 16998 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); |
| 16999 | } |
| 17000 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); |
| 17001 | |
| 17002 | static void |
| 17003 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
| 17004 | struct net_device *netdev, int index, |
| 17005 | const u8 *bssid, bool preauth, gfp_t gfp) |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17006 | { |
| 17007 | struct sk_buff *msg; |
| 17008 | struct nlattr *attr; |
| 17009 | void *hdr; |
| 17010 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17011 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17012 | if (!msg) |
| 17013 | return; |
| 17014 | |
| 17015 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); |
| 17016 | if (!hdr) { |
| 17017 | nlmsg_free(msg); |
| 17018 | return; |
| 17019 | } |
| 17020 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17021 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17022 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 17023 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17024 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17025 | attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17026 | if (!attr) |
| 17027 | goto nla_put_failure; |
| 17028 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17029 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
| 17030 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || |
| 17031 | (preauth && |
| 17032 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) |
| 17033 | goto nla_put_failure; |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17034 | |
| 17035 | nla_nest_end(msg, attr); |
| 17036 | |
Johannes Berg | 3b7b72e | 2011-10-22 19:05:51 +0200 | [diff] [blame] | 17037 | genlmsg_end(msg, hdr); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17038 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17039 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17040 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17041 | return; |
| 17042 | |
| 17043 | nla_put_failure: |
Jouni Malinen | c9df56b | 2011-09-16 18:56:23 +0300 | [diff] [blame] | 17044 | nlmsg_free(msg); |
| 17045 | } |
| 17046 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17047 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
| 17048 | const u8 *bssid, bool preauth, gfp_t gfp) |
| 17049 | { |
| 17050 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17051 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17052 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17053 | |
| 17054 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); |
| 17055 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); |
| 17056 | } |
| 17057 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); |
| 17058 | |
| 17059 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
| 17060 | struct net_device *netdev, |
| 17061 | struct cfg80211_chan_def *chandef, |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17062 | gfp_t gfp, |
| 17063 | enum nl80211_commands notif, |
| 17064 | u8 count) |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17065 | { |
| 17066 | struct sk_buff *msg; |
| 17067 | void *hdr; |
| 17068 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17069 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17070 | if (!msg) |
| 17071 | return; |
| 17072 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17073 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17074 | if (!hdr) { |
| 17075 | nlmsg_free(msg); |
| 17076 | return; |
| 17077 | } |
| 17078 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 17079 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
| 17080 | goto nla_put_failure; |
| 17081 | |
| 17082 | if (nl80211_send_chandef(msg, chandef)) |
John W. Linville | 7eab0f6 | 2012-04-12 14:25:14 -0400 | [diff] [blame] | 17083 | goto nla_put_failure; |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17084 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17085 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
| 17086 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) |
| 17087 | goto nla_put_failure; |
| 17088 | |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17089 | genlmsg_end(msg, hdr); |
| 17090 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17091 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17092 | NL80211_MCGRP_MLME, gfp); |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17093 | return; |
| 17094 | |
| 17095 | nla_put_failure: |
Thomas Pedersen | 5314526 | 2012-04-06 13:35:47 -0700 | [diff] [blame] | 17096 | nlmsg_free(msg); |
| 17097 | } |
| 17098 | |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17099 | void cfg80211_ch_switch_notify(struct net_device *dev, |
| 17100 | struct cfg80211_chan_def *chandef) |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 17101 | { |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17102 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17103 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17104 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17105 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 17106 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17107 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 17108 | trace_cfg80211_ch_switch_notify(dev, chandef); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17109 | |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 17110 | wdev->chandef = *chandef; |
Janusz Dziedzic | 96f55f1 | 2014-01-24 14:29:21 +0100 | [diff] [blame] | 17111 | wdev->preset_chandef = *chandef; |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 17112 | |
| 17113 | if (wdev->iftype == NL80211_IFTYPE_STATION && |
| 17114 | !WARN_ON(!wdev->current_bss)) |
Sergey Matyukevich | 0afd425 | 2019-07-26 16:39:34 +0000 | [diff] [blame] | 17115 | cfg80211_update_assoc_bss_entry(wdev, chandef->chan); |
Sergey Matyukevich | 5dc8cdc | 2019-03-26 09:27:37 +0000 | [diff] [blame] | 17116 | |
Michael Vassernis | d34990b | 2019-07-29 06:01:16 +0000 | [diff] [blame] | 17117 | cfg80211_sched_dfs_chan_update(rdev); |
| 17118 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17119 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 17120 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); |
Johannes Berg | 947add3 | 2013-02-22 22:05:20 +0100 | [diff] [blame] | 17121 | } |
| 17122 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); |
| 17123 | |
Luciano Coelho | f8d7552 | 2014-11-07 14:31:35 +0200 | [diff] [blame] | 17124 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
| 17125 | struct cfg80211_chan_def *chandef, |
| 17126 | u8 count) |
| 17127 | { |
| 17128 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17129 | struct wiphy *wiphy = wdev->wiphy; |
| 17130 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17131 | |
| 17132 | trace_cfg80211_ch_switch_started_notify(dev, chandef); |
| 17133 | |
| 17134 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
| 17135 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); |
| 17136 | } |
| 17137 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); |
| 17138 | |
Thomas Pedersen | 84f1070 | 2012-07-12 16:17:33 -0700 | [diff] [blame] | 17139 | void |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17140 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 17141 | const struct cfg80211_chan_def *chandef, |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17142 | enum nl80211_radar_event event, |
| 17143 | struct net_device *netdev, gfp_t gfp) |
| 17144 | { |
| 17145 | struct sk_buff *msg; |
| 17146 | void *hdr; |
| 17147 | |
| 17148 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17149 | if (!msg) |
| 17150 | return; |
| 17151 | |
| 17152 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); |
| 17153 | if (!hdr) { |
| 17154 | nlmsg_free(msg); |
| 17155 | return; |
| 17156 | } |
| 17157 | |
| 17158 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17159 | goto nla_put_failure; |
| 17160 | |
| 17161 | /* NOP and radar events don't need a netdev parameter */ |
| 17162 | if (netdev) { |
| 17163 | struct wireless_dev *wdev = netdev->ieee80211_ptr; |
| 17164 | |
| 17165 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17166 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17167 | NL80211_ATTR_PAD)) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17168 | goto nla_put_failure; |
| 17169 | } |
| 17170 | |
| 17171 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) |
| 17172 | goto nla_put_failure; |
| 17173 | |
| 17174 | if (nl80211_send_chandef(msg, chandef)) |
| 17175 | goto nla_put_failure; |
| 17176 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17177 | genlmsg_end(msg, hdr); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17178 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17179 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17180 | NL80211_MCGRP_MLME, gfp); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17181 | return; |
| 17182 | |
| 17183 | nla_put_failure: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 17184 | nlmsg_free(msg); |
| 17185 | } |
| 17186 | |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 17187 | void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac, |
| 17188 | struct sta_opmode_info *sta_opmode, |
| 17189 | gfp_t gfp) |
| 17190 | { |
| 17191 | struct sk_buff *msg; |
| 17192 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17193 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17194 | void *hdr; |
| 17195 | |
| 17196 | if (WARN_ON(!mac)) |
| 17197 | return; |
| 17198 | |
| 17199 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17200 | if (!msg) |
| 17201 | return; |
| 17202 | |
| 17203 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED); |
| 17204 | if (!hdr) { |
| 17205 | nlmsg_free(msg); |
| 17206 | return; |
| 17207 | } |
| 17208 | |
| 17209 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
| 17210 | goto nla_put_failure; |
| 17211 | |
| 17212 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
| 17213 | goto nla_put_failure; |
| 17214 | |
| 17215 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
| 17216 | goto nla_put_failure; |
| 17217 | |
| 17218 | if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) && |
| 17219 | nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode)) |
| 17220 | goto nla_put_failure; |
| 17221 | |
| 17222 | if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) && |
Johannes Berg | 0016d32 | 2020-03-25 09:05:32 +0100 | [diff] [blame] | 17223 | nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw)) |
tamizhr@codeaurora.org | 466b993 | 2018-01-31 16:24:49 +0530 | [diff] [blame] | 17224 | goto nla_put_failure; |
| 17225 | |
| 17226 | if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) && |
| 17227 | nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss)) |
| 17228 | goto nla_put_failure; |
| 17229 | |
| 17230 | genlmsg_end(msg, hdr); |
| 17231 | |
| 17232 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17233 | NL80211_MCGRP_MLME, gfp); |
| 17234 | |
| 17235 | return; |
| 17236 | |
| 17237 | nla_put_failure: |
| 17238 | nlmsg_free(msg); |
| 17239 | } |
| 17240 | EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify); |
| 17241 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17242 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 17243 | u64 cookie, bool acked, s32 ack_signal, |
| 17244 | bool is_valid_ack_signal, gfp_t gfp) |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17245 | { |
| 17246 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17247 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17248 | struct sk_buff *msg; |
| 17249 | void *hdr; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17250 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17251 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
| 17252 | |
Thomas Graf | 58050fc | 2012-06-28 03:57:45 +0000 | [diff] [blame] | 17253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17254 | |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17255 | if (!msg) |
| 17256 | return; |
| 17257 | |
| 17258 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); |
| 17259 | if (!hdr) { |
| 17260 | nlmsg_free(msg); |
| 17261 | return; |
| 17262 | } |
| 17263 | |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17264 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17265 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17266 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17267 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
| 17268 | NL80211_ATTR_PAD) || |
Venkateswara Naralasetty | c4b50cd | 2018-02-13 11:03:06 +0530 | [diff] [blame] | 17269 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) || |
| 17270 | (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL, |
| 17271 | ack_signal))) |
David S. Miller | 9360ffd | 2012-03-29 04:41:26 -0400 | [diff] [blame] | 17272 | goto nla_put_failure; |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17273 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17274 | genlmsg_end(msg, hdr); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17275 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17276 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17277 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17278 | return; |
| 17279 | |
| 17280 | nla_put_failure: |
Johannes Berg | 7f6cf31 | 2011-11-04 11:18:15 +0100 | [diff] [blame] | 17281 | nlmsg_free(msg); |
| 17282 | } |
| 17283 | EXPORT_SYMBOL(cfg80211_probe_status); |
| 17284 | |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17285 | void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame, |
| 17286 | size_t len, int freq, int sig_dbm) |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17287 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17288 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17289 | struct sk_buff *msg; |
| 17290 | void *hdr; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17291 | struct cfg80211_beacon_registration *reg; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17292 | |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 17293 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
| 17294 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17295 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17296 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { |
| 17297 | msg = nlmsg_new(len + 100, GFP_ATOMIC); |
| 17298 | if (!msg) { |
| 17299 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
| 17300 | return; |
| 17301 | } |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17302 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17303 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
| 17304 | if (!hdr) |
| 17305 | goto nla_put_failure; |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17306 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17307 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17308 | (freq && |
Thomas Pedersen | 942ba88 | 2020-04-30 10:25:51 -0700 | [diff] [blame] | 17309 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 17310 | KHZ_TO_MHZ(freq)) || |
| 17311 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, |
| 17312 | freq % 1000))) || |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17313 | (sig_dbm && |
| 17314 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || |
| 17315 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) |
| 17316 | goto nla_put_failure; |
| 17317 | |
| 17318 | genlmsg_end(msg, hdr); |
| 17319 | |
| 17320 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17321 | } |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17322 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17323 | return; |
| 17324 | |
| 17325 | nla_put_failure: |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17326 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17327 | nlmsg_free(msg); |
| 17328 | } |
Thomas Pedersen | e76fede | 2020-04-30 10:25:50 -0700 | [diff] [blame] | 17329 | EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17330 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17331 | #ifdef CONFIG_PM |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17332 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
| 17333 | struct cfg80211_wowlan_wakeup *wakeup) |
| 17334 | { |
| 17335 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; |
| 17336 | struct nlattr *nl_results, *nl_match, *nl_freqs; |
| 17337 | int i, j; |
| 17338 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17339 | nl_results = nla_nest_start_noflag(msg, |
| 17340 | NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17341 | if (!nl_results) |
| 17342 | return -EMSGSIZE; |
| 17343 | |
| 17344 | for (i = 0; i < nd->n_matches; i++) { |
| 17345 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; |
| 17346 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17347 | nl_match = nla_nest_start_noflag(msg, i); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17348 | if (!nl_match) |
| 17349 | break; |
| 17350 | |
| 17351 | /* The SSID attribute is optional in nl80211, but for |
| 17352 | * simplicity reasons it's always present in the |
| 17353 | * cfg80211 structure. If a driver can't pass the |
| 17354 | * SSID, that needs to be changed. A zero length SSID |
| 17355 | * is still a valid SSID (wildcard), so it cannot be |
| 17356 | * used for this purpose. |
| 17357 | */ |
| 17358 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, |
| 17359 | match->ssid.ssid)) { |
| 17360 | nla_nest_cancel(msg, nl_match); |
| 17361 | goto out; |
| 17362 | } |
| 17363 | |
| 17364 | if (match->n_channels) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17365 | nl_freqs = nla_nest_start_noflag(msg, |
| 17366 | NL80211_ATTR_SCAN_FREQUENCIES); |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17367 | if (!nl_freqs) { |
| 17368 | nla_nest_cancel(msg, nl_match); |
| 17369 | goto out; |
| 17370 | } |
| 17371 | |
| 17372 | for (j = 0; j < match->n_channels; j++) { |
Samuel Tan | 5528fae8 | 2015-02-09 21:29:15 +0200 | [diff] [blame] | 17373 | if (nla_put_u32(msg, j, match->channels[j])) { |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17374 | nla_nest_cancel(msg, nl_freqs); |
| 17375 | nla_nest_cancel(msg, nl_match); |
| 17376 | goto out; |
| 17377 | } |
| 17378 | } |
| 17379 | |
| 17380 | nla_nest_end(msg, nl_freqs); |
| 17381 | } |
| 17382 | |
| 17383 | nla_nest_end(msg, nl_match); |
| 17384 | } |
| 17385 | |
| 17386 | out: |
| 17387 | nla_nest_end(msg, nl_results); |
| 17388 | return 0; |
| 17389 | } |
| 17390 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17391 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
| 17392 | struct cfg80211_wowlan_wakeup *wakeup, |
| 17393 | gfp_t gfp) |
| 17394 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17395 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17396 | struct sk_buff *msg; |
| 17397 | void *hdr; |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17398 | int size = 200; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17399 | |
| 17400 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); |
| 17401 | |
| 17402 | if (wakeup) |
| 17403 | size += wakeup->packet_present_len; |
| 17404 | |
| 17405 | msg = nlmsg_new(size, gfp); |
| 17406 | if (!msg) |
| 17407 | return; |
| 17408 | |
| 17409 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); |
| 17410 | if (!hdr) |
| 17411 | goto free_msg; |
| 17412 | |
| 17413 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17414 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17415 | NL80211_ATTR_PAD)) |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17416 | goto free_msg; |
| 17417 | |
| 17418 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
| 17419 | wdev->netdev->ifindex)) |
| 17420 | goto free_msg; |
| 17421 | |
| 17422 | if (wakeup) { |
| 17423 | struct nlattr *reasons; |
| 17424 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 17425 | reasons = nla_nest_start_noflag(msg, |
| 17426 | NL80211_ATTR_WOWLAN_TRIGGERS); |
Johannes Berg | 7fa322c | 2013-10-25 11:16:58 +0200 | [diff] [blame] | 17427 | if (!reasons) |
| 17428 | goto free_msg; |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17429 | |
| 17430 | if (wakeup->disconnect && |
| 17431 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) |
| 17432 | goto free_msg; |
| 17433 | if (wakeup->magic_pkt && |
| 17434 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) |
| 17435 | goto free_msg; |
| 17436 | if (wakeup->gtk_rekey_failure && |
| 17437 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) |
| 17438 | goto free_msg; |
| 17439 | if (wakeup->eap_identity_req && |
| 17440 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) |
| 17441 | goto free_msg; |
| 17442 | if (wakeup->four_way_handshake && |
| 17443 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) |
| 17444 | goto free_msg; |
| 17445 | if (wakeup->rfkill_release && |
| 17446 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) |
| 17447 | goto free_msg; |
| 17448 | |
| 17449 | if (wakeup->pattern_idx >= 0 && |
| 17450 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
| 17451 | wakeup->pattern_idx)) |
| 17452 | goto free_msg; |
| 17453 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17454 | if (wakeup->tcp_match && |
| 17455 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) |
| 17456 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17457 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17458 | if (wakeup->tcp_connlost && |
| 17459 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) |
| 17460 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17461 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17462 | if (wakeup->tcp_nomoretokens && |
| 17463 | nla_put_flag(msg, |
| 17464 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) |
| 17465 | goto free_msg; |
Johannes Berg | 2a0e047 | 2013-01-23 22:57:40 +0100 | [diff] [blame] | 17466 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17467 | if (wakeup->packet) { |
| 17468 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; |
| 17469 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; |
| 17470 | |
| 17471 | if (!wakeup->packet_80211) { |
| 17472 | pkt_attr = |
| 17473 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; |
| 17474 | len_attr = |
| 17475 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; |
| 17476 | } |
| 17477 | |
| 17478 | if (wakeup->packet_len && |
| 17479 | nla_put_u32(msg, len_attr, wakeup->packet_len)) |
| 17480 | goto free_msg; |
| 17481 | |
| 17482 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, |
| 17483 | wakeup->packet)) |
| 17484 | goto free_msg; |
| 17485 | } |
| 17486 | |
Luciano Coelho | 8cd4d45 | 2014-09-17 11:55:28 +0300 | [diff] [blame] | 17487 | if (wakeup->net_detect && |
| 17488 | cfg80211_net_detect_results(msg, wakeup)) |
| 17489 | goto free_msg; |
| 17490 | |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17491 | nla_nest_end(msg, reasons); |
| 17492 | } |
| 17493 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17494 | genlmsg_end(msg, hdr); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17495 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17496 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17497 | NL80211_MCGRP_MLME, gfp); |
Johannes Berg | cd8f7cb | 2013-01-22 12:34:29 +0100 | [diff] [blame] | 17498 | return; |
| 17499 | |
| 17500 | free_msg: |
| 17501 | nlmsg_free(msg); |
| 17502 | } |
| 17503 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); |
| 17504 | #endif |
| 17505 | |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17506 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
| 17507 | enum nl80211_tdls_operation oper, |
| 17508 | u16 reason_code, gfp_t gfp) |
| 17509 | { |
| 17510 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17511 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17512 | struct sk_buff *msg; |
| 17513 | void *hdr; |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17514 | |
| 17515 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, |
| 17516 | reason_code); |
| 17517 | |
| 17518 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17519 | if (!msg) |
| 17520 | return; |
| 17521 | |
| 17522 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); |
| 17523 | if (!hdr) { |
| 17524 | nlmsg_free(msg); |
| 17525 | return; |
| 17526 | } |
| 17527 | |
| 17528 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17529 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17530 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || |
| 17531 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || |
| 17532 | (reason_code > 0 && |
| 17533 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) |
| 17534 | goto nla_put_failure; |
| 17535 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17536 | genlmsg_end(msg, hdr); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17537 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17538 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17539 | NL80211_MCGRP_MLME, gfp); |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17540 | return; |
| 17541 | |
| 17542 | nla_put_failure: |
Jouni Malinen | 3475b09 | 2012-11-16 22:49:57 +0200 | [diff] [blame] | 17543 | nlmsg_free(msg); |
| 17544 | } |
| 17545 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); |
| 17546 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17547 | static int nl80211_netlink_notify(struct notifier_block * nb, |
| 17548 | unsigned long state, |
| 17549 | void *_notify) |
| 17550 | { |
| 17551 | struct netlink_notify *notify = _notify; |
| 17552 | struct cfg80211_registered_device *rdev; |
| 17553 | struct wireless_dev *wdev; |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17554 | struct cfg80211_beacon_registration *reg, *tmp; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17555 | |
Dmitry Ivanov | 8f815cd | 2016-04-06 17:23:18 +0300 | [diff] [blame] | 17556 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17557 | return NOTIFY_DONE; |
| 17558 | |
| 17559 | rcu_read_lock(); |
| 17560 | |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17561 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17562 | struct cfg80211_sched_scan_request *sched_scan_req; |
Jukka Rissanen | 93a1e86 | 2014-12-15 13:25:39 +0200 | [diff] [blame] | 17563 | |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17564 | list_for_each_entry_rcu(sched_scan_req, |
| 17565 | &rdev->sched_scan_req_list, |
| 17566 | list) { |
| 17567 | if (sched_scan_req->owner_nlportid == notify->portid) { |
| 17568 | sched_scan_req->nl_owner_dead = true; |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17569 | schedule_work(&rdev->sched_scan_stop_wk); |
Arend Van Spriel | ca986ad | 2017-04-21 13:05:00 +0100 | [diff] [blame] | 17570 | } |
Johannes Berg | 753aacf | 2017-01-05 10:57:14 +0100 | [diff] [blame] | 17571 | } |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17572 | |
Johannes Berg | 53873f1 | 2016-05-03 16:52:04 +0300 | [diff] [blame] | 17573 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
Eric W. Biederman | 15e4730 | 2012-09-07 20:12:54 +0000 | [diff] [blame] | 17574 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17575 | |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17576 | if (wdev->owner_nlportid == notify->portid) { |
| 17577 | wdev->nl_owner_dead = true; |
| 17578 | schedule_work(&rdev->destroy_work); |
| 17579 | } else if (wdev->conn_owner_nlportid == notify->portid) { |
Andrzej Zaborowski | bd2522b | 2017-01-06 16:33:43 -0500 | [diff] [blame] | 17580 | schedule_work(&wdev->disconnect_wk); |
Johannes Berg | ab81007 | 2017-04-26 07:43:41 +0200 | [diff] [blame] | 17581 | } |
Johannes Berg | 9bb7e0f | 2018-09-10 13:29:12 +0200 | [diff] [blame] | 17582 | |
| 17583 | cfg80211_release_pmsr(wdev, notify->portid); |
Johannes Berg | 78f22b6 | 2014-03-24 17:57:27 +0100 | [diff] [blame] | 17584 | } |
| 17585 | |
Ben Greear | 37c73b5 | 2012-10-26 14:49:25 -0700 | [diff] [blame] | 17586 | spin_lock_bh(&rdev->beacon_registrations_lock); |
| 17587 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, |
| 17588 | list) { |
| 17589 | if (reg->nlportid == notify->portid) { |
| 17590 | list_del(®->list); |
| 17591 | kfree(reg); |
| 17592 | break; |
| 17593 | } |
| 17594 | } |
| 17595 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
Johannes Berg | 5e76023 | 2011-11-04 11:18:17 +0100 | [diff] [blame] | 17596 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17597 | |
| 17598 | rcu_read_unlock(); |
| 17599 | |
Ilan peer | 0505075 | 2015-03-04 00:32:06 -0500 | [diff] [blame] | 17600 | /* |
| 17601 | * It is possible that the user space process that is controlling the |
| 17602 | * indoor setting disappeared, so notify the regulatory core. |
| 17603 | */ |
| 17604 | regulatory_netlink_notify(notify->portid); |
Zhao, Gang | 6784c7d | 2014-04-21 12:53:04 +0800 | [diff] [blame] | 17605 | return NOTIFY_OK; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17606 | } |
| 17607 | |
| 17608 | static struct notifier_block nl80211_netlink_notifier = { |
| 17609 | .notifier_call = nl80211_netlink_notify, |
| 17610 | }; |
| 17611 | |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17612 | void cfg80211_ft_event(struct net_device *netdev, |
| 17613 | struct cfg80211_ft_event_params *ft_event) |
| 17614 | { |
| 17615 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17616 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17617 | struct sk_buff *msg; |
| 17618 | void *hdr; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17619 | |
| 17620 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); |
| 17621 | |
| 17622 | if (!ft_event->target_ap) |
| 17623 | return; |
| 17624 | |
Dedy Lansky | 1039d08 | 2018-05-17 16:25:03 +0300 | [diff] [blame] | 17625 | msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len, |
| 17626 | GFP_KERNEL); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17627 | if (!msg) |
| 17628 | return; |
| 17629 | |
| 17630 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17631 | if (!hdr) |
| 17632 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17633 | |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17634 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17635 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17636 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) |
| 17637 | goto out; |
| 17638 | |
| 17639 | if (ft_event->ies && |
| 17640 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) |
| 17641 | goto out; |
| 17642 | if (ft_event->ric_ies && |
| 17643 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, |
| 17644 | ft_event->ric_ies)) |
| 17645 | goto out; |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17646 | |
Johannes Berg | 9c90a9f | 2013-06-04 12:46:03 +0200 | [diff] [blame] | 17647 | genlmsg_end(msg, hdr); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17648 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 17649 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 17650 | NL80211_MCGRP_MLME, GFP_KERNEL); |
Johannes Berg | ae917c9 | 2013-10-25 11:05:22 +0200 | [diff] [blame] | 17651 | return; |
| 17652 | out: |
| 17653 | nlmsg_free(msg); |
Jouni Malinen | 355199e | 2013-02-27 17:14:27 +0200 | [diff] [blame] | 17654 | } |
| 17655 | EXPORT_SYMBOL(cfg80211_ft_event); |
| 17656 | |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17657 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
| 17658 | { |
| 17659 | struct cfg80211_registered_device *rdev; |
| 17660 | struct sk_buff *msg; |
| 17661 | void *hdr; |
| 17662 | u32 nlportid; |
| 17663 | |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17664 | rdev = wiphy_to_rdev(wdev->wiphy); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17665 | if (!rdev->crit_proto_nlportid) |
| 17666 | return; |
| 17667 | |
| 17668 | nlportid = rdev->crit_proto_nlportid; |
| 17669 | rdev->crit_proto_nlportid = 0; |
| 17670 | |
| 17671 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17672 | if (!msg) |
| 17673 | return; |
| 17674 | |
| 17675 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); |
| 17676 | if (!hdr) |
| 17677 | goto nla_put_failure; |
| 17678 | |
| 17679 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17680 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17681 | NL80211_ATTR_PAD)) |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17682 | goto nla_put_failure; |
| 17683 | |
| 17684 | genlmsg_end(msg, hdr); |
| 17685 | |
| 17686 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
| 17687 | return; |
| 17688 | |
| 17689 | nla_put_failure: |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17690 | nlmsg_free(msg); |
Arend van Spriel | 5de1798 | 2013-04-18 15:49:00 +0200 | [diff] [blame] | 17691 | } |
| 17692 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); |
| 17693 | |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17694 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
| 17695 | { |
| 17696 | struct wiphy *wiphy = wdev->wiphy; |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 17697 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17698 | struct sk_buff *msg; |
| 17699 | void *hdr; |
| 17700 | |
| 17701 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
| 17702 | if (!msg) |
| 17703 | return; |
| 17704 | |
| 17705 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); |
| 17706 | if (!hdr) |
| 17707 | goto out; |
| 17708 | |
| 17709 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17710 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || |
Nicolas Dichtel | 2dad624 | 2016-04-25 10:25:22 +0200 | [diff] [blame] | 17711 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
| 17712 | NL80211_ATTR_PAD)) |
Johannes Berg | 348baf0 | 2014-01-24 14:06:29 +0100 | [diff] [blame] | 17713 | goto out; |
| 17714 | |
| 17715 | genlmsg_end(msg, hdr); |
| 17716 | |
| 17717 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, |
| 17718 | NL80211_MCGRP_MLME, GFP_KERNEL); |
| 17719 | return; |
| 17720 | out: |
| 17721 | nlmsg_free(msg); |
| 17722 | } |
| 17723 | |
Srinivas Dasari | 40cbfa9 | 2018-01-25 17:13:38 +0200 | [diff] [blame] | 17724 | int cfg80211_external_auth_request(struct net_device *dev, |
| 17725 | struct cfg80211_external_auth_params *params, |
| 17726 | gfp_t gfp) |
| 17727 | { |
| 17728 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
| 17729 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
| 17730 | struct sk_buff *msg; |
| 17731 | void *hdr; |
| 17732 | |
| 17733 | if (!wdev->conn_owner_nlportid) |
| 17734 | return -EINVAL; |
| 17735 | |
| 17736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17737 | if (!msg) |
| 17738 | return -ENOMEM; |
| 17739 | |
| 17740 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 17741 | if (!hdr) |
| 17742 | goto nla_put_failure; |
| 17743 | |
| 17744 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17745 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
| 17746 | nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) || |
| 17747 | nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION, |
| 17748 | params->action) || |
| 17749 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) || |
| 17750 | nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len, |
| 17751 | params->ssid.ssid)) |
| 17752 | goto nla_put_failure; |
| 17753 | |
| 17754 | genlmsg_end(msg, hdr); |
| 17755 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, |
| 17756 | wdev->conn_owner_nlportid); |
| 17757 | return 0; |
| 17758 | |
| 17759 | nla_put_failure: |
| 17760 | nlmsg_free(msg); |
| 17761 | return -ENOBUFS; |
| 17762 | } |
| 17763 | EXPORT_SYMBOL(cfg80211_external_auth_request); |
| 17764 | |
Sunil Dutt | cb74e97 | 2019-02-20 16:18:07 +0530 | [diff] [blame] | 17765 | void cfg80211_update_owe_info_event(struct net_device *netdev, |
| 17766 | struct cfg80211_update_owe_info *owe_info, |
| 17767 | gfp_t gfp) |
| 17768 | { |
| 17769 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; |
| 17770 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
| 17771 | struct sk_buff *msg; |
| 17772 | void *hdr; |
| 17773 | |
| 17774 | trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info); |
| 17775 | |
| 17776 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
| 17777 | if (!msg) |
| 17778 | return; |
| 17779 | |
| 17780 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO); |
| 17781 | if (!hdr) |
| 17782 | goto nla_put_failure; |
| 17783 | |
| 17784 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
| 17785 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
| 17786 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer)) |
| 17787 | goto nla_put_failure; |
| 17788 | |
| 17789 | if (!owe_info->ie_len || |
| 17790 | nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie)) |
| 17791 | goto nla_put_failure; |
| 17792 | |
| 17793 | genlmsg_end(msg, hdr); |
| 17794 | |
| 17795 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
| 17796 | NL80211_MCGRP_MLME, gfp); |
| 17797 | return; |
| 17798 | |
| 17799 | nla_put_failure: |
| 17800 | genlmsg_cancel(msg, hdr); |
| 17801 | nlmsg_free(msg); |
| 17802 | } |
| 17803 | EXPORT_SYMBOL(cfg80211_update_owe_info_event); |
| 17804 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17805 | /* initialisation/exit functions */ |
| 17806 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 17807 | int __init nl80211_init(void) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17808 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 17809 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17810 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 17811 | err = genl_register_family(&nl80211_fam); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17812 | if (err) |
| 17813 | return err; |
| 17814 | |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17815 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
| 17816 | if (err) |
| 17817 | goto err_out; |
| 17818 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17819 | return 0; |
| 17820 | err_out: |
| 17821 | genl_unregister_family(&nl80211_fam); |
| 17822 | return err; |
| 17823 | } |
| 17824 | |
| 17825 | void nl80211_exit(void) |
| 17826 | { |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 17827 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17828 | genl_unregister_family(&nl80211_fam); |
| 17829 | } |