blob: 554796a6c6fe5dcb3461d688f12a08a19a4a92cf [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Johannes Berg55682962007-09-20 13:09:35 -04002/*
3 * This is the new netlink-based wireless configuration interface.
4 *
Jouni Malinen026331c2010-02-15 12:53:10 +02005 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03006 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg66cd7942017-02-07 22:40:44 +02007 * Copyright 2015-2017 Intel Deutschland GmbH
Shaul Triebitz7e8d6f12020-01-31 13:12:54 +02008 * Copyright (C) 2018-2020 Intel Corporation
Johannes Berg55682962007-09-20 13:09:35 -04009 */
10
11#include <linux/if.h>
12#include <linux/module.h>
13#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090014#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040015#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 Williams259d8c12018-01-29 17:03:15 -080021#include <linux/nospec.h>
Johannes Berg2a519312009-02-10 21:25:55 +010022#include <linux/etherdevice.h>
Johannes Berge3ae39e2020-02-24 09:38:15 +010023#include <linux/if_vlan.h>
Johannes Berg463d0182009-07-14 00:33:35 +020024#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include <net/genetlink.h>
26#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020027#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010028#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040029#include "core.h"
30#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070031#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030032#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040033
Jouni Malinen5fb628e2011-08-10 23:54:35 +030034static 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 Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020040static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040041
Johannes Berg2a94fe42013-11-19 15:19:39 +010042/* multicast groups */
43enum nl80211_multicast_groups {
44 NL80211_MCGRP_CONFIG,
45 NL80211_MCGRP_SCAN,
46 NL80211_MCGRP_REGULATORY,
47 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010048 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030049 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010050 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
51};
52
53static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010054 [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 Beker50bcd312016-09-20 17:31:17 +030059 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010060#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010061 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010062#endif
63};
64
Johannes Berg89a54e42012-06-15 14:33:17 +020065/* returns ERR_PTR values */
66static struct wireless_dev *
67__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040068{
Johannes Berg89a54e42012-06-15 14:33:17 +020069 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 Berg55682962007-09-20 13:09:35 -040076
Johannes Berg5fe231e2013-05-08 21:45:15 +020077 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040078
Johannes Berg89a54e42012-06-15 14:33:17 +020079 if (!have_ifidx && !have_wdev_id)
80 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040081
Johannes Berg89a54e42012-06-15 14:33:17 +020082 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 Berg55682962007-09-20 13:09:35 -040087 }
88
Johannes Berg89a54e42012-06-15 14:33:17 +020089 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 Berg53873f12016-05-03 16:52:04 +030098 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020099 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 Berg89a54e42012-06-15 14:33:17 +0200109
110 if (result)
111 break;
112 }
113
114 if (result)
115 return result;
116 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400117}
118
Johannes Berga9455402012-06-15 13:32:49 +0200119static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200120__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200121{
Johannes Berg7fee47782012-06-15 14:09:58 +0200122 struct cfg80211_registered_device *rdev = NULL, *tmp;
123 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200124
Johannes Berg5fe231e2013-05-08 21:45:15 +0200125 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200126
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200128 !attrs[NL80211_ATTR_IFINDEX] &&
129 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200130 return ERR_PTR(-EINVAL);
131
Johannes Berg878d9ec2012-06-15 14:18:32 +0200132 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200133 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200135
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 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 Berg53873f12016-05-03 16:52:04 +0300144 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200145 if (wdev->identifier != (u32)wdev_id)
146 continue;
147 found = true;
148 break;
149 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200150
151 if (!found)
152 tmp = NULL;
153
154 if (rdev && tmp != rdev)
155 return ERR_PTR(-EINVAL);
156 rdev = tmp;
157 }
158 }
159
Johannes Berg878d9ec2012-06-15 14:18:32 +0200160 if (attrs[NL80211_ATTR_IFINDEX]) {
161 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700162
Ying Xue7f2b8562014-01-15 10:23:45 +0800163 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200164 if (netdev) {
165 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800166 tmp = wiphy_to_rdev(
167 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200168 else
169 tmp = NULL;
170
Johannes Berg7fee47782012-06-15 14:09:58 +0200171 /* 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 Berga9455402012-06-15 13:32:49 +0200180 }
Johannes Berga9455402012-06-15 13:32:49 +0200181 }
182
Johannes Berg4f7eff12012-06-15 14:14:22 +0200183 if (!rdev)
184 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200185
Johannes Berg4f7eff12012-06-15 14:14:22 +0200186 if (netns != wiphy_net(&rdev->wiphy))
187 return ERR_PTR(-ENODEV);
188
189 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200190}
191
192/*
193 * This function returns a pointer to the driver
194 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200195 *
196 * The result of this can be a PTR_ERR and hence must
197 * be checked with IS_ERR() for errors.
198 */
199static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200200cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200201{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200202 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200203}
204
Johannes Bergf88eb7c2019-09-20 21:54:17 +0200205static 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 Pedersen1d47f112020-09-08 12:03:05 -0700212 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 Bergf88eb7c2019-09-20 21:54:17 +0200224
225 if (len < fixedlen)
226 goto err;
227
Thomas Pedersen1d47f112020-09-08 12:03:05 -0700228 if (ieee80211_hdrlen(mgmt->frame_control) != hdrlen)
Johannes Bergf88eb7c2019-09-20 21:54:17 +0200229 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
241err:
242 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
243 return -EINVAL;
244}
245
Johannes Berg3d7af872018-10-02 10:00:08 +0200246static int validate_ie_attr(const struct nlattr *attr,
247 struct netlink_ext_ack *extack)
248{
Johannes Berg9f308612019-02-07 23:39:19 +0100249 const u8 *data = nla_data(attr);
250 unsigned int len = nla_len(attr);
Jouni Malinen7388afe2019-02-11 16:29:04 +0200251 const struct element *elem;
Johannes Berg3d7af872018-10-02 10:00:08 +0200252
Johannes Berg9f308612019-02-07 23:39:19 +0100253 for_each_element(elem, data, len) {
254 /* nothing */
Johannes Berg3d7af872018-10-02 10:00:08 +0200255 }
256
Johannes Berg9f308612019-02-07 23:39:19 +0100257 if (for_each_element_completed(elem, data, len))
258 return 0;
259
Johannes Berg3d7af872018-10-02 10:00:08 +0200260 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
261 return -EINVAL;
262}
263
Johannes Berg55682962007-09-20 13:09:35 -0400264/* policy for the attributes */
Johannes Bergd15da2a2020-04-30 22:13:07 +0200265static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR];
266
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700267static const struct nla_policy
268nl80211_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 Berg9bb7e0f2018-09-10 13:29:12 +0200276static const struct nla_policy
277nl80211_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 Erenfeldea187092019-02-06 13:17:08 +0200286 NLA_POLICY_MAX(NLA_U8, 31),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200287 [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 Sternefb55202020-01-31 13:12:38 +0200290 [NL80211_PMSR_FTM_REQ_ATTR_TRIGGER_BASED] = { .type = NLA_FLAG },
291 [NL80211_PMSR_FTM_REQ_ATTR_NON_TRIGGER_BASED] = { .type = NLA_FLAG },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200292};
293
294static const struct nla_policy
295nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
296 [NL80211_PMSR_TYPE_FTM] =
Johannes Berg23323282019-01-25 10:08:28 +0100297 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200298};
299
300static const struct nla_policy
301nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
302 [NL80211_PMSR_REQ_ATTR_DATA] =
Johannes Berg23323282019-01-25 10:08:28 +0100303 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200304 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
305};
306
307static const struct nla_policy
308nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
309 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
Johannes Bergd15da2a2020-04-30 22:13:07 +0200310 [NL80211_PMSR_PEER_ATTR_CHAN] = NLA_POLICY_NESTED(nl80211_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200311 [NL80211_PMSR_PEER_ATTR_REQ] =
Johannes Berg23323282019-01-25 10:08:28 +0100312 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200313 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
314};
315
316static const struct nla_policy
317nl80211_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 Berg23323282019-01-25 10:08:28 +0100323 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200324};
325
John Crispin796e90f2019-07-30 18:37:00 +0200326static const struct nla_policy
327he_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 Manoharanf5bec332020-09-28 00:28:11 -0700332 [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 Crispin796e90f2019-07-30 18:37:00 +0200339};
340
John Crispin5c5e52d2019-12-17 15:19:18 +0100341static const struct nla_policy
342he_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 Chelvam9a5f6482020-05-13 13:41:44 +0530348static 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 Hueb89a6a2020-08-04 10:16:29 +0200355 [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 Chelvam9a5f6482020-05-13 13:41:44 +0530362};
363
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530364static const struct nla_policy
365nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
Johannes Berg3710a8a2020-02-24 11:34:25 +0100366 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
367 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530368 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
Johannes Berg3710a8a2020-02-24 11:34:25 +0100369 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530370 [NL80211_TID_CONFIG_ATTR_NOACK] =
371 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Tamizh chelvam6a21d162020-01-20 13:21:23 +0530372 [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 chelvamade274b2020-01-20 13:21:24 +0530374 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] =
375 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Tamizh chelvam04f7d142020-01-20 13:21:25 +0530376 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] =
377 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Sergey Matyukevich33462e62020-04-24 14:29:03 +0300378 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] =
379 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +0530380 [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 chelvam77f576d2020-01-20 13:21:22 +0530384};
385
Aloka Dixit291c49d2020-09-11 00:05:29 +0000386static const struct nla_policy
387nl80211_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 Dixit7443dcd2020-09-11 00:33:00 +0000395static const struct nla_policy
396nl80211_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 Bergd15da2a2020-04-30 22:13:07 +0200402static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg6d4dd4e2019-07-31 10:58:20 +0200403 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
Johannes Berg55682962007-09-20 13:09:35 -0400404 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
405 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700406 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200407 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100408
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200409 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530410 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +0300411 [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 Berg3d9d1d62012-11-08 23:14:50 +0100418 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
419 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
Thomas Pedersen942ba882020-04-30 10:25:51 -0700420 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100421 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
422
Johannes Bergab0d76f2018-10-02 10:00:07 +0200423 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
424 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200425 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
426 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100427 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200428 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400429
Johannes Bergab0d76f2018-10-02 10:00:07 +0200430 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400431 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
432 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100433
Johannes Bergc7721c02020-04-30 22:13:10 +0200434 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
435 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Johannes Berg41ade002007-12-19 02:03:29 +0100436
Johannes Bergb9454e82009-07-08 13:29:08 +0200437 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100438 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
439 .len = WLAN_MAX_KEY_LEN },
Jouni Malinen56be3932020-02-22 15:25:43 +0200440 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
Johannes Berg41ade002007-12-19 02:03:29 +0100441 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
442 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200443 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200444 [NL80211_ATTR_KEY_TYPE] =
445 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100446
447 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
448 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
Johannes Bergf88eb7c2019-09-20 21:54:17 +0200449 [NL80211_ATTR_BEACON_HEAD] =
450 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
451 IEEE80211_MAX_DATA_LEN),
Johannes Berg3d7af872018-10-02 10:00:08 +0200452 [NL80211_ATTR_BEACON_TAIL] =
453 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
454 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200455 [NL80211_ATTR_STA_AID] =
456 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100457 [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 Bergab0d76f2018-10-02 10:00:07 +0200461 [NL80211_ATTR_STA_PLINK_ACTION] =
462 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +0530463 [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 Berg5727ef12007-12-19 02:03:34 +0100468 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200469 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100470 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800471 .len = IEEE80211_MAX_MESH_ID_LEN },
Markus Theil1fab1b82019-10-29 10:30:03 +0100472 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300473
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700474 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
475 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
476
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300477 [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 Malinen90c97a02008-10-30 16:59:22 +0200480 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
481 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100482 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300483
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800484 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700485 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700486
Johannes Bergc7721c02020-04-30 22:13:10 +0200487 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200488
489 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200490 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
491 validate_ie_attr,
492 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100493 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
494 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200495
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 Berg04a773a2009-04-19 21:24:32 +0200500 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300501 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200502 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
503 NL80211_MFP_NO,
504 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300505 [NL80211_ATTR_STA_FLAGS2] = {
506 .len = sizeof(struct nl80211_sta_flag_update),
507 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300508 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300509 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
510 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500511 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200512 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
Sergey Matyukevichea750802020-02-13 13:16:16 +0000513 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200514 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
515 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200516 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100517 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200518 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100519 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
520 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200521 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200522 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
523 .len = IEEE80211_MAX_DATA_LEN },
524 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200525 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
526 NL80211_PS_DISABLED,
527 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200528 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300529 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200530 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300531 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
532 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200533 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900534 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
535 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100536 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100537 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100538 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200539 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200540 [NL80211_ATTR_STA_PLINK_STATE] =
541 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
Jakub Kicinski056e9372020-03-02 21:10:57 -0800542 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
543 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200544 [NL80211_ATTR_MESH_PEER_AID] =
545 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300546 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200547 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200548 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200549 [NL80211_ATTR_HIDDEN_SSID] =
550 NLA_POLICY_RANGE(NLA_U32,
551 NL80211_HIDDEN_SSID_NOT_IN_USE,
552 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200553 [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 Natarajanf4b34b52011-08-29 14:23:03 +0530559 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300560 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530561 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300562 [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 Nemtsov31fa97c2014-06-11 17:18:21 +0300567 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100568 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200569 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
570 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700571 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800572 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
573 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
574 .len = NL80211_HT_CAPABILITY_LEN
575 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100576 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530577 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530578 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200579 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700580 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200581
582 /* need to include at least Auth Transaction and Status Code */
583 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4),
584
Johannes Bergc7721c02020-04-30 22:13:10 +0200585 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
Sam Lefflered4737712012-10-11 21:03:31 -0700586 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200587 [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 Thiagarajan77765ea2013-01-18 11:18:45 +0530593 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
594 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200595 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
596 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100597 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100598 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
599 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
600 .len = NL80211_VHT_CAPABILITY_LEN,
601 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200602 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
603 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
604 .len = IEEE80211_MAX_DATA_LEN },
Jakub Kicinski0e1a1d82020-03-02 21:10:56 -0800605 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200606 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] =
607 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200608 [NL80211_ATTR_PEER_AID] =
609 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200610 [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 Crispin00c207e2020-08-11 10:01:03 +0200613 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY },
614 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200615 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2),
Johannes Bergc8b82802020-08-19 08:56:43 +0200616 /*
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 Wunderlich5336fa82013-10-07 18:41:05 +0200622 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100623 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100624 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
625 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
626 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Johannes Bergc8b82802020-08-19 08:56:43 +0200627 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY,
628 IEEE80211_QOS_MAP_LEN_MIN,
629 IEEE80211_QOS_MAP_LEN_MAX),
Johannes Bergc7721c02020-04-30 22:13:10 +0200630 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Jouni Malinen1df4a512014-01-15 00:00:47 +0200631 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530632 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200633 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300634 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300635 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200636 [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 Berg960d01a2014-09-09 22:55:35 +0300639 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300640 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Jakub Kicinski5cde05c2020-03-02 21:10:58 -0800641 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200642 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200643 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200644 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200645 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500646 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200647 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100648 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200649 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
650 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300651 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
652 .len = VHT_MUMIMO_GROUPS_DATA_LEN
653 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200654 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200655 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200656 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300657 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300658 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
659 .len = FILS_MAX_KEK_LEN },
Johannes Bergc7721c02020-04-30 22:13:10 +0200660 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
Michael Braunce0ce132016-10-10 19:12:22 +0200661 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Johannes Bergc7721c02020-04-30 22:13:10 +0200662 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200663 [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 Kushwaha3093ebbeab2017-01-13 01:12:21 +0200667 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300668 [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 Bergc7721c02020-04-30 22:13:10 +0200675 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300676 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200677 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN),
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100678 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200679 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200680
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 Bergc8b82802020-08-19 08:56:43 +0200684 [NL80211_ATTR_HE_CAPABILITY] =
685 NLA_POLICY_RANGE(NLA_BINARY,
686 NL80211_HE_MIN_CAPABILITY_LEN,
687 NL80211_HE_MAX_CAPABILITY_LEN),
Johannes Berg0e012b42020-04-12 00:40:30 +0200688 [NL80211_ATTR_FTM_RESPONDER] =
689 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200690 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
691 [NL80211_ATTR_PEER_MEASUREMENTS] =
Johannes Berg23323282019-01-25 10:08:28 +0100692 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800693 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +0000694 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
695 .len = SAE_PASSWORD_MAX_LEN },
John Crispina0de1ca32019-05-28 13:49:48 +0200696 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
John Crispin796e90f2019-07-30 18:37:00 +0200697 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +0200698 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
John Crispin5c5e52d2019-12-17 15:19:18 +0100699 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530700 [NL80211_ATTR_TID_CONFIG] =
701 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
Markus Theil5631d962020-03-12 10:10:53 +0100702 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
Veerendranath Jakkam7fc82af2020-03-13 01:59:03 +0200703 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
704 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
Johannes Berg9dba48a2020-04-17 12:40:15 +0200705 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
Thomas Pedersen942ba882020-04-30 10:25:51 -0700706 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
Thomas Pedersen2032f3b2020-04-30 10:25:52 -0700707 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
Johannes Berg81408602020-08-18 10:17:31 +0200708 [NL80211_ATTR_HE_6GHZ_CAPABILITY] =
709 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)),
Aloka Dixit291c49d2020-09-11 00:05:29 +0000710 [NL80211_ATTR_FILS_DISCOVERY] =
711 NLA_POLICY_NESTED(nl80211_fils_discovery_policy),
Aloka Dixit7443dcd2020-09-11 00:33:00 +0000712 [NL80211_ATTR_UNSOL_BCAST_PROBE_RESP] =
713 NLA_POLICY_NESTED(nl80211_unsol_bcast_probe_resp_policy),
Thomas Pedersend2b75882020-09-21 19:28:04 -0700714 [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 Berg55682962007-09-20 13:09:35 -0400718};
719
Johannes Berge31b8212010-10-05 19:39:30 +0200720/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000721static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200722 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200723 [NL80211_KEY_IDX] = { .type = NLA_U8 },
724 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200725 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200726 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
727 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200728 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100729 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100730 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100731};
732
733/* policy for the key default flags */
734static const struct nla_policy
735nl80211_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 Bergb9454e82009-07-08 13:29:08 +0200738};
739
Johannes Bergf83ace32016-10-17 08:04:07 +0200740#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200741/* policy for WoWLAN attributes */
742static const struct nla_policy
743nl80211_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 Berg77dbbb12011-07-13 10:48:55 +0200748 [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 Berg2a0e0472013-01-23 22:57:40 +0100752 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300753 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100754};
755
756static const struct nla_policy
757nl80211_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 Bergc7721c02020-04-30 22:13:10 +0200760 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Johannes Berg2a0e0472013-01-23 22:57:40 +0100761 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
762 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Bergbc043582020-08-18 10:17:32 +0200763 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
Johannes Berg2a0e0472013-01-23 22:57:40 +0100764 [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 Bergbc043582020-08-18 10:17:32 +0200771 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
772 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1),
Johannes Bergff1b6e62011-05-04 15:37:28 +0200773};
Johannes Bergf83ace32016-10-17 08:04:07 +0200774#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200775
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700776/* policy for coalesce rule attributes */
777static const struct nla_policy
778nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
779 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200780 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
781 NLA_POLICY_RANGE(NLA_U32,
782 NL80211_COALESCE_CONDITION_MATCH,
783 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700784 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
785};
786
Johannes Berge5497d72011-07-05 16:35:40 +0200787/* policy for GTK rekey offload attributes */
788static const struct nla_policy
789nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Nathan Errera093a48d2020-05-28 21:22:38 +0200790 [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 Bergcb9abd42020-08-05 15:47:16 +0200798 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN),
Nathan Errera093a48d2020-05-28 21:22:38 +0200799 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200800};
801
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300802static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530803nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
804 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
805 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
Arend van Spriele548a1c2019-08-02 13:31:02 +0200806 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530807 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
808};
809
810static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300811nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200812 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300813 .len = IEEE80211_MAX_SSID_LEN },
Johannes Bergc7721c02020-04-30 22:13:10 +0200814 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700815 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530816 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
817 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300818};
819
Avraham Stern3b06d272015-10-12 09:51:34 +0300820static const struct nla_policy
821nl80211_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 Spriel38de03d2016-03-02 20:37:18 +0100826static const struct nla_policy
827nl80211_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 Bekera442b762016-09-20 17:31:15 +0300835/* policy for NAN function attributes */
836static const struct nla_policy
837nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
Johannes Bergcb9abd42020-08-05 15:47:16 +0200838 [NL80211_NAN_FUNC_TYPE] =
839 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE),
Srinivas Dasari0a278442017-07-07 01:43:40 +0300840 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300841 .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 Bergc7721c02020-04-30 22:13:10 +0200847 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Ayala Bekera442b762016-09-20 17:31:15 +0300848 [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 */
860static const struct nla_policy
861nl80211_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 Xuad670232017-10-03 23:21:51 +0300869/* policy for packet pattern attributes */
870static const struct nla_policy
871nl80211_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 Berg9bb7e0f2018-09-10 13:29:12 +0200877int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
878 struct cfg80211_registered_device **rdev,
879 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100880{
Johannes Berg67748892010-10-04 21:14:06 +0200881 int err;
882
Johannes Berg97990a02013-04-19 01:02:55 +0200883 if (!cb->args[0]) {
Johannes Berg50508d92019-07-29 16:31:09 +0200884 struct nlattr **attrbuf;
885
886 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
887 GFP_KERNEL);
888 if (!attrbuf)
889 return -ENOMEM;
890
Johannes Berg8cb08172019-04-26 14:07:28 +0200891 err = nlmsg_parse_deprecated(cb->nlh,
892 GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Berg50508d92019-07-29 16:31:09 +0200893 attrbuf, nl80211_fam.maxattr,
Johannes Berg8cb08172019-04-26 14:07:28 +0200894 nl80211_policy, NULL);
Johannes Berg50508d92019-07-29 16:31:09 +0200895 if (err) {
896 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100897 return err;
Johannes Berg50508d92019-07-29 16:31:09 +0200898 }
Johannes Berg97990a02013-04-19 01:02:55 +0200899
Johannes Berg50508d92019-07-29 16:31:09 +0200900 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
901 attrbuf);
902 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100903 if (IS_ERR(*wdev))
904 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800905 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200906 /* 0 is the first index - add 1 to parse only once */
907 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200908 cb->args[1] = (*wdev)->identifier;
909 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200910 /* subtract the 1 again here */
911 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200912 struct wireless_dev *tmp;
913
Johannes Bergea90e0d2017-03-15 14:26:04 +0100914 if (!wiphy)
915 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800916 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200917 *wdev = NULL;
918
Johannes Berg53873f12016-05-03 16:52:04 +0300919 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200920 if (tmp->identifier == cb->args[1]) {
921 *wdev = tmp;
922 break;
923 }
924 }
Johannes Berg97990a02013-04-19 01:02:55 +0200925
Johannes Bergea90e0d2017-03-15 14:26:04 +0100926 if (!*wdev)
927 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200928 }
929
Johannes Berg67748892010-10-04 21:14:06 +0200930 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200931}
932
Johannes Berg55682962007-09-20 13:09:35 -0400933/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200934void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
935 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400936{
937 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000938 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400939}
940
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300941static 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 Kubecekae0be8d2019-04-26 11:13:06 +0200946 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300947
948 if (!nl_wmm_rules)
949 goto nla_put_failure;
950
951 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200952 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300953
954 if (!nl_wmm_rule)
955 goto nla_put_failure;
956
957 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200958 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300959 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200960 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300961 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200962 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300963 nla_put_u16(msg, NL80211_WMMR_TXOP,
964 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300965 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
973nla_put_failure:
974 return -ENOBUFS;
975}
976
977static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100978 struct ieee80211_channel *chan,
979 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400980{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200981 /* 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 Bergf8d504c2020-09-28 13:06:56 +0200987 if (!large && chan->freq_offset)
988 return 0;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200989
David S. Miller9360ffd2012-03-29 04:41:26 -0400990 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
991 chan->center_freq))
992 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400993
Thomas Pedersen942ba882020-04-30 10:25:51 -0700994 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
995 goto nla_put_failure;
996
David S. Miller9360ffd2012-03-29 04:41:26 -0400997 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
998 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
999 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +02001000 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 Bergcdc89b92013-02-18 23:54:36 +01001006 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 Dziedzic089027e2014-02-21 19:46:12 +01001020 if (nla_put_u32(msg,
1021 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
1022 chan->dfs_cac_ms))
1023 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001024 }
1025 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001026
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001027 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 Spinadel570dbde2014-02-23 09:12:59 +02001040 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
1041 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
1042 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +03001043 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
1044 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +02001045 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +02001046 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 Dreyfuss1e61d822020-01-21 10:12:13 +02001052 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
1053 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
1054 goto nla_put_failure;
Thomas Pedersend65a9772020-09-08 12:03:03 -07001055 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 Bergfe1abaf2013-02-27 15:39:45 +01001070 }
1071
David S. Miller9360ffd2012-03-29 04:41:26 -04001072 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. Rodriguez5dab3b82009-04-02 14:08:08 -04001075
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001076 if (large) {
1077 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +03001078 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001079
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +02001080 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001081 if (nl80211_msg_put_wmm_rules(msg, rule))
1082 goto nla_put_failure;
1083 }
1084 }
1085
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001086 return 0;
1087
1088 nla_put_failure:
1089 return -ENOBUFS;
1090}
1091
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02001092static 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 Kubecekae0be8d2019-04-26 11:13:06 +02001104 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02001105 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 Berg55682962007-09-20 13:09:35 -04001125/* netlink command implementations */
1126
Johannes Bergb9454e82009-07-08 13:29:08 +02001127struct key_parse {
1128 struct key_params p;
1129 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +02001130 int type;
Jouni Malinen56be3932020-02-22 15:25:43 +02001131 bool def, defmgmt, defbeacon;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001132 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +02001133};
1134
Johannes Berg768075e2017-11-13 15:35:06 +01001135static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1136 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +02001137{
1138 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +02001139 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1140 nl80211_key_policy,
1141 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +02001142 if (err)
1143 return err;
1144
1145 k->def = !!tb[NL80211_KEY_DEFAULT];
1146 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
Jouni Malinen56be3932020-02-22 15:25:43 +02001147 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
Johannes Bergb9454e82009-07-08 13:29:08 +02001148
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001149 if (k->def) {
1150 k->def_uni = true;
1151 k->def_multi = true;
1152 }
Jouni Malinen56be3932020-02-22 15:25:43 +02001153 if (k->defmgmt || k->defbeacon)
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001154 k->def_multi = true;
1155
Johannes Bergb9454e82009-07-08 13:29:08 +02001156 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 Bergab0d76f2018-10-02 10:00:07 +02001172 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001173 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001174
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001175 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1176 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001177
Johannes Berg8cb08172019-04-26 14:07:28 +02001178 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 Bergdbd2fd62010-12-09 19:58:59 +01001183 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 Wetzel6cdd3972019-03-19 21:34:07 +01001190 if (tb[NL80211_KEY_MODE])
1191 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1192
Johannes Bergb9454e82009-07-08 13:29:08 +02001193 return 0;
1194}
1195
1196static 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 Bergdbd2fd62010-12-09 19:58:59 +01001217 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 Bergab0d76f2018-10-02 10:00:07 +02001224 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001225 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001226
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001227 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1228 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001229 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 Bergdbd2fd62010-12-09 19:58:59 +01001234 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 Bergb9454e82009-07-08 13:29:08 +02001241 return 0;
1242}
1243
1244static 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 Berge31b8212010-10-05 19:39:30 +02001250 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001251
1252 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001253 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001254 else
1255 err = nl80211_parse_key_old(info, k);
1256
1257 if (err)
1258 return err;
1259
Jouni Malinen56be3932020-02-22 15:25:43 +02001260 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 Bergb9454e82009-07-08 13:29:08 +02001264 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001265 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001266
Jouni Malinen56be3932020-02-22 15:25:43 +02001267 if (k->defmgmt || k->defbeacon) {
Johannes Berg768075e2017-11-13 15:35:06 +01001268 if (k->def_uni || !k->def_multi) {
Jouni Malinen56be3932020-02-22 15:25:43 +02001269 GENL_SET_ERR_MSG(info,
1270 "defmgmt/defbeacon key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001271 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001272 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001273 }
1274
Johannes Bergb9454e82009-07-08 13:29:08 +02001275 if (k->idx != -1) {
1276 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001277 if (k->idx < 4 || k->idx > 5) {
1278 GENL_SET_ERR_MSG(info,
1279 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001280 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001281 }
Jouni Malinen56be3932020-02-22 15:25:43 +02001282 } 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 Bergb9454e82009-07-08 13:29:08 +02001288 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001289 if (k->idx < 0 || k->idx > 3) {
1290 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001291 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001292 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001293 } else {
Jouni Malinen56be3932020-02-22 15:25:43 +02001294 if (k->idx < 0 || k->idx > 7) {
1295 GENL_SET_ERR_MSG(info, "key idx not 0-7");
Johannes Bergb9454e82009-07-08 13:29:08 +02001296 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001297 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001298 }
1299 }
1300
1301 return 0;
1302}
1303
Johannes Bergfffd0932009-07-08 14:22:54 +02001304static struct cfg80211_cached_keys *
1305nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001306 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001307{
Johannes Berg768075e2017-11-13 15:35:06 +01001308 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001309 struct key_parse parse;
1310 struct nlattr *key;
1311 struct cfg80211_cached_keys *result;
1312 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001313 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 Bergfffd0932009-07-08 14:22:54 +02001322
1323 result = kzalloc(sizeof(*result), GFP_KERNEL);
1324 if (!result)
1325 return ERR_PTR(-ENOMEM);
1326
1327 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001328
1329 nla_for_each_nested(key, keys, rem) {
1330 memset(&parse, 0, sizeof(parse));
1331 parse.idx = -1;
1332
Johannes Berg768075e2017-11-13 15:35:06 +01001333 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001334 if (err)
1335 goto error;
1336 err = -EINVAL;
1337 if (!parse.p.key)
1338 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001339 if (parse.idx < 0 || parse.idx > 3) {
1340 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001341 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001342 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001343 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001344 if (def) {
1345 GENL_SET_ERR_MSG(info,
1346 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001347 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001348 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001349 def = 1;
1350 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001351 if (!parse.def_uni || !parse.def_multi)
1352 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001353 } else if (parse.defmgmt)
1354 goto error;
1355 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001356 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001357 if (err)
1358 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001359 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1360 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001361 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001362 err = -EINVAL;
1363 goto error;
1364 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001365 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 Manoharande7044e2012-10-18 10:19:28 +05301369
Johannes Berg386b1f22016-09-13 16:10:02 +02001370 /* must be WEP key if we got here */
1371 if (no_ht)
1372 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001373 }
1374
Johannes Bergf1c1f172016-09-13 17:08:23 +02001375 if (result->def < 0) {
1376 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001377 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001378 goto error;
1379 }
1380
Johannes Bergfffd0932009-07-08 14:22:54 +02001381 return result;
1382 error:
1383 kfree(result);
1384 return ERR_PTR(err);
1385}
1386
1387static int nl80211_key_allowed(struct wireless_dev *wdev)
1388{
1389 ASSERT_WDEV_LOCK(wdev);
1390
Johannes Bergfffd0932009-07-08 14:22:54 +02001391 switch (wdev->iftype) {
1392 case NL80211_IFTYPE_AP:
1393 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001394 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001395 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001396 break;
1397 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001398 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001399 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001400 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001401 return -ENOLINK;
1402 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001403 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001404 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001405 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001406 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001407 case NL80211_IFTYPE_P2P_DEVICE:
1408 case NL80211_IFTYPE_WDS:
1409 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001410 return -EINVAL;
1411 }
1412
1413 return 0;
1414}
1415
Jouni Malinen664834d2014-01-15 00:01:44 +02001416static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
Thomas Pedersen942ba882020-04-30 10:25:51 -07001417 u32 freq)
Jouni Malinen664834d2014-01-15 00:01:44 +02001418{
1419 struct ieee80211_channel *chan;
1420
Thomas Pedersen942ba882020-04-30 10:25:51 -07001421 chan = ieee80211_get_channel_khz(wiphy, freq);
Jouni Malinen664834d2014-01-15 00:01:44 +02001422 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1423 return NULL;
1424 return chan;
1425}
1426
Johannes Berg7527a782011-05-13 10:58:57 +02001427static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1428{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001429 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001430 int i;
1431
1432 if (!nl_modes)
1433 goto nla_put_failure;
1434
1435 i = 0;
1436 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001437 if ((ifmodes & 1) && nla_put_flag(msg, i))
1438 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001439 ifmodes >>= 1;
1440 i++;
1441 }
1442
1443 nla_nest_end(msg, nl_modes);
1444 return 0;
1445
1446nla_put_failure:
1447 return -ENOBUFS;
1448}
1449
1450static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001451 struct sk_buff *msg,
1452 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001453{
1454 struct nlattr *nl_combis;
1455 int i, j;
1456
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001457 nl_combis = nla_nest_start_noflag(msg,
1458 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001459 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 Kubecekae0be8d2019-04-26 11:13:06 +02001468 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001469 if (!nl_combi)
1470 goto nla_put_failure;
1471
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001472 nl_limits = nla_nest_start_noflag(msg,
1473 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001474 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 Kubecekae0be8d2019-04-26 11:13:06 +02001480 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001481 if (!nl_limit)
1482 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001483 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1484 c->limits[j].max))
1485 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001486 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. Miller9360ffd2012-03-29 04:41:26 -04001494 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 Bergcdc89b92013-02-18 23:54:36 +01001502 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001503 (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 Bergcdc89b92013-02-18 23:54:36 +01001507 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301508 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 Berg7527a782011-05-13 10:58:57 +02001512
1513 nla_nest_end(msg, nl_combi);
1514 }
1515
1516 nla_nest_end(msg, nl_combis);
1517
1518 return 0;
1519nla_put_failure:
1520 return -ENOBUFS;
1521}
1522
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001524static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1525 struct sk_buff *msg)
1526{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001527 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001528 struct nlattr *nl_tcp;
1529
1530 if (!tcp)
1531 return 0;
1532
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001533 nl_tcp = nla_nest_start_noflag(msg,
1534 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001535 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 Berg3713b4e2013-02-14 16:19:38 +01001565static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001566 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001567 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568{
1569 struct nlattr *nl_wowlan;
1570
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 return 0;
1573
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001574 nl_wowlan = nla_nest_start_noflag(msg,
1575 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 if (!nl_wowlan)
1577 return -ENOBUFS;
1578
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001579 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001581 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001583 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001588 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001591 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1595 return -ENOBUFS;
1596
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001597 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001598 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001599 .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 Berg3713b4e2013-02-14 16:19:38 +01001603 };
1604
1605 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1606 sizeof(pat), &pat))
1607 return -ENOBUFS;
1608 }
1609
Luciano Coelho75453cc2015-01-09 14:06:37 +02001610 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, Gang1b8ec872014-04-21 12:53:02 +08001615 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001616 return -ENOBUFS;
1617
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 nla_nest_end(msg, nl_wowlan);
1619
1620 return 0;
1621}
1622#endif
1623
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001624static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001626{
1627 struct nl80211_coalesce_rule_support rule;
1628
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001629 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001630 return 0;
1631
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 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 Karwarbe29b99a2013-06-28 11:51:26 -07001638
1639 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1640 return -ENOBUFS;
1641
1642 return 0;
1643}
1644
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001645static int
1646nl80211_send_iftype_data(struct sk_buff *msg,
Johannes Berg22395212020-05-28 21:34:31 +02001647 const struct ieee80211_supported_band *sband,
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001648 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 Berg22395212020-05-28 21:34:31 +02001671 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 Coelhoc4cbaf72018-06-09 09:14:42 +03001677 return 0;
1678}
1679
Johannes Berg3713b4e2013-02-14 16:19:38 +01001680static int nl80211_send_band_rateinfo(struct sk_buff *msg,
Johannes Bergf8d504c2020-09-28 13:06:56 +02001681 struct ieee80211_supported_band *sband,
1682 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001683{
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 Bergf8d504c2020-09-28 13:06:56 +02001710 if (large && sband->n_iftype_data) {
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001711 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001712 nla_nest_start_noflag(msg,
1713 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001714 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 Kubecekae0be8d2019-04-26 11:13:06 +02001722 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001723 if (!iftdata)
1724 return -ENOBUFS;
1725
Johannes Berg22395212020-05-28 21:34:31 +02001726 err = nl80211_send_iftype_data(msg, sband,
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001727 &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 Lazar2a380752019-08-18 17:35:17 +03001737 /* add EDMG info */
Johannes Bergf8d504c2020-09-28 13:06:56 +02001738 if (large && sband->edmg_cap.channels &&
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03001739 (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 Berg3713b4e2013-02-14 16:19:38 +01001746 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001747 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001748 if (!nl_rates)
1749 return -ENOBUFS;
1750
1751 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001752 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001753 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
1773static int
1774nl80211_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 Kubecekae0be8d2019-04-26 11:13:06 +02001785 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001786 if (!nl_ifs)
1787 return -ENOBUFS;
1788
1789 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001790 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001791 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 Kubecekae0be8d2019-04-26 11:13:06 +02001808 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001809 if (!nl_ifs)
1810 return -ENOBUFS;
1811
1812 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001813 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 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 Berg17948992016-10-26 11:42:04 +02001833#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
1842static 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 Sprielca986ad2017-04-21 13:05:00 +01001890 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001891 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 Berg9bb7e0f2018-09-10 13:29:12 +02001922static int
1923nl80211_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 Kubecekae0be8d2019-04-26 11:13:06 +02001931 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001932 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 Sternefb55202020-01-31 13:12:38 +02001960 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 Berg9bb7e0f2018-09-10 13:29:12 +02001966
1967 nla_nest_end(msg, ftm);
1968 return 0;
1969}
1970
1971static 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 Kubecekae0be8d2019-04-26 11:13:06 +02001985 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001986 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 Kubecekae0be8d2019-04-26 11:13:06 +02002000 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002001 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 Jakkamd6039a32020-01-27 02:00:32 +05302013static int
2014nl80211_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 Berg3710a8a2020-02-24 11:34:25 +01002053static int
2054nl80211_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 chelvam6a21d162020-01-20 13:21:23 +05302079 /* 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 Berg3710a8a2020-02-24 11:34:25 +01002087 nla_nest_end(msg, supp);
2088
2089 return 0;
2090fail:
2091 nla_nest_cancel(msg, supp);
2092 return -ENOBUFS;
2093}
2094
Johannes Berg86e8cf92013-06-19 10:57:22 +02002095struct nl80211_dump_wiphy_state {
2096 s64 filter_wiphy;
2097 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302098 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002099 bool split;
2100};
2101
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002102static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02002103 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002104 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002105 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04002106{
2107 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01002108 struct nlattr *nl_bands, *nl_band;
2109 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01002110 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002111 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01002112 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01002113 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02002114 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002115 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002116 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04002117
Johannes Berg3bb20552014-05-26 13:52:25 +02002118 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002119 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002120 return -ENOBUFS;
2121
Johannes Berg86e8cf92013-06-19 10:57:22 +02002122 if (WARN_ON(!state))
2123 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04002124
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002125 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002126 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002127 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002128 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002129 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04002130 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002131
Johannes Berg3bb20552014-05-26 13:52:25 +02002132 if (cmd != NL80211_CMD_NEW_WIPHY)
2133 goto finish;
2134
Johannes Berg86e8cf92013-06-19 10:57:22 +02002135 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002136 case 0:
2137 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002138 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002139 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002140 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002141 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002142 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002143 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002144 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002145 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002146 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002147 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002148 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002149 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002150 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002151 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002152 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002153 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002154 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002155 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Johannes Bergf8d504c2020-09-28 13:06:56 +02002156 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01002157 goto nla_put_failure;
2158
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002159 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002160 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2161 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002162 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002163 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2164 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002165 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002166 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2167 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002168 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002169 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2170 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002171 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002172 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2173 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002174 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002175 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04002176 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002177 state->split_start++;
2178 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002179 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002180 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002181 case 1:
2182 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002183 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2184 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00002185 goto nla_put_failure;
2186
Johannes Berg3713b4e2013-02-14 16:19:38 +01002187 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002188 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01002189 goto nla_put_failure;
2190
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002191 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002192 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2193 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002194
Johannes Berg3713b4e2013-02-14 16:19:38 +01002195 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002196 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002197 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002198 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002199 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002200
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002201 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002202 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002203 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002204 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02002205
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002206 if ((rdev->wiphy.available_antennas_tx ||
2207 rdev->wiphy.available_antennas_rx) &&
2208 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002209 u32 tx_ant = 0, rx_ant = 0;
2210 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002211
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002212 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002213 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 Bergee688b002008-01-24 19:38:39 +01002222 }
2223
Johannes Berg86e8cf92013-06-19 10:57:22 +02002224 state->split_start++;
2225 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002226 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002227 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002228 case 2:
2229 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002230 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002231 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002232 state->split_start++;
2233 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002234 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002235 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002236 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002237 nl_bands = nla_nest_start_noflag(msg,
2238 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002239 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01002240 goto nla_put_failure;
2241
Johannes Berg86e8cf92013-06-19 10:57:22 +02002242 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002243 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002244 struct ieee80211_supported_band *sband;
2245
Johannes Bergf8d504c2020-09-28 13:06:56 +02002246 /* omit higher bands for ancient software */
2247 if (band > NL80211_BAND_5GHZ && !state->split)
2248 break;
2249
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002250 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01002251
2252 if (!sband)
2253 continue;
2254
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002255 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002256 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01002257 goto nla_put_failure;
2258
Johannes Berg86e8cf92013-06-19 10:57:22 +02002259 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002260 case 0:
Johannes Bergf8d504c2020-09-28 13:06:56 +02002261 if (nl80211_send_band_rateinfo(msg, sband,
2262 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002263 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002264 state->chan_start++;
2265 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002266 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002267 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002268 default:
2269 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002270 nl_freqs = nla_nest_start_noflag(msg,
2271 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002272 if (!nl_freqs)
2273 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002274
Johannes Berg86e8cf92013-06-19 10:57:22 +02002275 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002276 i < sband->n_channels;
2277 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002278 nl_freq = nla_nest_start_noflag(msg,
2279 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002280 if (!nl_freq)
2281 goto nla_put_failure;
2282
2283 chan = &sband->channels[i];
2284
Johannes Berg86e8cf92013-06-19 10:57:22 +02002285 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002286 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002287 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002288 goto nla_put_failure;
2289
2290 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002291 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002292 break;
2293 }
2294 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002295 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002296 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002297 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002298 nla_nest_end(msg, nl_freqs);
2299 }
2300
2301 nla_nest_end(msg, nl_band);
2302
Johannes Berg86e8cf92013-06-19 10:57:22 +02002303 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002304 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002305 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002306 band--;
2307 break;
2308 }
Johannes Bergee688b002008-01-24 19:38:39 +01002309 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002310 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002311
Johannes Berg57fbcce2016-04-12 15:56:15 +02002312 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002313 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002314 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002315 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002316
Johannes Berg3713b4e2013-02-14 16:19:38 +01002317 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002318 if (state->band_start == 0 && state->chan_start == 0)
2319 state->split_start++;
2320 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002321 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002322 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002323 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002324 nl_cmds = nla_nest_start_noflag(msg,
2325 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002326 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002327 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002328
Johannes Berg17948992016-10-26 11:42:04 +02002329 i = nl80211_add_commands_unsplit(rdev, msg);
2330 if (i < 0)
2331 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002332 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002333 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2334 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002335 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002336 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002337 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002338 if (rdev->wiphy.features &
2339 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002340 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002341 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002342 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Matthew Wang70109982019-08-22 10:48:06 -07002343 CMD(update_ft_ies, UPDATE_FT_IES);
Arend van Spriel5de17982013-04-18 15:49:00 +02002344 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002345#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002346
Johannes Berg3713b4e2013-02-14 16:19:38 +01002347 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002348 state->split_start++;
2349 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002350 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002351 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002352 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002353 if (rdev->ops->remain_on_channel &&
2354 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002355 nla_put_u32(msg,
2356 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002357 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002358 goto nla_put_failure;
2359
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002360 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002361 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2362 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002363
Johannes Berg86e8cf92013-06-19 10:57:22 +02002364 state->split_start++;
2365 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002366 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002367 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002368 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002369#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002370 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002371 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002372 state->split_start++;
2373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002374 break;
2375#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002376 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002377#endif
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002378 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002379 case 7:
2380 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002381 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002382 goto nla_put_failure;
2383
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002384 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002385 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002386 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002387
Johannes Berg86e8cf92013-06-19 10:57:22 +02002388 state->split_start++;
2389 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002390 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002391 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002392 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002393 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002394 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002395 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002396 goto nla_put_failure;
2397
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002398 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002399 /*
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 Berg86e8cf92013-06-19 10:57:22 +02002404 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002405 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2406 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002407 goto nla_put_failure;
2408
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002409 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002410 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002411 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2412 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002413 goto nla_put_failure;
2414
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002415 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2416 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002417 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002418 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002419 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 Bergab10c222020-09-28 13:07:18 +02002431 if (state->split)
2432 state->split_start++;
2433 else
2434 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002435 break;
2436 case 9:
Johannes Bergf8d504c2020-09-28 13:06:56 +02002437 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, Gang1b8ec872014-04-21 12:53:02 +08002448 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002449 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002450 rdev->wiphy.extended_capabilities_len,
2451 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002452 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002453 rdev->wiphy.extended_capabilities_len,
2454 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002455 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002456
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002457 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002458 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002459 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2460 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002461 goto nla_put_failure;
2462
Denis Kenziorae6fa4d2019-07-22 06:33:12 -05002463 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 Karwarbe29b99a2013-06-28 11:51:26 -07002487 state->split_start++;
2488 break;
2489 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002490 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002491 goto nla_put_failure;
2492
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002493 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002494 (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 Malinenb43504c2014-01-15 00:01:08 +02002497
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002498 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002499 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002500 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002501 goto nla_put_failure;
2502
Johannes Bergad7e7182013-11-13 13:37:47 +01002503 state->split_start++;
2504 break;
2505 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002506 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002507 const struct nl80211_vendor_cmd_info *info;
2508 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002509
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002510 nested = nla_nest_start_noflag(msg,
2511 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002512 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002513 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002514
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002515 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2516 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002517 if (nla_put(msg, i + 1, sizeof(*info), info))
2518 goto nla_put_failure;
2519 }
2520 nla_nest_end(msg, nested);
2521 }
2522
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002523 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002524 const struct nl80211_vendor_cmd_info *info;
2525 struct nlattr *nested;
2526
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002527 nested = nla_nest_start_noflag(msg,
2528 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002529 if (!nested)
2530 goto nla_put_failure;
2531
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002532 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2533 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002534 if (nla_put(msg, i + 1, sizeof(*info), info))
2535 goto nla_put_failure;
2536 }
2537 nla_nest_end(msg, nested);
2538 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002539 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 Fietkau01e0daa2013-11-09 14:57:54 +01002546
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002547 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 Sprielca986ad2017-04-21 13:05:00 +01002551 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 Shuklad75bb062014-12-23 16:55:19 +01002556 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 Spriel38de03d2016-03-02 20:37:18 +01002561 if (rdev->wiphy.bss_select_support) {
2562 struct nlattr *nested;
2563 u32 bss_select_support = rdev->wiphy.bss_select_support;
2564
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002565 nested = nla_nest_start_noflag(msg,
2566 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002567 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, Vidyullatha019ae3a2016-05-16 10:41:04 +05302581 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 Kubecekae0be8d2019-04-26 11:13:06 +02002588 nested = nla_nest_start_noflag(msg,
2589 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302590 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 Kubecekae0be8d2019-04-26 11:13:06 +02002599 nested_ext_capab = nla_nest_start_noflag(msg,
2600 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302601 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 Coelho85859892017-02-08 15:00:34 +02002623 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2624 rdev->wiphy.nan_supported_bands))
2625 goto nla_put_failure;
2626
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002627 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 Berg9bb7e0f2018-09-10 13:29:12 +02002649 state->split_start++;
2650 break;
2651 case 14:
2652 if (nl80211_send_pmsr_capa(rdev, msg))
2653 goto nla_put_failure;
2654
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302655 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 Jakkamd6039a32020-01-27 02:00:32 +05302664 if (nl80211_put_iftype_akm_suites(rdev, msg))
2665 goto nla_put_failure;
2666
Johannes Berg3710a8a2020-02-24 11:34:25 +01002667 if (nl80211_put_tid_config_support(rdev, msg))
2668 goto nla_put_failure;
2669
Johannes Berg3713b4e2013-02-14 16:19:38 +01002670 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002671 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002672 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002673 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002674 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002675 genlmsg_end(msg, hdr);
2676 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002677
2678 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002679 genlmsg_cancel(msg, hdr);
2680 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002681}
2682
Johannes Berg86e8cf92013-06-19 10:57:22 +02002683static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2684 struct netlink_callback *cb,
2685 struct nl80211_dump_wiphy_state *state)
2686{
Johannes Berg50508d92019-07-29 16:31:09 +02002687 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 Berg86e8cf92013-06-19 10:57:22 +02002697 /* ignore parse errors for backward compatibility */
Johannes Berg50508d92019-07-29 16:31:09 +02002698 if (ret) {
2699 ret = 0;
2700 goto out;
2701 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002702
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 Xue7f2b8562014-01-15 10:23:45 +08002713 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg50508d92019-07-29 16:31:09 +02002714 if (!netdev) {
2715 ret = -ENODEV;
2716 goto out;
2717 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002718 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002719 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002720 netdev->ieee80211_ptr->wiphy);
2721 state->filter_wiphy = rdev->wiphy_idx;
2722 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002723 }
2724
Johannes Berg50508d92019-07-29 16:31:09 +02002725 ret = 0;
2726out:
2727 kfree(tb);
2728 return ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002729}
2730
Johannes Berg55682962007-09-20 13:09:35 -04002731static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2732{
Johannes Berg645e77d2013-03-01 14:03:49 +01002733 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002734 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002735 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002736
Johannes Berg5fe231e2013-05-08 21:45:15 +02002737 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002738 if (!state) {
2739 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002740 if (!state) {
2741 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002742 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002743 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002744 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 Berg3713b4e2013-02-14 16:19:38 +01002750 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002751 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002752 }
2753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002754 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2755 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002756 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002757 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002758 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002759 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002760 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002761 continue;
2762 /* attempt to fit multiple wiphy data chunks into the skb */
2763 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002764 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2765 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002766 NETLINK_CB(cb->skb).portid,
2767 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002768 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002769 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 Fuchsf12cb282014-01-16 15:00:40 +01002784 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002785 cb->min_dump_alloc < 4096) {
2786 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002787 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002788 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002789 return 1;
2790 }
2791 idx--;
2792 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002793 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002794 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002795 break;
Johannes Berg55682962007-09-20 13:09:35 -04002796 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002797 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002798
Johannes Berg86e8cf92013-06-19 10:57:22 +02002799 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002800
2801 return skb->len;
2802}
2803
Johannes Berg86e8cf92013-06-19 10:57:22 +02002804static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2805{
2806 kfree((void *)cb->args[0]);
2807 return 0;
2808}
2809
Johannes Berg55682962007-09-20 13:09:35 -04002810static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2811{
2812 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002814 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002815
Johannes Berg645e77d2013-03-01 14:03:49 +01002816 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002817 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002818 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002819
Johannes Berg3bb20552014-05-26 13:52:25 +02002820 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2821 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002822 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002823 nlmsg_free(msg);
2824 return -ENOBUFS;
2825 }
Johannes Berg55682962007-09-20 13:09:35 -04002826
Johannes Berg134e6372009-07-10 09:51:34 +00002827 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002828}
2829
Jouni Malinen31888482008-10-30 16:59:24 +02002830static 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
2838static int parse_txq_params(struct nlattr *tb[],
2839 struct ieee80211_txq_params *txq_params)
2840{
Dan Williams259d8c12018-01-29 17:03:15 -08002841 u8 ac;
2842
Johannes Berga3304b02012-03-28 11:04:24 +02002843 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002844 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2845 !tb[NL80211_TXQ_ATTR_AIFS])
2846 return -EINVAL;
2847
Dan Williams259d8c12018-01-29 17:03:15 -08002848 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002849 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 Williams259d8c12018-01-29 17:03:15 -08002854 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002855 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002856 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002857 return 0;
2858}
2859
Johannes Bergf444de02010-05-05 15:25:02 +02002860static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2861{
2862 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002863 * 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 Bergf444de02010-05-05 15:25:02 +02002872 *
2873 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002874 * whatever else is going on, so they have their own special
2875 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002876 */
2877 return !wdev ||
2878 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002879 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002880 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2881 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002882}
2883
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002884int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2885 struct genl_info *info,
2886 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002887{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002888 struct netlink_ext_ack *extack = info->extack;
2889 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302890 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002891
Johannes Berg49f9cf02018-10-01 11:55:09 +02002892 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002893 return -EINVAL;
2894
Thomas Pedersen942ba882020-04-30 10:25:51 -07002895 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 Berg683b6d32012-11-08 21:25:48 +01002900
Johannes Bergf43e5212019-09-23 13:51:16 +02002901 memset(chandef, 0, sizeof(*chandef));
Thomas Pedersen942ba882020-04-30 10:25:51 -07002902 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002903 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
Thomas Pedersen942ba882020-04-30 10:25:51 -07002904 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
2905 chandef->freq1_offset = control_freq % 1000;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002906 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002907
2908 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002909 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 Berg683b6d32012-11-08 21:25:48 +01002912 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002913 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002914
Johannes Berg49f9cf02018-10-01 11:55:09 +02002915 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002916 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002917
Johannes Berg49f9cf02018-10-01 11:55:09 +02002918 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002919
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 Mussaiffa46292017-08-05 11:44:38 +03002927 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002928 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 Mussaiffa46292017-08-05 11:44:38 +03002933 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002934 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002935 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002936 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 Mussaiffa46292017-08-05 11:44:38 +03002941 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002942 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002943 break;
2944 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002945 NL_SET_ERR_MSG_ATTR(extack,
2946 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2947 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002948 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002949 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002950 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002951 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002952 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
Thomas Pedersen942ba882020-04-30 10:25:51 -07002953 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002954 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002955 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
Thomas Pedersen942ba882020-04-30 10:25:51 -07002956 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 Berg49f9cf02018-10-01 11:55:09 +02002962 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002963 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002964 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002965 }
2966
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03002967 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 Berg49f9cf02018-10-01 11:55:09 +02002979 if (!cfg80211_chandef_valid(chandef)) {
2980 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002981 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002982 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002983
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002984 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002985 IEEE80211_CHAN_DISABLED)) {
2986 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002987 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002988 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002989
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002990 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2991 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002992 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2993 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002994 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002995 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002996
Johannes Berg683b6d32012-11-08 21:25:48 +01002997 return 0;
2998}
2999
Johannes Bergf444de02010-05-05 15:25:02 +02003000static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03003001 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02003002 struct genl_info *info)
3003{
Johannes Berg683b6d32012-11-08 21:25:48 +01003004 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02003005 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02003006 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03003007 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02003008
Jouni Malinene16821b2014-04-28 11:22:08 +03003009 if (dev)
3010 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02003011 if (!nl80211_can_set_dev_channel(wdev))
3012 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03003013 if (wdev)
3014 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02003015
Johannes Berg683b6d32012-11-08 21:25:48 +01003016 result = nl80211_parse_chandef(rdev, info, &chandef);
3017 if (result)
3018 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02003019
Johannes Berge8c9bd52012-06-06 08:18:22 +02003020 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02003021 case NL80211_IFTYPE_AP:
3022 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03003023 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
3024 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02003025 result = -EINVAL;
3026 break;
3027 }
Jouni Malinene16821b2014-04-28 11:22:08 +03003028 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 Berg683b6d32012-11-08 21:25:48 +01003045 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02003046 result = 0;
3047 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02003048 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01003049 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02003050 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02003051 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01003052 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02003053 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02003054 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02003055 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02003056 }
Johannes Bergf444de02010-05-05 15:25:02 +02003057
3058 return result;
3059}
3060
3061static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
3062{
Johannes Berg4c476992010-10-04 21:36:35 +02003063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3064 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02003065
Jouni Malinene16821b2014-04-28 11:22:08 +03003066 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02003067}
3068
Bill Jordane8347eb2010-10-01 13:54:28 -04003069static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
3070{
Johannes Berg43b19952010-10-07 13:10:30 +02003071 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 Berg388ac772010-10-07 13:11:09 +02003074 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04003075
3076 if (!info->attrs[NL80211_ATTR_MAC])
3077 return -EINVAL;
3078
Johannes Berg43b19952010-10-07 13:10:30 +02003079 if (netif_running(dev))
3080 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04003081
Johannes Berg43b19952010-10-07 13:10:30 +02003082 if (!rdev->ops->set_wds_peer)
3083 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04003084
Johannes Berg43b19952010-10-07 13:10:30 +02003085 if (wdev->iftype != NL80211_IFTYPE_WDS)
3086 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04003087
3088 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03003089 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04003090}
3091
Johannes Berg55682962007-09-20 13:09:35 -04003092static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3093{
3094 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02003095 struct net_device *netdev = NULL;
3096 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04003097 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02003098 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003099 u32 changed;
3100 u8 retry_short = 0, retry_long = 0;
3101 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01003102 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003103 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04003104
Johannes Berg5fe231e2013-05-08 21:45:15 +02003105 ASSERT_RTNL();
3106
Johannes Bergf444de02010-05-05 15:25:02 +02003107 /*
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 Berg4bbf4d52009-03-24 09:35:46 +01003116
Johannes Bergf444de02010-05-05 15:25:02 +02003117 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3118 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3119
Ying Xue7f2b8562014-01-15 10:23:45 +08003120 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003121 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08003122 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003123 else
Johannes Bergf444de02010-05-05 15:25:02 +02003124 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003125 }
3126
Johannes Bergf444de02010-05-05 15:25:02 +02003127 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02003128 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3129 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003130 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02003131 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02003132 wdev = NULL;
3133 netdev = NULL;
3134 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02003135 } else
Johannes Bergf444de02010-05-05 15:25:02 +02003136 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02003137
3138 /*
3139 * end workaround code, by now the rdev is available
3140 * and locked, and wdev may or may not be NULL.
3141 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003142
3143 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02003144 result = cfg80211_dev_rename(
3145 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003146
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003147 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003148 return result;
Johannes Berg55682962007-09-20 13:09:35 -04003149
Jouni Malinen31888482008-10-30 16:59:24 +02003150 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 Xue7f2b8562014-01-15 10:23:45 +08003154 if (!rdev->ops->set_txq_params)
3155 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02003156
Ying Xue7f2b8562014-01-15 10:23:45 +08003157 if (!netdev)
3158 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03003159
Johannes Berg133a3ff2011-11-03 14:50:13 +01003160 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08003161 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3162 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01003163
Ying Xue7f2b8562014-01-15 10:23:45 +08003164 if (!netif_running(netdev))
3165 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02003166
Jouni Malinen31888482008-10-30 16:59:24 +02003167 nla_for_each_nested(nl_txq_params,
3168 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3169 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02003170 result = nla_parse_nested_deprecated(tb,
3171 NL80211_TXQ_ATTR_MAX,
3172 nl_txq_params,
3173 txq_params_policy,
3174 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01003175 if (result)
3176 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003177 result = parse_txq_params(tb, &txq_params);
3178 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003179 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003180
Hila Gonene35e4d22012-06-27 17:19:42 +03003181 result = rdev_set_txq_params(rdev, netdev,
3182 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02003183 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003184 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003185 }
3186 }
3187
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003188 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03003189 result = __nl80211_set_channel(
3190 rdev,
3191 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3192 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003193 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003194 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003195 }
3196
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003197 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02003198 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003199 enum nl80211_tx_power_setting type;
3200 int idx, mbm = 0;
3201
Johannes Bergc8442112012-10-24 10:17:18 +02003202 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3203 txp_wdev = NULL;
3204
Ying Xue7f2b8562014-01-15 10:23:45 +08003205 if (!rdev->ops->set_tx_power)
3206 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003207
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 Xue7f2b8562014-01-15 10:23:45 +08003212 (type != NL80211_TX_POWER_AUTOMATIC))
3213 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003214
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 Bergc8442112012-10-24 10:17:18 +02003220 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003221 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003222 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003223 }
3224
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003225 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3226 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3227 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003228
Bruno Randolf7f531e02010-12-16 11:30:22 +09003229 if ((!rdev->wiphy.available_antennas_tx &&
3230 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08003231 !rdev->ops->set_antenna)
3232 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003233
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 Randolfa7ffac92010-12-08 13:59:24 +09003237 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09003238 * available antenna masks, except for the "all" mask */
3239 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08003240 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
3241 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003242
Bruno Randolf7f531e02010-12-16 11:30:22 +09003243 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3244 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003245
Hila Gonene35e4d22012-06-27 17:19:42 +03003246 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003247 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003248 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003249 }
3250
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003251 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 Xue7f2b8562014-01-15 10:23:45 +08003256
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003257 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 Xue7f2b8562014-01-15 10:23:45 +08003263
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003264 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 Xue7f2b8562014-01-15 10:23:45 +08003270 if (frag_threshold < 256)
3271 return -EINVAL;
3272
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003273 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áš Turek81077e82009-12-21 22:50:47 +01003291 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003292 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3293 return -EINVAL;
3294
Lukáš Turek81077e82009-12-21 22:50:47 +01003295 coverage_class = nla_get_u8(
3296 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3297 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3298 }
3299
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003300 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ørgensen52539ca2018-05-08 13:03:50 +02003307 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 Malinenb9a5f8ca2009-04-20 18:39:05 +02003334 if (changed) {
3335 u8 old_retry_short, old_retry_long;
3336 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003337 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003338 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003339
Ying Xue7f2b8562014-01-15 10:23:45 +08003340 if (!rdev->ops->set_wiphy_params)
3341 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003342
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áš Turek81077e82009-12-21 22:50:47 +01003347 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003348 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 Malinenb9a5f8ca2009-04-20 18:39:05 +02003351
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áš Turek81077e82009-12-21 22:50:47 +01003360 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3361 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003362 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 Malinenb9a5f8ca2009-04-20 18:39:05 +02003368
Hila Gonene35e4d22012-06-27 17:19:42 +03003369 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003370 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áš Turek81077e82009-12-21 22:50:47 +01003375 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003376 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 Kazior9189ee32015-08-03 10:55:24 +02003379 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003380 }
3381 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003382 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003383}
3384
Johannes Berg683b6d32012-11-08 21:25:48 +01003385static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003386 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003387{
Johannes Berg601555c2014-11-27 17:26:56 +01003388 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3389 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003390
Johannes Berg683b6d32012-11-08 21:25:48 +01003391 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3392 chandef->chan->center_freq))
3393 return -ENOBUFS;
Thomas Pedersen942ba882020-04-30 10:25:51 -07003394 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3395 chandef->chan->freq_offset))
3396 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003397 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 Berg683b6d32012-11-08 21:25:48 +01003414 return -ENOBUFS;
3415 return 0;
3416}
3417
Eric W. Biederman15e47302012-09-07 20:12:54 +00003418static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003419 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003420 struct wireless_dev *wdev,
3421 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003422{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003423 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003424 void *hdr;
3425
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003426 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3427 cmd != NL80211_CMD_DEL_INTERFACE &&
3428 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003429
3430 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003431 if (!hdr)
3432 return -1;
3433
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003434 if (dev &&
3435 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003436 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003437 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 Dichtel2dad6242016-04-25 10:25:22 +02003441 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3442 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003443 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003444 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3445 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003446 (cfg80211_rdev_list_generation << 2)) ||
3447 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003448 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003449
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003450 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003451 int ret;
Johannes Bergf43e5212019-09-23 13:51:16 +02003452 struct cfg80211_chan_def chandef = {};
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003453
Johannes Berg683b6d32012-11-08 21:25:48 +01003454 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 Fuchsd91df0e2012-04-03 16:39:58 +02003459 }
3460
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003461 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 Berg44905262017-10-17 21:56:01 +02003471 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 Berg4564b182017-12-11 12:33:47 +01003476 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003477 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 Brodowski7a94b8c2018-01-15 08:12:15 +01003484 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003485 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3486 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003487 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 Berg44905262017-10-17 21:56:01 +02003491 break;
3492 }
3493 default:
3494 /* nothing */
3495 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003496 }
Johannes Berg44905262017-10-17 21:56:01 +02003497 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003498
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003499 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 Berg053c0952015-01-16 22:09:00 +01003509 genlmsg_end(msg, hdr);
3510 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003511
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003512 nla_put_failure_rcu_locked:
3513 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003514 nla_put_failure_locked:
3515 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003516 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003517 genlmsg_cancel(msg, hdr);
3518 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003519}
3520
3521static 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 Kenziorb7fb44d2016-08-03 17:02:15 -05003527 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003528 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003529 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003530 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003531
Johannes Berg5fe231e2013-05-08 21:45:15 +02003532 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003533 if (!cb->args[2]) {
3534 struct nl80211_dump_wiphy_state state = {
3535 .filter_wiphy = -1,
3536 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003537
3538 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3539 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003540 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003541
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 Bergf5ea9122009-08-07 16:17:38 +02003556 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3557 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003558 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003559 if (wp_idx < wp_start) {
3560 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003561 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003562 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003563
3564 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3565 continue;
3566
Johannes Berg55682962007-09-20 13:09:35 -04003567 if_idx = 0;
3568
Johannes Berg53873f12016-05-03 16:52:04 +03003569 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003570 if (if_idx < if_start) {
3571 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003572 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003573 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003574 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003575 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003576 rdev, wdev,
3577 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003578 goto out;
3579 }
3580 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003581 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003582
3583 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003584 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003585 out:
Johannes Berg55682962007-09-20 13:09:35 -04003586 cb->args[0] = wp_idx;
3587 cb->args[1] = if_idx;
3588
Johannes Bergea90e0d2017-03-15 14:26:04 +01003589 ret = skb->len;
3590 out_unlock:
3591 rtnl_unlock();
3592
3593 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003594}
3595
3596static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3597{
3598 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003600 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003601
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003602 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003603 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003604 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003605
Eric W. Biederman15e47302012-09-07 20:12:54 +00003606 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003607 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003608 nlmsg_free(msg);
3609 return -ENOBUFS;
3610 }
Johannes Berg55682962007-09-20 13:09:35 -04003611
Johannes Berg134e6372009-07-10 09:51:34 +00003612 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003613}
3614
Michael Wu66f7ac52008-01-31 19:48:22 +01003615static 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 Fietkaue057d3c2013-05-28 13:01:52 +02003621 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003622};
3623
3624static 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 Berg8cb08172019-04-26 14:07:28 +02003634 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003635 return -EINVAL;
3636
3637 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3638 if (flags[flag])
3639 *mntrflags |= (1<<flag);
3640
Johannes Berg818a9862017-04-12 11:23:28 +02003641 *mntrflags |= MONITOR_FLAG_CHANGED;
3642
Michael Wu66f7ac52008-01-31 19:48:22 +01003643 return 0;
3644}
3645
Johannes Berg1db77592017-04-12 11:36:31 +02003646static 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 &params->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 Berg49546012017-04-27 09:13:38 +02003684 if ((mumimo_groups[0] & BIT(0)) ||
3685 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003686 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 Berg9bc383d2009-11-19 11:55:19 +01003709static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003710 struct net_device *netdev, u8 use_4addr,
3711 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003712{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003713 if (!use_4addr) {
Julian Wiedmann2e92a2d2020-02-20 09:00:07 +01003714 if (netdev && netif_is_bridge_port(netdev))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003715 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003716 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003717 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003718
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 Berg55682962007-09-20 13:09:35 -04003735static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3736{
Johannes Berg4c476992010-10-04 21:36:35 +02003737 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003738 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003739 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003740 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003741 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003742 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003743
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003744 memset(&params, 0, sizeof(params));
3745
Johannes Berg04a773a2009-04-19 21:24:32 +02003746 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003747
Johannes Berg723b0382008-09-16 20:22:09 +02003748 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003749 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003750 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003751 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003752 }
3753
Johannes Berg92ffe052008-09-16 20:39:36 +02003754 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003755 struct wireless_dev *wdev = dev->ieee80211_ptr;
3756
Johannes Berg4c476992010-10-04 21:36:35 +02003757 if (ntype != NL80211_IFTYPE_MESH_POINT)
3758 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003759 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 Cobo2ec600d2008-02-23 15:17:06 +01003770 }
3771
Felix Fietkau8b787642009-11-10 18:53:10 +01003772 if (info->attrs[NL80211_ATTR_4ADDR]) {
3773 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3774 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003775 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003776 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003777 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003778 } else {
3779 params.use_4addr = -1;
3780 }
3781
Johannes Berg1db77592017-04-12 11:36:31 +02003782 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3783 if (err < 0)
3784 return err;
3785 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003786 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003787
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003788 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003789 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003790 else
3791 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003792
Johannes Berg9bc383d2009-11-19 11:55:19 +01003793 if (!err && params.use_4addr != -1)
3794 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3795
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003796 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 Berg55682962007-09-20 13:09:35 -04003802 return err;
3803}
3804
3805static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3806{
Johannes Berg4c476992010-10-04 21:36:35 +02003807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003808 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003809 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003810 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003811 int err;
3812 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3813
Johannes Berg78f22b62014-03-24 17:57:27 +01003814 /* to avoid failing a new interface creation due to pending removal */
3815 cfg80211_destroy_ifaces(rdev);
3816
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003817 memset(&params, 0, sizeof(params));
3818
Johannes Berg55682962007-09-20 13:09:35 -04003819 if (!info->attrs[NL80211_ATTR_IFNAME])
3820 return -EINVAL;
3821
Johannes Bergab0d76f2018-10-02 10:00:07 +02003822 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003823 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003824
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303825 if (!rdev->ops->add_virtual_intf)
Johannes Berg4c476992010-10-04 21:36:35 +02003826 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003827
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003828 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003829 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3830 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003831 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 Berg9bc383d2009-11-19 11:55:19 +01003837 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003838 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003839 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003840 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003841 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003842 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003843
Manikanta Pubbisettye6f40512019-07-22 12:44:50 +05303844 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303845 return -EOPNOTSUPP;
3846
Johannes Berg1db77592017-04-12 11:36:31 +02003847 err = nl80211_parse_mon_options(rdev, type, info, &params);
3848 if (err < 0)
3849 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003850
Johannes Berga18c7192015-02-24 10:56:42 +01003851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3852 if (!msg)
3853 return -ENOMEM;
3854
Hila Gonene35e4d22012-06-27 17:19:42 +03003855 wdev = rdev_add_virtual_intf(rdev,
3856 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003857 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003858 if (WARN_ON(!wdev)) {
3859 nlmsg_free(msg);
3860 return -EPROTO;
3861 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003862 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003863 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003864 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003865
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003866 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003867 wdev->owner_nlportid = info->snd_portid;
3868
Johannes Berg98104fde2012-06-16 00:19:54 +02003869 switch (type) {
3870 case NL80211_IFTYPE_MESH_POINT:
3871 if (!info->attrs[NL80211_ATTR_MESH_ID])
3872 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003873 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 Berg98104fde2012-06-16 00:19:54 +02003881 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003882 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003883 case NL80211_IFTYPE_P2P_DEVICE:
3884 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003885 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003886 * through the netdev notifier and must be added here
3887 */
Johannes Berge4d42162018-09-13 14:12:03 +02003888 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003889 break;
3890 default:
3891 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003892 }
3893
Eric W. Biederman15e47302012-09-07 20:12:54 +00003894 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003895 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003896 nlmsg_free(msg);
3897 return -ENOBUFS;
3898 }
3899
3900 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003901}
3902
3903static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3904{
Johannes Berg4c476992010-10-04 21:36:35 +02003905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003906 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003907
Johannes Berg4c476992010-10-04 21:36:35 +02003908 if (!rdev->ops->del_virtual_intf)
3909 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003910
Johannes Berg84efbb82012-06-16 00:00:26 +02003911 /*
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 Kenzior7f8ed012016-08-03 16:58:35 -05003921 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003922}
3923
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003924static 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 Gonene35e4d22012-06-27 17:19:42 +03003938 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003939}
3940
Johannes Berg41ade002007-12-19 02:03:29 +01003941struct get_key_cookie {
3942 struct sk_buff *msg;
3943 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003944 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003945};
3946
3947static void get_key_callback(void *c, struct key_params *params)
3948{
Johannes Bergb9454e82009-07-08 13:29:08 +02003949 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003950 struct get_key_cookie *cookie = c;
3951
David S. Miller9360ffd2012-03-29 04:41:26 -04003952 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 Berg41ade002007-12-19 02:03:29 +01003962
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003963 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003964 if (!key)
3965 goto nla_put_failure;
3966
David S. Miller9360ffd2012-03-29 04:41:26 -04003967 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 Bergb9454e82009-07-08 13:29:08 +02003977
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003978 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003979 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003980
3981 nla_nest_end(cookie->msg, key);
3982
Johannes Berg41ade002007-12-19 02:03:29 +01003983 return;
3984 nla_put_failure:
3985 cookie->error = 1;
3986}
3987
3988static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3989{
Johannes Berg4c476992010-10-04 21:36:35 +02003990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003991 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003992 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003993 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003994 const u8 *mac_addr = NULL;
3995 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003996 struct get_key_cookie cookie = {
3997 .error = 0,
3998 };
3999 void *hdr;
4000 struct sk_buff *msg;
Johannes Berg155d7c72020-04-20 14:06:00 +02004001 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 Berg41ade002007-12-19 02:03:29 +01004012
Jouni Malinen56be3932020-02-22 15:25:43 +02004013 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
Johannes Berg41ade002007-12-19 02:03:29 +01004014 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
Johannes Berg155d7c72020-04-20 14:06:00 +02004015
4016 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
4017 GENL_SET_ERR_MSG(info, "BIGTK not supported");
Jouni Malinen56be3932020-02-22 15:25:43 +02004018 return -EINVAL;
Johannes Berg155d7c72020-04-20 14:06:00 +02004019 }
Jouni Malinen56be3932020-02-22 15:25:43 +02004020 }
Johannes Berg41ade002007-12-19 02:03:29 +01004021
Johannes Berg41ade002007-12-19 02:03:29 +01004022 if (info->attrs[NL80211_ATTR_MAC])
4023 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4024
Johannes Berge31b8212010-10-05 19:39:30 +02004025 pairwise = !!mac_addr;
4026 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
4027 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07004028
Johannes Berge31b8212010-10-05 19:39:30 +02004029 if (kt != NL80211_KEYTYPE_GROUP &&
4030 kt != NL80211_KEYTYPE_PAIRWISE)
4031 return -EINVAL;
4032 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
4033 }
4034
Johannes Berg4c476992010-10-04 21:36:35 +02004035 if (!rdev->ops->get_key)
4036 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01004037
Johannes Berg0fa7b392015-01-23 11:10:12 +01004038 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4039 return -ENOENT;
4040
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004041 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004042 if (!msg)
4043 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01004044
Eric W. Biederman15e47302012-09-07 20:12:54 +00004045 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01004046 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03004047 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02004048 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01004049
4050 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02004051 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01004052
David S. Miller9360ffd2012-03-29 04:41:26 -04004053 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 Berg41ade002007-12-19 02:03:29 +01004059
Hila Gonene35e4d22012-06-27 17:19:42 +03004060 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
4061 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01004062
4063 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03004064 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01004065
4066 if (cookie.error)
4067 goto nla_put_failure;
4068
4069 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004070 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01004071
4072 nla_put_failure:
4073 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03004074 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01004075 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01004076 return err;
4077}
4078
4079static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
4080{
Johannes Berg4c476992010-10-04 21:36:35 +02004081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02004082 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01004083 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004084 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01004085
Johannes Bergb9454e82009-07-08 13:29:08 +02004086 err = nl80211_parse_key(info, &key);
4087 if (err)
4088 return err;
4089
4090 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01004091 return -EINVAL;
4092
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004093 /* Only support setting default key and
4094 * Extended Key ID action NL80211_KEY_SET_TX.
4095 */
Jouni Malinen56be3932020-02-22 15:25:43 +02004096 if (!key.def && !key.defmgmt && !key.defbeacon &&
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004097 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01004098 return -EINVAL;
4099
Johannes Bergfffd0932009-07-08 14:22:54 +02004100 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004101
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 Gonene35e4d22012-06-27 17:19:42 +03004112 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004113 key.def_uni, key.def_multi);
4114
4115 if (err)
4116 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02004117
Johannes Berg3d23e342009-09-29 23:27:28 +02004118#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004119 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02004120#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004121 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004122 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 Gonene35e4d22012-06-27 17:19:42 +03004136 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004137 if (err)
4138 goto out;
4139
4140#ifdef CONFIG_CFG80211_WEXT
4141 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
4142#endif
Jouni Malinen56be3932020-02-22 15:25:43 +02004143 } 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 Wetzel6cdd3972019-03-19 21:34:07 +01004161 } 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 Bergdbd2fd62010-12-09 19:58:59 +01004165
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004166 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 Bergdbd2fd62010-12-09 19:58:59 +01004180 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02004181 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01004182
Johannes Berg41ade002007-12-19 02:03:29 +01004183 return err;
4184}
4185
4186static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4187{
Johannes Berg4c476992010-10-04 21:36:35 +02004188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02004189 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004190 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02004191 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02004192 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01004193
Johannes Bergb9454e82009-07-08 13:29:08 +02004194 err = nl80211_parse_key(info, &key);
4195 if (err)
4196 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01004197
Jouni Malinenf8af7642020-02-22 15:25:42 +02004198 if (!key.p.key) {
4199 GENL_SET_ERR_MSG(info, "no key");
Johannes Berg41ade002007-12-19 02:03:29 +01004200 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004201 }
Johannes Berg41ade002007-12-19 02:03:29 +01004202
Johannes Berg41ade002007-12-19 02:03:29 +01004203 if (info->attrs[NL80211_ATTR_MAC])
4204 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4205
Johannes Berge31b8212010-10-05 19:39:30 +02004206 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 Malinenf8af7642020-02-22 15:25:42 +02004215 key.type != NL80211_KEYTYPE_GROUP) {
4216 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
Johannes Berge31b8212010-10-05 19:39:30 +02004217 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004218 }
Johannes Berge31b8212010-10-05 19:39:30 +02004219
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02004220 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 Berg4c476992010-10-04 21:36:35 +02004224 if (!rdev->ops->add_key)
4225 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004226
Johannes Berge31b8212010-10-05 19:39:30 +02004227 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4228 key.type == NL80211_KEYTYPE_PAIRWISE,
Jouni Malinenf8af7642020-02-22 15:25:42 +02004229 mac_addr)) {
4230 GENL_SET_ERR_MSG(info, "key setting validation failed");
Johannes Berg4c476992010-10-04 21:36:35 +02004231 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004232 }
Johannes Bergfffd0932009-07-08 14:22:54 +02004233
4234 wdev_lock(dev->ieee80211_ptr);
4235 err = nl80211_key_allowed(dev->ieee80211_ptr);
Jouni Malinenf8af7642020-02-22 15:25:42 +02004236 if (err)
4237 GENL_SET_ERR_MSG(info, "key not allowed");
4238 if (!err) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004239 err = rdev_add_key(rdev, dev, key.idx,
4240 key.type == NL80211_KEYTYPE_PAIRWISE,
4241 mac_addr, &key.p);
Jouni Malinenf8af7642020-02-22 15:25:42 +02004242 if (err)
4243 GENL_SET_ERR_MSG(info, "key addition failed");
4244 }
Johannes Bergfffd0932009-07-08 14:22:54 +02004245 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01004246
Johannes Berg41ade002007-12-19 02:03:29 +01004247 return err;
4248}
4249
4250static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4251{
Johannes Berg4c476992010-10-04 21:36:35 +02004252 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01004253 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004254 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01004255 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02004256 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01004257
Johannes Bergb9454e82009-07-08 13:29:08 +02004258 err = nl80211_parse_key(info, &key);
4259 if (err)
4260 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01004261
Anant Thazhemadam3dc289f2020-10-07 09:24:01 +05304262 if (key.idx < 0)
4263 return -EINVAL;
4264
Johannes Berg41ade002007-12-19 02:03:29 +01004265 if (info->attrs[NL80211_ATTR_MAC])
4266 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4267
Johannes Berge31b8212010-10-05 19:39:30 +02004268 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 Berg4c476992010-10-04 21:36:35 +02004280 if (!rdev->ops->del_key)
4281 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01004282
Johannes Bergfffd0932009-07-08 14:22:54 +02004283 wdev_lock(dev->ieee80211_ptr);
4284 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02004285
Johannes Berg0fa7b392015-01-23 11:10:12 +01004286 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02004287 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4288 err = -ENOENT;
4289
Johannes Bergfffd0932009-07-08 14:22:54 +02004290 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004291 err = rdev_del_key(rdev, dev, key.idx,
4292 key.type == NL80211_KEYTYPE_PAIRWISE,
4293 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01004294
Johannes Berg3d23e342009-09-29 23:27:28 +02004295#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02004296 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02004297 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02004298 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02004299 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02004300 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
4301 }
4302#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02004303 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02004304
Johannes Berg41ade002007-12-19 02:03:29 +01004305 return err;
4306}
4307
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304308/* This function returns an error or the number of nested attributes */
4309static 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 */
4329static 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. Silva391d1322019-04-03 10:37:44 -05004358 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304359 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
4373static 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 Kushwahaa7c7fbf2016-09-14 17:38:44 +05304398static 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
4423static 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 Honma30fe6d52018-09-25 11:15:00 +09004442 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304443 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
4452static 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
4475static 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
4486static 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 Hueb89a6a2020-08-04 10:16:29 +02004512static 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
4529static 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
4540static 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
4561static 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 Kushwahaa7c7fbf2016-09-14 17:38:44 +05304593static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05304594 struct nlattr *attrs[],
4595 enum nl80211_attrs attr,
Miles Hueb89a6a2020-08-04 10:16:29 +02004596 struct cfg80211_bitrate_mask *mask,
4597 struct net_device *dev)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304598{
4599 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4600 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Miles Hueb89a6a2020-08-04 10:16:29 +02004601 struct wireless_dev *wdev = dev->ieee80211_ptr;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304602 int rem, i;
4603 struct nlattr *tx_rates;
4604 struct ieee80211_supported_band *sband;
Miles Hueb89a6a2020-08-04 10:16:29 +02004605 u16 vht_tx_mcs_map, he_tx_mcs_map;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304606
4607 memset(mask, 0, sizeof(*mask));
4608 /* Default to all rates enabled */
4609 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Miles Hueb89a6a2020-08-04 10:16:29 +02004610 const struct ieee80211_sta_he_cap *he_cap;
4611
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304612 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 Hueb89a6a2020-08-04 10:16:29 +02004627
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 Kushwahaa7c7fbf2016-09-14 17:38:44 +05304637 }
4638
4639 /* if no rates are given set it back to the defaults */
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05304640 if (!attrs[attr])
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304641 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 Chelvam9a5f6482020-05-13 13:41:44 +05304647 nla_for_each_nested(tx_rates, attrs[attr], rem) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304648 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 Berg8cb08172019-04-26 14:07:28 +02004656 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4657 tx_rates,
4658 nl80211_txattr_policy,
4659 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304660 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 Hueb89a6a2020-08-04 10:16:29 +02004692 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 Kushwahaa7c7fbf2016-09-14 17:38:44 +05304703
4704 if (mask->control[band].legacy == 0) {
Miles Hueb89a6a2020-08-04 10:16:29 +02004705 /* don't allow empty legacy rates if HT, VHT or HE
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304706 * are not even supported.
4707 */
4708 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
Miles Hueb89a6a2020-08-04 10:16:29 +02004709 rdev->wiphy.bands[band]->vht_cap.vht_supported ||
4710 ieee80211_get_he_iftype_cap(sband, wdev->iftype)))
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304711 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 Hueb89a6a2020-08-04 10:16:29 +02004721 for (i = 0; i < NL80211_HE_NSS_MAX; i++)
4722 if (mask->control[band].he_mcs[i])
4723 goto out;
4724
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304725 /* legacy and mcs rates may not be both empty */
4726 return -EINVAL;
4727 }
4728 }
4729
4730out:
4731 return 0;
4732}
4733
Johannes Berg8564e382016-09-19 09:44:44 +02004734static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4735 enum nl80211_band band,
4736 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304737{
Johannes Berg8564e382016-09-19 09:44:44 +02004738 u32 count_ht, count_vht, i;
4739 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304740
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 Berg8564e382016-09-19 09:44:44 +02004747 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304748 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004749 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304750 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 Berg8564e382016-09-19 09:44:44 +02004760 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304761 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004762 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304763 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 Berg8564e382016-09-19 09:44:44 +02004774 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 Kushwahaa7c7fbf2016-09-14 17:38:44 +05304787 return 0;
4788}
4789
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004790static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4791 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004792 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004793{
Johannes Berg88600202012-02-13 15:17:18 +01004794 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004795 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004796
Johannes Berg88600202012-02-13 15:17:18 +01004797 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004798
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004799 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 Berg88600202012-02-13 15:17:18 +01004802 if (!bcn->head_len)
4803 return -EINVAL;
4804 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004805 }
4806
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004807 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 Berg88600202012-02-13 15:17:18 +01004810 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004811 }
4812
Johannes Berg4c476992010-10-04 21:36:35 +02004813 if (!haveinfo)
4814 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004815
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004816 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 Malinen9946ecf2011-08-10 23:55:56 +03004819 }
4820
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004821 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004822 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004823 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004824 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004825 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004826 }
4827
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004828 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004829 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004830 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004831 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004832 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004833 }
4834
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004835 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 Nemtsov00f740e2011-11-10 11:28:56 +02004838 }
4839
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004840 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4841 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4842
Johannes Berg8cb08172019-04-26 14:07:28 +02004843 err = nla_parse_nested_deprecated(tb,
4844 NL80211_FTM_RESP_ATTR_MAX,
4845 attrs[NL80211_ATTR_FTM_RESPONDER],
4846 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004847 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 Berg88600202012-02-13 15:17:18 +01004870 return 0;
4871}
4872
John Crispin796e90f2019-07-30 18:37:00 +02004873static 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 Manoharanf5bec332020-09-28 00:28:11 -07004884 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 Manoharan6c8b6e42020-09-28 00:28:10 -07004889 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 Manoharanf5bec332020-09-28 00:28:11 -07004895 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 Crispin796e90f2019-07-30 18:37:00 +02004898
Rajkumar Manoharan6c8b6e42020-09-28 00:28:10 -07004899 if (he_obss_pd->min_offset > he_obss_pd->max_offset)
John Crispin796e90f2019-07-30 18:37:00 +02004900 return -EINVAL;
4901
Rajkumar Manoharanf5bec332020-09-28 00:28:11 -07004902 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 Crispin796e90f2019-07-30 18:37:00 +02004912 he_obss_pd->enable = true;
4913
4914 return 0;
4915}
4916
John Crispin5c5e52d2019-12-17 15:19:18 +01004917static 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 Berg75e6b592020-07-30 13:00:52 +02004933 he_bss_color->enabled =
4934 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
John Crispin5c5e52d2019-12-17 15:19:18 +01004935 he_bss_color->partial =
4936 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
4937
4938 return 0;
4939}
4940
Aloka Dixit291c49d2020-09-11 00:05:29 +00004941static 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 = &params->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 Dixit7443dcd2020-09-11 00:33:00 +00004971static int
4972nl80211_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 &params->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 Berg66cd7942017-02-07 22:40:44 +02005000static 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 Peer2a392592020-03-26 15:09:35 +02005013 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
5014 params->he_required = true;
Johannes Berg66cd7942017-02-07 22:40:44 +02005015 }
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 */
5023static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
5024{
5025 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07005026 size_t ies_len = bcn->tail_len;
5027 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02005028 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 Triebitz244eb9a2018-08-31 11:31:14 +03005043 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 Triebitz7e8d6f12020-01-31 13:12:54 +02005046 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 Berg66cd7942017-02-07 22:40:44 +02005049}
5050
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005051static 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 Berg53873f12016-05-03 16:52:04 +03005057 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005058 if (wdev->iftype != NL80211_IFTYPE_AP &&
5059 wdev->iftype != NL80211_IFTYPE_P2P_GO)
5060 continue;
5061
Johannes Berg683b6d32012-11-08 21:25:48 +01005062 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005063 continue;
5064
Johannes Berg683b6d32012-11-08 21:25:48 +01005065 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005066 ret = true;
5067 break;
5068 }
5069
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005070 return ret;
5071}
5072
Jouni Malinene39e5b52012-09-30 19:29:39 +03005073static 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 Malinen63181062016-10-27 00:42:02 +03005085 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 Malinene39e5b52012-09-30 19:29:39 +03005091 return true;
5092 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02005093 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00005094 !wiphy_ext_feature_isset(&rdev->wiphy,
5095 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
Srinivas Dasari10773a72018-01-25 17:13:39 +02005096 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03005097 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02005098
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03005099 /* 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 Malinene39e5b52012-09-30 19:29:39 +03005109 case NL80211_CMD_START_AP:
Chung-Hsien Hsu2831a632020-08-17 02:33:15 -05005110 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5111 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) &&
5112 auth_type == NL80211_AUTHTYPE_SAE)
Jouni Malinene39e5b52012-09-30 19:29:39 +03005113 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03005114 /* 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 Malinene39e5b52012-09-30 19:29:39 +03005119 return true;
5120 default:
5121 return false;
5122 }
5123}
5124
Johannes Berg88600202012-02-13 15:17:18 +01005125static 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(&params, 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 Chitrapu81e54d02018-09-20 17:30:09 -07005151 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01005152 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 Kushwaha0c317a02016-10-12 18:26:51 +05305160 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
5161 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01005162 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 Bergcb9abd42020-08-05 15:47:16 +02005176 if (params.ssid_len == 0)
Johannes Berg88600202012-02-13 15:17:18 +01005177 return -EINVAL;
5178 }
5179
Johannes Bergab0d76f2018-10-02 10:00:07 +02005180 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01005181 params.hidden_ssid = nla_get_u32(
5182 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01005183
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 Malinene39e5b52012-09-30 19:29:39 +03005189 if (!nl80211_valid_auth_type(rdev, params.auth_type,
5190 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01005191 return -EINVAL;
5192 } else
5193 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5194
5195 err = nl80211_crypto_settings(rdev, info, &params.crypto,
5196 NL80211_MAX_NR_CIPHER_SUITES);
5197 if (err)
5198 return err;
5199
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05305200 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 Berg53cabad2012-11-14 15:17:28 +01005207 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 Berg53cabad2012-11-14 15:17:28 +01005212 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 Berg53cabad2012-11-14 15:17:28 +01005223 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 Bergaa430da2012-05-16 23:50:18 +02005229 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01005230 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5231 if (err)
5232 return err;
5233 } else if (wdev->preset_chandef.chan) {
5234 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005235 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02005236 return -EINVAL;
5237
Arik Nemtsov923b3522015-07-08 15:41:44 +03005238 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
5239 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02005240 return -EINVAL;
5241
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05305242 if (info->attrs[NL80211_ATTR_TX_RATES]) {
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05305243 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
5244 NL80211_ATTR_TX_RATES,
Miles Hueb89a6a2020-08-04 10:16:29 +02005245 &params.beacon_rate,
5246 dev);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05305247 if (err)
5248 return err;
5249
Johannes Berg8564e382016-09-19 09:44:44 +02005250 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
5251 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05305252 if (err)
5253 return err;
5254 }
5255
Eliad Peller18998c32014-09-10 14:07:34 +03005256 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 Kushwaha6e8ef842016-07-05 13:44:51 +05305279 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 Olsson4baf6be2015-10-29 07:04:58 +01005283 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 Crispina0de1ca32019-05-28 13:49:48 +02005289 params.twt_responder =
5290 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
5291
John Crispin796e90f2019-07-30 18:37:00 +02005292 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
5293 err = nl80211_parse_he_obss_pd(
5294 info->attrs[NL80211_ATTR_HE_OBSS_PD],
5295 &params.he_obss_pd);
Luca Coelhobc7a39b2020-06-26 12:49:39 +03005296 if (err)
5297 goto out;
John Crispin796e90f2019-07-30 18:37:00 +02005298 }
5299
John Crispin5c5e52d2019-12-17 15:19:18 +01005300 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) {
5301 err = nl80211_parse_he_bss_color(
5302 info->attrs[NL80211_ATTR_HE_BSS_COLOR],
5303 &params.he_bss_color);
5304 if (err)
Luca Coelho60a01212020-06-26 12:49:40 +03005305 goto out;
John Crispin5c5e52d2019-12-17 15:19:18 +01005306 }
5307
Aloka Dixit291c49d2020-09-11 00:05:29 +00005308 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) {
5309 err = nl80211_parse_fils_discovery(rdev,
5310 info->attrs[NL80211_ATTR_FILS_DISCOVERY],
5311 &params);
5312 if (err)
5313 goto out;
5314 }
5315
Aloka Dixit7443dcd2020-09-11 00:33:00 +00005316 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 &params);
5320 if (err)
5321 return err;
5322 }
5323
Johannes Berg66cd7942017-02-07 22:40:44 +02005324 nl80211_calculate_ap_params(&params);
5325
Srinivas Dasarife494372019-01-23 18:06:56 +05305326 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
5327 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
5328
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005329 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03005330 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005331 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01005332 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01005333 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01005334 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01005335 wdev->ssid_len = params.ssid_len;
5336 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05005337
5338 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
5339 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005340 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005341 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05305342
Johannes Berg9951ebf2020-02-21 10:41:43 +01005343out:
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05305344 kfree(params.acl);
5345
Johannes Berg56d18932011-05-09 18:41:15 +02005346 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01005347}
5348
Johannes Berg88600202012-02-13 15:17:18 +01005349static 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 Chitrapu81e54d02018-09-20 17:30:09 -07005367 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01005368 if (err)
5369 return err;
5370
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005371 wdev_lock(wdev);
5372 err = rdev_change_beacon(rdev, dev, &params);
5373 wdev_unlock(wdev);
5374
5375 return err;
Johannes Berg88600202012-02-13 15:17:18 +01005376}
5377
5378static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01005379{
Johannes Berg4c476992010-10-04 21:36:35 +02005380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5381 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01005382
Ilan Peer7c8d5e02014-02-25 15:33:38 +02005383 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01005384}
5385
Johannes Berg5727ef12007-12-19 02:03:34 +01005386static 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 Malinen0e467242009-05-11 21:57:55 +03005390 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07005391 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01005392 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01005393};
5394
Johannes Bergeccb8e82009-05-11 21:57:56 +03005395static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005396 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03005397 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01005398{
5399 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03005400 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01005401 int flag;
5402
Johannes Bergeccb8e82009-05-11 21:57:56 +03005403 /*
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 Berg5727ef12007-12-19 02:03:34 +01005410
Johannes Bergeccb8e82009-05-11 21:57:56 +03005411 sta_flags = nla_data(nla);
5412 params->sta_flags_mask = sta_flags->mask;
5413 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005414 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03005415 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 Berg5727ef12007-12-19 02:03:34 +01005424 if (!nla)
5425 return 0;
5426
Johannes Berg8cb08172019-04-26 14:07:28 +02005427 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01005428 return -EINVAL;
5429
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005430 /*
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 Edlinger5cf30062018-07-08 09:57:22 +00005454 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005455 default:
5456 return -EINVAL;
5457 }
Johannes Berg5727ef12007-12-19 02:03:34 +01005458
Johannes Berg3383b5a2012-05-10 20:14:43 +02005459 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
5460 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03005461 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01005462
Johannes Berg3383b5a2012-05-10 20:14:43 +02005463 /* 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 Berg5727ef12007-12-19 02:03:34 +01005469 return 0;
5470}
5471
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02005472bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005473{
5474 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03005475 u32 bitrate;
5476 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07005477 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005478
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005479 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005480 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005481 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005482
5483 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5484 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03005485 /* report 16-bit bitrate only if we can */
5486 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005487 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 Bergb51f3be2015-01-15 16:14:02 +01005494 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 Lin7b506ff2020-08-22 04:23:23 -04005503 fallthrough;
Johannes Bergb51f3be2015-01-15 16:14:02 +01005504 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 Coelhoc4cbaf72018-06-09 09:14:42 +03005516 case RATE_INFO_BW_HE_RU:
5517 rate_flg = 0;
5518 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01005519 }
5520
5521 if (rate_flg && nla_put_flag(msg, rate_flg))
5522 return false;
5523
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005524 if (info->flags & RATE_INFO_FLAGS_MCS) {
5525 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
5526 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005527 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 Bergdb9c64c2012-11-09 14:56:41 +01005535 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5536 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5537 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005538 } 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 Bergdb9c64c2012-11-09 14:56:41 +01005551 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005552
5553 nla_nest_end(msg, rate);
5554 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005555}
5556
Felix Fietkau119363c2013-04-22 16:29:30 +02005557static 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 Kubecekae0be8d2019-04-26 11:13:06 +02005566 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02005567 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 Bergcf5ead82014-11-14 17:14:00 +01005583static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5584 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04005585 struct cfg80211_registered_device *rdev,
5586 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01005587 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005588{
5589 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07005590 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005591
Johannes Bergcf5ead82014-11-14 17:14:00 +01005592 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Andy Strohmanf77bf482019-05-24 23:27:29 -07005593 if (!hdr) {
5594 cfg80211_sinfo_release_content(sinfo);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005595 return -1;
Andy Strohmanf77bf482019-05-24 23:27:29 -07005596 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005597
David S. Miller9360ffd2012-03-29 04:41:26 -04005598 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 Bergf5ea9122009-08-07 16:17:38 +02005602
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005603 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005604 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005605 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005606
5607#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02005608 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03005609 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01005610 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5611 sinfo->memb)) \
5612 goto nla_put_failure; \
5613 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02005614#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03005615 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005616 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 Berg319090b2014-11-17 14:08:11 +01005620
5621 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5622 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
Ben Greear6c7a0032019-08-09 11:00:00 -07005623 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
Johannes Berg319090b2014-11-17 14:08:11 +01005624
Omer Efrat397c6572018-06-17 13:06:14 +03005625 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5626 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005627 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005628 (u32)sinfo->rx_bytes))
5629 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005630
Omer Efrat397c6572018-06-17 13:06:14 +03005631 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5632 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005633 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5634 (u32)sinfo->tx_bytes))
5635 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005636
Johannes Bergd686b922016-04-26 09:54:11 +02005637 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5638 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01005639 PUT_SINFO(LLID, llid, u16);
5640 PUT_SINFO(PLID, plid, u16);
5641 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02005642 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005643 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 Berg319090b2014-11-17 14:08:11 +01005648
John W. Linville66266b32012-03-15 13:25:41 -04005649 switch (rdev->wiphy.signal_type) {
5650 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01005651 PUT_SINFO(SIGNAL, signal, u8);
5652 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04005653 break;
5654 default:
5655 break;
5656 }
Omer Efrat397c6572018-06-17 13:06:14 +03005657 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005658 if (!nl80211_put_signal(msg, sinfo->chains,
5659 sinfo->chain_signal,
5660 NL80211_STA_INFO_CHAIN_SIGNAL))
5661 goto nla_put_failure;
5662 }
Omer Efrat397c6572018-06-17 13:06:14 +03005663 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005664 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 Efrat397c6572018-06-17 13:06:14 +03005669 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005670 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5671 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01005672 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005673 }
Omer Efrat397c6572018-06-17 13:06:14 +03005674 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005675 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5676 NL80211_STA_INFO_RX_BITRATE))
5677 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01005678 }
Johannes Berg319090b2014-11-17 14:08:11 +01005679
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 Mastiab606332019-02-07 12:16:05 -08005685 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01005686 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 Copelanddbdaee72018-10-25 15:48:53 -04005690 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Markus Theil1303a512020-06-11 16:02:38 +02005691 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01005692
Omer Efrat397c6572018-06-17 13:06:14 +03005693 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005694 bss_param = nla_nest_start_noflag(msg,
5695 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07005696 if (!bss_param)
5697 goto nla_put_failure;
5698
David S. Miller9360ffd2012-03-29 04:41:26 -04005699 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 Stewartf4263c92011-03-31 09:25:41 -07005710
5711 nla_nest_end(msg, bss_param);
5712 }
Omer Efrat397c6572018-06-17 13:06:14 +03005713 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005714 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 Berg319090b2014-11-17 14:08:11 +01005718
Johannes Bergd686b922016-04-26 09:54:11 +02005719 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 Berga76b1942014-11-17 14:12:22 +01005722 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005723 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5724 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305725 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305726 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 Berg319090b2014-11-17 14:08:11 +01005730
5731#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005732#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005733
Arend van Spriel8689c052018-05-10 13:50:12 +02005734 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005735 struct nlattr *tidsattr;
5736 int tid;
5737
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005738 tidsattr = nla_nest_start_noflag(msg,
5739 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005740 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 Kubecekae0be8d2019-04-26 11:13:06 +02005752 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005753 if (!tidattr)
5754 goto nla_put_failure;
5755
Johannes Bergd686b922016-04-26 09:54:11 +02005756#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005757 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005758 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5759 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005760 goto nla_put_failure; \
5761 } while (0)
5762
Johannes Bergd686b922016-04-26 09:54:11 +02005763 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 Berg6de39802014-12-19 12:34:00 +01005767
Johannes Bergd686b922016-04-26 09:54:11 +02005768#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005769 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 Berg6de39802014-12-19 12:34:00 +01005775 nla_nest_end(msg, tidattr);
5776 }
5777
5778 nla_nest_end(msg, tidsattr);
5779 }
5780
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005781 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005782
Johannes Berg319090b2014-11-17 14:08:11 +01005783 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005784 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5785 sinfo->assoc_req_ies))
5786 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005787
Johannes Berg7ea3e112018-05-18 11:40:44 +02005788 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005789 genlmsg_end(msg, hdr);
5790 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005791
5792 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005793 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005794 genlmsg_cancel(msg, hdr);
5795 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005796}
5797
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005798static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005799 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005800{
Johannes Berg73887fd2018-05-18 09:57:55 +02005801 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005802 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005803 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005804 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005805 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005806 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005807
Johannes Bergea90e0d2017-03-15 14:26:04 +01005808 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005809 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005810 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005811 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005812
Johannes Berg97990a02013-04-19 01:02:55 +02005813 if (!wdev->netdev) {
5814 err = -EINVAL;
5815 goto out_err;
5816 }
5817
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005818 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005819 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005820 goto out_err;
5821 }
5822
Johannes Bergbba95fe2008-07-29 13:22:51 +02005823 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005824 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005825 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005826 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005827 if (err == -ENOENT)
5828 break;
5829 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005830 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005831
Johannes Bergcf5ead82014-11-14 17:14:00 +01005832 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005833 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005834 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005835 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005836 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005837 goto out;
5838
5839 sta_idx++;
5840 }
5841
Johannes Bergbba95fe2008-07-29 13:22:51 +02005842 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005843 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005844 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005845 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005846 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005847
5848 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005849}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005850
Johannes Berg5727ef12007-12-19 02:03:34 +01005851static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5852{
Johannes Berg4c476992010-10-04 21:36:35 +02005853 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5854 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005855 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005856 struct sk_buff *msg;
5857 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005858 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005859
Johannes Berg73887fd2018-05-18 09:57:55 +02005860 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005861
Johannes Berg73887fd2018-05-18 09:57:55 +02005862 if (!info->attrs[NL80211_ATTR_MAC])
5863 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005864
5865 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5866
Johannes Berg73887fd2018-05-18 09:57:55 +02005867 if (!rdev->ops->get_station)
5868 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005869
Johannes Berg73887fd2018-05-18 09:57:55 +02005870 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005871 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005872 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005873
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005875 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005876 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005877 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005878 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005879
Johannes Bergcf5ead82014-11-14 17:14:00 +01005880 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5881 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005882 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005883 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005884 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005885 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005886
Johannes Berg73887fd2018-05-18 09:57:55 +02005887 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005888}
5889
Johannes Berg77ee7c82013-02-15 00:48:33 +01005890int cfg80211_check_station_change(struct wiphy *wiphy,
5891 struct station_parameters *params,
5892 enum cfg80211_station_type statype)
5893{
Ayala Bekere4208422015-10-23 11:20:06 +03005894 if (params->listen_interval != -1 &&
5895 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005896 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005897
Ayala Beker17b94242016-03-17 15:41:38 +02005898 if (params->support_p2p_ps != -1 &&
5899 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5900 return -EINVAL;
5901
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005902 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005903 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5904 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005905 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 Pederseneef941e2013-03-04 13:06:11 -08005911 case CFG80211_STA_MESH_PEER_KERNEL:
5912 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005913 /*
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 Beker47edb112015-09-21 15:49:53 +03005954 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5955 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005956 /* 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 Coelhoc4cbaf72018-06-09 09:14:42 +03005963 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5964 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005965 return -EINVAL;
5966 }
5967
Ayala Beker47edb112015-09-21 15:49:53 +03005968 if (statype != CFG80211_STA_AP_CLIENT &&
5969 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005970 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 Beker47edb112015-09-21 15:49:53 +03005981 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005982 /* 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 Pederseneef941e2013-03-04 13:06:11 -08006018 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01006019 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
6020 return -EINVAL;
6021 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08006022 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08006023 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
6024 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01006025 return -EINVAL;
6026 break;
6027 }
6028
Beni Lev06f7c882016-07-19 19:28:56 +03006029 /*
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 Berg77ee7c82013-02-15 00:48:33 +01006038 return 0;
6039}
6040EXPORT_SYMBOL(cfg80211_check_station_change);
6041
Johannes Berg5727ef12007-12-19 02:03:34 +01006042/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01006043 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01006044 */
Johannes Berg80b99892011-11-18 16:23:01 +01006045static struct net_device *get_vlan(struct genl_info *info,
6046 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01006047{
Johannes Berg463d0182009-07-14 00:33:35 +02006048 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01006049 struct net_device *v;
6050 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01006051
Johannes Berg80b99892011-11-18 16:23:01 +01006052 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 Berg5727ef12007-12-19 02:03:34 +01006062 }
Johannes Berg80b99892011-11-18 16:23:01 +01006063
Johannes Berg77ee7c82013-02-15 00:48:33 +01006064 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 Berg80b99892011-11-18 16:23:01 +01006071 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 Berg5727ef12007-12-19 02:03:34 +01006080}
6081
Johannes Berg94e860f2014-01-20 23:58:15 +01006082static const struct nla_policy
6083nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02006084 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
6085 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
6086};
6087
Johannes Bergff276692013-02-15 00:09:01 +01006088static int nl80211_parse_sta_wme(struct genl_info *info,
6089 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02006090{
Jouni Malinendf881292013-02-14 21:10:54 +02006091 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
6092 struct nlattr *nla;
6093 int err;
6094
Jouni Malinendf881292013-02-14 21:10:54 +02006095 /* 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 Berg8cb08172019-04-26 14:07:28 +02006100 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
6101 nl80211_sta_wme_policy,
6102 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02006103 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 Duttc01fc9a2013-10-09 20:45:21 +05306123static 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 Bergcb9abd42020-08-05 15:47:16 +02006133 * channels) tuple for each subband (checked in policy),
6134 * and must have proper tuples for the rest of the data as well.
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306135 */
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306136 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 Duttc01fc9a2013-10-09 20:45:21 +05306145 }
6146 return 0;
6147}
6148
Johannes Bergff276692013-02-15 00:09:01 +01006149static int nl80211_set_station_tdls(struct genl_info *info,
6150 struct station_parameters *params)
6151{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306152 int err;
Johannes Bergff276692013-02-15 00:09:01 +01006153 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006154 if (info->attrs[NL80211_ATTR_PEER_AID])
6155 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01006156 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 Coelhoc4cbaf72018-06-09 09:14:42 +03006162 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 Coelhoc4cbaf72018-06-09 09:14:42 +03006167 }
Johannes Bergff276692013-02-15 00:09:01 +01006168
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306169 err = nl80211_parse_sta_channel_info(info, params);
6170 if (err)
6171 return err;
6172
Johannes Bergff276692013-02-15 00:09:01 +01006173 return nl80211_parse_sta_wme(info, params);
6174}
6175
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05306176static 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 Berg5727ef12007-12-19 02:03:34 +01006206static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
6207{
Johannes Berg4c476992010-10-04 21:36:35 +02006208 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006209 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01006210 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01006211 u8 *mac_addr;
6212 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01006213
6214 memset(&params, 0, sizeof(params));
6215
Johannes Berg77ee7c82013-02-15 00:48:33 +01006216 if (!rdev->ops->change_station)
6217 return -EOPNOTSUPP;
6218
Ayala Bekere4208422015-10-23 11:20:06 +03006219 /*
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 Bekera9bc31e2015-11-26 16:26:12 +01006224 if (info->attrs[NL80211_ATTR_STA_AID])
6225 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03006226
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02006227 if (info->attrs[NL80211_ATTR_VLAN_ID])
6228 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6229
Ayala Bekere4208422015-10-23 11:20:06 +03006230 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 Berg5727ef12007-12-19 02:03:34 +01006235
Johannes Bergab0d76f2018-10-02 10:00:07 +02006236 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 Beker17b94242016-03-17 15:41:38 +02006240 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02006241
Johannes Berg5727ef12007-12-19 02:03:34 +01006242 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 Malinen9d62a982013-02-14 21:10:13 +02006254 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 Bergbdd3ae32012-01-02 13:30:03 +01006267 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01006268 return -EINVAL;
6269
Johannes Bergab0d76f2018-10-02 10:00:07 +02006270 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006271 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006272 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006273
Johannes Bergf8bacc22013-02-14 23:27:01 +01006274 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07006275 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006276 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02006277 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09006278 params.peer_aid = nla_get_u16(
6279 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01006280 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
6281 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07006282
Johannes Bergab0d76f2018-10-02 10:00:07 +02006283 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
6284 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006285 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
6286
Beni Lev06f7c882016-07-19 19:28:56 +03006287 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 Manoharan43e64bf2020-05-28 21:34:29 +02006293 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6294 params.he_6ghz_capa =
Johannes Bergfce2ff72020-08-05 15:35:18 +02006295 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006296
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08006297 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 Nagarajane96d1cd2019-03-29 16:18:21 +05306306 err = nl80211_parse_sta_txpower_setting(info, &params);
6307 if (err)
6308 return err;
6309
Johannes Berg77ee7c82013-02-15 00:48:33 +01006310 /* Include parameters for TDLS peer (will check later) */
6311 err = nl80211_set_station_tdls(info, &params);
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 Berga97f4422009-06-18 17:23:43 +02006319 switch (dev->ieee80211_ptr->iftype) {
6320 case NL80211_IFTYPE_AP:
6321 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02006322 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02006323 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02006324 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01006325 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02006326 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02006327 break;
6328 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01006329 err = -EOPNOTSUPP;
6330 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02006331 }
6332
Johannes Berg77ee7c82013-02-15 00:48:33 +01006333 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03006334 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006335
Johannes Berg77ee7c82013-02-15 00:48:33 +01006336 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01006337 if (params.vlan)
6338 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01006339
Johannes Berg5727ef12007-12-19 02:03:34 +01006340 return err;
6341}
6342
6343static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
6344{
Johannes Berg4c476992010-10-04 21:36:35 +02006345 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01006346 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006347 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01006348 struct station_parameters params;
6349 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01006350 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6351 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01006352
6353 memset(&params, 0, sizeof(params));
6354
Johannes Berg984c3112013-02-14 23:43:25 +01006355 if (!rdev->ops->add_station)
6356 return -EOPNOTSUPP;
6357
Johannes Berg5727ef12007-12-19 02:03:34 +01006358 if (!info->attrs[NL80211_ATTR_MAC])
6359 return -EINVAL;
6360
Johannes Berg5727ef12007-12-19 02:03:34 +01006361 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 Malinen5e4b6f52013-05-16 20:11:08 +03006367 if (!info->attrs[NL80211_ATTR_STA_AID] &&
6368 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02006369 return -EINVAL;
6370
Johannes Berg5727ef12007-12-19 02:03:34 +01006371 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 Berg51b50fb2009-05-24 16:42:30 +02006378
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02006379 if (info->attrs[NL80211_ATTR_VLAN_ID])
6380 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6381
Ayala Beker17b94242016-03-17 15:41:38 +02006382 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02006383 params.support_p2p_ps =
6384 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02006385 } 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 Malinen3d124ea2013-05-27 18:24:02 +03006394 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006395 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006396 else
6397 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02006398
Jouni Malinen9d62a982013-02-14 21:10:13 +02006399 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 Malinen36aedc92008-08-25 11:58:58 +03006412 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6413 params.ht_capa =
6414 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006415
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00006416 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6417 params.vht_capa =
6418 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6419
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006420 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 Coelhoc4cbaf72018-06-09 09:14:42 +03006425 }
6426
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006427 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 Kwaczynski60f4a7b2013-12-03 10:04:59 +01006431 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 Bergab0d76f2018-10-02 10:00:07 +02006437 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07006438 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006439 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07006440
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08006441 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 Nagarajane96d1cd2019-03-29 16:18:21 +05306450 err = nl80211_parse_sta_txpower_setting(info, &params);
6451 if (err)
6452 return err;
6453
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306454 err = nl80211_parse_sta_channel_info(info, &params);
6455 if (err)
6456 return err;
6457
Johannes Bergff276692013-02-15 00:09:01 +01006458 err = nl80211_parse_sta_wme(info, &params);
6459 if (err)
6460 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006461
Johannes Bergbdd3ae32012-01-02 13:30:03 +01006462 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01006463 return -EINVAL;
6464
Johannes Berg496fcc22015-03-12 08:53:27 +02006465 /* 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 Coelhoc4cbaf72018-06-09 09:14:42 +03006473
6474 /* HE requires WME */
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006475 if (params.he_capa_len || params.he_6ghz_capa)
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006476 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02006477 }
6478
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006479 /* 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 Berg77ee7c82013-02-15 00:48:33 +01006483 /* When you run into this, adjust the code below for the new flag */
6484 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6485
Johannes Bergbdd90d52011-12-14 12:20:27 +01006486 switch (dev->ieee80211_ptr->iftype) {
6487 case NL80211_IFTYPE_AP:
6488 case NL80211_IFTYPE_AP_VLAN:
6489 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01006490 /* 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 Pellerc75786c2011-08-23 14:37:46 +03006494
Johannes Bergbdd90d52011-12-14 12:20:27 +01006495 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006496 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6497 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02006498 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006499 /* but don't bother the driver with it */
6500 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03006501
Johannes Bergd582cff2012-10-26 17:53:44 +02006502 /* allow authenticated/associated only if driver handles it */
6503 if (!(rdev->wiphy.features &
6504 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01006505 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02006506 return -EINVAL;
6507
Johannes Bergbda95eb2015-11-26 16:26:13 +01006508 /* 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 Bergbdd90d52011-12-14 12:20:27 +01006523 /* 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 Berg984c3112013-02-14 23:43:25 +01006529 /* ignore uAPSD data */
6530 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6531
Johannes Bergd582cff2012-10-26 17:53:44 +02006532 /* associated is disallowed */
6533 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
6534 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006535 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006536 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6537 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02006538 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006539 break;
6540 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01006541 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01006542 /* ignore uAPSD data */
6543 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6544
Johannes Berg77ee7c82013-02-15 00:48:33 +01006545 /* these are disallowed */
6546 if (params.sta_flags_mask &
6547 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
6548 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02006549 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006550 /* 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 Berg77ee7c82013-02-15 00:48:33 +01006559 /*
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 Bergbdd90d52011-12-14 12:20:27 +01006564 break;
6565 default:
6566 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03006567 }
6568
Johannes Bergbdd90d52011-12-14 12:20:27 +01006569 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01006570
Hila Gonene35e4d22012-06-27 17:19:42 +03006571 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006572
Johannes Berg5727ef12007-12-19 02:03:34 +01006573 if (params.vlan)
6574 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01006575 return err;
6576}
6577
6578static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6579{
Johannes Berg4c476992010-10-04 21:36:35 +02006580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6581 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03006582 struct station_del_parameters params;
6583
6584 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01006585
6586 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03006587 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006588
Johannes Berg306b79e2020-03-20 11:38:35 +01006589 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 Cavallariedafcf42020-03-05 14:57:53 +01006601 return -EINVAL;
Johannes Berg306b79e2020-03-20 11:38:35 +01006602 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006603 return -EINVAL;
Johannes Berg306b79e2020-03-20 11:38:35 +01006604 }
Johannes Berge80cf852009-05-11 14:43:13 +02006605
Johannes Berg4c476992010-10-04 21:36:35 +02006606 if (!rdev->ops->del_station)
6607 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01006608
Jouni Malinen98856862014-10-20 13:20:45 +03006609 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 Malinen89c771e2014-10-10 20:52:40 +03006630 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006631}
6632
Eric W. Biederman15e47302012-09-07 20:12:54 +00006633static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006634 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 Rogge1ef4c852014-11-04 16:14:58 +01006641 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006642 if (!hdr)
6643 return -1;
6644
David S. Miller9360ffd2012-03-29 04:41:26 -04006645 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 Bergf5ea9122009-08-07 16:17:38 +02006650
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006651 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006652 if (!pinfoattr)
6653 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006654 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 Hsucc241632019-01-15 15:28:42 -08006674 pinfo->discovery_retries)) ||
6675 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6676 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08006677 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. Miller9360ffd2012-03-29 04:41:26 -04006681 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006682
6683 nla_nest_end(msg, pinfoattr);
6684
Johannes Berg053c0952015-01-16 22:09:00 +01006685 genlmsg_end(msg, hdr);
6686 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006687
6688 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07006689 genlmsg_cancel(msg, hdr);
6690 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006691}
6692
6693static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006694 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006695{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006696 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006697 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006698 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006699 u8 dst[ETH_ALEN];
6700 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02006701 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006702 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006703
Johannes Bergea90e0d2017-03-15 14:26:04 +01006704 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006705 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006706 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006707 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006708
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006709 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006710 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006711 goto out_err;
6712 }
6713
Johannes Berg97990a02013-04-19 01:02:55 +02006714 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006715 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006716 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006717 }
6718
Johannes Bergbba95fe2008-07-29 13:22:51 +02006719 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006720 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006721 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006722 if (err == -ENOENT)
6723 break;
6724 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006725 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006726
Eric W. Biederman15e47302012-09-07 20:12:54 +00006727 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006728 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006729 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006730 &pinfo) < 0)
6731 goto out;
6732
6733 path_idx++;
6734 }
6735
Johannes Bergbba95fe2008-07-29 13:22:51 +02006736 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006737 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006738 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006739 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006740 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006741 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006742}
6743
6744static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6745{
Johannes Berg4c476992010-10-04 21:36:35 +02006746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006747 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006748 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006749 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 Berg4c476992010-10-04 21:36:35 +02006761 if (!rdev->ops->get_mpath)
6762 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006763
Johannes Berg4c476992010-10-04 21:36:35 +02006764 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6765 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006766
Hila Gonene35e4d22012-06-27 17:19:42 +03006767 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006768 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006769 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006770
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006771 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006772 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006773 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006774
Eric W. Biederman15e47302012-09-07 20:12:54 +00006775 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006776 dev, dst, next_hop, &pinfo) < 0) {
6777 nlmsg_free(msg);
6778 return -ENOBUFS;
6779 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006780
Johannes Berg4c476992010-10-04 21:36:35 +02006781 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006782}
6783
6784static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6785{
Johannes Berg4c476992010-10-04 21:36:35 +02006786 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6787 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006788 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 Berg4c476992010-10-04 21:36:35 +02006800 if (!rdev->ops->change_mpath)
6801 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006802
Johannes Berg4c476992010-10-04 21:36:35 +02006803 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6804 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006805
Hila Gonene35e4d22012-06-27 17:19:42 +03006806 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006807}
Johannes Berg4c476992010-10-04 21:36:35 +02006808
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006809static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6810{
Johannes Berg4c476992010-10-04 21:36:35 +02006811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6812 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006813 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 Berg4c476992010-10-04 21:36:35 +02006825 if (!rdev->ops->add_mpath)
6826 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006827
Johannes Berg4c476992010-10-04 21:36:35 +02006828 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6829 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006830
Hila Gonene35e4d22012-06-27 17:19:42 +03006831 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006832}
6833
6834static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
6835{
Johannes Berg4c476992010-10-04 21:36:35 +02006836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6837 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006838 u8 *dst = NULL;
6839
6840 if (info->attrs[NL80211_ATTR_MAC])
6841 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6842
Johannes Berg4c476992010-10-04 21:36:35 +02006843 if (!rdev->ops->del_mpath)
6844 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006845
Miaoqing Panb5014262019-09-26 16:16:50 +08006846 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6847 return -EOPNOTSUPP;
6848
Hila Gonene35e4d22012-06-27 17:19:42 +03006849 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006850}
6851
Henning Rogge66be7d22014-09-12 08:58:49 +02006852static 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
6892static 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 Bergea90e0d2017-03-15 14:26:04 +01006903 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006904 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006905 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006906 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006907
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 Bergea90e0d2017-03-15 14:26:04 +01006939 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006940 return err;
6941}
6942
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006943static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6944{
Johannes Berg4c476992010-10-04 21:36:35 +02006945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6946 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006947 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006948 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006949 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006950
6951 memset(&params, 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 Fietkaufd8aaaf2010-04-27 01:23:35 +02006956 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006957 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006958 params.p2p_ctwindow = -1;
6959 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006960
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 Malinen90c97a02008-10-30 16:59:22 +02006970 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 Fietkaufd8aaaf2010-04-27 01:23:35 +02006976 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6977 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006978 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6979 params.ht_opmode =
6980 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006981
Johannes Berg53cabad2012-11-14 15:17:28 +01006982 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 Bergab0d76f2018-10-02 10:00:07 +02006986 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006987 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 Berg53cabad2012-11-14 15:17:28 +01006998 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 Berg4c476992010-10-04 21:36:35 +02007004 if (!rdev->ops->change_bss)
7005 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007006
Johannes Berg074ac8d2010-09-16 14:58:22 +02007007 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02007008 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
7009 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007010
Simon Wunderlichc56589e2013-11-21 18:19:49 +01007011 wdev_lock(wdev);
7012 err = rdev_change_bss(rdev, dev, &params);
7013 wdev_unlock(wdev);
7014
7015 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03007016}
7017
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007018static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
7019{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007020 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05007021 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07007022 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05007023 u32 owner_nlportid;
7024
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05007025 /*
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 Berg458f4f92012-12-06 15:47:38 +01007031 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05007032 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05007033
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07007034 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 Peer52616f22014-02-25 16:26:00 +02007043 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 peer05050752015-03-04 00:32:06 -05007049 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. Rodriguez57b5ce02012-07-12 11:49:18 -07007058 default:
7059 return -EINVAL;
7060 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007061}
7062
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02007063static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
7064{
7065 return reg_reload_regdb();
7066}
7067
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007068static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01007069 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007070{
Johannes Berg4c476992010-10-04 21:36:35 +02007071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02007072 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01007073 struct wireless_dev *wdev = dev->ieee80211_ptr;
7074 struct mesh_config cur_params;
7075 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007076 void *hdr;
7077 struct nlattr *pinfoattr;
7078 struct sk_buff *msg;
7079
Johannes Berg29cbe682010-12-03 09:20:44 +01007080 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7081 return -EOPNOTSUPP;
7082
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007083 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02007084 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02007085
Johannes Berg29cbe682010-12-03 09:20:44 +01007086 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 Gonene35e4d22012-06-27 17:19:42 +03007091 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01007092 wdev_unlock(wdev);
7093
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007094 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02007095 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007096
7097 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007098 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007099 if (!msg)
7100 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00007101 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007102 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007103 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01007104 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007105 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007106 if (!pinfoattr)
7107 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007108 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. Linville7eab0f62012-04-12 14:25:14 -04007125 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
7126 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007127 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 Honma335d5342017-03-16 10:57:17 +09007149 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07007150 cur_params.rssi_threshold) ||
7151 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08007152 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 Yeoh728b19e2012-06-14 02:06:10 +08007156 cur_params.dot11MeshHWMProotInterval) ||
7157 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01007158 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 Twitty8e7c0532013-06-03 09:53:39 -07007162 cur_params.dot11MeshAwakeWindowDuration) ||
7163 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04007164 cur_params.plink_timeout) ||
7165 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
Linus Lüssinge3718a62020-06-17 09:30:33 +02007166 cur_params.dot11MeshConnectedToMeshGate) ||
7167 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
Markus Theil184eebe2020-06-11 16:02:37 +02007168 cur_params.dot11MeshNolearn) ||
7169 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
7170 cur_params.dot11MeshConnectedToAuthServer))
David S. Miller9360ffd2012-03-29 04:41:26 -04007171 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007172 nla_nest_end(msg, pinfoattr);
7173 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007174 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007175
Johannes Berg3b858752009-03-12 09:55:09 +01007176 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01007177 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04007178 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02007179 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007180}
7181
Johannes Bergab0d76f2018-10-02 10:00:07 +02007182static const struct nla_policy
7183nl80211_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.com93da9cc2008-10-21 12:03:48 -07007198 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
7199 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02007200 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007201 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02007202 [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 Yeoha4f606e2012-06-11 11:59:36 +08007215 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08007216 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02007217 [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 Porsch3b1c5a52013-01-07 16:04:52 +01007225 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07007226 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04007227 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
Linus Lüssinge3718a62020-06-17 09:30:33 +02007228 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
Markus Theil184eebe2020-06-11 16:02:37 +02007229 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007230};
7231
Javier Cardonac80d5452010-12-16 17:37:49 -08007232static const struct nla_policy
7233 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07007234 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08007235 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
7236 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07007237 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07007238 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007239 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02007240 [NL80211_MESH_SETUP_IE] =
7241 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
7242 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07007243 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08007244};
7245
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007246static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007247 struct mesh_config *cfg,
7248 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007249{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007250 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007251 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09007252 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007253
Johannes Bergab0d76f2018-10-02 10:00:07 +02007254#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
7255do { \
7256 if (tb[attr]) { \
7257 cfg->param = fn(tb[attr]); \
7258 mask |= BIT((attr) - 1); \
7259 } \
Marco Porschea54fba2013-01-07 16:04:48 +01007260} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007261
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007262 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007263 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02007264 if (nla_parse_nested_deprecated(tb, NL80211_MESHCONF_ATTR_MAX, info->attrs[NL80211_ATTR_MESH_CONFIG], nl80211_meshconf_params_policy, info->extack))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007265 return -EINVAL;
7266
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007267 /* 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 Bergab0d76f2018-10-02 10:00:07 +02007272 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 Porschea54fba2013-01-07 16:04:48 +01007292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007293 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007294 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007295 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 Porschea54fba2013-01-07 16:04:48 +01007308 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007309 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007310 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007311 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 Porschea54fba2013-01-07 16:04:48 +01007317 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007318 nla_get_u16);
7319 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01007320 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007321 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007322 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007323 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007324 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007325 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 Porschea54fba2013-01-07 16:04:48 +01007332 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007333 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 Copeland01d66fb2018-10-25 17:36:34 -04007339 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
7340 NL80211_MESHCONF_CONNECTED_TO_GATE,
7341 nla_get_u8);
Markus Theil184eebe2020-06-11 16:02:37 +02007342 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
7343 NL80211_MESHCONF_CONNECTED_TO_AS,
7344 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09007345 /*
7346 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04007347 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09007348 */
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 Copeland188f60a2018-06-24 21:10:49 -04007357 /* NON_HT_STA bit is reserved, but some programs set it */
7358 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09007359
Masashi Honma97572352016-08-03 10:07:44 +09007360 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09007361 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09007362 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08007363 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007364 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 Yeoh728b19e2012-06-14 02:06:10 +08007376 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007377 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üssinge3718a62020-06-17 09:30:33 +02007384 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
7385 NL80211_MESHCONF_NOLEARN, nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007386 if (mask_out)
7387 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08007388
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007389 return 0;
7390
7391#undef FILL_IN_MESH_PARAM_IF_SET
7392}
7393
Javier Cardonac80d5452010-12-16 17:37:49 -08007394static int nl80211_parse_mesh_setup(struct genl_info *info,
7395 struct mesh_setup *setup)
7396{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08007398 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
7399
7400 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
7401 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02007402 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 Cardonac80d5452010-12-16 17:37:49 -08007403 return -EINVAL;
7404
Javier Cardonad299a1f2012-03-31 11:31:33 -07007405 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 Cardonac80d5452010-12-16 17:37:49 -08007411 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 Cardona581a8b02011-04-07 15:08:27 -07007423 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08007424 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07007425 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07007426 setup->ie = nla_data(ieattr);
7427 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08007428 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007429 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 Cardonab130e5c2011-05-03 16:57:07 -07007433 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 Pedersenbb2798d2013-03-04 13:06:10 -08007435 if (setup->is_secure)
7436 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08007437
Colleen Twitty6e16d902013-05-08 11:45:59 -07007438 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 Cardonac80d5452010-12-16 17:37:49 -08007445 return 0;
7446}
7447
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007448static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01007449 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007450{
7451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7452 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01007453 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007454 struct mesh_config cfg;
7455 u32 mask;
7456 int err;
7457
Johannes Berg29cbe682010-12-03 09:20:44 +01007458 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7459 return -EOPNOTSUPP;
7460
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007461 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007462 return -EOPNOTSUPP;
7463
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007464 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007465 if (err)
7466 return err;
7467
Johannes Berg29cbe682010-12-03 09:20:44 +01007468 wdev_lock(wdev);
7469 if (!wdev->mesh_id_len)
7470 err = -ENOLINK;
7471
7472 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03007473 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007474
7475 wdev_unlock(wdev);
7476
7477 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007478}
7479
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007480static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
7481 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007482{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007483 struct nlattr *nl_reg_rules;
7484 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007485
Johannes Berg458f4f92012-12-06 15:47:38 +01007486 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 Nemtsovad30ca22014-12-15 19:25:59 +02007489 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01007490
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007491 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007492 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007493 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007494
Johannes Berg458f4f92012-12-06 15:47:38 +01007495 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007496 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 Dziedzic97524822014-01-30 09:52:20 +01007500 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007501
Johannes Berg458f4f92012-12-06 15:47:38 +01007502 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007503 freq_range = &reg_rule->freq_range;
7504 power_rule = &reg_rule->power_rule;
7505
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007506 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007507 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007508 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007509
Janusz Dziedzic97524822014-01-30 09:52:20 +01007510 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. Miller9360ffd2012-03-29 04:41:26 -04007515 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 Dziedzic97524822014-01-30 09:52:20 +01007522 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007523 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 Dziedzic089027e2014-02-21 19:46:12 +01007526 power_rule->max_eirp) ||
7527 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
7528 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007529 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007530
7531 nla_nest_end(msg, nl_reg_rule);
7532 }
7533
7534 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007535 return 0;
7536
7537nla_put_failure:
7538 return -EMSGSIZE;
7539}
7540
7541static 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 Nemtsov1bdd7162014-12-15 19:26:01 +02007559 bool self_managed;
7560
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007561 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 Nemtsov1bdd7162014-12-15 19:26:01 +02007568 self_managed = wiphy->regulatory_flags &
7569 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007570 regdom = get_wiphy_regdom(wiphy);
7571
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007572 /* 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 Nemtsovad30ca22014-12-15 19:25:59 +02007578 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. Rodriguezf1303472009-01-30 09:26:42 -08007597
7598 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007599 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007600
Johannes Berg458f4f92012-12-06 15:47:38 +01007601nla_put_failure_rcu:
7602 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007603nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01007604put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04007605 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007606 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007607}
7608
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007609static 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 Kubecek0a833c22017-11-15 13:09:32 +01007619 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007620
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 Nemtsov1bdd7162014-12-15 19:26:01 +02007633 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 Berg053c0952015-01-16 22:09:00 +01007637 genlmsg_end(msg, hdr);
7638 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007639
7640nla_put_failure:
7641 genlmsg_cancel(msg, hdr);
7642 return -EMSGSIZE;
7643}
7644
7645static 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;
7682out_err:
7683 rtnl_unlock();
7684 return err;
7685}
7686
Johannes Bergb6863032015-10-15 09:25:18 +02007687#ifdef CONFIG_CFG80211_CRDA_SUPPORT
7688static 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
7698static int parse_reg_rule(struct nlattr *tb[],
7699 struct ieee80211_reg_rule *reg_rule)
7700{
7701 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
7702 struct ieee80211_power_rule *power_rule = &reg_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. Rodriguezb2e1b302008-09-09 23:19:48 -07007738static 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 Bergea372c52014-11-28 14:54:31 +01007742 char *alpha2;
7743 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007744 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007745 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007746 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007747
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. Rodriguez8b60b072011-10-11 10:59:02 -07007756 if (info->attrs[NL80211_ATTR_DFS_REGION])
7757 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7758
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007759 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007760 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007761 num_rules++;
7762 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007763 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007764 }
7765
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007766 if (!reg_is_valid_request(alpha2))
7767 return -EINVAL;
7768
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007769 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007770 if (!rd)
7771 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007772
7773 rd->n_reg_rules = num_rules;
7774 rd->alpha2[0] = alpha2[0];
7775 rd->alpha2[1] = alpha2[1];
7776
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007777 /*
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. Rodriguezb2e1b302008-09-09 23:19:48 -07007784 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007785 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007786 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7787 nl_reg_rule, reg_rule_policy,
7788 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007789 if (r)
7790 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007791 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7792 if (r)
7793 goto bad_reg;
7794
7795 rule_idx++;
7796
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007797 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7798 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007799 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007800 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007801 }
7802
Johannes Berg06627992016-06-09 10:40:09 +02007803 /* set_regdom takes ownership of rd */
7804 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007805 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007806 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007807 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007808}
Johannes Bergb6863032015-10-15 09:25:18 +02007809#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007810
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007811static int validate_scan_freqs(struct nlattr *freqs)
7812{
7813 struct nlattr *attr1, *attr2;
7814 int n_channels = 0, tmp1, tmp2;
7815
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007816 nla_for_each_nested(attr1, freqs, tmp1)
7817 if (nla_len(attr1) != sizeof(u32))
7818 return 0;
7819
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007820 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 Berg57fbcce2016-04-12 15:56:15 +02007840static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007841{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007842 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007843}
7844
7845static 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 Berg8cb08172019-04-26 14:07:28 +02007859 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7860 nest, nl80211_bss_select_policy,
7861 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007862 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 Berg9bb7e0f2018-09-10 13:29:12 +02007908int nl80211_parse_random_mac(struct nlattr **attrs,
7909 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007910{
7911 int i;
7912
7913 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007914 eth_zero_addr(mac_addr);
7915 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007916 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 Thiagarajan34373d12017-02-27 17:04:34 +05307945static 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 Bergdb0a4ad2018-05-28 15:47:37 +02007958static 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 Zamir2d23d072017-08-06 11:38:22 +03007968static int
7969nl80211_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 Dutt5037a002018-01-25 17:13:37 +02008000 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
8001 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02008002 !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 Berg2e076f12018-05-28 15:47:40 +02008022 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 Zamir2d23d072017-08-06 11:38:22 +03008029 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 Zamir2d23d072017-08-06 11:38:22 +03008043 return 0;
8044}
8045
Johannes Berg2a519312009-02-10 21:25:55 +01008046static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
8047{
Johannes Berg4c476992010-10-04 21:36:35 +02008048 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02008049 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01008050 struct cfg80211_scan_request *request;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008051 struct nlattr *scan_freqs = NULL;
8052 bool scan_freqs_khz = false;
Johannes Berg2a519312009-02-10 21:25:55 +01008053 struct nlattr *attr;
8054 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02008055 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02008056 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01008057
Johannes Berg79c97e92009-07-07 03:56:12 +02008058 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01008059
Ayala Bekercb3b7d82016-09-20 17:31:13 +03008060 if (wdev->iftype == NL80211_IFTYPE_NAN)
8061 return -EOPNOTSUPP;
8062
Johannes Berg4c476992010-10-04 21:36:35 +02008063 if (!rdev->ops->scan)
8064 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01008065
Christophe JAILLET83286852020-07-12 19:35:39 +02008066 if (rdev->scan_req || rdev->scan_msg)
8067 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01008068
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008069 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 JAILLET83286852020-07-12 19:35:39 +02008080 if (!n_channels)
8081 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01008082 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02008083 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01008084 }
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 JAILLET83286852020-07-12 19:35:39 +02008090 if (n_ssids > wiphy->max_scan_ssids)
8091 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01008092
Jouni Malinen70692ad2009-02-16 19:39:13 +02008093 if (info->attrs[NL80211_ATTR_IE])
8094 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8095 else
8096 ie_len = 0;
8097
Christophe JAILLET83286852020-07-12 19:35:39 +02008098 if (ie_len > wiphy->max_scan_ie_len)
8099 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02008100
Johannes Berg2a519312009-02-10 21:25:55 +01008101 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008102 + sizeof(*request->ssids) * n_ssids
8103 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02008104 + ie_len, GFP_KERNEL);
Christophe JAILLET83286852020-07-12 19:35:39 +02008105 if (!request)
8106 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01008107
Johannes Berg2a519312009-02-10 21:25:55 +01008108 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02008109 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01008110 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02008111 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01008112 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02008113 request->ie = (void *)(request->ssids + n_ssids);
8114 else
8115 request->ie = (void *)(request->channels + n_channels);
8116 }
Johannes Berg2a519312009-02-10 21:25:55 +01008117
Johannes Berg584991d2009-11-02 13:32:03 +01008118 i = 0;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008119 if (scan_freqs) {
Johannes Berg2a519312009-02-10 21:25:55 +01008120 /* user specified, bail out if channel not found */
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008121 nla_for_each_nested(attr, scan_freqs, tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01008122 struct ieee80211_channel *chan;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008123 int freq = nla_get_u32(attr);
Johannes Berg584991d2009-11-02 13:32:03 +01008124
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008125 if (!scan_freqs_khz)
8126 freq = MHZ_TO_KHZ(freq);
Johannes Berg584991d2009-11-02 13:32:03 +01008127
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008128 chan = ieee80211_get_channel_khz(wiphy, freq);
Johannes Berg584991d2009-11-02 13:32:03 +01008129 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01008130 err = -EINVAL;
8131 goto out_free;
8132 }
Johannes Berg584991d2009-11-02 13:32:03 +01008133
8134 /* ignore disabled channels */
8135 if (chan->flags & IEEE80211_CHAN_DISABLED)
8136 continue;
8137
8138 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01008139 i++;
8140 }
8141 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008142 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02008143
Johannes Berg2a519312009-02-10 21:25:55 +01008144 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008145 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01008146 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008147
Johannes Berg2a519312009-02-10 21:25:55 +01008148 if (!wiphy->bands[band])
8149 continue;
8150 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01008151 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 Berg2a519312009-02-10 21:25:55 +01008159 i++;
8160 }
8161 }
8162 }
8163
Johannes Berg584991d2009-11-02 13:32:03 +01008164 if (!i) {
8165 err = -EINVAL;
8166 goto out_free;
8167 }
8168
8169 request->n_channels = i;
8170
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05308171 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 Berg2a519312009-02-10 21:25:55 +01008190 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01008191 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01008192 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008193 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01008194 err = -EINVAL;
8195 goto out_free;
8196 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008197 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01008198 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01008199 i++;
8200 }
8201 }
8202
Jouni Malinen70692ad2009-02-16 19:39:13 +02008203 if (info->attrs[NL80211_ATTR_IE]) {
8204 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02008205 memcpy((void *)request->ie,
8206 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02008207 request->ie_len);
8208 }
8209
Johannes Berg57fbcce2016-04-12 15:56:15 +02008210 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02008211 if (wiphy->bands[i])
8212 request->rates[i] =
8213 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02008214
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 Berg57fbcce2016-04-12 15:56:15 +02008219 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02008220
Johannes Berg57fbcce2016-04-12 15:56:15 +02008221 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02008222 err = -EINVAL;
8223 goto out_free;
8224 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01008225
8226 if (!wiphy->bands[band])
8227 continue;
8228
Johannes Berg34850ab2011-07-18 18:08:35 +02008229 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 Stern1d762502016-07-05 17:10:13 +03008238 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 Zamir2d23d072017-08-06 11:38:22 +03008251 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
8252 false);
8253 if (err)
8254 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008255
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308256 request->no_cck =
8257 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
8258
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02008259 /* 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 Malinen818965d2016-02-26 22:12:47 +02008273 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
8274 ETH_ALEN);
8275 else
8276 eth_broadcast_addr(request->bssid);
8277
Johannes Bergfd014282012-06-18 19:17:03 +02008278 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02008279 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07008280 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01008281
Johannes Berg79c97e92009-07-07 03:56:12 +02008282 rdev->scan_req = request;
Tova Mussaic8cb5b82020-09-18 11:33:13 +02008283 err = cfg80211_scan(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008284
Christophe JAILLET504776b2020-07-12 19:35:51 +02008285 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 Berg2a519312009-02-10 21:25:55 +01008294 out_free:
Christophe JAILLET504776b2020-07-12 19:35:51 +02008295 rdev->scan_req = NULL;
8296 kfree(request);
Johannes Berg3b858752009-03-12 09:55:09 +01008297
Johannes Berg2a519312009-02-10 21:25:55 +01008298 return err;
8299}
8300
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05308301static 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 Stern3b06d272015-10-12 09:51:34 +03008319static int
8320nl80211_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 Spriel5a88de52016-11-17 09:02:40 +00008332 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03008333 * case one scan plan will be set with the specified scan
8334 * interval and infinite number of iterations.
8335 */
Avraham Stern3b06d272015-10-12 09:51:34 +03008336 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 Berg8cb08172019-04-26 14:07:28 +02008359 err = nla_parse_nested_deprecated(plan,
8360 NL80211_SCHED_SCAN_PLAN_MAX,
8361 attr, nl80211_plan_policy,
8362 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03008363 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 krishna1e1b11b2019-02-01 18:34:51 +05308404static int
8405nl80211_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 Coelho256da022014-11-10 16:13:46 +02008439static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02008440nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008441 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008442{
8443 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008444 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03008445 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02008446 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008447 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008448 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01008449 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008450
Luciano Coelho256da022014-11-10 16:13:46 +02008451 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008452 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02008453 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008454 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02008455 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008456 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02008457 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008458 }
8459
Luciano Coelho256da022014-11-10 16:13:46 +02008460 if (attrs[NL80211_ATTR_SCAN_SSIDS])
8461 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008462 tmp)
8463 n_ssids++;
8464
Luciano Coelho93b6aa62011-07-13 14:57:28 +03008465 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02008466 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008467
Johannes Bergea73cbc2014-01-24 10:53:53 +01008468 /*
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 Coelho256da022014-11-10 16:13:46 +02008477 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008478 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008479 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01008480 tmp) {
8481 struct nlattr *rssi;
8482
Johannes Berg8cb08172019-04-26 14:07:28 +02008483 err = nla_parse_nested_deprecated(tb,
8484 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8485 attr,
8486 nl80211_match_policy,
8487 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01008488 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02008489 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01008490
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 Bergea73cbc2014-01-24 10:53:53 +01008496 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01008497 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
8498 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01008499 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 Coelhoa1f1c212011-08-31 16:01:48 +03008511
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008512 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02008513 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008514
Luciano Coelho256da022014-11-10 16:13:46 +02008515 if (attrs[NL80211_ATTR_IE])
8516 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008517 else
8518 ie_len = 0;
8519
Luciano Coelho5a865ba2011-07-13 14:57:29 +03008520 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02008521 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03008522
Avraham Stern3b06d272015-10-12 09:51:34 +03008523 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 krishnabf95ecd2017-01-13 01:12:20 +02008550 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 Coelho807f8a82011-05-11 17:09:35 +03008556 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008557 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008558 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03008559 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008560 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03008561 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02008562 if (!request)
8563 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008564
8565 if (n_ssids)
8566 request->ssids = (void *)&request->channels[n_channels];
8567 request->n_ssids = n_ssids;
8568 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01008569 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008570 request->ie = (void *)(request->ssids + n_ssids);
8571 else
8572 request->ie = (void *)(request->channels + n_channels);
8573 }
8574
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008575 if (n_match_sets) {
8576 if (request->ie)
8577 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01008578 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008579 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 Stern3b06d272015-10-12 09:51:34 +03008587 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 Coelho807f8a82011-05-11 17:09:35 +03008599 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008600 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008601 /* user specified, bail out if channel not found */
8602 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008603 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008604 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 Berg57fbcce2016-04-12 15:56:15 +02008623 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008624 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008625
Luciano Coelho807f8a82011-05-11 17:09:35 +03008626 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 Berg13874e42015-01-23 11:25:20 +01008650 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02008651 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008652 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008653 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008654 err = -EINVAL;
8655 goto out_free;
8656 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008657 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008658 memcpy(request->ssids[i].ssid, nla_data(attr),
8659 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03008660 i++;
8661 }
8662 }
8663
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008664 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008665 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008666 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008667 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008668 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01008669 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008670
Johannes Berg8cb08172019-04-26 14:07:28 +02008671 err = nla_parse_nested_deprecated(tb,
8672 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8673 attr,
8674 nl80211_match_policy,
8675 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01008676 if (err)
8677 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02008678 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01008679 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02008680
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 Bergd39f3b42019-04-08 13:40:47 +02008696 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 Coelhoa1f1c212011-08-31 16:01:48 +03008700 }
Johannes Bergcb9abd42020-08-05 15:47:16 +02008701 if (bssid)
Johannes Bergd39f3b42019-04-08 13:40:47 +02008702 memcpy(request->match_sets[i].bssid,
8703 nla_data(bssid), ETH_ALEN);
Johannes Bergd39f3b42019-04-08 13:40:47 +02008704
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 krishna1e1b11b2019-02-01 18:34:51 +05308711
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 Coelhoa1f1c212011-08-31 16:01:48 +03008720 i++;
8721 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01008722
8723 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02008724 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008725 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 Coelhoa1f1c212011-08-31 16:01:48 +03008734 }
8735
Johannes Berg9900e482014-02-04 21:01:25 +01008736 if (ie_len) {
8737 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008738 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008739 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008740 request->ie_len);
8741 }
8742
Roee Zamir2d23d072017-08-06 11:38:22 +03008743 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8744 if (err)
8745 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008746
Luciano Coelho9c748932015-01-16 16:04:09 +02008747 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8748 request->delay =
8749 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8750
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008751 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 Stern3b06d272015-10-12 09:51:34 +03008771 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8772 if (err)
8773 goto out_free;
8774
Sam Leffler15d60302012-10-11 21:03:34 -07008775 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008776
Luciano Coelho256da022014-11-10 16:13:46 +02008777 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008778
8779out_free:
8780 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008781 return ERR_PTR(err);
8782}
8783
8784static 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 Bergad2b26a2014-06-12 21:39:05 +02008789 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008790 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008791 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008792 int err;
8793
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008794 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008795 return -EOPNOTSUPP;
8796
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008797 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 Coelho256da022014-11-10 16:13:46 +02008801
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008802 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008803 info->attrs,
8804 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008805
8806 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008807 if (err)
8808 goto out_err;
8809
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008810 /* leave request id zero for legacy request
8811 * or if driver does not support multi-scheduled scan
8812 */
Denis Kenzior2fd351a2019-10-08 11:43:50 -05008813 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
8814 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008815
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008816 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008817 if (err)
8818 goto out_free;
8819
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008820 sched_scan_req->dev = dev;
8821 sched_scan_req->wiphy = &rdev->wiphy;
8822
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008823 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8824 sched_scan_req->owner_nlportid = info->snd_portid;
8825
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008826 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008827
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008828 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008829 return 0;
8830
8831out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008832 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008833out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008834 return err;
8835}
8836
8837static int nl80211_stop_sched_scan(struct sk_buff *skb,
8838 struct genl_info *info)
8839{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008840 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008841 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008842 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008843
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008844 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008845 return -EOPNOTSUPP;
8846
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008847 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 Coelho807f8a82011-05-11 17:09:35 +03008861}
8862
Simon Wunderlich04f39042013-02-08 18:16:19 +01008863static 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 Lebed13cf6de2018-03-01 12:39:15 +03008869 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008870 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008871 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008872 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008873 int err;
8874
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008875 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008876 if (dfs_region == NL80211_DFS_UNSET)
8877 return -EINVAL;
8878
Simon Wunderlich04f39042013-02-08 18:16:19 +01008879 err = nl80211_parse_chandef(rdev, info, &chandef);
8880 if (err)
8881 return err;
8882
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008883 if (netif_carrier_ok(dev))
8884 return -EBUSY;
8885
Simon Wunderlich04f39042013-02-08 18:16:19 +01008886 if (wdev->cac_started)
8887 return -EBUSY;
8888
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008889 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008890 if (err < 0)
8891 return err;
8892
8893 if (err == 0)
8894 return -EINVAL;
8895
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008896 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008897 return -EINVAL;
8898
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008899 /* 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 Wunderlich04f39042013-02-08 18:16:19 +01008903 if (!rdev->ops->start_radar_detection)
8904 return -EOPNOTSUPP;
8905
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008906 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 Peera1056b1b2015-10-22 22:27:46 +03008910 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008911 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008912 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008913 wdev->cac_started = true;
8914 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008915 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008916 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008917 return err;
8918}
8919
Sriram R30c63112018-12-04 17:46:52 +05308920static 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 Coelhoa680fe42019-04-17 09:34:40 +03008966 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308967
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 Wunderlich16ef1fe2013-07-11 16:09:05 +02008974static 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 Wunderlich16ef1fe2013-07-11 16:09:05 +02008984 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008985 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008986 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008987 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008988 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008989
8990 if (!rdev->ops->channel_switch ||
8991 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8992 return -EOPNOTSUPP;
8993
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008994 switch (dev->ieee80211_ptr->iftype) {
8995 case NL80211_IFTYPE_AP:
8996 case NL80211_IFTYPE_P2P_GO:
8997 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008998 /* 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 Wunderlichee4bc9e2013-08-28 13:41:33 +02009004
9005 /* useless if AP is not running */
9006 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01009007 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02009008 break;
9009 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01009010 if (!wdev->ssid_len)
9011 return -ENOTCONN;
9012 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07009013 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01009014 if (!wdev->mesh_id_len)
9015 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02009016 break;
9017 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009018 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02009019 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009020
9021 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01009022 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009023
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 Otcheretianskid0a361a2013-10-17 10:52:17 +02009029 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009030 return -EINVAL;
9031
Luciano Coelho252e07c2014-10-08 09:48:34 +03009032 /* 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 Wunderlich16ef1fe2013-07-11 16:09:05 +02009040
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02009041 if (!need_new_beacon)
9042 goto skip_beacons;
9043
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07009044 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009045 if (err)
9046 return err;
9047
Johannes Berg8cb08172019-04-26 14:07:28 +02009048 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
9049 info->attrs[NL80211_ATTR_CSA_IES],
9050 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009051 if (err)
9052 return err;
9053
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07009054 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009055 if (err)
9056 return err;
9057
John Crispin00c207e2020-08-11 10:01:03 +02009058 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009059 return -EINVAL;
9060
John Crispin00c207e2020-08-11 10:01:03 +02009061 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009062 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009063 return -EINVAL;
9064
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009065 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 Wunderlich16ef1fe2013-07-11 16:09:05 +02009069 return -EINVAL;
9070
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009071 params.counter_offsets_beacon =
John Crispin00c207e2020-08-11 10:01:03 +02009072 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009073
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 Crispin00c207e2020-08-11 10:01:03 +02009085 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
9086 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009087 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009088 return -EINVAL;
9089
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009090 params.n_counter_offsets_presp = len / sizeof(u16);
9091 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02009092 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009093 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009094 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009095
9096 params.counter_offsets_presp =
John Crispin00c207e2020-08-11 10:01:03 +02009097 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009098
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 Wunderlich16ef1fe2013-07-11 16:09:05 +02009110 }
9111
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02009112skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009113 err = nl80211_parse_chandef(rdev, info, &params.chandef);
9114 if (err)
9115 return err;
9116
Arik Nemtsov923b3522015-07-08 15:41:44 +03009117 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
9118 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009119 return -EINVAL;
9120
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02009121 err = cfg80211_chandef_dfs_required(wdev->wiphy,
9122 &params.chandef,
9123 wdev->iftype);
9124 if (err < 0)
9125 return err;
9126
Benjamin Berg8d9de162017-05-16 11:23:12 +02009127 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02009128 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02009129 if (need_handle_dfs_flag &&
9130 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
9131 return -EINVAL;
9132 }
9133 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009134
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009135 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
9136 params.block_tx = true;
9137
Simon Wunderlichc56589e2013-11-21 18:19:49 +01009138 wdev_lock(wdev);
9139 err = rdev_channel_switch(rdev, dev, &params);
9140 wdev_unlock(wdev);
9141
9142 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009143}
9144
Johannes Berg9720bb32011-06-21 09:45:33 +02009145static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
9146 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01009147 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02009148 struct wireless_dev *wdev,
9149 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01009150{
Johannes Berg48ab9052009-07-10 18:42:31 +02009151 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01009152 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01009153 void *hdr;
9154 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02009155
9156 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009157
Eric W. Biederman15e47302012-09-07 20:12:54 +00009158 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01009159 NL80211_CMD_NEW_SCAN_RESULTS);
9160 if (!hdr)
9161 return -1;
9162
Michal Kubecek0a833c22017-11-15 13:09:32 +01009163 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02009164
Johannes Berg97990a02013-04-19 01:02:55 +02009165 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
9166 goto nla_put_failure;
9167 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009168 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
9169 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009170 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
9171 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02009172 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009173
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009174 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01009175 if (!bss)
9176 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009177 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01009178 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009179 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01009180
9181 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02009182 /* 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 Berg9caf0362012-11-29 01:25:20 +01009190 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01009191 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009192 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
9193 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01009194 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01009195 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
9196 ies->len, ies->data))
9197 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01009198 }
Johannes Berg0e227082014-08-12 20:34:30 +02009199
9200 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01009201 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02009202 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009203 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
9204 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01009205 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 Berg9caf0362012-11-29 01:25:20 +01009209 }
9210 rcu_read_unlock();
9211
David S. Miller9360ffd2012-03-29 04:41:26 -04009212 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 Pedersen942ba882020-04-30 10:25:51 -07009217 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
9218 res->channel->freq_offset) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02009219 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009220 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
9221 jiffies_to_msecs(jiffies - intbss->ts)))
9222 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009223
Avraham Stern1d762502016-07-05 17:10:13 +03009224 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 Shmidt6e19bc42015-10-07 11:32:53 +02009231 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009232 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
9233 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02009234 goto nla_put_failure;
9235
Sunil Dutt983dafa2017-12-13 19:51:36 +02009236 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 Berg77965c972009-02-18 18:45:06 +01009241 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01009242 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04009243 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
9244 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009245 break;
9246 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04009247 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
9248 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009249 break;
9250 default:
9251 break;
9252 }
9253
Johannes Berg48ab9052009-07-10 18:42:31 +02009254 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02009255 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02009256 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04009257 if (intbss == wdev->current_bss &&
9258 nla_put_u32(msg, NL80211_BSS_STATUS,
9259 NL80211_BSS_STATUS_ASSOCIATED))
9260 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02009261 break;
9262 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04009263 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 Berg48ab9052009-07-10 18:42:31 +02009267 break;
9268 default:
9269 break;
9270 }
9271
Johannes Berg2a519312009-02-10 21:25:55 +01009272 nla_nest_end(msg, bss);
9273
Johannes Berg053c0952015-01-16 22:09:00 +01009274 genlmsg_end(msg, hdr);
9275 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01009276
Johannes Berg8cef2c92013-02-05 16:54:31 +01009277 fail_unlock_rcu:
9278 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01009279 nla_put_failure:
9280 genlmsg_cancel(msg, hdr);
9281 return -EMSGSIZE;
9282}
9283
Johannes Berg97990a02013-04-19 01:02:55 +02009284static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01009285{
Johannes Berg48ab9052009-07-10 18:42:31 +02009286 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01009287 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02009288 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02009289 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01009290 int err;
9291
Johannes Bergea90e0d2017-03-15 14:26:04 +01009292 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02009293 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01009294 if (err) {
9295 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02009296 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01009297 }
Johannes Berg2a519312009-02-10 21:25:55 +01009298
Johannes Berg48ab9052009-07-10 18:42:31 +02009299 wdev_lock(wdev);
9300 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05009301
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 Berg48ab9052009-07-10 18:42:31 +02009310
Johannes Berg9720bb32011-06-21 09:45:33 +02009311 cb->seq = rdev->bss_generation;
9312
Johannes Berg48ab9052009-07-10 18:42:31 +02009313 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01009314 if (++idx <= start)
9315 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02009316 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01009317 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02009318 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009319 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02009320 break;
Johannes Berg2a519312009-02-10 21:25:55 +01009321 }
9322 }
9323
Johannes Berg48ab9052009-07-10 18:42:31 +02009324 spin_unlock_bh(&rdev->bss_lock);
9325 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009326
Johannes Berg97990a02013-04-19 01:02:55 +02009327 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01009328 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01009329
Johannes Berg67748892010-10-04 21:14:06 +02009330 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01009331}
9332
Eric W. Biederman15e47302012-09-07 20:12:54 +00009333static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01009334 int flags, struct net_device *dev,
9335 bool allow_radio_stats,
9336 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01009337{
9338 void *hdr;
9339 struct nlattr *infoattr;
9340
Johannes Berg11f78ac2014-11-14 16:43:50 +01009341 /* skip radio stats if userspace didn't request them */
9342 if (!survey->channel && !allow_radio_stats)
9343 return 0;
9344
Eric W. Biederman15e47302012-09-07 20:12:54 +00009345 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01009346 NL80211_CMD_NEW_SURVEY_RESULTS);
9347 if (!hdr)
9348 return -ENOMEM;
9349
David S. Miller9360ffd2012-03-29 04:41:26 -04009350 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
9351 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01009352
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009353 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01009354 if (!infoattr)
9355 goto nla_put_failure;
9356
Johannes Berg11f78ac2014-11-14 16:43:50 +01009357 if (survey->channel &&
9358 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04009359 survey->channel->center_freq))
9360 goto nla_put_failure;
9361
Thomas Pedersen58ef7c12020-09-21 19:28:16 -07009362 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. Miller9360ffd2012-03-29 04:41:26 -04009367 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 Berg4ed20be2014-11-14 16:35:34 +01009373 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009374 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
9375 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009376 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009377 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009378 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
9379 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009380 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009381 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009382 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
9383 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009384 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009385 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009386 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
9387 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009388 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009389 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009390 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
9391 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009392 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01009393 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009394 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
9395 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01009396 goto nla_put_failure;
Felix Fietkauc8cd6e72019-08-28 12:20:42 +02009397 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 Schurig61fa7132009-11-11 12:25:40 +01009401
9402 nla_nest_end(msg, infoattr);
9403
Johannes Berg053c0952015-01-16 22:09:00 +01009404 genlmsg_end(msg, hdr);
9405 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01009406
9407 nla_put_failure:
9408 genlmsg_cancel(msg, hdr);
9409 return -EMSGSIZE;
9410}
9411
Johannes Berg11f78ac2014-11-14 16:43:50 +01009412static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01009413{
Johannes Berg50508d92019-07-29 16:31:09 +02009414 struct nlattr **attrbuf;
Holger Schurig61fa7132009-11-11 12:25:40 +01009415 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009416 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02009417 struct wireless_dev *wdev;
9418 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01009419 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01009420 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01009421
Johannes Berg50508d92019-07-29 16:31:09 +02009422 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
9423 if (!attrbuf)
9424 return -ENOMEM;
9425
Johannes Bergea90e0d2017-03-15 14:26:04 +01009426 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02009427 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02009428 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01009429 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01009430
Johannes Berg11f78ac2014-11-14 16:43:50 +01009431 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02009432 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01009433
Johannes Berg97990a02013-04-19 01:02:55 +02009434 if (!wdev->netdev) {
9435 res = -EINVAL;
9436 goto out_err;
9437 }
9438
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009439 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01009440 res = -EOPNOTSUPP;
9441 goto out_err;
9442 }
9443
9444 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009445 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01009446 if (res == -ENOENT)
9447 break;
9448 if (res)
9449 goto out_err;
9450
Johannes Berg11f78ac2014-11-14 16:43:50 +01009451 /* don't send disabled channels, but do send non-channel data */
9452 if (survey.channel &&
9453 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07009454 survey_idx++;
9455 continue;
9456 }
9457
Holger Schurig61fa7132009-11-11 12:25:40 +01009458 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009459 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01009460 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01009461 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01009462 goto out;
9463 survey_idx++;
9464 }
9465
9466 out:
Johannes Berg97990a02013-04-19 01:02:55 +02009467 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01009468 res = skb->len;
9469 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02009470 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +01009471 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01009472 return res;
9473}
9474
Samuel Ortizb23aa672009-07-01 21:26:54 +02009475static bool nl80211_valid_wpa_versions(u32 wpa_versions)
9476{
9477 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
Chung-Hsien Hsucc3e14c2019-05-09 09:49:05 +00009478 NL80211_WPA_VERSION_2 |
9479 NL80211_WPA_VERSION_3));
Samuel Ortizb23aa672009-07-01 21:26:54 +02009480}
9481
Jouni Malinen636a5d32009-03-19 13:39:22 +02009482static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
9483{
Johannes Berg4c476992010-10-04 21:36:35 +02009484 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9485 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009486 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009487 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
9488 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02009489 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02009490 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009491 bool local_state_change;
Thomas Pedersen942ba882020-04-30 10:25:51 -07009492 u32 freq;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009493
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009494 if (!info->attrs[NL80211_ATTR_MAC])
9495 return -EINVAL;
9496
Jouni Malinen17780922009-03-27 20:52:47 +02009497 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
9498 return -EINVAL;
9499
Johannes Berg19957bb2009-07-02 17:20:43 +02009500 if (!info->attrs[NL80211_ATTR_SSID])
9501 return -EINVAL;
9502
9503 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9504 return -EINVAL;
9505
Johannes Bergfffd0932009-07-08 14:22:54 +02009506 err = nl80211_parse_key(info, &key);
9507 if (err)
9508 return err;
9509
9510 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02009511 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
9512 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02009513 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 Bergb6b55552016-09-13 16:25:58 +02009520 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02009521 return -EINVAL;
9522 } else {
9523 key.p.key_len = 0;
9524 key.p.key = NULL;
9525 }
9526
Johannes Bergafea0b72010-08-10 09:46:42 +02009527 if (key.idx >= 0) {
9528 int i;
9529 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009530
Johannes Bergafea0b72010-08-10 09:46:42 +02009531 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 Berg4c476992010-10-04 21:36:35 +02009537 if (!ok)
9538 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02009539 }
9540
Johannes Berg4c476992010-10-04 21:36:35 +02009541 if (!rdev->ops->auth)
9542 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009543
Johannes Berg074ac8d2010-09-16 14:58:22 +02009544 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009545 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9546 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009547
Johannes Berg19957bb2009-07-02 17:20:43 +02009548 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Thomas Pedersen942ba882020-04-30 10:25:51 -07009549 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 Malinen664834d2014-01-15 00:01:44 +02009555 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009556 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009557
Johannes Berg19957bb2009-07-02 17:20:43 +02009558 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 Malinene39e5b52012-09-30 19:29:39 +03009567 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02009568 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02009569
Jouni Malinen63181062016-10-27 00:42:02 +03009570 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 Malinen11b6b5a2016-10-27 00:41:58 +03009574 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03009575 return -EINVAL;
9576
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009577 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03009578 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 Malinene39e5b52012-09-30 19:29:39 +03009582 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009583 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
9584 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009585 }
9586
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009587 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9588
Johannes Berg95de8172012-01-20 13:55:25 +01009589 /*
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 Berg91bf9b22013-05-15 17:44:01 +02009596 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 Malinen11b6b5a2016-10-27 00:41:58 +03009600 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009601 wdev_unlock(dev->ieee80211_ptr);
9602 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009603}
9604
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009605static 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 Bergc0692b82010-08-27 14:26:53 +03009621static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9622 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009623 struct cfg80211_crypto_settings *settings,
9624 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009625{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02009626 memset(settings, 0, sizeof(*settings));
9627
Samuel Ortizb23aa672009-07-01 21:26:54 +02009628 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9629
Johannes Bergc0692b82010-08-27 14:26:53 +03009630 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9631 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009632
Johannes Bergc0692b82010-08-27 14:26:53 +03009633 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 Kenzior64bf3d42018-03-26 12:52:43 -05009644 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 Theil7f3f96c2020-03-12 10:10:54 +01009651
9652 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
9653 settings->control_port_no_preauth = true;
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009654 }
9655
Samuel Ortizb23aa672009-07-01 21:26:54 +02009656 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 Berg3dc27d22009-07-02 21:36:37 +02009667 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009668 return -EINVAL;
9669
9670 memcpy(settings->ciphers_pairwise, data, len);
9671
9672 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009673 if (!cfg80211_supported_cipher_suite(
9674 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009675 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 Malinen38ba3c52011-09-21 18:14:56 +03009682 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9683 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009684 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 Malinen6d302402011-09-21 18:11:33 +03009696 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009697
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 Malinen1b9ca022011-09-21 16:13:07 +03009705 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9706 return -EINVAL;
9707
Samuel Ortizb23aa672009-07-01 21:26:54 +02009708 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009709 }
9710
Eliad Peller91b5ab62017-06-09 13:08:42 +01009711 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 Hsuf9662272020-06-23 08:49:35 -05009715 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
9716 !wiphy_ext_feature_isset(&rdev->wiphy,
9717 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
Eliad Peller91b5ab62017-06-09 13:08:42 +01009718 return -EINVAL;
9719 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9720 }
9721
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009722 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9723 if (!wiphy_ext_feature_isset(&rdev->wiphy,
Chung-Hsien Hsu2831a632020-08-17 02:33:15 -05009724 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
9725 !wiphy_ext_feature_isset(&rdev->wiphy,
9726 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009727 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 Ortizb23aa672009-07-01 21:26:54 +02009734 return 0;
9735}
9736
Jouni Malinen636a5d32009-03-19 13:39:22 +02009737static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9738{
Johannes Berg4c476992010-10-04 21:36:35 +02009739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9740 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02009741 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01009742 struct cfg80211_assoc_request req = {};
9743 const u8 *bssid, *ssid;
9744 int err, ssid_len = 0;
Thomas Pedersen942ba882020-04-30 10:25:51 -07009745 u32 freq;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009746
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009747 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9748 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9749 return -EPERM;
9750
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009751 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02009752 !info->attrs[NL80211_ATTR_SSID] ||
9753 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009754 return -EINVAL;
9755
Johannes Berg4c476992010-10-04 21:36:35 +02009756 if (!rdev->ops->assoc)
9757 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009758
Johannes Berg074ac8d2010-09-16 14:58:22 +02009759 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009760 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9761 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009762
Johannes Berg19957bb2009-07-02 17:20:43 +02009763 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009764
Thomas Pedersen942ba882020-04-30 10:25:51 -07009765 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 Malinen664834d2014-01-15 00:01:44 +02009770 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009771 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009772
Johannes Berg19957bb2009-07-02 17:20:43 +02009773 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9774 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009775
9776 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009777 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9778 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009779 }
9780
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009781 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009782 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009783 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009784 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009785 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009786 else if (mfp != NL80211_MFP_NO)
9787 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009788 }
9789
Johannes Berg3e5d7642009-07-07 14:37:26 +02009790 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009791 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009792
Ben Greear7e7c8922011-11-18 11:31:59 -08009793 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009794 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009795
9796 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009797 memcpy(&req.ht_capa_mask,
9798 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9799 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009800
9801 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009802 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009803 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009804 memcpy(&req.ht_capa,
9805 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9806 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009807 }
9808
Johannes Bergee2aca32013-02-21 17:36:01 +01009809 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009810 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009811
9812 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009813 memcpy(&req.vht_capa_mask,
9814 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9815 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009816
9817 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009818 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009819 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009820 memcpy(&req.vht_capa,
9821 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9822 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009823 }
9824
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009825 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009826 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 Kraussbab5ab72014-09-03 15:25:01 +03009831 return -EINVAL;
9832 req.flags |= ASSOC_REQ_USE_RRM;
9833 }
9834
Jouni Malinen348bd452016-10-27 00:42:03 +03009835 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 Pedersend2b75882020-09-21 19:28:04 -07009844 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 Bergf62fab72013-02-21 20:09:09 +01009860 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009861 if (!err) {
9862 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009863
Johannes Bergf62fab72013-02-21 20:09:09 +01009864 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9865 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009866
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 Berg91bf9b22013-05-15 17:44:01 +02009874 wdev_unlock(dev->ieee80211_ptr);
9875 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009876
Jouni Malinen636a5d32009-03-19 13:39:22 +02009877 return err;
9878}
9879
9880static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9881{
Johannes Berg4c476992010-10-04 21:36:35 +02009882 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9883 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009884 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009885 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009886 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009887 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009888
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009889 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9890 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9891 return -EPERM;
9892
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009893 if (!info->attrs[NL80211_ATTR_MAC])
9894 return -EINVAL;
9895
9896 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9897 return -EINVAL;
9898
Johannes Berg4c476992010-10-04 21:36:35 +02009899 if (!rdev->ops->deauth)
9900 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009901
Johannes Berg074ac8d2010-09-16 14:58:22 +02009902 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009903 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9904 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009905
Johannes Berg19957bb2009-07-02 17:20:43 +02009906 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009907
Johannes Berg19957bb2009-07-02 17:20:43 +02009908 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9909 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009910 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009911 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009912 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009913
9914 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009915 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9916 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009917 }
9918
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009919 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9920
Johannes Berg91bf9b22013-05-15 17:44:01 +02009921 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 Malinen636a5d32009-03-19 13:39:22 +02009926}
9927
9928static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9929{
Johannes Berg4c476992010-10-04 21:36:35 +02009930 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9931 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009932 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009933 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009934 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009935 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009936
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009937 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9938 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9939 return -EPERM;
9940
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009941 if (!info->attrs[NL80211_ATTR_MAC])
9942 return -EINVAL;
9943
9944 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9945 return -EINVAL;
9946
Johannes Berg4c476992010-10-04 21:36:35 +02009947 if (!rdev->ops->disassoc)
9948 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009949
Johannes Berg074ac8d2010-09-16 14:58:22 +02009950 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009951 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9952 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009953
Johannes Berg19957bb2009-07-02 17:20:43 +02009954 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009955
Johannes Berg19957bb2009-07-02 17:20:43 +02009956 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9957 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009958 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009959 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009960 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009961
9962 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009963 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9964 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009965 }
9966
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009967 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9968
Johannes Berg91bf9b22013-05-15 17:44:01 +02009969 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 Malinen636a5d32009-03-19 13:39:22 +02009974}
9975
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009976static bool
9977nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009978 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009979 int rateval)
9980{
9981 struct wiphy *wiphy = &rdev->wiphy;
9982 bool found = false;
9983 int band, i;
9984
Johannes Berg57fbcce2016-04-12 15:56:15 +02009985 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009986 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 Berg04a773a2009-04-19 21:24:32 +020010004static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
10005{
Johannes Berg4c476992010-10-04 21:36:35 +020010006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10007 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +020010008 struct cfg80211_ibss_params ibss;
10009 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +020010010 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +020010011 int err;
10012
Johannes Berg8e30bc52009-04-22 17:45:38 +020010013 memset(&ibss, 0, sizeof(ibss));
10014
Johannes Berg683b6d32012-11-08 21:25:48 +010010015 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +020010016 !nla_len(info->attrs[NL80211_ATTR_SSID]))
10017 return -EINVAL;
10018
Johannes Berg8e30bc52009-04-22 17:45:38 +020010019 ibss.beacon_interval = 100;
10020
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010021 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +020010022 ibss.beacon_interval =
10023 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010024
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053010025 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
10026 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053010027 if (err)
10028 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +020010029
Johannes Berg4c476992010-10-04 21:36:35 +020010030 if (!rdev->ops->join_ibss)
10031 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +020010032
Johannes Berg4c476992010-10-04 21:36:35 +020010033 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
10034 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +020010035
Johannes Berg79c97e92009-07-07 03:56:12 +020010036 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +020010037
Johannes Berg39193492011-09-16 13:45:25 +020010038 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +020010039 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +020010040
10041 if (!is_valid_ether_addr(ibss.bssid))
10042 return -EINVAL;
10043 }
Johannes Berg04a773a2009-04-19 21:24:32 +020010044 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 Berg683b6d32012-11-08 21:25:48 +010010052 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
10053 if (err)
10054 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +010010055
Ilan Peer174e0cd2014-02-23 09:13:01 +020010056 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
10057 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +010010058 return -EINVAL;
10059
Simon Wunderlich2f301ab2013-05-16 13:00:28 +020010060 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +020010061 case NL80211_CHAN_WIDTH_5:
10062 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +020010063 case NL80211_CHAN_WIDTH_20_NOHT:
10064 break;
10065 case NL80211_CHAN_WIDTH_20:
10066 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +010010067 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 Wunderlich2f301ab2013-05-16 13:00:28 +020010079 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +010010080 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +020010081 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +010010082
Johannes Berg04a773a2009-04-19 21:24:32 +020010083 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +020010084 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +020010085
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +030010086 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 Berg683b6d32012-11-08 21:25:48 +010010092 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +030010093
Johannes Berg34850ab2011-07-18 18:08:35 +020010094 err = ieee80211_get_ratemask(sband, rates, n_rates,
10095 &ibss.basic_rates);
10096 if (err)
10097 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +030010098 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +010010099
Simon Wunderlich803768f2013-06-28 10:39:58 +020010100 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 Fietkaudd5b4cc2010-11-22 20:58:24 +010010113 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 Paasikivifbd2c8d2010-06-14 12:55:31 +030010117
Johannes Berg4c476992010-10-04 21:36:35 +020010118 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +053010119 bool no_ht = false;
10120
Johannes Berg768075e2017-11-13 15:35:06 +010010121 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +020010122 if (IS_ERR(connkeys))
10123 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +053010124
Johannes Berg3d9d1d62012-11-08 23:14:50 +010010125 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
10126 no_ht) {
Waiman Long453431a2020-08-06 23:18:13 -070010127 kfree_sensitive(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +053010128 return -EINVAL;
10129 }
Johannes Berg4c476992010-10-04 21:36:35 +020010130 }
Johannes Berg04a773a2009-04-19 21:24:32 +020010131
Antonio Quartulli267335d2012-01-31 20:25:47 +010010132 ibss.control_port =
10133 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
10134
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -050010135 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10136 int r = validate_pae_over_nl80211(rdev, info);
10137
Johannes Bergd350a0f2018-12-15 11:03:22 +020010138 if (r < 0) {
Waiman Long453431a2020-08-06 23:18:13 -070010139 kfree_sensitive(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -050010140 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +020010141 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -050010142
10143 ibss.control_port_over_nl80211 = true;
10144 }
10145
Simon Wunderlich5336fa82013-10-07 18:41:05 +020010146 ibss.userspace_handles_dfs =
10147 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10148
Denis Kenziorf8d16d32018-03-26 12:52:45 -050010149 wdev_lock(dev->ieee80211_ptr);
10150 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +020010151 if (err)
Waiman Long453431a2020-08-06 23:18:13 -070010152 kfree_sensitive(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -050010153 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 Berg04a773a2009-04-19 21:24:32 +020010157 return err;
10158}
10159
10160static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
10161{
Johannes Berg4c476992010-10-04 21:36:35 +020010162 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10163 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +020010164
Johannes Berg4c476992010-10-04 21:36:35 +020010165 if (!rdev->ops->leave_ibss)
10166 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +020010167
Johannes Berg4c476992010-10-04 21:36:35 +020010168 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
10169 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +020010170
Johannes Berg4c476992010-10-04 21:36:35 +020010171 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +020010172}
10173
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010174static 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 Berg57fbcce2016-04-12 15:56:15 +020010178 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010179 u32 nla_rate;
10180 int err;
10181
10182 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +020010183 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
10184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010185 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 Peera1056b1b2015-10-22 22:27:46 +030010199 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010200
10201 return err;
10202}
10203
Johannes Bergad7e7182013-11-13 13:37:47 +010010204static struct sk_buff *
10205__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010206 struct wireless_dev *wdev, int approxlen,
10207 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +010010208 enum nl80211_attrs attr,
10209 const struct nl80211_vendor_cmd_info *info,
10210 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +010010211{
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 Berg567ffc32013-12-18 14:43:31 +010010228
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 Kholaif6c09e792015-02-26 15:26:53 +020010238 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010239 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10240 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010241 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 Kubecekae0be8d2019-04-26 11:13:06 +020010248 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010249 if (!data)
10250 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +010010251
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 Quartullif4e583c2012-11-02 13:27:48 +010010262
Johannes Berge03ad6e2014-01-01 17:22:30 +010010263struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010264 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +010010265 enum nl80211_commands cmd,
10266 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010267 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +010010268 int vendor_event_idx,
10269 int approxlen, gfp_t gfp)
10270{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010271 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +010010272 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 Berg55c1fdf2019-02-06 13:17:19 +020010291 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +010010292 cmd, attr, info, gfp);
10293}
10294EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
10295
10296void __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 Berg55c1fdf2019-02-06 13:17:19 +020010300 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +010010301 struct nlattr *data = ((void **)skb->cb)[2];
10302 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
10303
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010304 /* clear CB data for netlink core to own from now on */
10305 memset(skb->cb, 0, sizeof(skb->cb));
10306
Johannes Berge03ad6e2014-01-01 17:22:30 +010010307 nla_nest_end(skb, data);
10308 genlmsg_end(skb, hdr);
10309
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010310 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 Berge03ad6e2014-01-01 17:22:30 +010010316
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010317 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
10318 skb, 0, mcgrp, gfp);
10319 }
Johannes Berge03ad6e2014-01-01 17:22:30 +010010320}
10321EXPORT_SYMBOL(__cfg80211_send_event_skb);
10322
Johannes Bergaff89a92009-07-01 21:26:51 +020010323#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +020010324static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
10325{
Johannes Berg4c476992010-10-04 21:36:35 +020010326 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +030010327 struct wireless_dev *wdev =
10328 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +020010329 int err;
10330
David Spinadelfc73f112013-07-31 18:04:15 +030010331 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 Bergaff89a92009-07-01 21:26:51 +020010343 if (!info->attrs[NL80211_ATTR_TESTDATA])
10344 return -EINVAL;
10345
Johannes Bergad7e7182013-11-13 13:37:47 +010010346 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +030010347 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +020010348 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
10349 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +010010350 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +020010351
Johannes Bergaff89a92009-07-01 21:26:51 +020010352 return err;
10353}
10354
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010355static int nl80211_testmode_dump(struct sk_buff *skb,
10356 struct netlink_callback *cb)
10357{
Johannes Berg00918d32011-12-13 17:22:05 +010010358 struct cfg80211_registered_device *rdev;
Johannes Berg50508d92019-07-29 16:31:09 +020010359 struct nlattr **attrbuf = NULL;
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010360 int err;
10361 long phy_idx;
10362 void *data = NULL;
10363 int data_len = 0;
10364
Johannes Berg5fe231e2013-05-08 21:45:15 +020010365 rtnl_lock();
10366
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010367 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 Coelhoa4956dc2017-02-07 22:13:56 +020010373
10374 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
10375 if (!rdev) {
10376 err = -ENOENT;
10377 goto out_err;
10378 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010379 } else {
Johannes Berg50508d92019-07-29 16:31:09 +020010380 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
10381 GFP_KERNEL);
10382 if (!attrbuf) {
10383 err = -ENOMEM;
10384 goto out_err;
10385 }
Johannes Bergc90c39d2016-10-24 14:40:01 +020010386
Johannes Berg8cb08172019-04-26 14:07:28 +020010387 err = nlmsg_parse_deprecated(cb->nlh,
10388 GENL_HDRLEN + nl80211_fam.hdrsize,
10389 attrbuf, nl80211_fam.maxattr,
10390 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010391 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +020010392 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +010010393
Johannes Bergc90c39d2016-10-24 14:40:01 +020010394 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +020010395 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010396 err = PTR_ERR(rdev);
10397 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +010010398 }
Johannes Berg2bd7e352012-06-15 14:23:16 +020010399 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +020010400
Johannes Bergc90c39d2016-10-24 14:40:01 +020010401 if (attrbuf[NL80211_ATTR_TESTDATA])
10402 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010403 }
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 Berg00918d32011-12-13 17:22:05 +010010410 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010411 err = -EOPNOTSUPP;
10412 goto out_err;
10413 }
10414
10415 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000010416 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010417 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10418 NL80211_CMD_TESTMODE);
10419 struct nlattr *tmdata;
10420
Dan Carpentercb35fba2013-08-14 14:50:01 +030010421 if (!hdr)
10422 break;
10423
David S. Miller9360ffd2012-03-29 04:41:26 -040010424 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010425 genlmsg_cancel(skb, hdr);
10426 break;
10427 }
10428
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010429 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010430 if (!tmdata) {
10431 genlmsg_cancel(skb, hdr);
10432 break;
10433 }
Hila Gonene35e4d22012-06-27 17:19:42 +030010434 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010435 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 Berg50508d92019-07-29 16:31:09 +020010452 kfree(attrbuf);
Johannes Berg5fe231e2013-05-08 21:45:15 +020010453 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010454 return err;
10455}
Johannes Bergaff89a92009-07-01 21:26:51 +020010456#endif
10457
Samuel Ortizb23aa672009-07-01 21:26:54 +020010458static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
10459{
Johannes Berg4c476992010-10-04 21:36:35 +020010460 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10461 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010462 struct cfg80211_connect_params connect;
10463 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +020010464 struct cfg80211_cached_keys *connkeys = NULL;
Thomas Pedersen942ba882020-04-30 10:25:51 -070010465 u32 freq = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010466 int err;
10467
10468 memset(&connect, 0, sizeof(connect));
10469
Samuel Ortizb23aa672009-07-01 21:26:54 +020010470 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 Malinene39e5b52012-09-30 19:29:39 +030010477 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
10478 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +020010479 return -EINVAL;
10480 } else
10481 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
10482
10483 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
10484
Avraham Stern3a00df52017-06-09 13:08:43 +010010485 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 Bergc0692b82010-08-27 14:26:53 +030010491 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +020010492 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010493 if (err)
10494 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010495
Johannes Berg074ac8d2010-09-16 14:58:22 +020010496 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010497 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10498 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010499
Johannes Berg79c97e92009-07-07 03:56:12 +020010500 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010501
Bala Shanmugam4486ea92012-03-07 17:27:12 +053010502 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 Ortizb23aa672009-07-01 21:26:54 +020010509 if (info->attrs[NL80211_ATTR_MAC])
10510 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +020010511 else if (info->attrs[NL80211_ATTR_MAC_HINT])
10512 connect.bssid_hint =
10513 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010514 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 Malinencee00a92013-01-15 17:15:57 +020010522 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10523 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +030010524 if (connect.mfp == NL80211_MFP_OPTIONAL &&
10525 !wiphy_ext_feature_isset(&rdev->wiphy,
10526 NL80211_EXT_FEATURE_MFP_OPTIONAL))
10527 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +020010528 } else {
10529 connect.mfp = NL80211_MFP_NO;
10530 }
10531
Jouni Malinenba6fbac2016-03-29 13:53:27 +030010532 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10533 connect.prev_bssid =
10534 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10535
Thomas Pedersen942ba882020-04-30 10:25:51 -070010536 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 Malinen664834d2014-01-15 00:01:44 +020010545 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +020010546 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +020010547 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Thomas Pedersen942ba882020-04-30 10:25:51 -070010548 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 Malinen664834d2014-01-15 00:01:44 +020010551 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +020010552 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010553 }
10554
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +030010555 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 Bergfffd0932009-07-08 14:22:54 +020010564 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +010010565 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +020010566 if (IS_ERR(connkeys))
10567 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +020010568 }
10569
Ben Greear7e7c8922011-11-18 11:31:59 -080010570 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 Yongjunb4e4f472012-09-02 21:41:04 +080010579 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Waiman Long453431a2020-08-06 23:18:13 -070010580 kfree_sensitive(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -080010581 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +080010582 }
Ben Greear7e7c8922011-11-18 11:31:59 -080010583 memcpy(&connect.ht_capa,
10584 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10585 sizeof(connect.ht_capa));
10586 }
10587
Johannes Bergee2aca32013-02-21 17:36:01 +010010588 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 Long453431a2020-08-06 23:18:13 -070010598 kfree_sensitive(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +010010599 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 Kraussbab5ab72014-09-03 15:25:01 +030010606 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +020010607 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 Long453431a2020-08-06 23:18:13 -070010612 kfree_sensitive(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010613 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +010010614 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010615 connect.flags |= ASSOC_REQ_USE_RRM;
10616 }
10617
Lior David34d50512016-01-28 10:58:25 +020010618 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +020010619 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Waiman Long453431a2020-08-06 23:18:13 -070010620 kfree_sensitive(connkeys);
Lior David34d50512016-01-28 10:58:25 +020010621 return -EOPNOTSUPP;
10622 }
10623
Arend van Spriel38de03d2016-03-02 20:37:18 +010010624 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10625 /* bss selection makes no sense if bssid is set */
10626 if (connect.bssid) {
Waiman Long453431a2020-08-06 23:18:13 -070010627 kfree_sensitive(connkeys);
Arend van Spriel38de03d2016-03-02 20:37:18 +010010628 return -EINVAL;
10629 }
10630
10631 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10632 wiphy, &connect.bss_select);
10633 if (err) {
Waiman Long453431a2020-08-06 23:18:13 -070010634 kfree_sensitive(connkeys);
Arend van Spriel38de03d2016-03-02 20:37:18 +010010635 return err;
10636 }
10637 }
10638
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010639 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 Long453431a2020-08-06 23:18:13 -070010664 kfree_sensitive(connkeys);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010665 return -EINVAL;
10666 }
10667
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010668 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10669 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Waiman Long453431a2020-08-06 23:18:13 -070010670 kfree_sensitive(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010671 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 Berg83739b02013-05-15 17:44:01 +020010678 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010679
Jouni Malinen4ce2bd92016-03-29 13:53:28 +030010680 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10681 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +020010682 if (err)
Waiman Long453431a2020-08-06 23:18:13 -070010683 kfree_sensitive(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010684
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 Lin3b1648f2020-08-01 17:15:49 +080010691 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010692 }
10693
10694 wdev_unlock(dev->ieee80211_ptr);
10695
Samuel Ortizb23aa672009-07-01 21:26:54 +020010696 return err;
10697}
10698
vamsi krishna088e8df2016-10-27 16:51:11 +030010699static 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 Kanchanapally7f9a3e12018-05-22 10:19:08 +020010706 bool fils_sk_offload;
10707 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +030010708 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 krishna088e8df2016-10-27 16:51:11 +030010715 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 Kanchanapally7f9a3e12018-05-22 10:19:08 +020010720 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 krishna088e8df2016-10-27 16:51:11 +030010770 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 Ortizb23aa672009-07-01 21:26:54 +020010780static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10781{
Johannes Berg4c476992010-10-04 21:36:35 +020010782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10783 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010784 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +020010785 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010786
Andrew Zaborowskibad29292018-05-22 02:46:02 +020010787 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10788 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10789 return -EPERM;
10790
Samuel Ortizb23aa672009-07-01 21:26:54 +020010791 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 Berg074ac8d2010-09-16 14:58:22 +020010799 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010800 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10801 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010802
Johannes Berg83739b02013-05-15 17:44:01 +020010803 wdev_lock(dev->ieee80211_ptr);
10804 ret = cfg80211_disconnect(rdev, dev, reason, true);
10805 wdev_unlock(dev->ieee80211_ptr);
10806 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010807}
10808
Johannes Berg463d0182009-07-14 00:33:35 +020010809static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10810{
Johannes Berg4c476992010-10-04 21:36:35 +020010811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010812 struct net *net;
10813 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010814
Vadim Kochan4b681c82015-01-12 16:34:05 +020010815 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 Berg463d0182009-07-14 00:33:35 +020010824 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010825 }
Johannes Berg463d0182009-07-14 00:33:35 +020010826
Johannes Berg4c476992010-10-04 21:36:35 +020010827 if (IS_ERR(net))
10828 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010829
10830 err = 0;
10831
10832 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010833 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10834 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010835
Johannes Berg463d0182009-07-14 00:33:35 +020010836 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010837 return err;
10838}
10839
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010840static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10841{
Johannes Berg4c476992010-10-04 21:36:35 +020010842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010843 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10844 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010845 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010846 struct cfg80211_pmksa pmksa;
10847
10848 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10849
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010850 if (!info->attrs[NL80211_ATTR_PMKID])
10851 return -EINVAL;
10852
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010853 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010854
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 Ortiz67fbb162009-11-24 23:59:15 +010010872
Veerendranath Jakkam7fc82af2020-03-13 01:59:03 +020010873 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 Berg074ac8d2010-09-16 14:58:22 +020010882 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010883 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 Berg4c476992010-10-04 21:36:35 +020010887 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010888
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 Berg4c476992010-10-04 21:36:35 +020010901 if (!rdev_ops)
10902 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010903
Johannes Berg4c476992010-10-04 21:36:35 +020010904 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010905}
10906
10907static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10908{
Johannes Berg4c476992010-10-04 21:36:35 +020010909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10910 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010911
Johannes Berg074ac8d2010-09-16 14:58:22 +020010912 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010913 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10914 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010915
Johannes Berg4c476992010-10-04 21:36:35 +020010916 if (!rdev->ops->flush_pmksa)
10917 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010918
Hila Gonene35e4d22012-06-27 17:19:42 +030010919 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010920}
10921
Arik Nemtsov109086c2011-09-28 14:12:50 +030010922static 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 Undekaridf942e72014-02-20 16:22:09 +053010927 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010928 u16 status_code;
10929 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010930 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010931
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 Nemtsov31fa97c2014-06-11 17:18:21 +030010947 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010948 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10949 peer_capability =
10950 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010951
Hila Gonene35e4d22012-06-27 17:19:42 +030010952 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010953 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010954 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010955 nla_data(info->attrs[NL80211_ATTR_IE]),
10956 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010957}
10958
10959static 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 Gonene35e4d22012-06-27 17:19:42 +030010977 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010978}
10979
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010980static int nl80211_remain_on_channel(struct sk_buff *skb,
10981 struct genl_info *info)
10982{
Johannes Berg4c476992010-10-04 21:36:35 +020010983 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010984 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010985 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010986 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010987 struct sk_buff *msg;
10988 void *hdr;
10989 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010990 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010991 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 Berg7c4ef712011-11-18 15:33:48 +010010999 if (!rdev->ops->remain_on_channel ||
11000 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020011001 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011002
Johannes Bergebf348f2012-06-01 12:50:54 +020011003 /*
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 Berg683b6d32012-11-08 21:25:48 +010011011 err = nl80211_parse_chandef(rdev, info, &chandef);
11012 if (err)
11013 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011014
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053011015 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 Malinen9588bbd2009-12-23 13:15:41 +010011027 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020011028 if (!msg)
11029 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011030
Eric W. Biederman15e47302012-09-07 20:12:54 +000011031 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011032 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011033 if (!hdr) {
11034 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011035 goto free_msg;
11036 }
11037
Johannes Berg683b6d32012-11-08 21:25:48 +010011038 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
11039 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011040
11041 if (err)
11042 goto free_msg;
11043
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011044 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11045 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011046 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011047
11048 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020011049
11050 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011051
11052 nla_put_failure:
11053 err = -ENOBUFS;
11054 free_msg:
11055 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011056 return err;
11057}
11058
11059static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
11060 struct genl_info *info)
11061{
Johannes Berg4c476992010-10-04 21:36:35 +020011062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020011063 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011064 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011065
11066 if (!info->attrs[NL80211_ATTR_COOKIE])
11067 return -EINVAL;
11068
Johannes Berg4c476992010-10-04 21:36:35 +020011069 if (!rdev->ops->cancel_remain_on_channel)
11070 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011071
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011072 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11073
Hila Gonene35e4d22012-06-27 17:19:42 +030011074 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011075}
11076
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011077static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
11078 struct genl_info *info)
11079{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011080 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053011081 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020011082 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053011083 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011084
Johannes Berg4c476992010-10-04 21:36:35 +020011085 if (!rdev->ops->set_bitrate_mask)
11086 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011087
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053011088 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
Miles Hueb89a6a2020-08-04 10:16:29 +020011089 NL80211_ATTR_TX_RATES, &mask,
11090 dev);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053011091 if (err)
11092 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010011093
Hila Gonene35e4d22012-06-27 17:19:42 +030011094 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011095}
11096
Johannes Berg2e161f782010-08-12 15:38:38 +020011097static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020011098{
Johannes Berg4c476992010-10-04 21:36:35 +020011099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020011100 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020011101 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020011102
11103 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
11104 return -EINVAL;
11105
Johannes Berg2e161f782010-08-12 15:38:38 +020011106 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
11107 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020011108
Johannes Berg71bbc992012-06-15 15:30:18 +020011109 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 Berg98104fde2012-06-16 00:19:54 +020011117 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020011118 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011119 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020011120 default:
Johannes Berg4c476992010-10-04 21:36:35 +020011121 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020011122 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011123
11124 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020011125 if (!rdev->ops->mgmt_tx)
11126 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020011127
Johannes Berg9dba48a2020-04-17 12:40:15 +020011128 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. Biederman15e47302012-09-07 20:12:54 +000011136 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Ilan Peerff74c512020-01-31 13:45:29 +020011137 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
11138 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
Johannes Berg9dba48a2020-04-17 12:40:15 +020011139 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
Ilan Peerff74c512020-01-31 13:45:29 +020011140 info->extack);
Jouni Malinen026331c2010-02-15 12:53:10 +020011141}
11142
Johannes Berg2e161f782010-08-12 15:38:38 +020011143static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020011144{
Johannes Berg4c476992010-10-04 21:36:35 +020011145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020011146 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010011147 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020011148 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010011149 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020011150 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010011151 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011152 struct cfg80211_mgmt_tx_params params = {
11153 .dont_wait_for_ack =
11154 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
11155 };
Jouni Malinen026331c2010-02-15 12:53:10 +020011156
Johannes Berg683b6d32012-11-08 21:25:48 +010011157 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020011158 return -EINVAL;
11159
Johannes Berg4c476992010-10-04 21:36:35 +020011160 if (!rdev->ops->mgmt_tx)
11161 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020011162
Johannes Berg71bbc992012-06-15 15:30:18 +020011163 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020011164 case NL80211_IFTYPE_P2P_DEVICE:
11165 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
11166 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020011167 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 Bekercb3b7d82016-09-20 17:31:13 +030011175 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020011176 default:
Johannes Berg4c476992010-10-04 21:36:35 +020011177 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020011178 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011179
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011180 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010011181 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011182 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011183 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020011184
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 Otcheretianskib176e622013-11-18 19:06:49 +020011189 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
11190 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020011191 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011192 }
11193
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011194 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011195
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011196 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010011197 return -EINVAL;
11198
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011199 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053011200
Antonio Quartulliea141b752013-06-11 14:20:03 +020011201 /* 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 Otcheretianskib176e622013-11-18 19:06:49 +020011211 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020011212 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020011213
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053011214 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 Otcheretianski34d22ce2014-05-09 14:11:44 +030011221 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 Otcheretianskib176e622013-11-18 19:06:49 +020011242 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010011243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11244 if (!msg)
11245 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020011246
Eric W. Biederman15e47302012-09-07 20:12:54 +000011247 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010011248 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011249 if (!hdr) {
11250 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010011251 goto free_msg;
11252 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011253 }
Johannes Berge247bd902011-11-04 11:18:21 +010011254
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011255 params.chan = chandef.chan;
11256 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020011257 if (err)
11258 goto free_msg;
11259
Johannes Berge247bd902011-11-04 11:18:21 +010011260 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011261 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11262 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011263 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011264
Johannes Berge247bd902011-11-04 11:18:21 +010011265 genlmsg_end(msg, hdr);
11266 return genlmsg_reply(msg, info);
11267 }
11268
11269 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020011270
11271 nla_put_failure:
11272 err = -ENOBUFS;
11273 free_msg:
11274 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020011275 return err;
11276}
11277
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011278static 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 Berg71bbc992012-06-15 15:30:18 +020011281 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011282 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 Berg71bbc992012-06-15 15:30:18 +020011290 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 Berg98104fde2012-06-16 00:19:54 +020011297 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020011298 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011299 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020011300 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011301 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020011302 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011303
11304 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11305
Hila Gonene35e4d22012-06-27 17:19:42 +030011306 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011307}
11308
Kalle Valoffb9eb32010-02-17 17:58:10 +020011309static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
11310{
Johannes Berg4c476992010-10-04 21:36:35 +020011311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011312 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011313 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011314 u8 ps_state;
11315 bool state;
11316 int err;
11317
Johannes Berg4c476992010-10-04 21:36:35 +020011318 if (!info->attrs[NL80211_ATTR_PS_STATE])
11319 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011320
11321 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
11322
Kalle Valoffb9eb32010-02-17 17:58:10 +020011323 wdev = dev->ieee80211_ptr;
11324
Johannes Berg4c476992010-10-04 21:36:35 +020011325 if (!rdev->ops->set_power_mgmt)
11326 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011327
11328 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
11329
11330 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020011331 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011332
Hila Gonene35e4d22012-06-27 17:19:42 +030011333 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020011334 if (!err)
11335 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011336 return err;
11337}
11338
11339static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
11340{
Johannes Berg4c476992010-10-04 21:36:35 +020011341 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011342 enum nl80211_ps_state ps_state;
11343 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011344 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011345 struct sk_buff *msg;
11346 void *hdr;
11347 int err;
11348
Kalle Valoffb9eb32010-02-17 17:58:10 +020011349 wdev = dev->ieee80211_ptr;
11350
Johannes Berg4c476992010-10-04 21:36:35 +020011351 if (!rdev->ops->set_power_mgmt)
11352 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011353
11354 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020011355 if (!msg)
11356 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011357
Eric W. Biederman15e47302012-09-07 20:12:54 +000011358 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011359 NL80211_CMD_GET_POWER_SAVE);
11360 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020011361 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011362 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. Miller9360ffd2012-03-29 04:41:26 -040011370 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
11371 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011372
11373 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020011374 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020011375
Johannes Berg4c476992010-10-04 21:36:35 +020011376 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020011377 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020011378 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020011379 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020011380 return err;
11381}
11382
Johannes Berg94e860f2014-01-20 23:58:15 +010011383static const struct nla_policy
11384nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011385 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011386 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
11387 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070011388 [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 Zaborowskibee427b2017-01-25 12:43:41 +010011391 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011392};
11393
Thomas Pedersen84f10702012-07-12 16:17:33 -070011394static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010011395 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011396{
11397 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070011398 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011399 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070011400
Johannes Bergd9d8b012012-11-26 12:51:52 +010011401 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011402 return -EINVAL;
11403
Thomas Pedersen84f10702012-07-12 16:17:33 -070011404 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 Gonene35e4d22012-06-27 17:19:42 +030011411 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011412}
11413
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011414static 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 Honma1222a162018-09-25 11:15:01 +090011420 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011421 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 Berg73887fd2018-05-18 09:57:55 +020011435 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011436 u8 *mac_addr;
11437
11438 mac_addr = wdev->current_bss->pub.bssid;
11439
Johannes Berg73887fd2018-05-18 09:57:55 +020011440 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
11441 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011442 return err;
11443
Felix Fietkaudf167372020-01-08 18:06:30 +010011444 cfg80211_sinfo_release_content(&sinfo);
Omer Efrat397c6572018-06-17 13:06:14 +030011445 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011446 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020011447 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011448 }
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 Honma4b2c5a12019-09-08 09:56:53 +090011454 for (i = 0; i < n; i++) {
11455 i = array_index_nospec(i, n);
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011456 if (last < wdev->cqm_config->rssi_thresholds[i])
11457 break;
Masashi Honma4b2c5a12019-09-08 09:56:53 +090011458 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011459
Masashi Honma1222a162018-09-25 11:15:01 +090011460 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 Zaborowski4a4b8162017-02-10 10:02:31 +010011473
11474 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
11475}
11476
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011477static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011478 const s32 *thresholds, int n_thresholds,
11479 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011480{
Johannes Berg4c476992010-10-04 21:36:35 +020011481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020011482 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011483 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011484 int i, err;
11485 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011486
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011487 /* 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 Oikarinend6dc1a32010-03-23 09:02:33 +020011491
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011492 prev = thresholds[i];
11493 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011494
Johannes Berg074ac8d2010-09-16 14:58:22 +020011495 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020011496 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11497 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011498
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011499 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
11539unlock:
11540 wdev_unlock(wdev);
11541
11542 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011543}
11544
11545static 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 Berg1da5fcc2013-08-06 14:10:48 +020011552 if (!cqm)
11553 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011554
Johannes Berg8cb08172019-04-26 14:07:28 +020011555 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
11556 nl80211_attr_cqm_policy,
11557 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011558 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011559 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011560
11561 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
11562 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011563 const s32 *thresholds =
11564 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11565 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011566 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011567
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011568 if (len % 4)
11569 return -EINVAL;
11570
11571 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
11572 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011573 }
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 Oikarinend6dc1a32010-03-23 09:02:33 +020011586}
11587
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011588static 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
11602static 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 Berg29cbe682010-12-03 09:20:44 +010011610static 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 Cardonac80d5452010-12-16 17:37:49 -080011615 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010011616 int err;
11617
11618 /* start with default */
11619 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080011620 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010011621
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011622 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010011623 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011624 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010011625 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 Cardonac80d5452010-12-16 17:37:49 -080011633 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 Yeoh4bb62342011-11-24 17:15:20 -080011636 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 Porsch9bdbf042013-01-07 16:04:51 +010011641 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
11642 setup.beacon_interval =
11643 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011644
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053011645 err = cfg80211_validate_beacon_int(rdev,
11646 NL80211_IFTYPE_MESH_POINT,
11647 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011648 if (err)
11649 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010011650 }
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 Cardonac80d5452010-12-16 17:37:49 -080011659 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 Pedersend37bb182013-03-04 13:06:13 -080011666 if (setup.user_mpm)
11667 cfg.auto_open_plinks = false;
11668
Johannes Bergcc1d2802012-05-16 23:50:20 +020011669 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010011670 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11671 if (err)
11672 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011673 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050011674 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010011675 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011676 }
11677
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070011678 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 Berg8564e382016-09-19 09:44:44 +020011695 if (info->attrs[NL80211_ATTR_TX_RATES]) {
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053011696 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
11697 NL80211_ATTR_TX_RATES,
Miles Hueb89a6a2020-08-04 10:16:29 +020011698 &setup.beacon_rate,
11699 dev);
Johannes Berg8564e382016-09-19 09:44:44 +020011700 if (err)
11701 return err;
11702
Johannes Berg265698d2017-09-18 22:46:36 +020011703 if (!setup.chandef.chan)
11704 return -EINVAL;
11705
Johannes Berg8564e382016-09-19 09:44:44 +020011706 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11707 &setup.beacon_rate);
11708 if (err)
11709 return err;
11710 }
11711
Benjamin Bergd37d49c2017-05-16 11:23:11 +020011712 setup.userspace_handles_dfs =
11713 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11714
Denis Kenzior1224f582018-03-26 12:52:49 -050011715 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 Kenzior188c1b32018-03-26 12:52:46 -050011724 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 Berg29cbe682010-12-03 09:20:44 +010011731}
11732
11733static 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 Bergdfb89c52012-06-27 09:23:48 +020011741#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011742static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11743 struct cfg80211_registered_device *rdev)
11744{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011745 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011746 struct nlattr *nl_pats, *nl_pat;
11747 int i, pat_len;
11748
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011749 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011750 return 0;
11751
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011752 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011753 if (!nl_pats)
11754 return -ENOBUFS;
11755
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011756 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011757 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011758 if (!nl_pat)
11759 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011760 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011761 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011762 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011763 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11764 wowlan->patterns[i].pattern) ||
11765 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011766 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011767 return -ENOBUFS;
11768 nla_nest_end(msg, nl_pat);
11769 }
11770 nla_nest_end(msg, nl_pats);
11771
11772 return 0;
11773}
11774
Johannes Berg2a0e0472013-01-23 22:57:40 +010011775static 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 Kubecekae0be8d2019-04-26 11:13:06 +020011783 nl_tcp = nla_nest_start_noflag(msg,
11784 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011785 if (!nl_tcp)
11786 return -ENOBUFS;
11787
Jiri Benc930345e2015-03-29 16:59:25 +020011788 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 Berg2a0e0472013-01-23 22:57:40 +010011790 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 Berge248ad32013-05-16 10:24:28 +020011814 nla_nest_end(msg, nl_tcp);
11815
Johannes Berg2a0e0472013-01-23 22:57:40 +010011816 return 0;
11817}
11818
Luciano Coelho75453cc2015-01-09 14:06:37 +020011819static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11820 struct cfg80211_sched_scan_request *req)
11821{
Avraham Stern3b06d272015-10-12 09:51:34 +030011822 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011823 int i;
11824
11825 if (!req)
11826 return 0;
11827
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011828 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011829 if (!nd)
11830 return -ENOBUFS;
11831
Avraham Stern3b06d272015-10-12 09:51:34 +030011832 if (req->n_scan_plans == 1 &&
11833 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11834 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011835 return -ENOBUFS;
11836
Luciano Coelho21fea562015-03-17 16:36:01 +020011837 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11838 return -ENOBUFS;
11839
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011840 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 Kubecekae0be8d2019-04-26 11:13:06 +020011854 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011855 if (!freqs)
11856 return -ENOBUFS;
11857
Johannes Berg53b18982016-09-14 09:59:21 +020011858 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 Coelho75453cc2015-01-09 14:06:37 +020011862
11863 nla_nest_end(msg, freqs);
11864
11865 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011866 matches = nla_nest_start_noflag(msg,
11867 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011868 if (!matches)
11869 return -ENOBUFS;
11870
Luciano Coelho75453cc2015-01-09 14:06:37 +020011871 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011872 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011873 if (!match)
11874 return -ENOBUFS;
11875
Johannes Berg53b18982016-09-14 09:59:21 +020011876 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 Coelho75453cc2015-01-09 14:06:37 +020011880 nla_nest_end(msg, match);
11881 }
11882 nla_nest_end(msg, matches);
11883 }
11884
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011885 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011886 if (!scan_plans)
11887 return -ENOBUFS;
11888
11889 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011890 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011891 if (!scan_plan)
11892 return -ENOBUFS;
11893
Colin Ian King67626962018-09-06 10:58:44 +010011894 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011895 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 Coelho75453cc2015-01-09 14:06:37 +020011904 nla_nest_end(msg, nd);
11905
11906 return 0;
11907}
11908
Johannes Bergff1b6e62011-05-04 15:37:28 +020011909static 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 Berg2a0e0472013-01-23 22:57:40 +010011914 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011915
Johannes Berg964dc9e2013-06-03 17:25:34 +020011916 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011917 return -EOPNOTSUPP;
11918
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011919 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011920 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011921 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 Berg2a0e0472013-01-23 22:57:40 +010011925 }
11926
11927 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011928 if (!msg)
11929 return -ENOMEM;
11930
Eric W. Biederman15e47302012-09-07 20:12:54 +000011931 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011932 NL80211_CMD_GET_WOWLAN);
11933 if (!hdr)
11934 goto nla_put_failure;
11935
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011936 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011937 struct nlattr *nl_wowlan;
11938
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011939 nl_wowlan = nla_nest_start_noflag(msg,
11940 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011941 if (!nl_wowlan)
11942 goto nla_put_failure;
11943
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011944 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011945 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011946 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011947 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011948 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011949 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011950 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011951 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011952 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011953 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011954 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011955 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011956 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011957 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11958 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011959
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011960 if (nl80211_send_wowlan_patterns(msg, rdev))
11961 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011962
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011963 if (nl80211_send_wowlan_tcp(msg,
11964 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011965 goto nla_put_failure;
11966
Luciano Coelho75453cc2015-01-09 14:06:37 +020011967 if (nl80211_send_wowlan_nd(
11968 msg,
11969 rdev->wiphy.wowlan_config->nd_config))
11970 goto nla_put_failure;
11971
Johannes Bergff1b6e62011-05-04 15:37:28 +020011972 nla_nest_end(msg, nl_wowlan);
11973 }
11974
11975 genlmsg_end(msg, hdr);
11976 return genlmsg_reply(msg, info);
11977
11978nla_put_failure:
11979 nlmsg_free(msg);
11980 return -ENOBUFS;
11981}
11982
Johannes Berg2a0e0472013-01-23 22:57:40 +010011983static 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 Berg964dc9e2013-06-03 17:25:34 +020011995 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011996 return -EINVAL;
11997
Johannes Berg8cb08172019-04-26 14:07:28 +020011998 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11999 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010012000 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 Berg964dc9e2013-06-03 17:25:34 +020012014 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012015 return -EINVAL;
12016
12017 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020012018 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010012019 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012020 return -EINVAL;
12021
12022 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020012023 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012024 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 Berg964dc9e2013-06-03 17:25:34 +020012038 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012039 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020012040 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012041 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020012042 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012043 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020012044 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012045 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 Berg964dc9e2013-06-03 17:25:34 +020012052 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010012053 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 Benc67b61f62015-03-29 16:59:26 +020012068 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 Berg2a0e0472013-01-23 22:57:40 +010012070 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 Coelho8cd4d452014-09-17 11:55:28 +030012127static 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 Cook6396bb22018-06-12 14:03:40 -070012135 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012136 if (!tb)
12137 return -ENOMEM;
12138
12139 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
12140 err = -EOPNOTSUPP;
12141 goto out;
12142 }
12143
Johannes Berg8cb08172019-04-26 14:07:28 +020012144 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
12145 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012146 if (err)
12147 goto out;
12148
Arend Van Sprielaad1e812017-01-27 12:27:44 +000012149 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
12150 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012151 err = PTR_ERR_OR_ZERO(trig->nd_config);
12152 if (err)
12153 trig->nd_config = NULL;
12154
12155out:
12156 kfree(tb);
12157 return err;
12158}
12159
Johannes Bergff1b6e62011-05-04 15:37:28 +020012160static 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 Bergff1b6e62011-05-04 15:37:28 +020012164 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020012165 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020012166 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012167 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012168 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020012169 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012170
Johannes Berg964dc9e2013-06-03 17:25:34 +020012171 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020012172 return -EOPNOTSUPP;
12173
Johannes Bergae33bd82012-07-12 16:25:02 +020012174 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
12175 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012176 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020012177 goto set_wakeup;
12178 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020012179
Johannes Berg8cb08172019-04-26 14:07:28 +020012180 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
12181 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
12182 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020012183 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 Berg98fc4382015-03-01 09:10:13 +020012196 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012197 }
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 Berg98fc4382015-03-01 09:10:13 +020012203 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012204 }
12205
Johannes Berg77dbbb12011-07-13 10:48:55 +020012206 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 Berg98fc4382015-03-01 09:10:13 +020012213 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012214 }
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 Berg98fc4382015-03-01 09:10:13 +020012220 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012221 }
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 Berg98fc4382015-03-01 09:10:13 +020012227 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012228 }
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 Berg98fc4382015-03-01 09:10:13 +020012234 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012235 }
12236
Johannes Bergff1b6e62011-05-04 15:37:28 +020012237 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
12238 struct nlattr *pat;
12239 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080012240 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012241 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020012242
Johannes Berg98fc4382015-03-01 09:10:13 +020012243 regular = true;
12244
Johannes Bergff1b6e62011-05-04 15:37:28 +020012245 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 Berg922bd802014-05-19 17:59:50 +020012262 u8 *mask_pat;
12263
Johannes Berg8cb08172019-04-26 14:07:28 +020012264 err = nla_parse_nested_deprecated(pat_tb,
12265 MAX_NL80211_PKTPAT,
12266 pat,
12267 nl80211_packet_pattern_policy,
12268 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020012269 if (err)
12270 goto error;
12271
Johannes Bergff1b6e62011-05-04 15:37:28 +020012272 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012273 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12274 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020012275 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012276 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020012277 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012278 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020012279 goto error;
12280 if (pat_len > wowlan->pattern_max_len ||
12281 pat_len < wowlan->pattern_min_len)
12282 goto error;
12283
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012284 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080012285 pkt_offset = 0;
12286 else
12287 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012288 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080012289 if (pkt_offset > wowlan->max_pkt_offset)
12290 goto error;
12291 new_triggers.patterns[i].pkt_offset = pkt_offset;
12292
Johannes Berg922bd802014-05-19 17:59:50 +020012293 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12294 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020012295 err = -ENOMEM;
12296 goto error;
12297 }
Johannes Berg922bd802014-05-19 17:59:50 +020012298 new_triggers.patterns[i].mask = mask_pat;
12299 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020012300 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020012301 mask_pat += mask_len;
12302 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012303 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020012304 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012305 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020012306 pat_len);
12307 i++;
12308 }
12309 }
12310
Johannes Berg2a0e0472013-01-23 22:57:40 +010012311 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020012312 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012313 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 Coelho8cd4d452014-09-17 11:55:28 +030012320 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020012321 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012322 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 Berg98fc4382015-03-01 09:10:13 +020012329 /* 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 Bergae33bd82012-07-12 16:25:02 +020012340 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
12341 if (!ntrig) {
12342 err = -ENOMEM;
12343 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012344 }
Johannes Bergae33bd82012-07-12 16:25:02 +020012345 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012346 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012347
Johannes Bergae33bd82012-07-12 16:25:02 +020012348 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012349 if (rdev->ops->set_wakeup &&
12350 prev_enabled != !!rdev->wiphy.wowlan_config)
12351 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020012352
Johannes Bergff1b6e62011-05-04 15:37:28 +020012353 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 Berg2a0e0472013-01-23 22:57:40 +010012358 if (new_triggers.tcp && new_triggers.tcp->sock)
12359 sock_release(new_triggers.tcp->sock);
12360 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010012361 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020012362 return err;
12363}
Johannes Bergdfb89c52012-06-27 09:23:48 +020012364#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020012365
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012366static 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 Kubecekae0be8d2019-04-26 11:13:06 +020012376 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012377 if (!nl_rules)
12378 return -ENOBUFS;
12379
12380 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012381 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012382 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 Kubecekae0be8d2019-04-26 11:13:06 +020012394 nl_pats = nla_nest_start_noflag(msg,
12395 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012396 if (!nl_pats)
12397 return -ENOBUFS;
12398
12399 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012400 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012401 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
12422static 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
12446nla_put_failure:
12447 nlmsg_free(msg);
12448 return -ENOBUFS;
12449}
12450
12451void 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
12471static 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 Berg8cb08172019-04-26 14:07:28 +020012481 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
12482 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012483 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 Karwarbe29b99a2013-06-28 11:51:26 -070012495
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 Berg922bd802014-05-19 17:59:50 +020012515 u8 *mask_pat;
12516
Johannes Berg8cb08172019-04-26 14:07:28 +020012517 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
12518 pat,
12519 nl80211_packet_pattern_policy,
12520 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020012521 if (err)
12522 return err;
12523
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012524 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 Berg922bd802014-05-19 17:59:50 +020012543 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12544 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012545 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020012546
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 Karwarbe29b99a2013-06-28 11:51:26 -070012553 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020012554 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12555 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012556 i++;
12557 }
12558
12559 return 0;
12560}
12561
12562static 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 Peera1056b1b2015-10-22 22:27:46 +030012577 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012578 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 Peera1056b1b2015-10-22 22:27:46 +030012605 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012606 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;
12618error:
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 Berge5497d72011-07-05 16:35:40 +020012630static 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 Berg8cb08172019-04-26 14:07:28 +020012642 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
12643 info->attrs[NL80211_ATTR_REKEY_DATA],
12644 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020012645 if (err)
12646 return err;
12647
Vladis Dronove785fa02017-09-13 00:21:21 +020012648 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12649 !tb[NL80211_REKEY_DATA_KCK])
12650 return -EINVAL;
Nathan Errera093a48d2020-05-28 21:22:38 +020012651 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 Berge5497d72011-07-05 16:35:40 +020012654 return -ERANGE;
Nathan Errera093a48d2020-05-28 21:22:38 +020012655 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 Berge5497d72011-07-05 16:35:40 +020012658 return -ERANGE;
12659
Johannes Berg78f686c2014-09-10 22:28:06 +030012660 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 Errera093a48d2020-05-28 21:22:38 +020012663 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 Berge5497d72011-07-05 16:35:40 +020012667
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 Gonene35e4d22012-06-27 17:19:42 +030012679 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020012680 out:
12681 wdev_unlock(wdev);
12682 return err;
12683}
12684
Johannes Berg28946da2011-11-04 11:18:12 +010012685static 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. Biederman15e47302012-09-07 20:12:54 +000012695 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012696 return -EBUSY;
12697
Eric W. Biederman15e47302012-09-07 20:12:54 +000012698 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010012699 return 0;
12700}
12701
Johannes Berg7f6cf312011-11-04 11:18:15 +010012702static 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. Biederman15e47302012-09-07 20:12:54 +000012728 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010012729 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030012730 if (!hdr) {
12731 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012732 goto free_msg;
12733 }
12734
12735 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12736
Hila Gonene35e4d22012-06-27 17:19:42 +030012737 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012738 if (err)
12739 goto free_msg;
12740
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012741 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12742 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012743 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012744
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 Berg5e760232011-11-04 11:18:17 +010012756static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12757{
12758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070012759 struct cfg80211_beacon_registration *reg, *nreg;
12760 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012761
12762 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12763 return -EOPNOTSUPP;
12764
Ben Greear37c73b52012-10-26 14:49:25 -070012765 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12766 if (!nreg)
12767 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010012768
Ben Greear37c73b52012-10-26 14:49:25 -070012769 /* 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 Berg5e760232011-11-04 11:18:17 +010012782
12783 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070012784out_err:
12785 spin_unlock_bh(&rdev->beacon_registrations_lock);
12786 kfree(nreg);
12787 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012788}
12789
Johannes Berg98104fde2012-06-16 00:19:54 +020012790static 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 Spriel73c7da32016-10-20 20:08:22 +010012802 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020012803 return 0;
12804
Luciano Coelhob6a55012014-02-27 11:07:21 +020012805 if (rfkill_blocked(rdev->rfkill))
12806 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020012807
Johannes Bergeeb126e2012-10-23 15:16:50 +020012808 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012809 if (err)
12810 return err;
12811
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012812 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020012813 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020012814
12815 return 0;
12816}
12817
12818static 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 Bergf9f47522013-03-19 15:04:07 +010012829 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012830
12831 return 0;
12832}
12833
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012834static 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 Bergeeb04a92016-11-21 13:55:48 +010012844 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012845 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 Bekercb3b7d82016-09-20 17:31:13 +030012853 conf.master_pref =
12854 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012855
Luca Coelho85859892017-02-08 15:00:34 +020012856 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 Bekercb3b7d82016-09-20 17:31:13 +030012867
12868 err = rdev_start_nan(rdev, wdev, &conf);
12869 if (err)
12870 return err;
12871
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012872 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012873 rdev->opencount++;
12874
12875 return 0;
12876}
12877
12878static 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 Bekera442b762016-09-20 17:31:15 +030012891static 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
12907static 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 Grafb15ca182016-10-26 10:53:16 +020012927 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012928 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
12942static 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 Spriel73c7da32016-10-20 20:08:22 +010012956 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012957 return -ENOTCONN;
12958
12959 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12960 return -EINVAL;
12961
Johannes Berg8cb08172019-04-26 14:07:28 +020012962 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 Bekera442b762016-09-20 17:31:15 +030012966 if (err)
12967 return err;
12968
12969 func = kzalloc(sizeof(*func), GFP_KERNEL);
12970 if (!func)
12971 return -ENOMEM;
12972
Johannes Bergb60ad342018-10-01 11:52:07 +020012973 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012974
Johannes Bergcb9abd42020-08-05 15:47:16 +020012975 if (!tb[NL80211_NAN_FUNC_TYPE]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012976 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 Chen3ea15452018-01-03 11:00:31 +080013034 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
13035 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030013036 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 Berg8cb08172019-04-26 14:07:28 +020013060 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 Bekera442b762016-09-20 17:31:15 +030013065 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 Cook6396bb22018-06-12 14:03:40 -070013108 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030013109 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);
13150out:
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 Kubecekae0be8d2019-04-26 11:13:06 +020013162 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030013163 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
13175nla_put_failure:
13176 nlmsg_free(msg);
13177 return -ENOBUFS;
13178}
13179
13180static 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 Spriel73c7da32016-10-20 20:08:22 +010013190 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030013191 return -ENOTCONN;
13192
13193 if (!info->attrs[NL80211_ATTR_COOKIE])
13194 return -EINVAL;
13195
Ayala Bekera442b762016-09-20 17:31:15 +030013196 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 Bekera5a9dcf2016-09-20 17:31:16 +030013203static 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 Spriel73c7da32016-10-20 20:08:22 +010013214 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013215 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 Coelho85859892017-02-08 15:00:34 +020013226 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 Bekera5a9dcf2016-09-20 17:31:16 +030013237 }
13238
13239 if (!changed)
13240 return -EINVAL;
13241
13242 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
13243}
13244
Ayala Beker50bcd312016-09-20 17:31:17 +030013245void 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 Kubecekae0be8d2019-04-26 11:13:06 +020013279 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030013280 if (!match_attr)
13281 goto nla_put_failure;
13282
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013283 local_func_attr = nla_nest_start_noflag(msg,
13284 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030013285 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 Kubecekae0be8d2019-04-26 11:13:06 +020013293 peer_func_attr = nla_nest_start_noflag(msg,
13294 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030013295 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
13320nla_put_failure:
13321 nlmsg_free(msg);
13322}
13323EXPORT_SYMBOL(cfg80211_nan_match);
13324
Ayala Beker368e5a72016-09-20 17:31:18 +030013325void 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 Kubecekae0be8d2019-04-26 11:13:06 +020013360 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030013361 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
13380nla_put_failure:
13381 nlmsg_free(msg);
13382}
13383EXPORT_SYMBOL(cfg80211_nan_func_terminated);
13384
Johannes Berg3713b4e2013-02-14 16:19:38 +010013385static 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 Malinen355199e2013-02-27 17:14:27 +020013412static 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 Berg3d7af872018-10-02 10:00:08 +020013422 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020013423 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 Spriel5de17982013-04-18 15:49:00 +020013433static 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 Spriel5de17982013-04-18 15:49:00 +020013465 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
13472static 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 Berg901bb982019-05-28 10:56:03 +020013488static 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 Kubecek32d51092019-12-11 10:58:19 +010013507 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
Johannes Berg901bb982019-05-28 10:56:03 +020013508}
13509
Johannes Bergad7e7182013-11-13 13:37:47 +010013510static 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 Spriel73c7da32016-10-20 20:08:22 +010013555 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010013556 return -ENETDOWN;
13557 }
13558 } else {
13559 wdev = NULL;
13560 }
13561
Julian Squires4052d3d2020-07-06 17:13:53 -040013562 if (!vcmd->doit)
13563 return -EOPNOTSUPP;
13564
Johannes Bergad7e7182013-11-13 13:37:47 +010013565 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 Berg901bb982019-05-28 10:56:03 +020013568
13569 err = nl80211_vendor_check_policy(vcmd,
13570 info->attrs[NL80211_ATTR_VENDOR_DATA],
13571 info->extack);
13572 if (err)
13573 return err;
Johannes Bergad7e7182013-11-13 13:37:47 +010013574 }
13575
13576 rdev->cur_cmd_info = info;
Johannes Berg901bb982019-05-28 10:56:03 +020013577 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
Johannes Bergad7e7182013-11-13 13:37:47 +010013578 rdev->cur_cmd_info = NULL;
13579 return err;
13580 }
13581
13582 return -EOPNOTSUPP;
13583}
13584
Johannes Berg7bdbe402015-08-15 22:39:49 +030013585static 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 Berg50508d92019-07-29 16:31:09 +020013590 struct nlattr **attrbuf;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013591 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 Berg7bdbe402015-08-15 22:39:49 +030013598 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 Bergea90e0d2017-03-15 14:26:04 +010013603 if (!wiphy)
13604 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013605 *rdev = wiphy_to_rdev(wiphy);
13606 *wdev = NULL;
13607
13608 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030013609 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013610 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 Berg50508d92019-07-29 16:31:09 +020013621 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
13622 if (!attrbuf)
13623 return -ENOMEM;
13624
Johannes Berg8cb08172019-04-26 14:07:28 +020013625 err = nlmsg_parse_deprecated(cb->nlh,
13626 GENL_HDRLEN + nl80211_fam.hdrsize,
13627 attrbuf, nl80211_fam.maxattr,
13628 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013629 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020013630 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013631
Johannes Bergc90c39d2016-10-24 14:40:01 +020013632 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg50508d92019-07-29 16:31:09 +020013633 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
13634 err = -EINVAL;
13635 goto out;
13636 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013637
Johannes Bergc90c39d2016-10-24 14:40:01 +020013638 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013639 if (IS_ERR(*wdev))
13640 *wdev = NULL;
13641
Johannes Bergc90c39d2016-10-24 14:40:01 +020013642 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg50508d92019-07-29 16:31:09 +020013643 if (IS_ERR(*rdev)) {
13644 err = PTR_ERR(*rdev);
13645 goto out;
13646 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013647
Johannes Bergc90c39d2016-10-24 14:40:01 +020013648 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
13649 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013650
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 Berg50508d92019-07-29 16:31:09 +020013659 if (!vcmd->dumpit) {
13660 err = -EOPNOTSUPP;
13661 goto out;
13662 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013663
13664 vcmd_idx = i;
13665 break;
13666 }
13667
Johannes Berg50508d92019-07-29 16:31:09 +020013668 if (vcmd_idx < 0) {
13669 err = -EOPNOTSUPP;
13670 goto out;
13671 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013672
Johannes Bergc90c39d2016-10-24 14:40:01 +020013673 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 Berg901bb982019-05-28 10:56:03 +020013676
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 Berg50508d92019-07-29 16:31:09 +020013682 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013683 }
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 Berg50508d92019-07-29 16:31:09 +020013694 err = 0;
13695out:
13696 kfree(attrbuf);
13697 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013698}
13699
13700static 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 Bergea90e0d2017-03-15 14:26:04 +010013712 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030013713 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13714 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010013715 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013716
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 Bergea90e0d2017-03-15 14:26:04 +010013724 if (!wdev) {
13725 err = -EINVAL;
13726 goto out;
13727 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013728 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010013729 !wdev->netdev) {
13730 err = -EINVAL;
13731 goto out;
13732 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013733
13734 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013735 if (!wdev_running(wdev)) {
13736 err = -ENETDOWN;
13737 goto out;
13738 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013739 }
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 Dichtel2dad6242016-04-25 10:25:22 +020013750 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13751 wdev_id(wdev),
13752 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013753 genlmsg_cancel(skb, hdr);
13754 break;
13755 }
13756
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013757 vendor_data = nla_nest_start_noflag(skb,
13758 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013759 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 Squires9c167b22020-07-20 12:20:35 -023013771 } else if (err <= 0) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013772 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 Bergad7e7182013-11-13 13:37:47 +010013785struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13786 enum nl80211_commands cmd,
13787 enum nl80211_attrs attr,
13788 int approxlen)
13789{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013790 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010013791
13792 if (WARN_ON(!rdev->cur_cmd_info))
13793 return NULL;
13794
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020013795 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010013796 rdev->cur_cmd_info->snd_portid,
13797 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010013798 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010013799}
13800EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13801
13802int 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 Bergbd8c78e2014-07-30 14:55:26 +020013808 /* clear CB data for netlink core to own from now on */
13809 memset(skb->cb, 0, sizeof(skb->cb));
13810
Johannes Bergad7e7182013-11-13 13:37:47 +010013811 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}
13820EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13821
Johannes Berg55c1fdf2019-02-06 13:17:19 +020013822unsigned 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}
13831EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13832
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013833static 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 Bergc8b82802020-08-19 08:56:43 +020013849 if (len % 2)
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013850 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 Berg960d01a2014-09-09 22:55:35 +030013883static 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 Berg723e73a2014-10-22 09:25:06 +020013893 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013894 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 Berg960d01a2014-09-09 22:55:35 +030013901 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013902
13903 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013904 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013905 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013906 * need more attributes for that (e.g. BA session requirement);
13907 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013908 */
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
13941static 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 Nemtsov1057d352014-11-19 12:54:26 +020013963static 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 Berg57fbcce2016-04-12 15:56:15 +020013999 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020014000 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 Nemtsov923b3522015-07-08 15:41:44 +030014005 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
14006 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020014007 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
14023static 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 Braunce0ce132016-10-10 19:12:22 +020014056static 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 Braunce0ce132016-10-10 19:12:22 +020014065 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 Stern3a00df52017-06-09 13:08:43 +010014078static 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 Bergcb9abd42020-08-05 15:47:16 +020014117 if (info->attrs[NL80211_ATTR_PMKR0_NAME])
Avraham Stern3a00df52017-06-09 13:08:43 +010014118 pmk_conf.pmk_r0_name =
14119 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
Avraham Stern3a00df52017-06-09 13:08:43 +010014120
14121 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
14122out:
14123 wdev_unlock(wdev);
14124 return ret;
14125}
14126
14127static 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 Dasari40cbfa92018-01-25 17:13:38 +020014154static 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 Dasaridb8d93a2018-02-02 11:15:27 +020014160 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014161 return -EOPNOTSUPP;
14162
Srinivas Dasarife494372019-01-23 18:06:56 +053014163 if (!info->attrs[NL80211_ATTR_SSID] &&
14164 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
14165 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014166 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(&params, 0, sizeof(params));
14175
Srinivas Dasarife494372019-01-23 18:06:56 +053014176 if (info->attrs[NL80211_ATTR_SSID]) {
14177 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Johannes Bergcb9abd42020-08-05 15:47:16 +020014178 if (params.ssid.ssid_len == 0)
Srinivas Dasarife494372019-01-23 18:06:56 +053014179 return -EINVAL;
14180 memcpy(params.ssid.ssid,
14181 nla_data(info->attrs[NL80211_ATTR_SSID]),
14182 params.ssid.ssid_len);
14183 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014184
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 Dasarife494372019-01-23 18:06:56 +053014190 if (info->attrs[NL80211_ATTR_PMKID])
14191 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
14192
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014193 return rdev_external_auth(rdev, dev, &params);
14194}
14195
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014196static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
14197{
Markus Theildca9ca22020-05-08 16:42:00 +020014198 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014199 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 Theildca9ca22020-05-08 16:42:00 +020014207 u64 cookie = 0;
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014208 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 Theildca9ca22020-05-08 16:42:00 +020014252 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 Kenzior2576a9a2018-03-26 12:52:42 -050014258 out:
14259 wdev_unlock(wdev);
14260 return err;
14261}
14262
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014263static 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 Emamdoost1399c592019-10-04 14:42:19 -050014292 goto nla_put_failure;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014293
14294 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
14295 goto nla_put_failure;
14296
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014297 ftm_stats_attr = nla_nest_start_noflag(msg,
14298 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014299 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
14329nla_put_failure:
14330 nlmsg_free(msg);
14331 return -ENOBUFS;
14332}
14333
Sunil Duttcb74e972019-02-20 16:18:07 +053014334static 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 Manoharan5ab92e72019-04-11 13:47:24 -070014359static 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 Fietkau2a279b342020-01-08 18:06:29 +010014397 cfg80211_sinfo_release_content(&sinfo);
14398
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014399 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
14400}
14401
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014402static int parse_tid_conf(struct cfg80211_registered_device *rdev,
14403 struct nlattr *attrs[], struct net_device *dev,
Johannes Berg3710a8a2020-02-24 11:34:25 +010014404 struct cfg80211_tid_cfg *tid_conf,
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014405 struct genl_info *info, const u8 *peer)
14406{
14407 struct netlink_ext_ack *extack = info->extack;
Johannes Berg3710a8a2020-02-24 11:34:25 +010014408 u64 mask;
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014409 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 Berg3710a8a2020-02-24 11:34:25 +010014416 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014417
14418 if (tid_conf->config_override) {
14419 if (rdev->ops->reset_tid_config) {
14420 err = rdev_reset_tid_config(rdev, dev, peer,
Johannes Berg3710a8a2020-02-24 11:34:25 +010014421 tid_conf->tids);
Sergey Matyukevichc0336952020-04-24 14:29:04 +030014422 if (err)
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014423 return err;
14424 } else {
14425 return -EINVAL;
14426 }
14427 }
14428
14429 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
Johannes Berg3710a8a2020-02-24 11:34:25 +010014430 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014431 tid_conf->noack =
14432 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
14433 }
14434
Tamizh chelvam6a21d162020-01-20 13:21:23 +053014435 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 chelvamade274b2020-01-20 13:21:24 +053014453 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 chelvam04f7d142020-01-20 13:21:25 +053014459 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 Matyukevich33462e62020-04-24 14:29:03 +030014465 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 Chelvam9a5f6482020-05-13 13:41:44 +053014471 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 Hueb89a6a2020-08-04 10:16:29 +020014479 &tid_conf->txrate_mask, dev);
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053014480 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 Berg3710a8a2020-02-24 11:34:25 +010014488 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 chelvam77f576d2020-01-20 13:21:22 +053014498 return 0;
14499}
14500
14501static 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 Berg3710a8a2020-02-24 11:34:25 +010014507 struct cfg80211_tid_config *tid_config;
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014508 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
14552bad_tid_conf:
14553 kfree(tid_config);
14554 return ret;
14555}
14556
Johannes Berg4c476992010-10-04 21:36:35 +020014557#define NL80211_FLAG_NEED_WIPHY 0x01
14558#define NL80211_FLAG_NEED_NETDEV 0x02
14559#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020014560#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 Berg1bf614e2012-06-15 15:23:36 +020014563#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020014564/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020014565#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14566 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030014567#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020014568
Johannes Bergf84f7712013-11-14 17:14:45 +010014569static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020014570 struct genl_info *info)
14571{
14572 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020014573 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020014574 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020014575 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 Berg4f7eff12012-06-15 14:14:22 +020014581 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020014582 if (IS_ERR(rdev)) {
14583 if (rtnl)
14584 rtnl_unlock();
14585 return PTR_ERR(rdev);
14586 }
14587 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020014588 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
14589 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020014590 ASSERT_RTNL();
14591
Johannes Berg89a54e42012-06-15 14:33:17 +020014592 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
14593 info->attrs);
14594 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020014595 if (rtnl)
14596 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020014597 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020014598 }
Johannes Berg89a54e42012-06-15 14:33:17 +020014599
Johannes Berg89a54e42012-06-15 14:33:17 +020014600 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014601 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020014602
Johannes Berg1bf614e2012-06-15 15:23:36 +020014603 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
14604 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020014605 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 Berg41265712010-10-04 21:14:05 +020014613 }
Johannes Berg89a54e42012-06-15 14:33:17 +020014614
Arend Van Spriel73c7da32016-10-20 20:08:22 +010014615 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
14616 !wdev_running(wdev)) {
14617 if (rtnl)
14618 rtnl_unlock();
14619 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020014620 }
14621
Arend Van Spriel73c7da32016-10-20 20:08:22 +010014622 if (dev)
14623 dev_hold(dev);
14624
Johannes Berg4c476992010-10-04 21:36:35 +020014625 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020014626 }
14627
14628 return 0;
14629}
14630
Johannes Bergf84f7712013-11-14 17:14:45 +010014631static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020014632 struct genl_info *info)
14633{
Johannes Berg1bf614e2012-06-15 15:23:36 +020014634 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 Berg5393b912014-09-10 15:00:16 +030014644
Johannes Berg4c476992010-10-04 21:36:35 +020014645 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
14646 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030014647
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 Berg4c476992010-10-04 21:36:35 +020014658}
14659
Johannes Berg4534de82013-11-14 17:14:46 +010014660static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040014661 {
14662 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014663 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014664 .doit = nl80211_get_wiphy,
14665 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020014666 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040014667 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020014668 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14669 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014670 },
Jakub Kicinski66a9b922020-10-02 14:49:54 -070014671};
14672
14673static const struct genl_small_ops nl80211_small_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040014674 {
14675 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014676 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014677 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014678 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014679 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014680 },
14681 {
14682 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014683 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014684 .doit = nl80211_get_interface,
14685 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040014686 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020014687 .internal_flags = NL80211_FLAG_NEED_WDEV |
14688 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014689 },
14690 {
14691 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014692 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014693 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014694 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014695 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14696 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014697 },
14698 {
14699 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014700 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014701 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014702 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014703 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14704 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014705 },
14706 {
14707 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014708 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014709 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014710 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020014711 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014712 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014713 },
Johannes Berg41ade002007-12-19 02:03:29 +010014714 {
14715 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014716 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014717 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014718 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014720 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010014721 },
14722 {
14723 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014724 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014725 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014726 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014727 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014728 NL80211_FLAG_NEED_RTNL |
14729 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010014730 },
14731 {
14732 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014733 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014734 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014735 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014736 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014737 NL80211_FLAG_NEED_RTNL |
14738 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010014739 },
14740 {
14741 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014742 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014743 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014744 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014745 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014746 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010014747 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010014748 {
14749 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020014750 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014751 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014752 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014753 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014754 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014755 },
14756 {
Johannes Berg88600202012-02-13 15:17:18 +010014757 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014758 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014759 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014760 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014761 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014762 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014763 },
14764 {
Johannes Berg88600202012-02-13 15:17:18 +010014765 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014766 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014767 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014768 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014769 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014770 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014771 },
Johannes Berg5727ef12007-12-19 02:03:34 +010014772 {
14773 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014774 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014775 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014776 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020014777 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14778 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014779 },
14780 {
14781 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014782 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014783 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014784 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014785 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014786 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014787 },
14788 {
14789 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014790 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014791 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014792 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014793 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014794 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014795 },
14796 {
14797 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014798 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014799 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014800 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014802 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014803 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014804 {
14805 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014806 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014807 .doit = nl80211_get_mpath,
14808 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014809 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014810 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014811 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014812 },
14813 {
Henning Rogge66be7d22014-09-12 08:58:49 +020014814 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014815 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020014816 .doit = nl80211_get_mpp,
14817 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020014818 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020014819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14820 NL80211_FLAG_NEED_RTNL,
14821 },
14822 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014823 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014824 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014825 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014826 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014827 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014828 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014829 },
14830 {
14831 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014832 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014833 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014834 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014835 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014836 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014837 },
14838 {
14839 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014840 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014841 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014842 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014844 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014845 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014846 {
14847 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014848 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014849 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014850 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014852 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014853 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014854 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014855 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014856 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014857 .doit = nl80211_get_reg_do,
14858 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014859 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014860 /* can be retrieved by unprivileged users */
14861 },
Johannes Bergb6863032015-10-15 09:25:18 +020014862#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014863 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014864 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014865 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014866 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014867 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014868 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014869 },
Johannes Bergb6863032015-10-15 09:25:18 +020014870#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014871 {
14872 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014873 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014874 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014875 .flags = GENL_ADMIN_PERM,
14876 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014877 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014878 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014879 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014880 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014881 .flags = GENL_ADMIN_PERM,
14882 },
14883 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014884 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014885 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014886 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014887 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014889 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014890 },
14891 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014892 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014893 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014894 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020014895 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014896 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014897 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014898 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020014899 {
Johannes Berg2a519312009-02-10 21:25:55 +010014900 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014901 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014902 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014903 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020014904 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014905 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010014906 },
14907 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014908 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014909 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014910 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014911 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014912 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14913 NL80211_FLAG_NEED_RTNL,
14914 },
14915 {
Johannes Berg2a519312009-02-10 21:25:55 +010014916 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014917 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014918 .dumpit = nl80211_dump_scan,
14919 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020014920 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014921 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014922 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014923 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014924 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014925 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14926 NL80211_FLAG_NEED_RTNL,
14927 },
14928 {
14929 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014930 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014931 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014932 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014933 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14934 NL80211_FLAG_NEED_RTNL,
14935 },
14936 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020014937 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014938 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014939 .doit = nl80211_authenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014940 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014941 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014942 NL80211_FLAG_NEED_RTNL |
14943 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014944 },
14945 {
14946 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014947 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014948 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014949 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014951 NL80211_FLAG_NEED_RTNL |
14952 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014953 },
14954 {
14955 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014956 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014957 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014958 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014960 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014961 },
14962 {
14963 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014964 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014965 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014966 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014968 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014969 },
Johannes Berg04a773a2009-04-19 21:24:32 +020014970 {
14971 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014972 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014973 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014974 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014976 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014977 },
14978 {
14979 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014980 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014981 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014982 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014984 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014985 },
Johannes Bergaff89a92009-07-01 21:26:51 +020014986#ifdef CONFIG_NL80211_TESTMODE
14987 {
14988 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014989 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020014990 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070014991 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014992 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014993 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14994 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020014995 },
14996#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020014997 {
14998 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014999 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020015000 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020015001 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020015002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015003 NL80211_FLAG_NEED_RTNL |
15004 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020015005 },
15006 {
vamsi krishna088e8df2016-10-27 16:51:11 +030015007 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015008 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030015009 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030015010 .flags = GENL_ADMIN_PERM,
15011 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015012 NL80211_FLAG_NEED_RTNL |
15013 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030015014 },
15015 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020015016 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015017 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020015018 .doit = nl80211_disconnect,
Martin Willi5617c6c2016-05-09 18:33:58 +020015019 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020015020 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020015021 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020015022 },
Johannes Berg463d0182009-07-14 00:33:35 +020015023 {
15024 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015025 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020015026 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020015027 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015028 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15029 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020015030 },
Holger Schurig61fa7132009-11-11 12:25:40 +010015031 {
15032 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020015033 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010015034 .dumpit = nl80211_dump_survey,
15035 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015036 {
15037 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020015038 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015039 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020015040 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020015041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015042 NL80211_FLAG_NEED_RTNL |
15043 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015044 },
15045 {
15046 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020015047 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015048 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020015049 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020015050 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020015051 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015052 },
15053 {
15054 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020015055 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015056 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020015057 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020015058 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020015059 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010015060 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015061 {
15062 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015063 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015064 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020015065 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020015066 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020015067 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015068 },
15069 {
15070 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015071 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015072 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020015073 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020015074 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020015075 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015076 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020015077 {
15078 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020015079 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020015080 .doit = nl80211_set_tx_bitrate_mask,
Martin Willi5617c6c2016-05-09 18:33:58 +020015081 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015082 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15083 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020015084 },
Jouni Malinen026331c2010-02-15 12:53:10 +020015085 {
Johannes Berg2e161f782010-08-12 15:38:38 +020015086 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020015088 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020015089 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020015090 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020015091 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020015092 },
15093 {
Johannes Berg2e161f782010-08-12 15:38:38 +020015094 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015095 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020015096 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020015097 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020015098 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020015099 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020015100 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020015101 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010015102 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015103 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010015104 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020015105 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020015106 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010015107 NL80211_FLAG_NEED_RTNL,
15108 },
15109 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020015110 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015111 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015112 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020015113 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015114 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15115 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015116 },
15117 {
15118 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015119 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015120 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015121 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020015122 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15123 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015124 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015125 {
15126 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020015127 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015128 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020015129 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015130 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15131 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015132 },
Johannes Bergf444de02010-05-05 15:25:02 +020015133 {
15134 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015135 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020015136 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020015137 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015138 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15139 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020015140 },
Bill Jordane8347eb2010-10-01 13:54:28 -040015141 {
15142 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020015143 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040015144 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020015145 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020015146 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15147 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040015148 },
Johannes Berg29cbe682010-12-03 09:20:44 +010015149 {
15150 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015151 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010015152 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020015153 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010015154 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15155 NL80211_FLAG_NEED_RTNL,
15156 },
15157 {
15158 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015159 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010015160 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020015161 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010015162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15163 NL80211_FLAG_NEED_RTNL,
15164 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015165 {
15166 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020015167 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015168 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020015169 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15171 NL80211_FLAG_NEED_RTNL,
15172 },
15173 {
15174 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020015175 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015176 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020015177 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15179 NL80211_FLAG_NEED_RTNL,
15180 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020015181#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020015182 {
15183 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020015184 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015185 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015186 /* 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 Bergef6243a2019-04-26 14:07:31 +020015192 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015193 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020015194 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015195 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15196 NL80211_FLAG_NEED_RTNL,
15197 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020015198#endif
Johannes Berge5497d72011-07-05 16:35:40 +020015199 {
15200 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020015201 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020015202 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020015203 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020015204 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030015205 NL80211_FLAG_NEED_RTNL |
15206 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020015207 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030015208 {
15209 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015210 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015211 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020015212 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015213 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15214 NL80211_FLAG_NEED_RTNL,
15215 },
15216 {
15217 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020015218 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015219 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020015220 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15222 NL80211_FLAG_NEED_RTNL,
15223 },
Johannes Berg28946da2011-11-04 11:18:12 +010015224 {
15225 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015226 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010015227 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020015228 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010015229 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15230 NL80211_FLAG_NEED_RTNL,
15231 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010015232 {
15233 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015234 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010015235 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020015236 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020015237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010015238 NL80211_FLAG_NEED_RTNL,
15239 },
Johannes Berg5e760232011-11-04 11:18:17 +010015240 {
15241 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015242 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010015243 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020015244 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010015245 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15246 NL80211_FLAG_NEED_RTNL,
15247 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010015248 {
15249 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020015250 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010015251 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020015252 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010015253 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15254 NL80211_FLAG_NEED_RTNL,
15255 },
Johannes Berg98104fde2012-06-16 00:19:54 +020015256 {
15257 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015258 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020015259 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020015260 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020015261 .internal_flags = NL80211_FLAG_NEED_WDEV |
15262 NL80211_FLAG_NEED_RTNL,
15263 },
15264 {
15265 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015266 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020015267 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020015268 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020015269 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15270 NL80211_FLAG_NEED_RTNL,
15271 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015272 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015273 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020015274 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015275 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015276 .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 Bergef6243a2019-04-26 14:07:31 +020015282 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015283 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015284 .flags = GENL_ADMIN_PERM,
15285 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15286 NL80211_FLAG_NEED_RTNL,
15287 },
15288 {
Ayala Bekera442b762016-09-20 17:31:15 +030015289 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020015290 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030015291 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030015292 .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 Bergef6243a2019-04-26 14:07:31 +020015298 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030015299 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030015300 .flags = GENL_ADMIN_PERM,
15301 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15302 NL80211_FLAG_NEED_RTNL,
15303 },
15304 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030015305 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020015306 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030015307 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030015308 .flags = GENL_ADMIN_PERM,
15309 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15310 NL80211_FLAG_NEED_RTNL,
15311 },
15312 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015313 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015314 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015315 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020015316 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015317 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15318 NL80211_FLAG_NEED_RTNL,
15319 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053015320 {
15321 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015322 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053015323 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020015324 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053015325 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15326 NL80211_FLAG_NEED_RTNL,
15327 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010015328 {
15329 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015330 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015331 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020015332 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015333 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15334 NL80211_FLAG_NEED_RTNL,
15335 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010015336 {
15337 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020015338 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010015339 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010015340 },
Jouni Malinen355199e2013-02-27 17:14:27 +020015341 {
15342 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020015343 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020015344 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020015345 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020015346 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15347 NL80211_FLAG_NEED_RTNL,
15348 },
Arend van Spriel5de17982013-04-18 15:49:00 +020015349 {
15350 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020015351 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020015352 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020015353 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020015354 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15355 NL80211_FLAG_NEED_RTNL,
15356 },
15357 {
15358 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020015359 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020015360 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020015361 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020015362 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15363 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015364 },
15365 {
15366 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015367 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015368 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015369 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15370 NL80211_FLAG_NEED_RTNL,
15371 },
15372 {
15373 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015374 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015375 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020015376 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015377 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15378 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020015379 },
15380 {
15381 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015382 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020015383 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020015384 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020015385 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15386 NL80211_FLAG_NEED_RTNL,
15387 },
Johannes Bergad7e7182013-11-13 13:37:47 +010015388 {
15389 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020015390 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010015391 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030015392 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020015393 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010015394 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015395 NL80211_FLAG_NEED_RTNL |
15396 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010015397 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080015398 {
15399 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020015400 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080015401 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020015402 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080015403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15404 NL80211_FLAG_NEED_RTNL,
15405 },
Johannes Berg960d01a2014-09-09 22:55:35 +030015406 {
15407 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015408 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030015409 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020015410 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030015411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15412 NL80211_FLAG_NEED_RTNL,
15413 },
15414 {
15415 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030015417 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020015418 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030015419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15420 NL80211_FLAG_NEED_RTNL,
15421 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020015422 {
15423 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015424 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015425 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020015426 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15428 NL80211_FLAG_NEED_RTNL,
15429 },
15430 {
15431 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015432 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015433 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020015434 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15436 NL80211_FLAG_NEED_RTNL,
15437 },
Michael Braunce0ce132016-10-10 19:12:22 +020015438 {
15439 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020015440 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020015441 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020015442 .flags = GENL_UNS_ADMIN_PERM,
15443 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15444 NL80211_FLAG_NEED_RTNL,
15445 },
Avraham Stern3a00df52017-06-09 13:08:43 +010015446 {
15447 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020015448 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010015449 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010015450 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015451 NL80211_FLAG_NEED_RTNL |
15452 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010015453 },
15454 {
15455 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020015456 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010015457 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010015458 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15459 NL80211_FLAG_NEED_RTNL,
15460 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015461 {
15462 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015463 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015464 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015465 .flags = GENL_ADMIN_PERM,
15466 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15467 NL80211_FLAG_NEED_RTNL,
15468 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015469 {
15470 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015471 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015472 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015473 .flags = GENL_UNS_ADMIN_PERM,
15474 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15475 NL80211_FLAG_NEED_RTNL,
15476 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015477 {
15478 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015479 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015480 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015481 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15482 NL80211_FLAG_NEED_RTNL,
15483 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015484 {
15485 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020015486 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015487 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015488 .flags = GENL_UNS_ADMIN_PERM,
15489 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15490 NL80211_FLAG_NEED_RTNL,
15491 },
Sriram R30c63112018-12-04 17:46:52 +053015492 {
15493 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020015494 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053015495 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053015496 .flags = GENL_UNS_ADMIN_PERM,
15497 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15498 NL80211_FLAG_NEED_RTNL,
15499 },
Sunil Duttcb74e972019-02-20 16:18:07 +053015500 {
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 Manoharan5ab92e72019-04-11 13:47:24 -070015507 {
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 chelvam77f576d2020-01-20 13:21:22 +053015514 {
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 Berg55682962007-09-20 13:09:35 -040015521};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015522
Johannes Berg56989f62016-10-24 14:40:05 +020015523static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020015524 .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 Berg3b0f31f2019-03-21 22:51:02 +010015528 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020015529 .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 Kicinski66a9b922020-10-02 14:49:54 -070015535 .small_ops = nl80211_small_ops,
15536 .n_small_ops = ARRAY_SIZE(nl80211_small_ops),
Johannes Berg489111e2016-10-24 14:40:03 +020015537 .mcgrps = nl80211_mcgrps,
15538 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
Johannes Berg50508d92019-07-29 16:31:09 +020015539 .parallel_ops = true,
Johannes Berg489111e2016-10-24 14:40:03 +020015540};
15541
Johannes Berg55682962007-09-20 13:09:35 -040015542/* notification functions */
15543
Johannes Berg3bb20552014-05-26 13:52:25 +020015544void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
15545 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040015546{
15547 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020015548 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040015549
Johannes Berg3bb20552014-05-26 13:52:25 +020015550 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
15551 cmd != NL80211_CMD_DEL_WIPHY);
15552
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015553 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040015554 if (!msg)
15555 return;
15556
Johannes Berg3bb20552014-05-26 13:52:25 +020015557 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040015558 nlmsg_free(msg);
15559 return;
15560 }
15561
Johannes Berg68eb5502013-11-19 15:19:38 +010015562 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015563 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040015564}
15565
Denis Kenzior896ff062016-08-03 16:58:33 -050015566void 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 Kenzior896ff062016-08-03 16:58:33 -050015572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15573 if (!msg)
15574 return;
15575
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020015576 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050015577 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 Berg362a4152009-05-24 16:43:15 +020015585static 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 Mussaic8cb5b82020-09-18 11:33:13 +020015591 struct cfg80211_scan_info *info;
Johannes Berg362a4152009-05-24 16:43:15 +020015592
15593 if (WARN_ON(!req))
15594 return 0;
15595
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015596 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020015597 if (!nest)
15598 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040015599 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 Berg362a4152009-05-24 16:43:15 +020015603 nla_nest_end(msg, nest);
15604
Thomas Pedersen2032f3b2020-04-30 10:25:52 -070015605 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
15606 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
15607 if (!nest)
David S. Miller9360ffd2012-03-29 04:41:26 -040015608 goto nla_put_failure;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -070015609 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. Miller9360ffd2012-03-29 04:41:26 -040015625 }
Johannes Berg362a4152009-05-24 16:43:15 +020015626
David S. Miller9360ffd2012-03-29 04:41:26 -040015627 if (req->ie &&
15628 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
15629 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020015630
Johannes Bergae917c92013-10-25 11:05:22 +020015631 if (req->flags &&
15632 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
15633 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070015634
Tova Mussaic8cb5b82020-09-18 11:33:13 +020015635 info = rdev->int_scan_req ? &rdev->int_scan_req->info :
15636 &rdev->scan_req->info;
15637 if (info->scan_start_tsf &&
Avraham Stern1d762502016-07-05 17:10:13 +030015638 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
Tova Mussaic8cb5b82020-09-18 11:33:13 +020015639 info->scan_start_tsf, NL80211_BSS_PAD) ||
Avraham Stern1d762502016-07-05 17:10:13 +030015640 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
Tova Mussaic8cb5b82020-09-18 11:33:13 +020015641 info->tsf_bssid)))
Avraham Stern1d762502016-07-05 17:10:13 +030015642 goto nla_put_failure;
15643
Johannes Berg362a4152009-05-24 16:43:15 +020015644 return 0;
15645 nla_put_failure:
15646 return -ENOBUFS;
15647}
15648
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015649static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020015650 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020015651 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015652 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020015653 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010015654{
15655 void *hdr;
15656
Eric W. Biederman15e47302012-09-07 20:12:54 +000015657 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010015658 if (!hdr)
15659 return -1;
15660
David S. Miller9360ffd2012-03-29 04:41:26 -040015661 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020015662 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15663 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015664 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15665 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015666 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010015667
Johannes Berg362a4152009-05-24 16:43:15 +020015668 /* ignore errors and send incomplete event anyway */
15669 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010015670
Johannes Berg053c0952015-01-16 22:09:00 +010015671 genlmsg_end(msg, hdr);
15672 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010015673
15674 nla_put_failure:
15675 genlmsg_cancel(msg, hdr);
15676 return -EMSGSIZE;
15677}
15678
Luciano Coelho807f8a82011-05-11 17:09:35 +030015679static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015680nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015681 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030015682{
15683 void *hdr;
15684
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015685 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015686 if (!hdr)
15687 return -1;
15688
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015689 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. Miller9360ffd2012-03-29 04:41:26 -040015694 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030015695
Johannes Berg053c0952015-01-16 22:09:00 +010015696 genlmsg_end(msg, hdr);
15697 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030015698
15699 nla_put_failure:
15700 genlmsg_cancel(msg, hdr);
15701 return -EMSGSIZE;
15702}
15703
Johannes Berga538e2d2009-06-16 19:56:42 +020015704void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020015705 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020015706{
15707 struct sk_buff *msg;
15708
Thomas Graf58050fc2012-06-28 03:57:45 +000015709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020015710 if (!msg)
15711 return;
15712
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015713 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020015714 NL80211_CMD_TRIGGER_SCAN) < 0) {
15715 nlmsg_free(msg);
15716 return;
15717 }
15718
Johannes Berg68eb5502013-11-19 15:19:38 +010015719 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015720 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020015721}
15722
Johannes Bergf9d15d12014-01-22 11:14:19 +020015723struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
15724 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010015725{
15726 struct sk_buff *msg;
15727
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010015729 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020015730 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010015731
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015732 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020015733 aborted ? NL80211_CMD_SCAN_ABORTED :
15734 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010015735 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020015736 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010015737 }
15738
Johannes Bergf9d15d12014-01-22 11:14:19 +020015739 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010015740}
15741
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015742/* send message created by nl80211_build_scan_msg() */
15743void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
15744 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010015745{
Johannes Berg2a519312009-02-10 21:25:55 +010015746 if (!msg)
15747 return;
15748
Johannes Berg68eb5502013-11-19 15:19:38 +010015749 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015750 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010015751}
15752
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015753void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030015754{
15755 struct sk_buff *msg;
15756
Thomas Graf58050fc2012-06-28 03:57:45 +000015757 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015758 if (!msg)
15759 return;
15760
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015761 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030015762 nlmsg_free(msg);
15763 return;
15764 }
15765
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015766 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015767 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015768}
15769
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015770static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
15771 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015772{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015773 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040015774 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
15775 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015776
David S. Miller9360ffd2012-03-29 04:41:26 -040015777 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. Rodriguez73d54c92009-03-09 22:07:42 -040015796 }
15797
Arik Nemtsovad30ca22014-12-15 19:25:59 +020015798 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 Nemtsov1bdd7162014-12-15 19:26:01 +020015804
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 Nemtsovad30ca22014-12-15 19:25:59 +020015809 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015810
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015811 return true;
15812
15813nla_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 */
15821void 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 jiang24f6d762019-09-05 12:25:37 +080015832 if (!hdr)
15833 goto nla_put_failure;
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015834
zhong jiang24f6d762019-09-05 12:25:37 +080015835 if (!nl80211_reg_change_event_fill(msg, request))
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015836 goto nla_put_failure;
15837
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015838 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015839
Johannes Bergbc43b282009-07-25 10:54:13 +020015840 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015841 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015842 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020015843 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015844
15845 return;
15846
15847nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015848 nlmsg_free(msg);
15849}
15850
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015851static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15852 struct net_device *netdev,
15853 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015854 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015855 int uapsd_queues, const u8 *req_ies,
15856 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015857{
15858 struct sk_buff *msg;
15859 void *hdr;
15860
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015861 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015862 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. Miller9360ffd2012-03-29 04:41:26 -040015871 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15872 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015873 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. Miller9360ffd2012-03-29 04:41:26 -040015876 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015877
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015878 if (uapsd_queues >= 0) {
15879 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015880 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015881 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 Berg3b7b72e2011-10-22 19:05:51 +020015891 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015892
Johannes Berg68eb5502013-11-19 15:19:38 +010015893 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015894 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015895 return;
15896
15897 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015898 nlmsg_free(msg);
15899}
15900
15901void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015902 struct net_device *netdev, const u8 *buf,
15903 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015904{
15905 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015906 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015907}
15908
15909void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15910 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015911 size_t len, gfp_t gfp, int uapsd_queues,
15912 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015913{
Johannes Berge6d6e342009-07-01 21:26:47 +020015914 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015915 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15916 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015917}
15918
Jouni Malinen53b46b82009-03-27 20:53:56 +020015919void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015920 struct net_device *netdev, const u8 *buf,
15921 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015922{
15923 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015924 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015925}
15926
Jouni Malinen53b46b82009-03-27 20:53:56 +020015927void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15928 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020015929 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015930{
15931 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015932 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015933}
15934
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015935void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15936 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020015937{
Johannes Berg947add32013-02-22 22:05:20 +010015938 struct wireless_dev *wdev = dev->ieee80211_ptr;
15939 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015940 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015941 const struct ieee80211_mgmt *mgmt = (void *)buf;
15942 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020015943
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015944 if (WARN_ON(len < 2))
15945 return;
15946
Jouni Malinen4d797fc2020-04-01 17:25:47 +030015947 if (ieee80211_is_deauth(mgmt->frame_control)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015948 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
Jouni Malinen4d797fc2020-04-01 17:25:47 +030015949 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015950 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
Jouni Malinen4d797fc2020-04-01 17:25:47 +030015951 } 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 Berg6ff57cf2013-05-16 00:55:00 +020015960
15961 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015962 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15963 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015964}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015965EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015966
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040015967static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15968 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020015969 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015970{
15971 struct sk_buff *msg;
15972 void *hdr;
15973
Johannes Berge6d6e342009-07-01 21:26:47 +020015974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015975 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. Miller9360ffd2012-03-29 04:41:26 -040015984 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 Malinen1965c852009-04-22 21:38:25 +030015989
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015990 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030015991
Johannes Berg68eb5502013-11-19 15:19:38 +010015992 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015993 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015994 return;
15995
15996 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030015997 nlmsg_free(msg);
15998}
15999
16000void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020016001 struct net_device *netdev, const u8 *addr,
16002 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030016003{
16004 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020016005 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030016006}
16007
16008void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020016009 struct net_device *netdev, const u8 *addr,
16010 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030016011{
Johannes Berge6d6e342009-07-01 21:26:47 +020016012 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
16013 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030016014}
16015
Samuel Ortizb23aa672009-07-01 21:26:54 +020016016void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030016017 struct net_device *netdev,
16018 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020016019 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020016020{
16021 struct sk_buff *msg;
16022 void *hdr;
16023
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030016024 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020016025 cr->fils.kek_len + cr->fils.pmk_len +
16026 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016027 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. Miller9360ffd2012-03-29 04:41:26 -040016036 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16037 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030016038 (cr->bssid &&
16039 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030016040 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030016041 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
16042 cr->status) ||
16043 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020016044 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030016045 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 Kanchanapallya3caf742017-03-31 00:22:34 +030016051 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020016052 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030016053 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020016054 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030016055 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020016056 ((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. Miller9360ffd2012-03-29 04:41:26 -040016063 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020016064
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016065 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016066
Johannes Berg68eb5502013-11-19 15:19:38 +010016067 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016068 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016069 return;
16070
16071 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020016072 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016073}
16074
16075void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030016076 struct net_device *netdev,
16077 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020016078{
16079 struct sk_buff *msg;
16080 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030016081 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020016082
Arend Van Spriele841b7b2018-05-22 10:19:07 +020016083 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 Ortizb23aa672009-07-01 21:26:54 +020016086 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. Miller9360ffd2012-03-29 04:41:26 -040016095 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 Stern29ce6ec2017-04-26 10:58:49 +030016098 (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 Spriele841b7b2018-05-22 10:19:07 +020016103 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. Miller9360ffd2012-03-29 04:41:26 -040016114 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020016115
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016116 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016117
Johannes Berg68eb5502013-11-19 15:19:38 +010016118 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016119 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016120 return;
16121
16122 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020016123 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016124}
16125
Avraham Stern503c1fb2017-09-29 14:21:49 +020016126void 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 Hsuf4d75992019-05-09 09:48:25 +000016142 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 Stern503c1fb2017-09-29 14:21:49 +020016145 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 Stern503c1fb2017-09-29 14:21:49 +020016154 nlmsg_free(msg);
16155}
16156
Samuel Ortizb23aa672009-07-01 21:26:54 +020016157void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
16158 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020016159 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020016160{
16161 struct sk_buff *msg;
16162 void *hdr;
16163
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016164 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016165 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. Miller9360ffd2012-03-29 04:41:26 -040016174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020016176 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040016177 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 Ortizb23aa672009-07-01 21:26:54 +020016182
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016183 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016184
Johannes Berg68eb5502013-11-19 15:19:38 +010016185 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016186 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016187 return;
16188
16189 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020016190 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016191}
16192
Johannes Berg04a773a2009-04-19 21:24:32 +020016193void 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 Ayusofd2120c2009-05-19 15:27:55 -070016200 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020016201 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. Miller9360ffd2012-03-29 04:41:26 -040016210 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 Berg04a773a2009-04-19 21:24:32 +020016214
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016215 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020016216
Johannes Berg68eb5502013-11-19 15:19:38 +010016217 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016218 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020016219 return;
16220
16221 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020016222 nlmsg_free(msg);
16223}
16224
Johannes Berg947add32013-02-22 22:05:20 +010016225void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040016226 const u8 *ie, u8 ie_len,
16227 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070016228{
Johannes Berg947add32013-02-22 22:05:20 +010016229 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016230 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016231 struct sk_buff *msg;
16232 void *hdr;
16233
Johannes Berg947add32013-02-22 22:05:20 +010016234 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
16235 return;
16236
16237 trace_cfg80211_notify_new_peer_candidate(dev, addr);
16238
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016239 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016240 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. Miller9360ffd2012-03-29 04:41:26 -040016249 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010016250 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16251 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016252 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040016253 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. Miller9360ffd2012-03-29 04:41:26 -040016256 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070016257
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016258 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016259
Johannes Berg68eb5502013-11-19 15:19:38 +010016260 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016261 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016262 return;
16263
16264 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070016265 nlmsg_free(msg);
16266}
Johannes Berg947add32013-02-22 22:05:20 +010016267EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016268
Jouni Malinena3b8b052009-03-27 21:59:49 +020016269void 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 Berge6d6e342009-07-01 21:26:47 +020016272 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020016273{
16274 struct sk_buff *msg;
16275 void *hdr;
16276
Johannes Berge6d6e342009-07-01 21:26:47 +020016277 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020016278 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. Miller9360ffd2012-03-29 04:41:26 -040016287 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 Malinena3b8b052009-03-27 21:59:49 +020016295
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016296 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020016297
Johannes Berg68eb5502013-11-19 15:19:38 +010016298 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016299 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020016300 return;
16301
16302 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020016303 nlmsg_free(msg);
16304}
16305
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016306void 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 Ayusofd2120c2009-05-19 15:27:55 -070016314 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016315 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. Miller9360ffd2012-03-29 04:41:26 -040016328 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
16329 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016330
16331 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016332 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016333 if (!nl_freq)
16334 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030016335
16336 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016337 goto nla_put_failure;
16338 nla_nest_end(msg, nl_freq);
16339
16340 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016341 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016342 if (!nl_freq)
16343 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030016344
16345 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016346 goto nla_put_failure;
16347 nla_nest_end(msg, nl_freq);
16348
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016349 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016350
Johannes Berg463d0182009-07-14 00:33:35 +020016351 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010016352 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016353 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020016354 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016355
16356 return;
16357
16358nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016359 nlmsg_free(msg);
16360}
16361
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016362static void nl80211_send_remain_on_chan_event(
16363 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020016364 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016365 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016366 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. Miller9360ffd2012-03-29 04:41:26 -040016381 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016382 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16383 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016384 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16385 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016386 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010016387 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
16388 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016389 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16390 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040016391 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016392
David S. Miller9360ffd2012-03-29 04:41:26 -040016393 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
16394 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
16395 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016396
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016397 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016398
Johannes Berg68eb5502013-11-19 15:19:38 +010016399 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016400 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016401 return;
16402
16403 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016404 nlmsg_free(msg);
16405}
16406
Johannes Berg947add32013-02-22 22:05:20 +010016407void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
16408 struct ieee80211_channel *chan,
16409 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016410{
Johannes Berg947add32013-02-22 22:05:20 +010016411 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016412 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016413
16414 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016415 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020016416 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010016417 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016418}
Johannes Berg947add32013-02-22 22:05:20 +010016419EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016420
Johannes Berg947add32013-02-22 22:05:20 +010016421void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
16422 struct ieee80211_channel *chan,
16423 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016424{
Johannes Berg947add32013-02-22 22:05:20 +010016425 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016426 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016427
16428 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016429 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010016430 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016431}
Johannes Berg947add32013-02-22 22:05:20 +010016432EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016433
James Prestwood1c38c7f2019-06-12 12:35:09 -070016434void 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}
16445EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
16446
Johannes Berg947add32013-02-22 22:05:20 +010016447void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
16448 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010016449{
Johannes Berg947add32013-02-22 22:05:20 +010016450 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016451 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010016452 struct sk_buff *msg;
16453
Johannes Berg947add32013-02-22 22:05:20 +010016454 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
16455
Thomas Graf58050fc2012-06-28 03:57:45 +000016456 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010016457 if (!msg)
16458 return;
16459
Johannes Bergcf5ead82014-11-14 17:14:00 +010016460 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040016461 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010016462 nlmsg_free(msg);
16463 return;
16464 }
16465
Johannes Berg68eb5502013-11-19 15:19:38 +010016466 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016467 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010016468}
Johannes Berg947add32013-02-22 22:05:20 +010016469EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010016470
Johannes Bergcf5ead82014-11-14 17:14:00 +010016471void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
16472 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020016473{
Johannes Berg947add32013-02-22 22:05:20 +010016474 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016475 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020016476 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020016477 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010016478
Johannes Berg73887fd2018-05-18 09:57:55 +020016479 if (!sinfo)
16480 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020016481
Johannes Berg947add32013-02-22 22:05:20 +010016482 trace_cfg80211_del_sta(dev, mac_addr);
16483
Thomas Graf58050fc2012-06-28 03:57:45 +000016484 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020016485 if (!msg) {
16486 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020016487 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020016488 }
Jouni Malinenec15e682011-03-23 15:29:52 +020016489
Johannes Bergcf5ead82014-11-14 17:14:00 +010016490 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010016491 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020016492 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020016493 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020016494 }
16495
Johannes Berg68eb5502013-11-19 15:19:38 +010016496 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016497 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020016498}
Johannes Bergcf5ead82014-11-14 17:14:00 +010016499EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020016500
Johannes Berg947add32013-02-22 22:05:20 +010016501void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
16502 enum nl80211_connect_failed_reason reason,
16503 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016504{
Johannes Berg947add32013-02-22 22:05:20 +010016505 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016506 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016507 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 Berg68eb5502013-11-19 15:19:38 +010016527 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016528 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016529 return;
16530
16531 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016532 nlmsg_free(msg);
16533}
Johannes Berg947add32013-02-22 22:05:20 +010016534EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016535
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016536static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
16537 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010016538{
16539 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016540 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010016541 struct sk_buff *msg;
16542 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070016543 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010016544
Eric W. Biederman15e47302012-09-07 20:12:54 +000016545 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010016546 return false;
16547
16548 msg = nlmsg_new(100, gfp);
16549 if (!msg)
16550 return true;
16551
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016552 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010016553 if (!hdr) {
16554 nlmsg_free(msg);
16555 return true;
16556 }
16557
David S. Miller9360ffd2012-03-29 04:41:26 -040016558 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 Berg28946da2011-11-04 11:18:12 +010016562
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016563 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000016564 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010016565 return true;
16566
16567 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010016568 nlmsg_free(msg);
16569 return true;
16570}
16571
Johannes Berg947add32013-02-22 22:05:20 +010016572bool cfg80211_rx_spurious_frame(struct net_device *dev,
16573 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016574{
Johannes Berg947add32013-02-22 22:05:20 +010016575 struct wireless_dev *wdev = dev->ieee80211_ptr;
16576 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016577
Johannes Berg947add32013-02-22 22:05:20 +010016578 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 Bergb92ab5d2011-11-04 11:18:19 +010016589}
Johannes Berg947add32013-02-22 22:05:20 +010016590EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
16591
16592bool 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}
16612EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016613
Johannes Berg2e161f782010-08-12 15:38:38 +020016614int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000016615 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010016616 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030016617 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020016618{
Johannes Berg71bbc992012-06-15 15:30:18 +020016619 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020016620 struct sk_buff *msg;
16621 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020016622
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016623 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016624 if (!msg)
16625 return -ENOMEM;
16626
Johannes Berg2e161f782010-08-12 15:38:38 +020016627 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020016628 if (!hdr) {
16629 nlmsg_free(msg);
16630 return -ENOMEM;
16631 }
16632
David S. Miller9360ffd2012-03-29 04:41:26 -040016633 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016634 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16635 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016636 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16637 NL80211_ATTR_PAD) ||
Thomas Pedersene76fede2020-04-30 10:25:50 -070016638 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) ||
Thomas Pedersen942ba882020-04-30 10:25:51 -070016639 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016640 (sig_dbm &&
16641 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030016642 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16643 (flags &&
16644 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016645 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020016646
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016647 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020016648
Eric W. Biederman15e47302012-09-07 20:12:54 +000016649 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020016650
16651 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020016652 nlmsg_free(msg);
16653 return -ENOBUFS;
16654}
16655
Markus Theildca9ca22020-05-08 16:42:00 +020016656static 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 Malinen026331c2010-02-15 12:53:10 +020016659{
Johannes Berg947add32013-02-22 22:05:20 +010016660 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020016662 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020016663 struct sk_buff *msg;
16664 void *hdr;
16665
Markus Theildca9ca22020-05-08 16:42:00 +020016666 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 Berg947add32013-02-22 22:05:20 +010016670
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016671 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016672 if (!msg)
16673 return;
16674
Markus Theildca9ca22020-05-08 16:42:00 +020016675 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
Jouni Malinen026331c2010-02-15 12:53:10 +020016676 if (!hdr) {
16677 nlmsg_free(msg);
16678 return;
16679 }
16680
David S. Miller9360ffd2012-03-29 04:41:26 -040016681 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016682 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16683 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016684 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16685 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016686 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016687 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16688 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016689 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
16690 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020016691
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016692 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020016693
Johannes Berg68eb5502013-11-19 15:19:38 +010016694 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016695 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016696 return;
16697
Markus Theildca9ca22020-05-08 16:42:00 +020016698nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020016699 nlmsg_free(msg);
16700}
Markus Theildca9ca22020-05-08 16:42:00 +020016701
16702void 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}
16709EXPORT_SYMBOL(cfg80211_control_port_tx_status);
16710
16711void 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 Berg947add32013-02-22 22:05:20 +010016717EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020016718
Denis Kenzior6a671a52018-03-26 12:52:41 -050016719static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050016720 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050016721 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 Kenziora948f712018-07-03 15:05:48 -050016725 struct ethhdr *ehdr = eth_hdr(skb);
Johannes Berg8d74a622020-02-24 10:19:12 +010016726 const u8 *addr = ehdr->h_source;
Denis Kenziora948f712018-07-03 15:05:48 -050016727 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016728 struct sk_buff *msg;
16729 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050016730 struct nlattr *frame;
16731
Denis Kenzior6a671a52018-03-26 12:52:41 -050016732 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
16733
16734 if (!nlportid)
16735 return -ENOENT;
16736
Denis Kenziora948f712018-07-03 15:05:48 -050016737 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016738 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 Berg8d74a622020-02-24 10:19:12 +010016751 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050016752 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 Kenziora948f712018-07-03 15:05:48 -050016757 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 Kenzior6a671a52018-03-26 12:52:41 -050016762 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
16771bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050016772 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050016773{
16774 int ret;
16775
Denis Kenziora948f712018-07-03 15:05:48 -050016776 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
16777 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016778 trace_cfg80211_return_bool(ret == 0);
16779 return ret == 0;
16780}
16781EXPORT_SYMBOL(cfg80211_rx_control_port);
16782
Johannes Berg5b97f492014-11-26 12:37:43 +010016783static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
16784 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016785{
Johannes Berg947add32013-02-22 22:05:20 +010016786 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010016787 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 Oikarinend6dc1a32010-03-23 09:02:33 +020016790
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016791 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010016792 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016793
Johannes Berg5b97f492014-11-26 12:37:43 +010016794 cb = (void **)msg->cb;
16795
16796 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
16797 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016798 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010016799 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016800 }
16801
David S. Miller9360ffd2012-03-29 04:41:26 -040016802 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010016803 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040016804 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016805
Johannes Berg5b97f492014-11-26 12:37:43 +010016806 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016807 goto nla_put_failure;
16808
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016809 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010016810 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
16821static 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
16835void cfg80211_cqm_rssi_notify(struct net_device *dev,
16836 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016837 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010016838{
16839 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010016840 struct wireless_dev *wdev = dev->ieee80211_ptr;
16841 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010016842
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016843 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010016844
Johannes Berg98f03342014-11-26 12:42:02 +010016845 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
16846 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
16847 return;
16848
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010016849 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 Berg5b97f492014-11-26 12:37:43 +010016858 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16859 if (!msg)
16860 return;
16861
David S. Miller9360ffd2012-03-29 04:41:26 -040016862 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16863 rssi_event))
16864 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016865
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016866 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16867 rssi_level))
16868 goto nla_put_failure;
16869
Johannes Berg5b97f492014-11-26 12:37:43 +010016870 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016871
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016872 return;
16873
16874 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016875 nlmsg_free(msg);
16876}
Johannes Berg947add32013-02-22 22:05:20 +010016877EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016878
Johannes Berg5b97f492014-11-26 12:37:43 +010016879void 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}
16904EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16905
16906void 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}
16926EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16927
Johannes Berg98f03342014-11-26 12:42:02 +010016928void 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}
16945EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16946
Johannes Berg947add32013-02-22 22:05:20 +010016947static 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 Berge5497d72011-07-05 16:35:40 +020016950{
16951 struct sk_buff *msg;
16952 struct nlattr *rekey_attr;
16953 void *hdr;
16954
Thomas Graf58050fc2012-06-28 03:57:45 +000016955 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016956 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. Miller9360ffd2012-03-29 04:41:26 -040016965 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 Berge5497d72011-07-05 16:35:40 +020016969
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016970 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020016971 if (!rekey_attr)
16972 goto nla_put_failure;
16973
David S. Miller9360ffd2012-03-29 04:41:26 -040016974 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16975 NL80211_REPLAY_CTR_LEN, replay_ctr))
16976 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016977
16978 nla_nest_end(msg, rekey_attr);
16979
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016980 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020016981
Johannes Berg68eb5502013-11-19 15:19:38 +010016982 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016983 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016984 return;
16985
16986 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020016987 nlmsg_free(msg);
16988}
16989
Johannes Berg947add32013-02-22 22:05:20 +010016990void 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, Gangf26cbf42014-04-21 12:53:03 +080016995 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016996
16997 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16998 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16999}
17000EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
17001
17002static void
17003nl80211_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 Malinenc9df56b2011-09-16 18:56:23 +030017006{
17007 struct sk_buff *msg;
17008 struct nlattr *attr;
17009 void *hdr;
17010
Thomas Graf58050fc2012-06-28 03:57:45 +000017011 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030017012 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. Miller9360ffd2012-03-29 04:41:26 -040017021 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 Malinenc9df56b2011-09-16 18:56:23 +030017024
Michal Kubecekae0be8d2019-04-26 11:13:06 +020017025 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030017026 if (!attr)
17027 goto nla_put_failure;
17028
David S. Miller9360ffd2012-03-29 04:41:26 -040017029 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 Malinenc9df56b2011-09-16 18:56:23 +030017034
17035 nla_nest_end(msg, attr);
17036
Johannes Berg3b7b72e2011-10-22 19:05:51 +020017037 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030017038
Johannes Berg68eb5502013-11-19 15:19:38 +010017039 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017040 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030017041 return;
17042
17043 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030017044 nlmsg_free(msg);
17045}
17046
Johannes Berg947add32013-02-22 22:05:20 +010017047void 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, Gangf26cbf42014-04-21 12:53:03 +080017052 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010017053
17054 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
17055 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
17056}
17057EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
17058
17059static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
17060 struct net_device *netdev,
17061 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020017062 gfp_t gfp,
17063 enum nl80211_commands notif,
17064 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070017065{
17066 struct sk_buff *msg;
17067 void *hdr;
17068
Thomas Graf58050fc2012-06-28 03:57:45 +000017069 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070017070 if (!msg)
17071 return;
17072
Luciano Coelhof8d75522014-11-07 14:31:35 +020017073 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070017074 if (!hdr) {
17075 nlmsg_free(msg);
17076 return;
17077 }
17078
Johannes Berg683b6d32012-11-08 21:25:48 +010017079 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. Linville7eab0f62012-04-12 14:25:14 -040017083 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070017084
Luciano Coelhof8d75522014-11-07 14:31:35 +020017085 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 Pedersen53145262012-04-06 13:35:47 -070017089 genlmsg_end(msg, hdr);
17090
Johannes Berg68eb5502013-11-19 15:19:38 +010017091 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017092 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070017093 return;
17094
17095 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070017096 nlmsg_free(msg);
17097}
17098
Johannes Berg947add32013-02-22 22:05:20 +010017099void cfg80211_ch_switch_notify(struct net_device *dev,
17100 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070017101{
Johannes Berg947add32013-02-22 22:05:20 +010017102 struct wireless_dev *wdev = dev->ieee80211_ptr;
17103 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017104 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010017105
Simon Wunderliche487eae2013-11-21 18:19:51 +010017106 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010017107
Simon Wunderliche487eae2013-11-21 18:19:51 +010017108 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010017109
Michal Kazior9e0e2962014-01-29 14:22:27 +010017110 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010017111 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000017112
17113 if (wdev->iftype == NL80211_IFTYPE_STATION &&
17114 !WARN_ON(!wdev->current_bss))
Sergey Matyukevich0afd4252019-07-26 16:39:34 +000017115 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000017116
Michael Vassernisd34990b2019-07-29 06:01:16 +000017117 cfg80211_sched_dfs_chan_update(rdev);
17118
Luciano Coelhof8d75522014-11-07 14:31:35 +020017119 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
17120 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010017121}
17122EXPORT_SYMBOL(cfg80211_ch_switch_notify);
17123
Luciano Coelhof8d75522014-11-07 14:31:35 +020017124void 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}
17137EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
17138
Thomas Pedersen84f10702012-07-12 16:17:33 -070017139void
Simon Wunderlich04f39042013-02-08 18:16:19 +010017140nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010017141 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010017142 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 Dichtel2dad6242016-04-25 10:25:22 +020017166 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17167 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010017168 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 Berg9c90a9f2013-06-04 12:46:03 +020017177 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010017178
Johannes Berg68eb5502013-11-19 15:19:38 +010017179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017180 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010017181 return;
17182
17183 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010017184 nlmsg_free(msg);
17185}
17186
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053017187void 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 Berg0016d322020-03-25 09:05:32 +010017223 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053017224 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
17237nla_put_failure:
17238 nlmsg_free(msg);
17239}
17240EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
17241
Johannes Berg7f6cf312011-11-04 11:18:15 +010017242void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053017243 u64 cookie, bool acked, s32 ack_signal,
17244 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010017245{
17246 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017247 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010017248 struct sk_buff *msg;
17249 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010017250
Beni Lev4ee3e062012-08-27 12:49:39 +030017251 trace_cfg80211_probe_status(dev, addr, cookie, acked);
17252
Thomas Graf58050fc2012-06-28 03:57:45 +000017253 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030017254
Johannes Berg7f6cf312011-11-04 11:18:15 +010017255 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. Miller9360ffd2012-03-29 04:41:26 -040017264 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 Dichtel2dad6242016-04-25 10:25:22 +020017267 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
17268 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053017269 (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. Miller9360ffd2012-03-29 04:41:26 -040017272 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010017273
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017274 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010017275
Johannes Berg68eb5502013-11-19 15:19:38 +010017276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017277 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010017278 return;
17279
17280 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010017281 nlmsg_free(msg);
17282}
17283EXPORT_SYMBOL(cfg80211_probe_status);
17284
Thomas Pedersene76fede2020-04-30 10:25:50 -070017285void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
17286 size_t len, int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010017287{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017288 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010017289 struct sk_buff *msg;
17290 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070017291 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010017292
Beni Lev4ee3e062012-08-27 12:49:39 +030017293 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
17294
Ben Greear37c73b52012-10-26 14:49:25 -070017295 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 Berg5e760232011-11-04 11:18:17 +010017302
Ben Greear37c73b52012-10-26 14:49:25 -070017303 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
17304 if (!hdr)
17305 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010017306
Ben Greear37c73b52012-10-26 14:49:25 -070017307 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17308 (freq &&
Thomas Pedersen942ba882020-04-30 10:25:51 -070017309 (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 Greear37c73b52012-10-26 14:49:25 -070017313 (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 Berg5e760232011-11-04 11:18:17 +010017321 }
Ben Greear37c73b52012-10-26 14:49:25 -070017322 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017323 return;
17324
17325 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070017326 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017327 nlmsg_free(msg);
17328}
Thomas Pedersene76fede2020-04-30 10:25:50 -070017329EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
Johannes Berg5e760232011-11-04 11:18:17 +010017330
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017331#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017332static 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 Kubecekae0be8d2019-04-26 11:13:06 +020017339 nl_results = nla_nest_start_noflag(msg,
17340 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017341 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 Kubecekae0be8d2019-04-26 11:13:06 +020017347 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017348 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 Kubecekae0be8d2019-04-26 11:13:06 +020017365 nl_freqs = nla_nest_start_noflag(msg,
17366 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017367 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 Tan5528fae82015-02-09 21:29:15 +020017373 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017374 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
17386out:
17387 nla_nest_end(msg, nl_results);
17388 return 0;
17389}
17390
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017391void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
17392 struct cfg80211_wowlan_wakeup *wakeup,
17393 gfp_t gfp)
17394{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017395 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017396 struct sk_buff *msg;
17397 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017398 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017399
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 Dichtel2dad6242016-04-25 10:25:22 +020017414 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17415 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017416 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 Kubecekae0be8d2019-04-26 11:13:06 +020017425 reasons = nla_nest_start_noflag(msg,
17426 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020017427 if (!reasons)
17428 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017429
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 Bergae917c92013-10-25 11:05:22 +020017454 if (wakeup->tcp_match &&
17455 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
17456 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010017457
Johannes Bergae917c92013-10-25 11:05:22 +020017458 if (wakeup->tcp_connlost &&
17459 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
17460 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010017461
Johannes Bergae917c92013-10-25 11:05:22 +020017462 if (wakeup->tcp_nomoretokens &&
17463 nla_put_flag(msg,
17464 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
17465 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010017466
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017467 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 Coelho8cd4d452014-09-17 11:55:28 +030017487 if (wakeup->net_detect &&
17488 cfg80211_net_detect_results(msg, wakeup))
17489 goto free_msg;
17490
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017491 nla_nest_end(msg, reasons);
17492 }
17493
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017494 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017495
Johannes Berg68eb5502013-11-19 15:19:38 +010017496 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017497 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017498 return;
17499
17500 free_msg:
17501 nlmsg_free(msg);
17502}
17503EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
17504#endif
17505
Jouni Malinen3475b092012-11-16 22:49:57 +020017506void 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, Gangf26cbf42014-04-21 12:53:03 +080017511 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020017512 struct sk_buff *msg;
17513 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020017514
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 Berg9c90a9f2013-06-04 12:46:03 +020017536 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020017537
Johannes Berg68eb5502013-11-19 15:19:38 +010017538 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017539 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020017540 return;
17541
17542 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020017543 nlmsg_free(msg);
17544}
17545EXPORT_SYMBOL(cfg80211_tdls_oper_request);
17546
Jouni Malinen026331c2010-02-15 12:53:10 +020017547static 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 Greear37c73b52012-10-26 14:49:25 -070017554 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020017555
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030017556 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020017557 return NOTIFY_DONE;
17558
17559 rcu_read_lock();
17560
Johannes Berg5e760232011-11-04 11:18:17 +010017561 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017562 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020017563
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017564 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 Berg753aacf2017-01-05 10:57:14 +010017569 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017570 }
Johannes Berg753aacf2017-01-05 10:57:14 +010017571 }
Johannes Berg78f22b62014-03-24 17:57:27 +010017572
Johannes Berg53873f12016-05-03 16:52:04 +030017573 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000017574 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070017575
Johannes Bergab810072017-04-26 07:43:41 +020017576 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 Zaborowskibd2522b2017-01-06 16:33:43 -050017580 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020017581 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020017582
17583 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010017584 }
17585
Ben Greear37c73b52012-10-26 14:49:25 -070017586 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(&reg->list);
17591 kfree(reg);
17592 break;
17593 }
17594 }
17595 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017596 }
Jouni Malinen026331c2010-02-15 12:53:10 +020017597
17598 rcu_read_unlock();
17599
Ilan peer05050752015-03-04 00:32:06 -050017600 /*
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, Gang6784c7d2014-04-21 12:53:04 +080017605 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020017606}
17607
17608static struct notifier_block nl80211_netlink_notifier = {
17609 .notifier_call = nl80211_netlink_notify,
17610};
17611
Jouni Malinen355199e2013-02-27 17:14:27 +020017612void 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, Gangf26cbf42014-04-21 12:53:03 +080017616 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020017617 struct sk_buff *msg;
17618 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020017619
17620 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
17621
17622 if (!ft_event->target_ap)
17623 return;
17624
Dedy Lansky1039d082018-05-17 16:25:03 +030017625 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
17626 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020017627 if (!msg)
17628 return;
17629
17630 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020017631 if (!hdr)
17632 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020017633
Johannes Bergae917c92013-10-25 11:05:22 +020017634 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 Malinen355199e2013-02-27 17:14:27 +020017646
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017647 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020017648
Johannes Berg68eb5502013-11-19 15:19:38 +010017649 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017650 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020017651 return;
17652 out:
17653 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020017654}
17655EXPORT_SYMBOL(cfg80211_ft_event);
17656
Arend van Spriel5de17982013-04-18 15:49:00 +020017657void 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, Gangf26cbf42014-04-21 12:53:03 +080017664 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020017665 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 Dichtel2dad6242016-04-25 10:25:22 +020017680 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17681 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020017682 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 Spriel5de17982013-04-18 15:49:00 +020017690 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020017691}
17692EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
17693
Johannes Berg348baf02014-01-24 14:06:29 +010017694void nl80211_send_ap_stopped(struct wireless_dev *wdev)
17695{
17696 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017697 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010017698 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 Dichtel2dad6242016-04-25 10:25:22 +020017711 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17712 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010017713 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 Dasari40cbfa92018-01-25 17:13:38 +020017724int 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}
17763EXPORT_SYMBOL(cfg80211_external_auth_request);
17764
Sunil Duttcb74e972019-02-20 16:18:07 +053017765void 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
17799nla_put_failure:
17800 genlmsg_cancel(msg, hdr);
17801 nlmsg_free(msg);
17802}
17803EXPORT_SYMBOL(cfg80211_update_owe_info_event);
17804
Johannes Berg55682962007-09-20 13:09:35 -040017805/* initialisation/exit functions */
17806
Johannes Berg56989f62016-10-24 14:40:05 +020017807int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040017808{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000017809 int err;
Johannes Berg55682962007-09-20 13:09:35 -040017810
Johannes Berg489111e2016-10-24 14:40:03 +020017811 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040017812 if (err)
17813 return err;
17814
Jouni Malinen026331c2010-02-15 12:53:10 +020017815 err = netlink_register_notifier(&nl80211_netlink_notifier);
17816 if (err)
17817 goto err_out;
17818
Johannes Berg55682962007-09-20 13:09:35 -040017819 return 0;
17820 err_out:
17821 genl_unregister_family(&nl80211_fam);
17822 return err;
17823}
17824
17825void nl80211_exit(void)
17826{
Jouni Malinen026331c2010-02-15 12:53:10 +020017827 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040017828 genl_unregister_family(&nl80211_fam);
17829}