blob: afe782887ca96c2b6daaf9f9b3e56613c4b4d14a [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),
332};
333
John Crispin5c5e52d2019-12-17 15:19:18 +0100334static const struct nla_policy
335he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = {
336 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63),
337 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG },
338 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG },
339};
340
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +0530341static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
342 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
343 .len = NL80211_MAX_SUPP_RATES },
344 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
345 .len = NL80211_MAX_SUPP_HT_RATES },
346 [NL80211_TXRATE_VHT] = NLA_POLICY_EXACT_LEN_WARN(sizeof(struct nl80211_txrate_vht)),
347 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Miles Hueb89a6a2020-08-04 10:16:29 +0200348 [NL80211_TXRATE_HE] = NLA_POLICY_EXACT_LEN(sizeof(struct nl80211_txrate_he)),
349 [NL80211_TXRATE_HE_GI] = NLA_POLICY_RANGE(NLA_U8,
350 NL80211_RATE_INFO_HE_GI_0_8,
351 NL80211_RATE_INFO_HE_GI_3_2),
352 [NL80211_TXRATE_HE_LTF] = NLA_POLICY_RANGE(NLA_U8,
353 NL80211_RATE_INFO_HE_1XLTF,
354 NL80211_RATE_INFO_HE_4XLTF),
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +0530355};
356
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530357static const struct nla_policy
358nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
Johannes Berg3710a8a2020-02-24 11:34:25 +0100359 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
360 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530361 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
Johannes Berg3710a8a2020-02-24 11:34:25 +0100362 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530363 [NL80211_TID_CONFIG_ATTR_NOACK] =
364 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Tamizh chelvam6a21d162020-01-20 13:21:23 +0530365 [NL80211_TID_CONFIG_ATTR_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
366 [NL80211_TID_CONFIG_ATTR_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Tamizh chelvamade274b2020-01-20 13:21:24 +0530367 [NL80211_TID_CONFIG_ATTR_AMPDU_CTRL] =
368 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Tamizh chelvam04f7d142020-01-20 13:21:25 +0530369 [NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL] =
370 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Sergey Matyukevich33462e62020-04-24 14:29:03 +0300371 [NL80211_TID_CONFIG_ATTR_AMSDU_CTRL] =
372 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +0530373 [NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE] =
374 NLA_POLICY_MAX(NLA_U8, NL80211_TX_RATE_FIXED),
375 [NL80211_TID_CONFIG_ATTR_TX_RATE] =
376 NLA_POLICY_NESTED(nl80211_txattr_policy),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530377};
378
Aloka Dixit291c49d2020-09-11 00:05:29 +0000379static const struct nla_policy
380nl80211_fils_discovery_policy[NL80211_FILS_DISCOVERY_ATTR_MAX + 1] = {
381 [NL80211_FILS_DISCOVERY_ATTR_INT_MIN] = NLA_POLICY_MAX(NLA_U32, 10000),
382 [NL80211_FILS_DISCOVERY_ATTR_INT_MAX] = NLA_POLICY_MAX(NLA_U32, 10000),
383 NLA_POLICY_RANGE(NLA_BINARY,
384 NL80211_FILS_DISCOVERY_TMPL_MIN_LEN,
385 IEEE80211_MAX_DATA_LEN),
386};
387
Johannes Bergd15da2a2020-04-30 22:13:07 +0200388static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg6d4dd4e2019-07-31 10:58:20 +0200389 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
Johannes Berg55682962007-09-20 13:09:35 -0400390 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
391 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700392 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200393 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100394
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200395 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530396 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +0300397 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
398 NL80211_EDMG_CHANNELS_MIN,
399 NL80211_EDMG_CHANNELS_MAX),
400 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
401 NL80211_EDMG_BW_CONFIG_MIN,
402 NL80211_EDMG_BW_CONFIG_MAX),
403
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100404 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
405 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
Thomas Pedersen942ba882020-04-30 10:25:51 -0700406 [NL80211_ATTR_CENTER_FREQ1_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100407 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
408
Johannes Bergab0d76f2018-10-02 10:00:07 +0200409 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
410 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200411 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
412 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100413 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200414 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400415
Johannes Bergab0d76f2018-10-02 10:00:07 +0200416 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400417 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
418 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100419
Johannes Bergc7721c02020-04-30 22:13:10 +0200420 [NL80211_ATTR_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
421 [NL80211_ATTR_PREV_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Johannes Berg41ade002007-12-19 02:03:29 +0100422
Johannes Bergb9454e82009-07-08 13:29:08 +0200423 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100424 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
425 .len = WLAN_MAX_KEY_LEN },
Jouni Malinen56be3932020-02-22 15:25:43 +0200426 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
Johannes Berg41ade002007-12-19 02:03:29 +0100427 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
428 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200429 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200430 [NL80211_ATTR_KEY_TYPE] =
431 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100432
433 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
434 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
Johannes Bergf88eb7c2019-09-20 21:54:17 +0200435 [NL80211_ATTR_BEACON_HEAD] =
436 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
437 IEEE80211_MAX_DATA_LEN),
Johannes Berg3d7af872018-10-02 10:00:08 +0200438 [NL80211_ATTR_BEACON_TAIL] =
439 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
440 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200441 [NL80211_ATTR_STA_AID] =
442 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100443 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
444 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
445 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
446 .len = NL80211_MAX_SUPP_RATES },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200447 [NL80211_ATTR_STA_PLINK_ACTION] =
448 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +0530449 [NL80211_ATTR_STA_TX_POWER_SETTING] =
450 NLA_POLICY_RANGE(NLA_U8,
451 NL80211_TX_POWER_AUTOMATIC,
452 NL80211_TX_POWER_FIXED),
453 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100454 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200455 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100456 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800457 .len = IEEE80211_MAX_MESH_ID_LEN },
Markus Theil1fab1b82019-10-29 10:30:03 +0100458 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300459
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700460 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
461 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
462
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300463 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
464 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
465 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200466 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
467 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100468 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300469
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800470 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700471 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700472
Johannes Bergc7721c02020-04-30 22:13:10 +0200473 [NL80211_ATTR_HT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_HT_CAPABILITY_LEN),
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200474
475 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200476 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
477 validate_ie_attr,
478 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100479 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
480 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200481
482 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
483 .len = IEEE80211_MAX_SSID_LEN },
484 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
485 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200486 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300487 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200488 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
489 NL80211_MFP_NO,
490 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300491 [NL80211_ATTR_STA_FLAGS2] = {
492 .len = sizeof(struct nl80211_sta_flag_update),
493 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300494 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300495 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
496 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500497 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200498 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
Sergey Matyukevichea750802020-02-13 13:16:16 +0000499 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200500 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
501 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200502 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100503 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200504 [NL80211_ATTR_PMKID] = NLA_POLICY_EXACT_LEN_WARN(WLAN_PMKID_LEN),
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100505 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
506 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200507 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200508 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
509 .len = IEEE80211_MAX_DATA_LEN },
510 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200511 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
512 NL80211_PS_DISABLED,
513 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200514 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300515 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200516 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300517 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
518 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200519 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900520 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
521 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100522 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100523 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100524 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200525 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200526 [NL80211_ATTR_STA_PLINK_STATE] =
527 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
Jakub Kicinski056e9372020-03-02 21:10:57 -0800528 [NL80211_ATTR_MEASUREMENT_DURATION] = { .type = NLA_U16 },
529 [NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200530 [NL80211_ATTR_MESH_PEER_AID] =
531 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300532 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200533 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200534 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200535 [NL80211_ATTR_HIDDEN_SSID] =
536 NLA_POLICY_RANGE(NLA_U32,
537 NL80211_HIDDEN_SSID_NOT_IN_USE,
538 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200539 [NL80211_ATTR_IE_PROBE_RESP] =
540 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
541 IEEE80211_MAX_DATA_LEN),
542 [NL80211_ATTR_IE_ASSOC_RESP] =
543 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
544 IEEE80211_MAX_DATA_LEN),
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530545 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300546 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530547 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300548 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
549 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
550 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
551 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
552 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300553 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100554 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200555 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
556 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700557 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800558 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
559 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
560 .len = NL80211_HT_CAPABILITY_LEN
561 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100562 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530563 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530564 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200565 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700566 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200567
568 /* need to include at least Auth Transaction and Status Code */
569 [NL80211_ATTR_AUTH_DATA] = NLA_POLICY_MIN_LEN(4),
570
Johannes Bergc7721c02020-04-30 22:13:10 +0200571 [NL80211_ATTR_VHT_CAPABILITY] = NLA_POLICY_EXACT_LEN_WARN(NL80211_VHT_CAPABILITY_LEN),
Sam Lefflered4737712012-10-11 21:03:31 -0700572 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200573 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
574 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
575 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
576 NLA_POLICY_RANGE(NLA_U32,
577 NL80211_MESH_POWER_UNKNOWN + 1,
578 NL80211_MESH_POWER_MAX),
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530579 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
580 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200581 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
582 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100583 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100584 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
585 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
586 .len = NL80211_VHT_CAPABILITY_LEN,
587 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200588 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
589 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
590 .len = IEEE80211_MAX_DATA_LEN },
Jakub Kicinski0e1a1d82020-03-02 21:10:56 -0800591 [NL80211_ATTR_CRIT_PROT_ID] = { .type = NLA_U16 },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200592 [NL80211_ATTR_MAX_CRIT_PROT_DURATION] =
593 NLA_POLICY_MAX(NLA_U16, NL80211_CRIT_PROTO_MAX_DURATION),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200594 [NL80211_ATTR_PEER_AID] =
595 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200596 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
597 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
598 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
John Crispin00c207e2020-08-11 10:01:03 +0200599 [NL80211_ATTR_CNTDWN_OFFS_BEACON] = { .type = NLA_BINARY },
600 [NL80211_ATTR_CNTDWN_OFFS_PRESP] = { .type = NLA_BINARY },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200601 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = NLA_POLICY_MIN_LEN(2),
Johannes Bergc8b82802020-08-19 08:56:43 +0200602 /*
603 * The value of the Length field of the Supported Operating
604 * Classes element is between 2 and 253.
605 */
606 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] =
607 NLA_POLICY_RANGE(NLA_BINARY, 2, 253),
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200608 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100609 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100610 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
611 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
612 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Johannes Bergc8b82802020-08-19 08:56:43 +0200613 [NL80211_ATTR_QOS_MAP] = NLA_POLICY_RANGE(NLA_BINARY,
614 IEEE80211_QOS_MAP_LEN_MIN,
615 IEEE80211_QOS_MAP_LEN_MAX),
Johannes Bergc7721c02020-04-30 22:13:10 +0200616 [NL80211_ATTR_MAC_HINT] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Jouni Malinen1df4a512014-01-15 00:00:47 +0200617 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530618 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200619 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300620 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300621 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200622 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
623 [NL80211_ATTR_USER_PRIO] =
624 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
Johannes Berg960d01a2014-09-09 22:55:35 +0300625 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300626 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Jakub Kicinski5cde05c2020-03-02 21:10:58 -0800627 [NL80211_ATTR_OPER_CLASS] = { .type = NLA_U8 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200628 [NL80211_ATTR_MAC_MASK] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200629 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200630 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200631 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500632 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200633 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100634 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200635 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
636 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300637 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
638 .len = VHT_MUMIMO_GROUPS_DATA_LEN
639 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200640 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200641 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200642 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300643 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300644 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
645 .len = FILS_MAX_KEK_LEN },
Johannes Bergc7721c02020-04-30 22:13:10 +0200646 [NL80211_ATTR_FILS_NONCES] = NLA_POLICY_EXACT_LEN_WARN(2 * FILS_NONCE_LEN),
Michael Braunce0ce132016-10-10 19:12:22 +0200647 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Johannes Bergc7721c02020-04-30 22:13:10 +0200648 [NL80211_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200649 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
650 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
651 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
652 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200653 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300654 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
655 .len = FILS_ERP_MAX_USERNAME_LEN },
656 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
657 .len = FILS_ERP_MAX_REALM_LEN },
658 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
659 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
660 .len = FILS_ERP_MAX_RRK_LEN },
Johannes Bergc7721c02020-04-30 22:13:10 +0200661 [NL80211_ATTR_FILS_CACHE_ID] = NLA_POLICY_EXACT_LEN_WARN(2),
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300662 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200663 [NL80211_ATTR_PMKR0_NAME] = NLA_POLICY_EXACT_LEN(WLAN_PMK_NAME_LEN),
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100664 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200665 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200666
667 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
668 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
669 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Johannes Bergc8b82802020-08-19 08:56:43 +0200670 [NL80211_ATTR_HE_CAPABILITY] =
671 NLA_POLICY_RANGE(NLA_BINARY,
672 NL80211_HE_MIN_CAPABILITY_LEN,
673 NL80211_HE_MAX_CAPABILITY_LEN),
Johannes Berg0e012b42020-04-12 00:40:30 +0200674 [NL80211_ATTR_FTM_RESPONDER] =
675 NLA_POLICY_NESTED(nl80211_ftm_responder_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200676 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
677 [NL80211_ATTR_PEER_MEASUREMENTS] =
Johannes Berg23323282019-01-25 10:08:28 +0100678 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800679 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +0000680 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
681 .len = SAE_PASSWORD_MAX_LEN },
John Crispina0de1ca32019-05-28 13:49:48 +0200682 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
John Crispin796e90f2019-07-30 18:37:00 +0200683 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +0200684 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
John Crispin5c5e52d2019-12-17 15:19:18 +0100685 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530686 [NL80211_ATTR_TID_CONFIG] =
687 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
Markus Theil5631d962020-03-12 10:10:53 +0100688 [NL80211_ATTR_CONTROL_PORT_NO_PREAUTH] = { .type = NLA_FLAG },
Veerendranath Jakkam7fc82af2020-03-13 01:59:03 +0200689 [NL80211_ATTR_PMK_LIFETIME] = NLA_POLICY_MIN(NLA_U32, 1),
690 [NL80211_ATTR_PMK_REAUTH_THRESHOLD] = NLA_POLICY_RANGE(NLA_U8, 1, 100),
Johannes Berg9dba48a2020-04-17 12:40:15 +0200691 [NL80211_ATTR_RECEIVE_MULTICAST] = { .type = NLA_FLAG },
Thomas Pedersen942ba882020-04-30 10:25:51 -0700692 [NL80211_ATTR_WIPHY_FREQ_OFFSET] = NLA_POLICY_RANGE(NLA_U32, 0, 999),
Thomas Pedersen2032f3b2020-04-30 10:25:52 -0700693 [NL80211_ATTR_SCAN_FREQ_KHZ] = { .type = NLA_NESTED },
Johannes Berg81408602020-08-18 10:17:31 +0200694 [NL80211_ATTR_HE_6GHZ_CAPABILITY] =
695 NLA_POLICY_EXACT_LEN(sizeof(struct ieee80211_he_6ghz_capa)),
Aloka Dixit291c49d2020-09-11 00:05:29 +0000696 [NL80211_ATTR_FILS_DISCOVERY] =
697 NLA_POLICY_NESTED(nl80211_fils_discovery_policy),
Johannes Berg55682962007-09-20 13:09:35 -0400698};
699
Johannes Berge31b8212010-10-05 19:39:30 +0200700/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000701static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200702 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200703 [NL80211_KEY_IDX] = { .type = NLA_U8 },
704 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200705 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200706 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
707 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200708 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100709 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100710 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100711};
712
713/* policy for the key default flags */
714static const struct nla_policy
715nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
716 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
717 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200718};
719
Johannes Bergf83ace32016-10-17 08:04:07 +0200720#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200721/* policy for WoWLAN attributes */
722static const struct nla_policy
723nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
724 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
725 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
726 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
727 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200728 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
729 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
730 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
731 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100732 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300733 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100734};
735
736static const struct nla_policy
737nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
738 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
739 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200740 [NL80211_WOWLAN_TCP_DST_MAC] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Johannes Berg2a0e0472013-01-23 22:57:40 +0100741 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
742 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Bergbc043582020-08-18 10:17:32 +0200743 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
Johannes Berg2a0e0472013-01-23 22:57:40 +0100744 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
745 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
746 },
747 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
748 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
749 },
750 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
Johannes Bergbc043582020-08-18 10:17:32 +0200751 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = NLA_POLICY_MIN_LEN(1),
752 [NL80211_WOWLAN_TCP_WAKE_MASK] = NLA_POLICY_MIN_LEN(1),
Johannes Bergff1b6e62011-05-04 15:37:28 +0200753};
Johannes Bergf83ace32016-10-17 08:04:07 +0200754#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200755
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700756/* policy for coalesce rule attributes */
757static const struct nla_policy
758nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
759 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200760 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
761 NLA_POLICY_RANGE(NLA_U32,
762 NL80211_COALESCE_CONDITION_MATCH,
763 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700764 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
765};
766
Johannes Berge5497d72011-07-05 16:35:40 +0200767/* policy for GTK rekey offload attributes */
768static const struct nla_policy
769nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Nathan Errera093a48d2020-05-28 21:22:38 +0200770 [NL80211_REKEY_DATA_KEK] = {
771 .type = NLA_BINARY,
772 .len = NL80211_KEK_EXT_LEN
773 },
774 [NL80211_REKEY_DATA_KCK] = {
775 .type = NLA_BINARY,
776 .len = NL80211_KCK_EXT_LEN
777 },
Johannes Bergcb9abd42020-08-05 15:47:16 +0200778 [NL80211_REKEY_DATA_REPLAY_CTR] = NLA_POLICY_EXACT_LEN(NL80211_REPLAY_CTR_LEN),
Nathan Errera093a48d2020-05-28 21:22:38 +0200779 [NL80211_REKEY_DATA_AKM] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200780};
781
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300782static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530783nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
784 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
785 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
Arend van Spriele548a1c2019-08-02 13:31:02 +0200786 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530787 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
788};
789
790static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300791nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200792 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300793 .len = IEEE80211_MAX_SSID_LEN },
Johannes Bergc7721c02020-04-30 22:13:10 +0200794 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700795 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530796 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
797 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300798};
799
Avraham Stern3b06d272015-10-12 09:51:34 +0300800static const struct nla_policy
801nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
802 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
803 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
804};
805
Arend van Spriel38de03d2016-03-02 20:37:18 +0100806static const struct nla_policy
807nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
808 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
809 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
810 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
811 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
812 },
813};
814
Ayala Bekera442b762016-09-20 17:31:15 +0300815/* policy for NAN function attributes */
816static const struct nla_policy
817nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
Johannes Bergcb9abd42020-08-05 15:47:16 +0200818 [NL80211_NAN_FUNC_TYPE] =
819 NLA_POLICY_MAX(NLA_U8, NL80211_NAN_FUNC_MAX_TYPE),
Srinivas Dasari0a278442017-07-07 01:43:40 +0300820 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300821 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
822 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
823 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
824 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
825 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
826 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
Johannes Bergc7721c02020-04-30 22:13:10 +0200827 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = NLA_POLICY_EXACT_LEN_WARN(ETH_ALEN),
Ayala Bekera442b762016-09-20 17:31:15 +0300828 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
829 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
830 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
831 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
832 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
833 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
834 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
835 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
836 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
837};
838
839/* policy for Service Response Filter attributes */
840static const struct nla_policy
841nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
842 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
843 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
844 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
845 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
846 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
847};
848
Peng Xuad670232017-10-03 23:21:51 +0300849/* policy for packet pattern attributes */
850static const struct nla_policy
851nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
852 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
853 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
854 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
855};
856
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200857int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
858 struct cfg80211_registered_device **rdev,
859 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100860{
Johannes Berg67748892010-10-04 21:14:06 +0200861 int err;
862
Johannes Berg97990a02013-04-19 01:02:55 +0200863 if (!cb->args[0]) {
Johannes Berg50508d92019-07-29 16:31:09 +0200864 struct nlattr **attrbuf;
865
866 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
867 GFP_KERNEL);
868 if (!attrbuf)
869 return -ENOMEM;
870
Johannes Berg8cb08172019-04-26 14:07:28 +0200871 err = nlmsg_parse_deprecated(cb->nlh,
872 GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Berg50508d92019-07-29 16:31:09 +0200873 attrbuf, nl80211_fam.maxattr,
Johannes Berg8cb08172019-04-26 14:07:28 +0200874 nl80211_policy, NULL);
Johannes Berg50508d92019-07-29 16:31:09 +0200875 if (err) {
876 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100877 return err;
Johannes Berg50508d92019-07-29 16:31:09 +0200878 }
Johannes Berg97990a02013-04-19 01:02:55 +0200879
Johannes Berg50508d92019-07-29 16:31:09 +0200880 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
881 attrbuf);
882 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100883 if (IS_ERR(*wdev))
884 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800885 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200886 /* 0 is the first index - add 1 to parse only once */
887 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200888 cb->args[1] = (*wdev)->identifier;
889 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200890 /* subtract the 1 again here */
891 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200892 struct wireless_dev *tmp;
893
Johannes Bergea90e0d2017-03-15 14:26:04 +0100894 if (!wiphy)
895 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800896 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200897 *wdev = NULL;
898
Johannes Berg53873f12016-05-03 16:52:04 +0300899 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200900 if (tmp->identifier == cb->args[1]) {
901 *wdev = tmp;
902 break;
903 }
904 }
Johannes Berg97990a02013-04-19 01:02:55 +0200905
Johannes Bergea90e0d2017-03-15 14:26:04 +0100906 if (!*wdev)
907 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200908 }
909
Johannes Berg67748892010-10-04 21:14:06 +0200910 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200911}
912
Johannes Berg55682962007-09-20 13:09:35 -0400913/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200914void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
915 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400916{
917 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000918 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400919}
920
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300921static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
922 const struct ieee80211_reg_rule *rule)
923{
924 int j;
925 struct nlattr *nl_wmm_rules =
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200926 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300927
928 if (!nl_wmm_rules)
929 goto nla_put_failure;
930
931 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200932 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300933
934 if (!nl_wmm_rule)
935 goto nla_put_failure;
936
937 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200938 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300939 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200940 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300941 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200942 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300943 nla_put_u16(msg, NL80211_WMMR_TXOP,
944 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300945 goto nla_put_failure;
946
947 nla_nest_end(msg, nl_wmm_rule);
948 }
949 nla_nest_end(msg, nl_wmm_rules);
950
951 return 0;
952
953nla_put_failure:
954 return -ENOBUFS;
955}
956
957static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100958 struct ieee80211_channel *chan,
959 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400960{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200961 /* Some channels must be completely excluded from the
962 * list to protect old user-space tools from breaking
963 */
964 if (!large && chan->flags &
965 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
966 return 0;
967
David S. Miller9360ffd2012-03-29 04:41:26 -0400968 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
969 chan->center_freq))
970 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400971
Thomas Pedersen942ba882020-04-30 10:25:51 -0700972 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_OFFSET, chan->freq_offset))
973 goto nla_put_failure;
974
David S. Miller9360ffd2012-03-29 04:41:26 -0400975 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
976 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
977 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200978 if (chan->flags & IEEE80211_CHAN_NO_IR) {
979 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
980 goto nla_put_failure;
981 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
982 goto nla_put_failure;
983 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100984 if (chan->flags & IEEE80211_CHAN_RADAR) {
985 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
986 goto nla_put_failure;
987 if (large) {
988 u32 time;
989
990 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
991
992 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
993 chan->dfs_state))
994 goto nla_put_failure;
995 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
996 time))
997 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100998 if (nla_put_u32(msg,
999 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
1000 chan->dfs_cac_ms))
1001 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001002 }
1003 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001004
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001005 if (large) {
1006 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
1007 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
1008 goto nla_put_failure;
1009 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
1010 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
1011 goto nla_put_failure;
1012 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
1013 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
1014 goto nla_put_failure;
1015 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
1016 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
1017 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +02001018 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
1019 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
1020 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +03001021 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
1022 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +02001023 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +02001024 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
1025 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
1026 goto nla_put_failure;
1027 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
1028 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
1029 goto nla_put_failure;
Haim Dreyfuss1e61d822020-01-21 10:12:13 +02001030 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
1031 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
1032 goto nla_put_failure;
Thomas Pedersend65a9772020-09-08 12:03:03 -07001033 if ((chan->flags & IEEE80211_CHAN_1MHZ) &&
1034 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_1MHZ))
1035 goto nla_put_failure;
1036 if ((chan->flags & IEEE80211_CHAN_2MHZ) &&
1037 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_2MHZ))
1038 goto nla_put_failure;
1039 if ((chan->flags & IEEE80211_CHAN_4MHZ) &&
1040 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_4MHZ))
1041 goto nla_put_failure;
1042 if ((chan->flags & IEEE80211_CHAN_8MHZ) &&
1043 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_8MHZ))
1044 goto nla_put_failure;
1045 if ((chan->flags & IEEE80211_CHAN_16MHZ) &&
1046 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_16MHZ))
1047 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001048 }
1049
David S. Miller9360ffd2012-03-29 04:41:26 -04001050 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
1051 DBM_TO_MBM(chan->max_power)))
1052 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001053
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001054 if (large) {
1055 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +03001056 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001057
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +02001058 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001059 if (nl80211_msg_put_wmm_rules(msg, rule))
1060 goto nla_put_failure;
1061 }
1062 }
1063
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001064 return 0;
1065
1066 nla_put_failure:
1067 return -ENOBUFS;
1068}
1069
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02001070static bool nl80211_put_txq_stats(struct sk_buff *msg,
1071 struct cfg80211_txq_stats *txqstats,
1072 int attrtype)
1073{
1074 struct nlattr *txqattr;
1075
1076#define PUT_TXQVAL_U32(attr, memb) do { \
1077 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1078 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1079 return false; \
1080 } while (0)
1081
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001082 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02001083 if (!txqattr)
1084 return false;
1085
1086 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1087 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1088 PUT_TXQVAL_U32(FLOWS, flows);
1089 PUT_TXQVAL_U32(DROPS, drops);
1090 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1091 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1092 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1093 PUT_TXQVAL_U32(COLLISIONS, collisions);
1094 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1095 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1096 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1097 nla_nest_end(msg, txqattr);
1098
1099#undef PUT_TXQVAL_U32
1100 return true;
1101}
1102
Johannes Berg55682962007-09-20 13:09:35 -04001103/* netlink command implementations */
1104
Johannes Bergb9454e82009-07-08 13:29:08 +02001105struct key_parse {
1106 struct key_params p;
1107 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +02001108 int type;
Jouni Malinen56be3932020-02-22 15:25:43 +02001109 bool def, defmgmt, defbeacon;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001110 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +02001111};
1112
Johannes Berg768075e2017-11-13 15:35:06 +01001113static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1114 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +02001115{
1116 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +02001117 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1118 nl80211_key_policy,
1119 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +02001120 if (err)
1121 return err;
1122
1123 k->def = !!tb[NL80211_KEY_DEFAULT];
1124 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
Jouni Malinen56be3932020-02-22 15:25:43 +02001125 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
Johannes Bergb9454e82009-07-08 13:29:08 +02001126
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001127 if (k->def) {
1128 k->def_uni = true;
1129 k->def_multi = true;
1130 }
Jouni Malinen56be3932020-02-22 15:25:43 +02001131 if (k->defmgmt || k->defbeacon)
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001132 k->def_multi = true;
1133
Johannes Bergb9454e82009-07-08 13:29:08 +02001134 if (tb[NL80211_KEY_IDX])
1135 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1136
1137 if (tb[NL80211_KEY_DATA]) {
1138 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1139 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1140 }
1141
1142 if (tb[NL80211_KEY_SEQ]) {
1143 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1144 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1145 }
1146
1147 if (tb[NL80211_KEY_CIPHER])
1148 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1149
Johannes Bergab0d76f2018-10-02 10:00:07 +02001150 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001151 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001152
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001153 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1154 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001155
Johannes Berg8cb08172019-04-26 14:07:28 +02001156 err = nla_parse_nested_deprecated(kdt,
1157 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1158 tb[NL80211_KEY_DEFAULT_TYPES],
1159 nl80211_key_default_policy,
1160 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001161 if (err)
1162 return err;
1163
1164 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1165 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1166 }
1167
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01001168 if (tb[NL80211_KEY_MODE])
1169 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1170
Johannes Bergb9454e82009-07-08 13:29:08 +02001171 return 0;
1172}
1173
1174static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1175{
1176 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1177 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1178 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1179 }
1180
1181 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1182 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1183 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1184 }
1185
1186 if (info->attrs[NL80211_ATTR_KEY_IDX])
1187 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1188
1189 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1190 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1191
1192 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1193 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1194
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001195 if (k->def) {
1196 k->def_uni = true;
1197 k->def_multi = true;
1198 }
1199 if (k->defmgmt)
1200 k->def_multi = true;
1201
Johannes Bergab0d76f2018-10-02 10:00:07 +02001202 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001203 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001204
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001205 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1206 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001207 int err = nla_parse_nested_deprecated(kdt,
1208 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1209 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1210 nl80211_key_default_policy,
1211 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001212 if (err)
1213 return err;
1214
1215 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1216 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1217 }
1218
Johannes Bergb9454e82009-07-08 13:29:08 +02001219 return 0;
1220}
1221
1222static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1223{
1224 int err;
1225
1226 memset(k, 0, sizeof(*k));
1227 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001228 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001229
1230 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001231 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001232 else
1233 err = nl80211_parse_key_old(info, k);
1234
1235 if (err)
1236 return err;
1237
Jouni Malinen56be3932020-02-22 15:25:43 +02001238 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1239 (k->defbeacon ? 1 : 0) > 1) {
1240 GENL_SET_ERR_MSG(info,
1241 "key with multiple default flags is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001242 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001243 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001244
Jouni Malinen56be3932020-02-22 15:25:43 +02001245 if (k->defmgmt || k->defbeacon) {
Johannes Berg768075e2017-11-13 15:35:06 +01001246 if (k->def_uni || !k->def_multi) {
Jouni Malinen56be3932020-02-22 15:25:43 +02001247 GENL_SET_ERR_MSG(info,
1248 "defmgmt/defbeacon key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001249 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001250 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001251 }
1252
Johannes Bergb9454e82009-07-08 13:29:08 +02001253 if (k->idx != -1) {
1254 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001255 if (k->idx < 4 || k->idx > 5) {
1256 GENL_SET_ERR_MSG(info,
1257 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001258 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001259 }
Jouni Malinen56be3932020-02-22 15:25:43 +02001260 } else if (k->defbeacon) {
1261 if (k->idx < 6 || k->idx > 7) {
1262 GENL_SET_ERR_MSG(info,
1263 "defbeacon key idx not 6 or 7");
1264 return -EINVAL;
1265 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001266 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001267 if (k->idx < 0 || k->idx > 3) {
1268 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001269 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001270 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001271 } else {
Jouni Malinen56be3932020-02-22 15:25:43 +02001272 if (k->idx < 0 || k->idx > 7) {
1273 GENL_SET_ERR_MSG(info, "key idx not 0-7");
Johannes Bergb9454e82009-07-08 13:29:08 +02001274 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001275 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001276 }
1277 }
1278
1279 return 0;
1280}
1281
Johannes Bergfffd0932009-07-08 14:22:54 +02001282static struct cfg80211_cached_keys *
1283nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001284 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001285{
Johannes Berg768075e2017-11-13 15:35:06 +01001286 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001287 struct key_parse parse;
1288 struct nlattr *key;
1289 struct cfg80211_cached_keys *result;
1290 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001291 bool have_key = false;
1292
1293 nla_for_each_nested(key, keys, rem) {
1294 have_key = true;
1295 break;
1296 }
1297
1298 if (!have_key)
1299 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001300
1301 result = kzalloc(sizeof(*result), GFP_KERNEL);
1302 if (!result)
1303 return ERR_PTR(-ENOMEM);
1304
1305 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001306
1307 nla_for_each_nested(key, keys, rem) {
1308 memset(&parse, 0, sizeof(parse));
1309 parse.idx = -1;
1310
Johannes Berg768075e2017-11-13 15:35:06 +01001311 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001312 if (err)
1313 goto error;
1314 err = -EINVAL;
1315 if (!parse.p.key)
1316 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001317 if (parse.idx < 0 || parse.idx > 3) {
1318 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001319 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001320 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001321 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001322 if (def) {
1323 GENL_SET_ERR_MSG(info,
1324 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001325 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001326 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001327 def = 1;
1328 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001329 if (!parse.def_uni || !parse.def_multi)
1330 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001331 } else if (parse.defmgmt)
1332 goto error;
1333 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001334 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001335 if (err)
1336 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001337 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1338 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001339 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001340 err = -EINVAL;
1341 goto error;
1342 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001343 result->params[parse.idx].cipher = parse.p.cipher;
1344 result->params[parse.idx].key_len = parse.p.key_len;
1345 result->params[parse.idx].key = result->data[parse.idx];
1346 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301347
Johannes Berg386b1f22016-09-13 16:10:02 +02001348 /* must be WEP key if we got here */
1349 if (no_ht)
1350 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001351 }
1352
Johannes Bergf1c1f172016-09-13 17:08:23 +02001353 if (result->def < 0) {
1354 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001355 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001356 goto error;
1357 }
1358
Johannes Bergfffd0932009-07-08 14:22:54 +02001359 return result;
1360 error:
1361 kfree(result);
1362 return ERR_PTR(err);
1363}
1364
1365static int nl80211_key_allowed(struct wireless_dev *wdev)
1366{
1367 ASSERT_WDEV_LOCK(wdev);
1368
Johannes Bergfffd0932009-07-08 14:22:54 +02001369 switch (wdev->iftype) {
1370 case NL80211_IFTYPE_AP:
1371 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001372 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001373 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001374 break;
1375 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001376 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001377 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001378 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001379 return -ENOLINK;
1380 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001381 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001382 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001383 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001384 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001385 case NL80211_IFTYPE_P2P_DEVICE:
1386 case NL80211_IFTYPE_WDS:
1387 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001388 return -EINVAL;
1389 }
1390
1391 return 0;
1392}
1393
Jouni Malinen664834d2014-01-15 00:01:44 +02001394static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
Thomas Pedersen942ba882020-04-30 10:25:51 -07001395 u32 freq)
Jouni Malinen664834d2014-01-15 00:01:44 +02001396{
1397 struct ieee80211_channel *chan;
1398
Thomas Pedersen942ba882020-04-30 10:25:51 -07001399 chan = ieee80211_get_channel_khz(wiphy, freq);
Jouni Malinen664834d2014-01-15 00:01:44 +02001400 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1401 return NULL;
1402 return chan;
1403}
1404
Johannes Berg7527a782011-05-13 10:58:57 +02001405static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1406{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001407 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001408 int i;
1409
1410 if (!nl_modes)
1411 goto nla_put_failure;
1412
1413 i = 0;
1414 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001415 if ((ifmodes & 1) && nla_put_flag(msg, i))
1416 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001417 ifmodes >>= 1;
1418 i++;
1419 }
1420
1421 nla_nest_end(msg, nl_modes);
1422 return 0;
1423
1424nla_put_failure:
1425 return -ENOBUFS;
1426}
1427
1428static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001429 struct sk_buff *msg,
1430 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001431{
1432 struct nlattr *nl_combis;
1433 int i, j;
1434
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001435 nl_combis = nla_nest_start_noflag(msg,
1436 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001437 if (!nl_combis)
1438 goto nla_put_failure;
1439
1440 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1441 const struct ieee80211_iface_combination *c;
1442 struct nlattr *nl_combi, *nl_limits;
1443
1444 c = &wiphy->iface_combinations[i];
1445
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001446 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001447 if (!nl_combi)
1448 goto nla_put_failure;
1449
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001450 nl_limits = nla_nest_start_noflag(msg,
1451 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001452 if (!nl_limits)
1453 goto nla_put_failure;
1454
1455 for (j = 0; j < c->n_limits; j++) {
1456 struct nlattr *nl_limit;
1457
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001458 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001459 if (!nl_limit)
1460 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001461 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1462 c->limits[j].max))
1463 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001464 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1465 c->limits[j].types))
1466 goto nla_put_failure;
1467 nla_nest_end(msg, nl_limit);
1468 }
1469
1470 nla_nest_end(msg, nl_limits);
1471
David S. Miller9360ffd2012-03-29 04:41:26 -04001472 if (c->beacon_int_infra_match &&
1473 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1474 goto nla_put_failure;
1475 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1476 c->num_different_channels) ||
1477 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1478 c->max_interfaces))
1479 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001480 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001481 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1482 c->radar_detect_widths) ||
1483 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1484 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001485 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301486 if (c->beacon_int_min_gcd &&
1487 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1488 c->beacon_int_min_gcd))
1489 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001490
1491 nla_nest_end(msg, nl_combi);
1492 }
1493
1494 nla_nest_end(msg, nl_combis);
1495
1496 return 0;
1497nla_put_failure:
1498 return -ENOBUFS;
1499}
1500
Johannes Berg3713b4e2013-02-14 16:19:38 +01001501#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001502static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1503 struct sk_buff *msg)
1504{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001505 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001506 struct nlattr *nl_tcp;
1507
1508 if (!tcp)
1509 return 0;
1510
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001511 nl_tcp = nla_nest_start_noflag(msg,
1512 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001513 if (!nl_tcp)
1514 return -ENOBUFS;
1515
1516 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1517 tcp->data_payload_max))
1518 return -ENOBUFS;
1519
1520 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1521 tcp->data_payload_max))
1522 return -ENOBUFS;
1523
1524 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1525 return -ENOBUFS;
1526
1527 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1528 sizeof(*tcp->tok), tcp->tok))
1529 return -ENOBUFS;
1530
1531 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1532 tcp->data_interval_max))
1533 return -ENOBUFS;
1534
1535 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1536 tcp->wake_payload_max))
1537 return -ENOBUFS;
1538
1539 nla_nest_end(msg, nl_tcp);
1540 return 0;
1541}
1542
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001544 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001545 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001546{
1547 struct nlattr *nl_wowlan;
1548
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001549 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001550 return 0;
1551
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001552 nl_wowlan = nla_nest_start_noflag(msg,
1553 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 if (!nl_wowlan)
1555 return -ENOBUFS;
1556
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001558 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001562 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001563 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001564 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001567 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001569 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1573 return -ENOBUFS;
1574
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001576 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1578 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1579 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1580 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 };
1582
1583 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1584 sizeof(pat), &pat))
1585 return -ENOBUFS;
1586 }
1587
Luciano Coelho75453cc2015-01-09 14:06:37 +02001588 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1589 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1590 rdev->wiphy.wowlan->max_nd_match_sets))
1591 return -ENOBUFS;
1592
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001593 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001594 return -ENOBUFS;
1595
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 nla_nest_end(msg, nl_wowlan);
1597
1598 return 0;
1599}
1600#endif
1601
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001602static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001603 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001604{
1605 struct nl80211_coalesce_rule_support rule;
1606
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001608 return 0;
1609
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1611 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1612 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1613 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1614 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1615 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001616
1617 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1618 return -ENOBUFS;
1619
1620 return 0;
1621}
1622
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001623static int
1624nl80211_send_iftype_data(struct sk_buff *msg,
Johannes Berg22395212020-05-28 21:34:31 +02001625 const struct ieee80211_supported_band *sband,
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001626 const struct ieee80211_sband_iftype_data *iftdata)
1627{
1628 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1629
1630 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1631 iftdata->types_mask))
1632 return -ENOBUFS;
1633
1634 if (he_cap->has_he) {
1635 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1636 sizeof(he_cap->he_cap_elem.mac_cap_info),
1637 he_cap->he_cap_elem.mac_cap_info) ||
1638 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1639 sizeof(he_cap->he_cap_elem.phy_cap_info),
1640 he_cap->he_cap_elem.phy_cap_info) ||
1641 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1642 sizeof(he_cap->he_mcs_nss_supp),
1643 &he_cap->he_mcs_nss_supp) ||
1644 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1645 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1646 return -ENOBUFS;
1647 }
1648
Johannes Berg22395212020-05-28 21:34:31 +02001649 if (sband->band == NL80211_BAND_6GHZ &&
1650 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_6GHZ_CAPA,
1651 sizeof(iftdata->he_6ghz_capa),
1652 &iftdata->he_6ghz_capa))
1653 return -ENOBUFS;
1654
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001655 return 0;
1656}
1657
Johannes Berg3713b4e2013-02-14 16:19:38 +01001658static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1659 struct ieee80211_supported_band *sband)
1660{
1661 struct nlattr *nl_rates, *nl_rate;
1662 struct ieee80211_rate *rate;
1663 int i;
1664
1665 /* add HT info */
1666 if (sband->ht_cap.ht_supported &&
1667 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1668 sizeof(sband->ht_cap.mcs),
1669 &sband->ht_cap.mcs) ||
1670 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1671 sband->ht_cap.cap) ||
1672 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1673 sband->ht_cap.ampdu_factor) ||
1674 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1675 sband->ht_cap.ampdu_density)))
1676 return -ENOBUFS;
1677
1678 /* add VHT info */
1679 if (sband->vht_cap.vht_supported &&
1680 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1681 sizeof(sband->vht_cap.vht_mcs),
1682 &sband->vht_cap.vht_mcs) ||
1683 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1684 sband->vht_cap.cap)))
1685 return -ENOBUFS;
1686
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001687 if (sband->n_iftype_data) {
1688 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001689 nla_nest_start_noflag(msg,
1690 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001691 int err;
1692
1693 if (!nl_iftype_data)
1694 return -ENOBUFS;
1695
1696 for (i = 0; i < sband->n_iftype_data; i++) {
1697 struct nlattr *iftdata;
1698
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001699 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001700 if (!iftdata)
1701 return -ENOBUFS;
1702
Johannes Berg22395212020-05-28 21:34:31 +02001703 err = nl80211_send_iftype_data(msg, sband,
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001704 &sband->iftype_data[i]);
1705 if (err)
1706 return err;
1707
1708 nla_nest_end(msg, iftdata);
1709 }
1710
1711 nla_nest_end(msg, nl_iftype_data);
1712 }
1713
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03001714 /* add EDMG info */
1715 if (sband->edmg_cap.channels &&
1716 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1717 sband->edmg_cap.channels) ||
1718 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1719 sband->edmg_cap.bw_config)))
1720
1721 return -ENOBUFS;
1722
Johannes Berg3713b4e2013-02-14 16:19:38 +01001723 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001724 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001725 if (!nl_rates)
1726 return -ENOBUFS;
1727
1728 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001729 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001730 if (!nl_rate)
1731 return -ENOBUFS;
1732
1733 rate = &sband->bitrates[i];
1734 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1735 rate->bitrate))
1736 return -ENOBUFS;
1737 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1738 nla_put_flag(msg,
1739 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1740 return -ENOBUFS;
1741
1742 nla_nest_end(msg, nl_rate);
1743 }
1744
1745 nla_nest_end(msg, nl_rates);
1746
1747 return 0;
1748}
1749
1750static int
1751nl80211_send_mgmt_stypes(struct sk_buff *msg,
1752 const struct ieee80211_txrx_stypes *mgmt_stypes)
1753{
1754 u16 stypes;
1755 struct nlattr *nl_ftypes, *nl_ifs;
1756 enum nl80211_iftype ift;
1757 int i;
1758
1759 if (!mgmt_stypes)
1760 return 0;
1761
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001762 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001763 if (!nl_ifs)
1764 return -ENOBUFS;
1765
1766 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001767 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001768 if (!nl_ftypes)
1769 return -ENOBUFS;
1770 i = 0;
1771 stypes = mgmt_stypes[ift].tx;
1772 while (stypes) {
1773 if ((stypes & 1) &&
1774 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1775 (i << 4) | IEEE80211_FTYPE_MGMT))
1776 return -ENOBUFS;
1777 stypes >>= 1;
1778 i++;
1779 }
1780 nla_nest_end(msg, nl_ftypes);
1781 }
1782
1783 nla_nest_end(msg, nl_ifs);
1784
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001785 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_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].rx;
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 nla_nest_end(msg, nl_ifs);
1806
1807 return 0;
1808}
1809
Johannes Berg17948992016-10-26 11:42:04 +02001810#define CMD(op, n) \
1811 do { \
1812 if (rdev->ops->op) { \
1813 i++; \
1814 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1815 goto nla_put_failure; \
1816 } \
1817 } while (0)
1818
1819static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1820 struct sk_buff *msg)
1821{
1822 int i = 0;
1823
1824 /*
1825 * do *NOT* add anything into this function, new things need to be
1826 * advertised only to new versions of userspace that can deal with
1827 * the split (and they can't possibly care about new features...
1828 */
1829 CMD(add_virtual_intf, NEW_INTERFACE);
1830 CMD(change_virtual_intf, SET_INTERFACE);
1831 CMD(add_key, NEW_KEY);
1832 CMD(start_ap, START_AP);
1833 CMD(add_station, NEW_STATION);
1834 CMD(add_mpath, NEW_MPATH);
1835 CMD(update_mesh_config, SET_MESH_CONFIG);
1836 CMD(change_bss, SET_BSS);
1837 CMD(auth, AUTHENTICATE);
1838 CMD(assoc, ASSOCIATE);
1839 CMD(deauth, DEAUTHENTICATE);
1840 CMD(disassoc, DISASSOCIATE);
1841 CMD(join_ibss, JOIN_IBSS);
1842 CMD(join_mesh, JOIN_MESH);
1843 CMD(set_pmksa, SET_PMKSA);
1844 CMD(del_pmksa, DEL_PMKSA);
1845 CMD(flush_pmksa, FLUSH_PMKSA);
1846 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1847 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1848 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1849 CMD(mgmt_tx, FRAME);
1850 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1851 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1852 i++;
1853 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1854 goto nla_put_failure;
1855 }
1856 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1857 rdev->ops->join_mesh) {
1858 i++;
1859 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1860 goto nla_put_failure;
1861 }
1862 CMD(set_wds_peer, SET_WDS_PEER);
1863 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1864 CMD(tdls_mgmt, TDLS_MGMT);
1865 CMD(tdls_oper, TDLS_OPER);
1866 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001867 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001868 CMD(sched_scan_start, START_SCHED_SCAN);
1869 CMD(probe_client, PROBE_CLIENT);
1870 CMD(set_noack_map, SET_NOACK_MAP);
1871 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1872 i++;
1873 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1874 goto nla_put_failure;
1875 }
1876 CMD(start_p2p_device, START_P2P_DEVICE);
1877 CMD(set_mcast_rate, SET_MCAST_RATE);
1878#ifdef CONFIG_NL80211_TESTMODE
1879 CMD(testmode_cmd, TESTMODE);
1880#endif
1881
1882 if (rdev->ops->connect || rdev->ops->auth) {
1883 i++;
1884 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1885 goto nla_put_failure;
1886 }
1887
1888 if (rdev->ops->disconnect || rdev->ops->deauth) {
1889 i++;
1890 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1891 goto nla_put_failure;
1892 }
1893
1894 return i;
1895 nla_put_failure:
1896 return -ENOBUFS;
1897}
1898
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001899static int
1900nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1901 struct sk_buff *msg)
1902{
1903 struct nlattr *ftm;
1904
1905 if (!cap->ftm.supported)
1906 return 0;
1907
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001908 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001909 if (!ftm)
1910 return -ENOBUFS;
1911
1912 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1913 return -ENOBUFS;
1914 if (cap->ftm.non_asap &&
1915 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1916 return -ENOBUFS;
1917 if (cap->ftm.request_lci &&
1918 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1919 return -ENOBUFS;
1920 if (cap->ftm.request_civicloc &&
1921 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1922 return -ENOBUFS;
1923 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1924 cap->ftm.preambles))
1925 return -ENOBUFS;
1926 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1927 cap->ftm.bandwidths))
1928 return -ENOBUFS;
1929 if (cap->ftm.max_bursts_exponent >= 0 &&
1930 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1931 cap->ftm.max_bursts_exponent))
1932 return -ENOBUFS;
1933 if (cap->ftm.max_ftms_per_burst &&
1934 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1935 cap->ftm.max_ftms_per_burst))
1936 return -ENOBUFS;
Avraham Sternefb55202020-01-31 13:12:38 +02001937 if (cap->ftm.trigger_based &&
1938 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_TRIGGER_BASED))
1939 return -ENOBUFS;
1940 if (cap->ftm.non_trigger_based &&
1941 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_TRIGGER_BASED))
1942 return -ENOBUFS;
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001943
1944 nla_nest_end(msg, ftm);
1945 return 0;
1946}
1947
1948static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1949 struct sk_buff *msg)
1950{
1951 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1952 struct nlattr *pmsr, *caps;
1953
1954 if (!cap)
1955 return 0;
1956
1957 /*
1958 * we don't need to clean up anything here since the caller
1959 * will genlmsg_cancel() if we fail
1960 */
1961
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001962 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001963 if (!pmsr)
1964 return -ENOBUFS;
1965
1966 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1967 return -ENOBUFS;
1968
1969 if (cap->report_ap_tsf &&
1970 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1971 return -ENOBUFS;
1972
1973 if (cap->randomize_mac_addr &&
1974 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1975 return -ENOBUFS;
1976
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001977 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001978 if (!caps)
1979 return -ENOBUFS;
1980
1981 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1982 return -ENOBUFS;
1983
1984 nla_nest_end(msg, caps);
1985 nla_nest_end(msg, pmsr);
1986
1987 return 0;
1988}
1989
Veerendranath Jakkamd6039a32020-01-27 02:00:32 +05301990static int
1991nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
1992 struct sk_buff *msg)
1993{
1994 int i;
1995 struct nlattr *nested, *nested_akms;
1996 const struct wiphy_iftype_akm_suites *iftype_akms;
1997
1998 if (!rdev->wiphy.num_iftype_akm_suites ||
1999 !rdev->wiphy.iftype_akm_suites)
2000 return 0;
2001
2002 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
2003 if (!nested)
2004 return -ENOBUFS;
2005
2006 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
2007 nested_akms = nla_nest_start(msg, i + 1);
2008 if (!nested_akms)
2009 return -ENOBUFS;
2010
2011 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
2012
2013 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
2014 iftype_akms->iftypes_mask))
2015 return -ENOBUFS;
2016
2017 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
2018 sizeof(u32) * iftype_akms->n_akm_suites,
2019 iftype_akms->akm_suites)) {
2020 return -ENOBUFS;
2021 }
2022 nla_nest_end(msg, nested_akms);
2023 }
2024
2025 nla_nest_end(msg, nested);
2026
2027 return 0;
2028}
2029
Johannes Berg3710a8a2020-02-24 11:34:25 +01002030static int
2031nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
2032 struct sk_buff *msg)
2033{
2034 struct nlattr *supp;
2035
2036 if (!rdev->wiphy.tid_config_support.vif &&
2037 !rdev->wiphy.tid_config_support.peer)
2038 return 0;
2039
2040 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
2041 if (!supp)
2042 return -ENOSPC;
2043
2044 if (rdev->wiphy.tid_config_support.vif &&
2045 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
2046 rdev->wiphy.tid_config_support.vif,
2047 NL80211_TID_CONFIG_ATTR_PAD))
2048 goto fail;
2049
2050 if (rdev->wiphy.tid_config_support.peer &&
2051 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
2052 rdev->wiphy.tid_config_support.peer,
2053 NL80211_TID_CONFIG_ATTR_PAD))
2054 goto fail;
2055
Tamizh chelvam6a21d162020-01-20 13:21:23 +05302056 /* for now we just use the same value ... makes more sense */
2057 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_SHORT,
2058 rdev->wiphy.tid_config_support.max_retry))
2059 goto fail;
2060 if (nla_put_u8(msg, NL80211_TID_CONFIG_ATTR_RETRY_LONG,
2061 rdev->wiphy.tid_config_support.max_retry))
2062 goto fail;
2063
Johannes Berg3710a8a2020-02-24 11:34:25 +01002064 nla_nest_end(msg, supp);
2065
2066 return 0;
2067fail:
2068 nla_nest_cancel(msg, supp);
2069 return -ENOBUFS;
2070}
2071
Johannes Berg86e8cf92013-06-19 10:57:22 +02002072struct nl80211_dump_wiphy_state {
2073 s64 filter_wiphy;
2074 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302075 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002076 bool split;
2077};
2078
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002079static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02002080 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002081 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002082 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04002083{
2084 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01002085 struct nlattr *nl_bands, *nl_band;
2086 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01002087 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002088 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01002089 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01002090 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02002091 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002092 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002093 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04002094
Johannes Berg3bb20552014-05-26 13:52:25 +02002095 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002096 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002097 return -ENOBUFS;
2098
Johannes Berg86e8cf92013-06-19 10:57:22 +02002099 if (WARN_ON(!state))
2100 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04002101
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002103 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002104 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002105 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002106 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04002107 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002108
Johannes Berg3bb20552014-05-26 13:52:25 +02002109 if (cmd != NL80211_CMD_NEW_WIPHY)
2110 goto finish;
2111
Johannes Berg86e8cf92013-06-19 10:57:22 +02002112 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002113 case 0:
2114 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002115 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002116 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002117 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002118 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002119 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002120 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002121 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002122 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002123 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002124 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002125 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002126 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002127 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002128 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002129 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002130 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002131 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002132 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03002133 rdev->wiphy.max_match_sets) ||
2134 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2135 rdev->wiphy.max_sched_scan_plans) ||
2136 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2137 rdev->wiphy.max_sched_scan_plan_interval) ||
2138 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2139 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01002140 goto nla_put_failure;
2141
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002142 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002143 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2144 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002145 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002146 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2147 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002148 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002149 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2150 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002151 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002152 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2153 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002154 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002155 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2156 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002157 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002158 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04002159 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002160 state->split_start++;
2161 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002162 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002163 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002164 case 1:
2165 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002166 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2167 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00002168 goto nla_put_failure;
2169
Johannes Berg3713b4e2013-02-14 16:19:38 +01002170 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002171 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01002172 goto nla_put_failure;
2173
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002174 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002175 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2176 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002177
Johannes Berg3713b4e2013-02-14 16:19:38 +01002178 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002179 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002180 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002181 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002182 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002183
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002184 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002185 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002186 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002187 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02002188
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002189 if ((rdev->wiphy.available_antennas_tx ||
2190 rdev->wiphy.available_antennas_rx) &&
2191 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002192 u32 tx_ant = 0, rx_ant = 0;
2193 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002194
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002195 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002196 if (!res) {
2197 if (nla_put_u32(msg,
2198 NL80211_ATTR_WIPHY_ANTENNA_TX,
2199 tx_ant) ||
2200 nla_put_u32(msg,
2201 NL80211_ATTR_WIPHY_ANTENNA_RX,
2202 rx_ant))
2203 goto nla_put_failure;
2204 }
Johannes Bergee688b002008-01-24 19:38:39 +01002205 }
2206
Johannes Berg86e8cf92013-06-19 10:57:22 +02002207 state->split_start++;
2208 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002209 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002210 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002211 case 2:
2212 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002213 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002214 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002215 state->split_start++;
2216 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002217 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002218 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002219 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002220 nl_bands = nla_nest_start_noflag(msg,
2221 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002222 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01002223 goto nla_put_failure;
2224
Johannes Berg86e8cf92013-06-19 10:57:22 +02002225 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002226 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002227 struct ieee80211_supported_band *sband;
2228
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002229 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01002230
2231 if (!sband)
2232 continue;
2233
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002234 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002235 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01002236 goto nla_put_failure;
2237
Johannes Berg86e8cf92013-06-19 10:57:22 +02002238 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002239 case 0:
2240 if (nl80211_send_band_rateinfo(msg, sband))
2241 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002242 state->chan_start++;
2243 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002244 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002245 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002246 default:
2247 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002248 nl_freqs = nla_nest_start_noflag(msg,
2249 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002250 if (!nl_freqs)
2251 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002252
Johannes Berg86e8cf92013-06-19 10:57:22 +02002253 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002254 i < sband->n_channels;
2255 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002256 nl_freq = nla_nest_start_noflag(msg,
2257 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002258 if (!nl_freq)
2259 goto nla_put_failure;
2260
2261 chan = &sband->channels[i];
2262
Johannes Berg86e8cf92013-06-19 10:57:22 +02002263 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002264 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002265 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002266 goto nla_put_failure;
2267
2268 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002269 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002270 break;
2271 }
2272 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002273 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002274 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002275 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002276 nla_nest_end(msg, nl_freqs);
2277 }
2278
2279 nla_nest_end(msg, nl_band);
2280
Johannes Berg86e8cf92013-06-19 10:57:22 +02002281 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002282 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002283 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002284 band--;
2285 break;
2286 }
Johannes Bergee688b002008-01-24 19:38:39 +01002287 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002288 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002289
Johannes Berg57fbcce2016-04-12 15:56:15 +02002290 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002291 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002292 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002293 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002294
Johannes Berg3713b4e2013-02-14 16:19:38 +01002295 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002296 if (state->band_start == 0 && state->chan_start == 0)
2297 state->split_start++;
2298 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002299 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002300 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002301 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002302 nl_cmds = nla_nest_start_noflag(msg,
2303 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002304 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002305 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002306
Johannes Berg17948992016-10-26 11:42:04 +02002307 i = nl80211_add_commands_unsplit(rdev, msg);
2308 if (i < 0)
2309 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002310 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002311 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2312 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002313 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002314 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002315 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002316 if (rdev->wiphy.features &
2317 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002318 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002319 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002320 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Matthew Wang70109982019-08-22 10:48:06 -07002321 CMD(update_ft_ies, UPDATE_FT_IES);
Arend van Spriel5de17982013-04-18 15:49:00 +02002322 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002323#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002324
Johannes Berg3713b4e2013-02-14 16:19:38 +01002325 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002326 state->split_start++;
2327 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002328 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002329 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002330 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002331 if (rdev->ops->remain_on_channel &&
2332 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002333 nla_put_u32(msg,
2334 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002335 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002336 goto nla_put_failure;
2337
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002338 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002339 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2340 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002341
Johannes Berg3713b4e2013-02-14 16:19:38 +01002342 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2343 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002344 state->split_start++;
2345 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002346 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002347 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002348 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002349#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002350 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002351 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002352 state->split_start++;
2353 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002354 break;
2355#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002356 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002357#endif
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002358 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002359 case 7:
2360 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002361 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002362 goto nla_put_failure;
2363
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002364 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002365 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002366 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002367
Johannes Berg86e8cf92013-06-19 10:57:22 +02002368 state->split_start++;
2369 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002370 break;
Miaohe Lin7b506ff2020-08-22 04:23:23 -04002371 fallthrough;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002372 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002373 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002374 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002375 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002376 goto nla_put_failure;
2377
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002378 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002379 /*
2380 * We can only add the per-channel limit information if the
2381 * dump is split, otherwise it makes it too big. Therefore
2382 * only advertise it in that case.
2383 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002384 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002385 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2386 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002387 goto nla_put_failure;
2388
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002389 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002390 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002391 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2392 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002393 goto nla_put_failure;
2394
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002395 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2396 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002397 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002398 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002399 goto nla_put_failure;
2400
2401 /*
2402 * Any information below this point is only available to
2403 * applications that can deal with it being split. This
2404 * helps ensure that newly added capabilities don't break
2405 * older tools by overrunning their buffers.
2406 *
2407 * We still increment split_start so that in the split
2408 * case we'll continue with more data in the next round,
2409 * but break unconditionally so unsplit data stops here.
2410 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002411 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002412 break;
2413 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002414 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002415 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002416 rdev->wiphy.extended_capabilities_len,
2417 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002418 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002419 rdev->wiphy.extended_capabilities_len,
2420 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002421 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002422
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002423 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002424 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002425 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2426 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002427 goto nla_put_failure;
2428
Denis Kenziorae6fa4d2019-07-22 06:33:12 -05002429 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2430 rdev->wiphy.perm_addr))
2431 goto nla_put_failure;
2432
2433 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2434 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2435 rdev->wiphy.addr_mask))
2436 goto nla_put_failure;
2437
2438 if (rdev->wiphy.n_addresses > 1) {
2439 void *attr;
2440
2441 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2442 if (!attr)
2443 goto nla_put_failure;
2444
2445 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2446 if (nla_put(msg, i + 1, ETH_ALEN,
2447 rdev->wiphy.addresses[i].addr))
2448 goto nla_put_failure;
2449
2450 nla_nest_end(msg, attr);
2451 }
2452
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002453 state->split_start++;
2454 break;
2455 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002456 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002457 goto nla_put_failure;
2458
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002459 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002460 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2461 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2462 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002463
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002464 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002465 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002466 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002467 goto nla_put_failure;
2468
Johannes Bergad7e7182013-11-13 13:37:47 +01002469 state->split_start++;
2470 break;
2471 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002472 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002473 const struct nl80211_vendor_cmd_info *info;
2474 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002475
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002476 nested = nla_nest_start_noflag(msg,
2477 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002478 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002479 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002480
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002481 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2482 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002483 if (nla_put(msg, i + 1, sizeof(*info), info))
2484 goto nla_put_failure;
2485 }
2486 nla_nest_end(msg, nested);
2487 }
2488
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002489 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002490 const struct nl80211_vendor_cmd_info *info;
2491 struct nlattr *nested;
2492
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002493 nested = nla_nest_start_noflag(msg,
2494 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002495 if (!nested)
2496 goto nla_put_failure;
2497
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002498 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2499 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002500 if (nla_put(msg, i + 1, sizeof(*info), info))
2501 goto nla_put_failure;
2502 }
2503 nla_nest_end(msg, nested);
2504 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002505 state->split_start++;
2506 break;
2507 case 12:
2508 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2509 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2510 rdev->wiphy.max_num_csa_counters))
2511 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002512
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002513 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2514 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2515 goto nla_put_failure;
2516
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002517 if (rdev->wiphy.max_sched_scan_reqs &&
2518 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2519 rdev->wiphy.max_sched_scan_reqs))
2520 goto nla_put_failure;
2521
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002522 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2523 sizeof(rdev->wiphy.ext_features),
2524 rdev->wiphy.ext_features))
2525 goto nla_put_failure;
2526
Arend van Spriel38de03d2016-03-02 20:37:18 +01002527 if (rdev->wiphy.bss_select_support) {
2528 struct nlattr *nested;
2529 u32 bss_select_support = rdev->wiphy.bss_select_support;
2530
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002531 nested = nla_nest_start_noflag(msg,
2532 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002533 if (!nested)
2534 goto nla_put_failure;
2535
2536 i = 0;
2537 while (bss_select_support) {
2538 if ((bss_select_support & 1) &&
2539 nla_put_flag(msg, i))
2540 goto nla_put_failure;
2541 i++;
2542 bss_select_support >>= 1;
2543 }
2544 nla_nest_end(msg, nested);
2545 }
2546
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302547 state->split_start++;
2548 break;
2549 case 13:
2550 if (rdev->wiphy.num_iftype_ext_capab &&
2551 rdev->wiphy.iftype_ext_capab) {
2552 struct nlattr *nested_ext_capab, *nested;
2553
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002554 nested = nla_nest_start_noflag(msg,
2555 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302556 if (!nested)
2557 goto nla_put_failure;
2558
2559 for (i = state->capa_start;
2560 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2561 const struct wiphy_iftype_ext_capab *capab;
2562
2563 capab = &rdev->wiphy.iftype_ext_capab[i];
2564
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002565 nested_ext_capab = nla_nest_start_noflag(msg,
2566 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302567 if (!nested_ext_capab ||
2568 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2569 capab->iftype) ||
2570 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2571 capab->extended_capabilities_len,
2572 capab->extended_capabilities) ||
2573 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2574 capab->extended_capabilities_len,
2575 capab->extended_capabilities_mask))
2576 goto nla_put_failure;
2577
2578 nla_nest_end(msg, nested_ext_capab);
2579 if (state->split)
2580 break;
2581 }
2582 nla_nest_end(msg, nested);
2583 if (i < rdev->wiphy.num_iftype_ext_capab) {
2584 state->capa_start = i + 1;
2585 break;
2586 }
2587 }
2588
Luca Coelho85859892017-02-08 15:00:34 +02002589 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2590 rdev->wiphy.nan_supported_bands))
2591 goto nla_put_failure;
2592
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002593 if (wiphy_ext_feature_isset(&rdev->wiphy,
2594 NL80211_EXT_FEATURE_TXQS)) {
2595 struct cfg80211_txq_stats txqstats = {};
2596 int res;
2597
2598 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2599 if (!res &&
2600 !nl80211_put_txq_stats(msg, &txqstats,
2601 NL80211_ATTR_TXQ_STATS))
2602 goto nla_put_failure;
2603
2604 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2605 rdev->wiphy.txq_limit))
2606 goto nla_put_failure;
2607 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2608 rdev->wiphy.txq_memory_limit))
2609 goto nla_put_failure;
2610 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2611 rdev->wiphy.txq_quantum))
2612 goto nla_put_failure;
2613 }
2614
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002615 state->split_start++;
2616 break;
2617 case 14:
2618 if (nl80211_send_pmsr_capa(rdev, msg))
2619 goto nla_put_failure;
2620
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302621 state->split_start++;
2622 break;
2623 case 15:
2624 if (rdev->wiphy.akm_suites &&
2625 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2626 sizeof(u32) * rdev->wiphy.n_akm_suites,
2627 rdev->wiphy.akm_suites))
2628 goto nla_put_failure;
2629
Veerendranath Jakkamd6039a32020-01-27 02:00:32 +05302630 if (nl80211_put_iftype_akm_suites(rdev, msg))
2631 goto nla_put_failure;
2632
Johannes Berg3710a8a2020-02-24 11:34:25 +01002633 if (nl80211_put_tid_config_support(rdev, msg))
2634 goto nla_put_failure;
2635
Johannes Berg3713b4e2013-02-14 16:19:38 +01002636 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002637 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002638 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002639 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002640 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002641 genlmsg_end(msg, hdr);
2642 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002643
2644 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002645 genlmsg_cancel(msg, hdr);
2646 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002647}
2648
Johannes Berg86e8cf92013-06-19 10:57:22 +02002649static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2650 struct netlink_callback *cb,
2651 struct nl80211_dump_wiphy_state *state)
2652{
Johannes Berg50508d92019-07-29 16:31:09 +02002653 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2654 int ret;
2655
2656 if (!tb)
2657 return -ENOMEM;
2658
2659 ret = nlmsg_parse_deprecated(cb->nlh,
2660 GENL_HDRLEN + nl80211_fam.hdrsize,
2661 tb, nl80211_fam.maxattr,
2662 nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002663 /* ignore parse errors for backward compatibility */
Johannes Berg50508d92019-07-29 16:31:09 +02002664 if (ret) {
2665 ret = 0;
2666 goto out;
2667 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002668
2669 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2670 if (tb[NL80211_ATTR_WIPHY])
2671 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2672 if (tb[NL80211_ATTR_WDEV])
2673 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2674 if (tb[NL80211_ATTR_IFINDEX]) {
2675 struct net_device *netdev;
2676 struct cfg80211_registered_device *rdev;
2677 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2678
Ying Xue7f2b8562014-01-15 10:23:45 +08002679 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg50508d92019-07-29 16:31:09 +02002680 if (!netdev) {
2681 ret = -ENODEV;
2682 goto out;
2683 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002684 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002685 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002686 netdev->ieee80211_ptr->wiphy);
2687 state->filter_wiphy = rdev->wiphy_idx;
2688 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002689 }
2690
Johannes Berg50508d92019-07-29 16:31:09 +02002691 ret = 0;
2692out:
2693 kfree(tb);
2694 return ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002695}
2696
Johannes Berg55682962007-09-20 13:09:35 -04002697static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2698{
Johannes Berg645e77d2013-03-01 14:03:49 +01002699 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002700 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002701 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002702
Johannes Berg5fe231e2013-05-08 21:45:15 +02002703 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002704 if (!state) {
2705 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002706 if (!state) {
2707 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002708 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002709 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002710 state->filter_wiphy = -1;
2711 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2712 if (ret) {
2713 kfree(state);
2714 rtnl_unlock();
2715 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002716 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002717 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002718 }
2719
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002720 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2721 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002722 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002723 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002724 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002725 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002726 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002727 continue;
2728 /* attempt to fit multiple wiphy data chunks into the skb */
2729 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002730 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2731 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002732 NETLINK_CB(cb->skb).portid,
2733 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002734 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002735 if (ret < 0) {
2736 /*
2737 * If sending the wiphy data didn't fit (ENOBUFS
2738 * or EMSGSIZE returned), this SKB is still
2739 * empty (so it's not too big because another
2740 * wiphy dataset is already in the skb) and
2741 * we've not tried to adjust the dump allocation
2742 * yet ... then adjust the alloc size to be
2743 * bigger, and return 1 but with the empty skb.
2744 * This results in an empty message being RX'ed
2745 * in userspace, but that is ignored.
2746 *
2747 * We can then retry with the larger buffer.
2748 */
2749 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002750 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002751 cb->min_dump_alloc < 4096) {
2752 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002753 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002754 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002755 return 1;
2756 }
2757 idx--;
2758 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002759 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002760 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002761 break;
Johannes Berg55682962007-09-20 13:09:35 -04002762 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002763 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002764
Johannes Berg86e8cf92013-06-19 10:57:22 +02002765 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002766
2767 return skb->len;
2768}
2769
Johannes Berg86e8cf92013-06-19 10:57:22 +02002770static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2771{
2772 kfree((void *)cb->args[0]);
2773 return 0;
2774}
2775
Johannes Berg55682962007-09-20 13:09:35 -04002776static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2777{
2778 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002780 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002781
Johannes Berg645e77d2013-03-01 14:03:49 +01002782 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002783 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002784 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002785
Johannes Berg3bb20552014-05-26 13:52:25 +02002786 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2787 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002788 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002789 nlmsg_free(msg);
2790 return -ENOBUFS;
2791 }
Johannes Berg55682962007-09-20 13:09:35 -04002792
Johannes Berg134e6372009-07-10 09:51:34 +00002793 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002794}
2795
Jouni Malinen31888482008-10-30 16:59:24 +02002796static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2797 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2798 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2799 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2800 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2801 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2802};
2803
2804static int parse_txq_params(struct nlattr *tb[],
2805 struct ieee80211_txq_params *txq_params)
2806{
Dan Williams259d8c12018-01-29 17:03:15 -08002807 u8 ac;
2808
Johannes Berga3304b02012-03-28 11:04:24 +02002809 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002810 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2811 !tb[NL80211_TXQ_ATTR_AIFS])
2812 return -EINVAL;
2813
Dan Williams259d8c12018-01-29 17:03:15 -08002814 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002815 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2816 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2817 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2818 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2819
Dan Williams259d8c12018-01-29 17:03:15 -08002820 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002821 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002822 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002823 return 0;
2824}
2825
Johannes Bergf444de02010-05-05 15:25:02 +02002826static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2827{
2828 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002829 * You can only set the channel explicitly for WDS interfaces,
2830 * all others have their channel managed via their respective
2831 * "establish a connection" command (connect, join, ...)
2832 *
2833 * For AP/GO and mesh mode, the channel can be set with the
2834 * channel userspace API, but is only stored and passed to the
2835 * low-level driver when the AP starts or the mesh is joined.
2836 * This is for backward compatibility, userspace can also give
2837 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002838 *
2839 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002840 * whatever else is going on, so they have their own special
2841 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002842 */
2843 return !wdev ||
2844 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002845 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002846 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2847 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002848}
2849
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002850int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2851 struct genl_info *info,
2852 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002853{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002854 struct netlink_ext_ack *extack = info->extack;
2855 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302856 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002857
Johannes Berg49f9cf02018-10-01 11:55:09 +02002858 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002859 return -EINVAL;
2860
Thomas Pedersen942ba882020-04-30 10:25:51 -07002861 control_freq = MHZ_TO_KHZ(
2862 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2863 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
2864 control_freq +=
2865 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002866
Johannes Bergf43e5212019-09-23 13:51:16 +02002867 memset(chandef, 0, sizeof(*chandef));
Thomas Pedersen942ba882020-04-30 10:25:51 -07002868 chandef->chan = ieee80211_get_channel_khz(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002869 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
Thomas Pedersen942ba882020-04-30 10:25:51 -07002870 chandef->center_freq1 = KHZ_TO_MHZ(control_freq);
2871 chandef->freq1_offset = control_freq % 1000;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002872 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002873
2874 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002875 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2876 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2877 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002878 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002879 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002880
Johannes Berg49f9cf02018-10-01 11:55:09 +02002881 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002882 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002883
Johannes Berg49f9cf02018-10-01 11:55:09 +02002884 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002885
2886 switch (chantype) {
2887 case NL80211_CHAN_NO_HT:
2888 case NL80211_CHAN_HT20:
2889 case NL80211_CHAN_HT40PLUS:
2890 case NL80211_CHAN_HT40MINUS:
2891 cfg80211_chandef_create(chandef, chandef->chan,
2892 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002893 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002894 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2895 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2896 NL_SET_ERR_MSG_ATTR(extack,
2897 attrs[NL80211_ATTR_CENTER_FREQ1],
2898 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002899 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002900 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002901 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002902 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2903 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2904 NL_SET_ERR_MSG_ATTR(extack,
2905 attrs[NL80211_ATTR_CENTER_FREQ2],
2906 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002907 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002908 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002909 break;
2910 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002911 NL_SET_ERR_MSG_ATTR(extack,
2912 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2913 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002914 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002915 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002916 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002917 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002918 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
Thomas Pedersen942ba882020-04-30 10:25:51 -07002919 if (attrs[NL80211_ATTR_CENTER_FREQ1]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002920 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002921 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
Thomas Pedersen942ba882020-04-30 10:25:51 -07002922 if (attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET])
2923 chandef->freq1_offset = nla_get_u32(
2924 attrs[NL80211_ATTR_CENTER_FREQ1_OFFSET]);
2925 else
2926 chandef->freq1_offset = 0;
2927 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002928 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002929 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002930 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002931 }
2932
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03002933 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
2934 chandef->edmg.channels =
2935 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
2936
2937 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
2938 chandef->edmg.bw_config =
2939 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
2940 } else {
2941 chandef->edmg.bw_config = 0;
2942 chandef->edmg.channels = 0;
2943 }
2944
Johannes Berg49f9cf02018-10-01 11:55:09 +02002945 if (!cfg80211_chandef_valid(chandef)) {
2946 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002947 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002948 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002949
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002950 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002951 IEEE80211_CHAN_DISABLED)) {
2952 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002953 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002954 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002955
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002956 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2957 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002958 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2959 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002960 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002961 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002962
Johannes Berg683b6d32012-11-08 21:25:48 +01002963 return 0;
2964}
2965
Johannes Bergf444de02010-05-05 15:25:02 +02002966static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002967 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002968 struct genl_info *info)
2969{
Johannes Berg683b6d32012-11-08 21:25:48 +01002970 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002971 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002972 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002973 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002974
Jouni Malinene16821b2014-04-28 11:22:08 +03002975 if (dev)
2976 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002977 if (!nl80211_can_set_dev_channel(wdev))
2978 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002979 if (wdev)
2980 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002981
Johannes Berg683b6d32012-11-08 21:25:48 +01002982 result = nl80211_parse_chandef(rdev, info, &chandef);
2983 if (result)
2984 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002985
Johannes Berge8c9bd52012-06-06 08:18:22 +02002986 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002987 case NL80211_IFTYPE_AP:
2988 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002989 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2990 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002991 result = -EINVAL;
2992 break;
2993 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002994 if (wdev->beacon_interval) {
2995 if (!dev || !rdev->ops->set_ap_chanwidth ||
2996 !(rdev->wiphy.features &
2997 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2998 result = -EBUSY;
2999 break;
3000 }
3001
3002 /* Only allow dynamic channel width changes */
3003 if (chandef.chan != wdev->preset_chandef.chan) {
3004 result = -EBUSY;
3005 break;
3006 }
3007 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
3008 if (result)
3009 break;
3010 }
Johannes Berg683b6d32012-11-08 21:25:48 +01003011 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02003012 result = 0;
3013 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02003014 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01003015 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02003016 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02003017 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01003018 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02003019 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02003020 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02003021 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02003022 }
Johannes Bergf444de02010-05-05 15:25:02 +02003023
3024 return result;
3025}
3026
3027static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
3028{
Johannes Berg4c476992010-10-04 21:36:35 +02003029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3030 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02003031
Jouni Malinene16821b2014-04-28 11:22:08 +03003032 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02003033}
3034
Bill Jordane8347eb2010-10-01 13:54:28 -04003035static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
3036{
Johannes Berg43b19952010-10-07 13:10:30 +02003037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3038 struct net_device *dev = info->user_ptr[1];
3039 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02003040 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04003041
3042 if (!info->attrs[NL80211_ATTR_MAC])
3043 return -EINVAL;
3044
Johannes Berg43b19952010-10-07 13:10:30 +02003045 if (netif_running(dev))
3046 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04003047
Johannes Berg43b19952010-10-07 13:10:30 +02003048 if (!rdev->ops->set_wds_peer)
3049 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04003050
Johannes Berg43b19952010-10-07 13:10:30 +02003051 if (wdev->iftype != NL80211_IFTYPE_WDS)
3052 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04003053
3054 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03003055 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04003056}
3057
Johannes Berg55682962007-09-20 13:09:35 -04003058static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
3059{
3060 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02003061 struct net_device *netdev = NULL;
3062 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04003063 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02003064 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003065 u32 changed;
3066 u8 retry_short = 0, retry_long = 0;
3067 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01003068 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003069 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04003070
Johannes Berg5fe231e2013-05-08 21:45:15 +02003071 ASSERT_RTNL();
3072
Johannes Bergf444de02010-05-05 15:25:02 +02003073 /*
3074 * Try to find the wiphy and netdev. Normally this
3075 * function shouldn't need the netdev, but this is
3076 * done for backward compatibility -- previously
3077 * setting the channel was done per wiphy, but now
3078 * it is per netdev. Previous userland like hostapd
3079 * also passed a netdev to set_wiphy, so that it is
3080 * possible to let that go to the right netdev!
3081 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003082
Johannes Bergf444de02010-05-05 15:25:02 +02003083 if (info->attrs[NL80211_ATTR_IFINDEX]) {
3084 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
3085
Ying Xue7f2b8562014-01-15 10:23:45 +08003086 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003087 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08003088 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003089 else
Johannes Bergf444de02010-05-05 15:25:02 +02003090 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003091 }
3092
Johannes Bergf444de02010-05-05 15:25:02 +02003093 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02003094 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3095 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003096 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02003097 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02003098 wdev = NULL;
3099 netdev = NULL;
3100 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02003101 } else
Johannes Bergf444de02010-05-05 15:25:02 +02003102 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02003103
3104 /*
3105 * end workaround code, by now the rdev is available
3106 * and locked, and wdev may or may not be NULL.
3107 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003108
3109 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02003110 result = cfg80211_dev_rename(
3111 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003112
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003113 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003114 return result;
Johannes Berg55682962007-09-20 13:09:35 -04003115
Jouni Malinen31888482008-10-30 16:59:24 +02003116 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3117 struct ieee80211_txq_params txq_params;
3118 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3119
Ying Xue7f2b8562014-01-15 10:23:45 +08003120 if (!rdev->ops->set_txq_params)
3121 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02003122
Ying Xue7f2b8562014-01-15 10:23:45 +08003123 if (!netdev)
3124 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03003125
Johannes Berg133a3ff2011-11-03 14:50:13 +01003126 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08003127 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3128 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01003129
Ying Xue7f2b8562014-01-15 10:23:45 +08003130 if (!netif_running(netdev))
3131 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02003132
Jouni Malinen31888482008-10-30 16:59:24 +02003133 nla_for_each_nested(nl_txq_params,
3134 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3135 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02003136 result = nla_parse_nested_deprecated(tb,
3137 NL80211_TXQ_ATTR_MAX,
3138 nl_txq_params,
3139 txq_params_policy,
3140 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01003141 if (result)
3142 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003143 result = parse_txq_params(tb, &txq_params);
3144 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003145 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003146
Hila Gonene35e4d22012-06-27 17:19:42 +03003147 result = rdev_set_txq_params(rdev, netdev,
3148 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02003149 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003150 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003151 }
3152 }
3153
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003154 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03003155 result = __nl80211_set_channel(
3156 rdev,
3157 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3158 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003159 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003160 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003161 }
3162
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003163 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02003164 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003165 enum nl80211_tx_power_setting type;
3166 int idx, mbm = 0;
3167
Johannes Bergc8442112012-10-24 10:17:18 +02003168 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3169 txp_wdev = NULL;
3170
Ying Xue7f2b8562014-01-15 10:23:45 +08003171 if (!rdev->ops->set_tx_power)
3172 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003173
3174 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3175 type = nla_get_u32(info->attrs[idx]);
3176
3177 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08003178 (type != NL80211_TX_POWER_AUTOMATIC))
3179 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003180
3181 if (type != NL80211_TX_POWER_AUTOMATIC) {
3182 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3183 mbm = nla_get_u32(info->attrs[idx]);
3184 }
3185
Johannes Bergc8442112012-10-24 10:17:18 +02003186 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003187 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003188 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003189 }
3190
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003191 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3192 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3193 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003194
Bruno Randolf7f531e02010-12-16 11:30:22 +09003195 if ((!rdev->wiphy.available_antennas_tx &&
3196 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08003197 !rdev->ops->set_antenna)
3198 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003199
3200 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3201 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3202
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003203 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09003204 * available antenna masks, except for the "all" mask */
3205 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08003206 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
3207 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003208
Bruno Randolf7f531e02010-12-16 11:30:22 +09003209 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3210 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003211
Hila Gonene35e4d22012-06-27 17:19:42 +03003212 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003213 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003214 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003215 }
3216
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003217 changed = 0;
3218
3219 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3220 retry_short = nla_get_u8(
3221 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003222
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003223 changed |= WIPHY_PARAM_RETRY_SHORT;
3224 }
3225
3226 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3227 retry_long = nla_get_u8(
3228 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003229
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003230 changed |= WIPHY_PARAM_RETRY_LONG;
3231 }
3232
3233 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3234 frag_threshold = nla_get_u32(
3235 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003236 if (frag_threshold < 256)
3237 return -EINVAL;
3238
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003239 if (frag_threshold != (u32) -1) {
3240 /*
3241 * Fragments (apart from the last one) are required to
3242 * have even length. Make the fragmentation code
3243 * simpler by stripping LSB should someone try to use
3244 * odd threshold value.
3245 */
3246 frag_threshold &= ~0x1;
3247 }
3248 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3249 }
3250
3251 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3252 rts_threshold = nla_get_u32(
3253 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3254 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3255 }
3256
Lukáš Turek81077e82009-12-21 22:50:47 +01003257 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003258 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3259 return -EINVAL;
3260
Lukáš Turek81077e82009-12-21 22:50:47 +01003261 coverage_class = nla_get_u8(
3262 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3263 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3264 }
3265
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003266 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3267 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3268 return -EOPNOTSUPP;
3269
3270 changed |= WIPHY_PARAM_DYN_ACK;
3271 }
3272
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003273 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3274 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3275 NL80211_EXT_FEATURE_TXQS))
3276 return -EOPNOTSUPP;
3277 txq_limit = nla_get_u32(
3278 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3279 changed |= WIPHY_PARAM_TXQ_LIMIT;
3280 }
3281
3282 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3283 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3284 NL80211_EXT_FEATURE_TXQS))
3285 return -EOPNOTSUPP;
3286 txq_memory_limit = nla_get_u32(
3287 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3288 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3289 }
3290
3291 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3292 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3293 NL80211_EXT_FEATURE_TXQS))
3294 return -EOPNOTSUPP;
3295 txq_quantum = nla_get_u32(
3296 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3297 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3298 }
3299
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003300 if (changed) {
3301 u8 old_retry_short, old_retry_long;
3302 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003303 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003304 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003305
Ying Xue7f2b8562014-01-15 10:23:45 +08003306 if (!rdev->ops->set_wiphy_params)
3307 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003308
3309 old_retry_short = rdev->wiphy.retry_short;
3310 old_retry_long = rdev->wiphy.retry_long;
3311 old_frag_threshold = rdev->wiphy.frag_threshold;
3312 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003313 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003314 old_txq_limit = rdev->wiphy.txq_limit;
3315 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3316 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003317
3318 if (changed & WIPHY_PARAM_RETRY_SHORT)
3319 rdev->wiphy.retry_short = retry_short;
3320 if (changed & WIPHY_PARAM_RETRY_LONG)
3321 rdev->wiphy.retry_long = retry_long;
3322 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3323 rdev->wiphy.frag_threshold = frag_threshold;
3324 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3325 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003326 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3327 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003328 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3329 rdev->wiphy.txq_limit = txq_limit;
3330 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3331 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3332 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3333 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003334
Hila Gonene35e4d22012-06-27 17:19:42 +03003335 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003336 if (result) {
3337 rdev->wiphy.retry_short = old_retry_short;
3338 rdev->wiphy.retry_long = old_retry_long;
3339 rdev->wiphy.frag_threshold = old_frag_threshold;
3340 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003341 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003342 rdev->wiphy.txq_limit = old_txq_limit;
3343 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3344 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02003345 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003346 }
3347 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003348 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003349}
3350
Johannes Berg683b6d32012-11-08 21:25:48 +01003351static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003352 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003353{
Johannes Berg601555c2014-11-27 17:26:56 +01003354 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3355 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003356
Johannes Berg683b6d32012-11-08 21:25:48 +01003357 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3358 chandef->chan->center_freq))
3359 return -ENOBUFS;
Thomas Pedersen942ba882020-04-30 10:25:51 -07003360 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
3361 chandef->chan->freq_offset))
3362 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003363 switch (chandef->width) {
3364 case NL80211_CHAN_WIDTH_20_NOHT:
3365 case NL80211_CHAN_WIDTH_20:
3366 case NL80211_CHAN_WIDTH_40:
3367 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3368 cfg80211_get_chandef_type(chandef)))
3369 return -ENOBUFS;
3370 break;
3371 default:
3372 break;
3373 }
3374 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3375 return -ENOBUFS;
3376 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3377 return -ENOBUFS;
3378 if (chandef->center_freq2 &&
3379 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01003380 return -ENOBUFS;
3381 return 0;
3382}
3383
Eric W. Biederman15e47302012-09-07 20:12:54 +00003384static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003385 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003386 struct wireless_dev *wdev,
3387 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003388{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003389 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003390 void *hdr;
3391
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003392 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3393 cmd != NL80211_CMD_DEL_INTERFACE &&
3394 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003395
3396 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003397 if (!hdr)
3398 return -1;
3399
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003400 if (dev &&
3401 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003402 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003403 goto nla_put_failure;
3404
3405 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3406 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003407 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3408 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003409 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003410 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3411 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003412 (cfg80211_rdev_list_generation << 2)) ||
3413 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003414 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003415
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003416 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003417 int ret;
Johannes Bergf43e5212019-09-23 13:51:16 +02003418 struct cfg80211_chan_def chandef = {};
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003419
Johannes Berg683b6d32012-11-08 21:25:48 +01003420 ret = rdev_get_channel(rdev, wdev, &chandef);
3421 if (ret == 0) {
3422 if (nl80211_send_chandef(msg, &chandef))
3423 goto nla_put_failure;
3424 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003425 }
3426
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003427 if (rdev->ops->get_tx_power) {
3428 int dbm, ret;
3429
3430 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3431 if (ret == 0 &&
3432 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3433 DBM_TO_MBM(dbm)))
3434 goto nla_put_failure;
3435 }
3436
Johannes Berg44905262017-10-17 21:56:01 +02003437 wdev_lock(wdev);
3438 switch (wdev->iftype) {
3439 case NL80211_IFTYPE_AP:
3440 if (wdev->ssid_len &&
3441 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003442 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003443 break;
3444 case NL80211_IFTYPE_STATION:
3445 case NL80211_IFTYPE_P2P_CLIENT:
3446 case NL80211_IFTYPE_ADHOC: {
3447 const u8 *ssid_ie;
3448 if (!wdev->current_bss)
3449 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003450 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003451 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3452 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003453 if (ssid_ie &&
3454 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3455 goto nla_put_failure_rcu_locked;
3456 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003457 break;
3458 }
3459 default:
3460 /* nothing */
3461 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003462 }
Johannes Berg44905262017-10-17 21:56:01 +02003463 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003464
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003465 if (rdev->ops->get_txq_stats) {
3466 struct cfg80211_txq_stats txqstats = {};
3467 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3468
3469 if (ret == 0 &&
3470 !nl80211_put_txq_stats(msg, &txqstats,
3471 NL80211_ATTR_TXQ_STATS))
3472 goto nla_put_failure;
3473 }
3474
Johannes Berg053c0952015-01-16 22:09:00 +01003475 genlmsg_end(msg, hdr);
3476 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003477
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003478 nla_put_failure_rcu_locked:
3479 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003480 nla_put_failure_locked:
3481 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003482 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003483 genlmsg_cancel(msg, hdr);
3484 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003485}
3486
3487static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3488{
3489 int wp_idx = 0;
3490 int if_idx = 0;
3491 int wp_start = cb->args[0];
3492 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003493 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003494 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003495 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003496 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003497
Johannes Berg5fe231e2013-05-08 21:45:15 +02003498 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003499 if (!cb->args[2]) {
3500 struct nl80211_dump_wiphy_state state = {
3501 .filter_wiphy = -1,
3502 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003503
3504 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3505 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003506 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003507
3508 filter_wiphy = state.filter_wiphy;
3509
3510 /*
3511 * if filtering, set cb->args[2] to +1 since 0 is the default
3512 * value needed to determine that parsing is necessary.
3513 */
3514 if (filter_wiphy >= 0)
3515 cb->args[2] = filter_wiphy + 1;
3516 else
3517 cb->args[2] = -1;
3518 } else if (cb->args[2] > 0) {
3519 filter_wiphy = cb->args[2] - 1;
3520 }
3521
Johannes Bergf5ea9122009-08-07 16:17:38 +02003522 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3523 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003524 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003525 if (wp_idx < wp_start) {
3526 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003527 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003528 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003529
3530 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3531 continue;
3532
Johannes Berg55682962007-09-20 13:09:35 -04003533 if_idx = 0;
3534
Johannes Berg53873f12016-05-03 16:52:04 +03003535 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003536 if (if_idx < if_start) {
3537 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003538 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003539 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003540 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003541 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003542 rdev, wdev,
3543 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003544 goto out;
3545 }
3546 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003547 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003548
3549 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003550 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003551 out:
Johannes Berg55682962007-09-20 13:09:35 -04003552 cb->args[0] = wp_idx;
3553 cb->args[1] = if_idx;
3554
Johannes Bergea90e0d2017-03-15 14:26:04 +01003555 ret = skb->len;
3556 out_unlock:
3557 rtnl_unlock();
3558
3559 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003560}
3561
3562static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3563{
3564 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003565 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003566 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003567
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003569 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003570 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003571
Eric W. Biederman15e47302012-09-07 20:12:54 +00003572 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003573 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003574 nlmsg_free(msg);
3575 return -ENOBUFS;
3576 }
Johannes Berg55682962007-09-20 13:09:35 -04003577
Johannes Berg134e6372009-07-10 09:51:34 +00003578 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003579}
3580
Michael Wu66f7ac52008-01-31 19:48:22 +01003581static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3582 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3583 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3584 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3585 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3586 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003587 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003588};
3589
3590static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3591{
3592 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3593 int flag;
3594
3595 *mntrflags = 0;
3596
3597 if (!nla)
3598 return -EINVAL;
3599
Johannes Berg8cb08172019-04-26 14:07:28 +02003600 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003601 return -EINVAL;
3602
3603 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3604 if (flags[flag])
3605 *mntrflags |= (1<<flag);
3606
Johannes Berg818a9862017-04-12 11:23:28 +02003607 *mntrflags |= MONITOR_FLAG_CHANGED;
3608
Michael Wu66f7ac52008-01-31 19:48:22 +01003609 return 0;
3610}
3611
Johannes Berg1db77592017-04-12 11:36:31 +02003612static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3613 enum nl80211_iftype type,
3614 struct genl_info *info,
3615 struct vif_params *params)
3616{
3617 bool change = false;
3618 int err;
3619
3620 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3621 if (type != NL80211_IFTYPE_MONITOR)
3622 return -EINVAL;
3623
3624 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3625 &params->flags);
3626 if (err)
3627 return err;
3628
3629 change = true;
3630 }
3631
3632 if (params->flags & MONITOR_FLAG_ACTIVE &&
3633 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3634 return -EOPNOTSUPP;
3635
3636 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3637 const u8 *mumimo_groups;
3638 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3639
3640 if (type != NL80211_IFTYPE_MONITOR)
3641 return -EINVAL;
3642
3643 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3644 return -EOPNOTSUPP;
3645
3646 mumimo_groups =
3647 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3648
3649 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003650 if ((mumimo_groups[0] & BIT(0)) ||
3651 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003652 return -EINVAL;
3653
3654 params->vht_mumimo_groups = mumimo_groups;
3655 change = true;
3656 }
3657
3658 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3659 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3660
3661 if (type != NL80211_IFTYPE_MONITOR)
3662 return -EINVAL;
3663
3664 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3665 return -EOPNOTSUPP;
3666
3667 params->vht_mumimo_follow_addr =
3668 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3669 change = true;
3670 }
3671
3672 return change ? 1 : 0;
3673}
3674
Johannes Berg9bc383d2009-11-19 11:55:19 +01003675static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003676 struct net_device *netdev, u8 use_4addr,
3677 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003678{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003679 if (!use_4addr) {
Julian Wiedmann2e92a2d2020-02-20 09:00:07 +01003680 if (netdev && netif_is_bridge_port(netdev))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003681 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003682 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003683 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003684
3685 switch (iftype) {
3686 case NL80211_IFTYPE_AP_VLAN:
3687 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3688 return 0;
3689 break;
3690 case NL80211_IFTYPE_STATION:
3691 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3692 return 0;
3693 break;
3694 default:
3695 break;
3696 }
3697
3698 return -EOPNOTSUPP;
3699}
3700
Johannes Berg55682962007-09-20 13:09:35 -04003701static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3702{
Johannes Berg4c476992010-10-04 21:36:35 +02003703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003704 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003705 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003706 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003707 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003708 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003709
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003710 memset(&params, 0, sizeof(params));
3711
Johannes Berg04a773a2009-04-19 21:24:32 +02003712 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003713
Johannes Berg723b0382008-09-16 20:22:09 +02003714 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003715 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003716 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003717 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003718 }
3719
Johannes Berg92ffe052008-09-16 20:39:36 +02003720 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003721 struct wireless_dev *wdev = dev->ieee80211_ptr;
3722
Johannes Berg4c476992010-10-04 21:36:35 +02003723 if (ntype != NL80211_IFTYPE_MESH_POINT)
3724 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003725 if (netif_running(dev))
3726 return -EBUSY;
3727
3728 wdev_lock(wdev);
3729 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3730 IEEE80211_MAX_MESH_ID_LEN);
3731 wdev->mesh_id_up_len =
3732 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3733 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3734 wdev->mesh_id_up_len);
3735 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003736 }
3737
Felix Fietkau8b787642009-11-10 18:53:10 +01003738 if (info->attrs[NL80211_ATTR_4ADDR]) {
3739 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3740 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003741 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003742 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003743 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003744 } else {
3745 params.use_4addr = -1;
3746 }
3747
Johannes Berg1db77592017-04-12 11:36:31 +02003748 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3749 if (err < 0)
3750 return err;
3751 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003752 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003753
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003754 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003755 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003756 else
3757 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003758
Johannes Berg9bc383d2009-11-19 11:55:19 +01003759 if (!err && params.use_4addr != -1)
3760 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3761
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003762 if (change && !err) {
3763 struct wireless_dev *wdev = dev->ieee80211_ptr;
3764
3765 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3766 }
3767
Johannes Berg55682962007-09-20 13:09:35 -04003768 return err;
3769}
3770
3771static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3772{
Johannes Berg4c476992010-10-04 21:36:35 +02003773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003774 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003775 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003776 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003777 int err;
3778 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3779
Johannes Berg78f22b62014-03-24 17:57:27 +01003780 /* to avoid failing a new interface creation due to pending removal */
3781 cfg80211_destroy_ifaces(rdev);
3782
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003783 memset(&params, 0, sizeof(params));
3784
Johannes Berg55682962007-09-20 13:09:35 -04003785 if (!info->attrs[NL80211_ATTR_IFNAME])
3786 return -EINVAL;
3787
Johannes Bergab0d76f2018-10-02 10:00:07 +02003788 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003789 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003790
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303791 if (!rdev->ops->add_virtual_intf)
Johannes Berg4c476992010-10-04 21:36:35 +02003792 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003793
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003794 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003795 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3796 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003797 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3798 ETH_ALEN);
3799 if (!is_valid_ether_addr(params.macaddr))
3800 return -EADDRNOTAVAIL;
3801 }
3802
Johannes Berg9bc383d2009-11-19 11:55:19 +01003803 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003804 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003805 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003806 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003807 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003808 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003809
Manikanta Pubbisettye6f40512019-07-22 12:44:50 +05303810 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303811 return -EOPNOTSUPP;
3812
Johannes Berg1db77592017-04-12 11:36:31 +02003813 err = nl80211_parse_mon_options(rdev, type, info, &params);
3814 if (err < 0)
3815 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003816
Johannes Berga18c7192015-02-24 10:56:42 +01003817 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3818 if (!msg)
3819 return -ENOMEM;
3820
Hila Gonene35e4d22012-06-27 17:19:42 +03003821 wdev = rdev_add_virtual_intf(rdev,
3822 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003823 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003824 if (WARN_ON(!wdev)) {
3825 nlmsg_free(msg);
3826 return -EPROTO;
3827 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003828 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003829 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003830 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003831
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003832 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003833 wdev->owner_nlportid = info->snd_portid;
3834
Johannes Berg98104fde2012-06-16 00:19:54 +02003835 switch (type) {
3836 case NL80211_IFTYPE_MESH_POINT:
3837 if (!info->attrs[NL80211_ATTR_MESH_ID])
3838 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003839 wdev_lock(wdev);
3840 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3841 IEEE80211_MAX_MESH_ID_LEN);
3842 wdev->mesh_id_up_len =
3843 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3844 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3845 wdev->mesh_id_up_len);
3846 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003847 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003848 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003849 case NL80211_IFTYPE_P2P_DEVICE:
3850 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003851 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003852 * through the netdev notifier and must be added here
3853 */
Johannes Berge4d42162018-09-13 14:12:03 +02003854 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003855 break;
3856 default:
3857 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003858 }
3859
Eric W. Biederman15e47302012-09-07 20:12:54 +00003860 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003861 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003862 nlmsg_free(msg);
3863 return -ENOBUFS;
3864 }
3865
3866 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003867}
3868
3869static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3870{
Johannes Berg4c476992010-10-04 21:36:35 +02003871 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003872 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003873
Johannes Berg4c476992010-10-04 21:36:35 +02003874 if (!rdev->ops->del_virtual_intf)
3875 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003876
Johannes Berg84efbb82012-06-16 00:00:26 +02003877 /*
3878 * If we remove a wireless device without a netdev then clear
3879 * user_ptr[1] so that nl80211_post_doit won't dereference it
3880 * to check if it needs to do dev_put(). Otherwise it crashes
3881 * since the wdev has been freed, unlike with a netdev where
3882 * we need the dev_put() for the netdev to really be freed.
3883 */
3884 if (!wdev->netdev)
3885 info->user_ptr[1] = NULL;
3886
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003887 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003888}
3889
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003890static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3891{
3892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3893 struct net_device *dev = info->user_ptr[1];
3894 u16 noack_map;
3895
3896 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3897 return -EINVAL;
3898
3899 if (!rdev->ops->set_noack_map)
3900 return -EOPNOTSUPP;
3901
3902 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3903
Hila Gonene35e4d22012-06-27 17:19:42 +03003904 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003905}
3906
Johannes Berg41ade002007-12-19 02:03:29 +01003907struct get_key_cookie {
3908 struct sk_buff *msg;
3909 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003910 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003911};
3912
3913static void get_key_callback(void *c, struct key_params *params)
3914{
Johannes Bergb9454e82009-07-08 13:29:08 +02003915 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003916 struct get_key_cookie *cookie = c;
3917
David S. Miller9360ffd2012-03-29 04:41:26 -04003918 if ((params->key &&
3919 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3920 params->key_len, params->key)) ||
3921 (params->seq &&
3922 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3923 params->seq_len, params->seq)) ||
3924 (params->cipher &&
3925 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3926 params->cipher)))
3927 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003928
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003929 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003930 if (!key)
3931 goto nla_put_failure;
3932
David S. Miller9360ffd2012-03-29 04:41:26 -04003933 if ((params->key &&
3934 nla_put(cookie->msg, NL80211_KEY_DATA,
3935 params->key_len, params->key)) ||
3936 (params->seq &&
3937 nla_put(cookie->msg, NL80211_KEY_SEQ,
3938 params->seq_len, params->seq)) ||
3939 (params->cipher &&
3940 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3941 params->cipher)))
3942 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003943
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003944 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003945 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003946
3947 nla_nest_end(cookie->msg, key);
3948
Johannes Berg41ade002007-12-19 02:03:29 +01003949 return;
3950 nla_put_failure:
3951 cookie->error = 1;
3952}
3953
3954static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3955{
Johannes Berg4c476992010-10-04 21:36:35 +02003956 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003957 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003958 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003959 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003960 const u8 *mac_addr = NULL;
3961 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003962 struct get_key_cookie cookie = {
3963 .error = 0,
3964 };
3965 void *hdr;
3966 struct sk_buff *msg;
Johannes Berg155d7c72020-04-20 14:06:00 +02003967 bool bigtk_support = false;
3968
3969 if (wiphy_ext_feature_isset(&rdev->wiphy,
3970 NL80211_EXT_FEATURE_BEACON_PROTECTION))
3971 bigtk_support = true;
3972
3973 if ((dev->ieee80211_ptr->iftype == NL80211_IFTYPE_STATION ||
3974 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
3975 wiphy_ext_feature_isset(&rdev->wiphy,
3976 NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT))
3977 bigtk_support = true;
Johannes Berg41ade002007-12-19 02:03:29 +01003978
Jouni Malinen56be3932020-02-22 15:25:43 +02003979 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
Johannes Berg41ade002007-12-19 02:03:29 +01003980 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
Johannes Berg155d7c72020-04-20 14:06:00 +02003981
3982 if (key_idx >= 6 && key_idx <= 7 && !bigtk_support) {
3983 GENL_SET_ERR_MSG(info, "BIGTK not supported");
Jouni Malinen56be3932020-02-22 15:25:43 +02003984 return -EINVAL;
Johannes Berg155d7c72020-04-20 14:06:00 +02003985 }
Jouni Malinen56be3932020-02-22 15:25:43 +02003986 }
Johannes Berg41ade002007-12-19 02:03:29 +01003987
Johannes Berg41ade002007-12-19 02:03:29 +01003988 if (info->attrs[NL80211_ATTR_MAC])
3989 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3990
Johannes Berge31b8212010-10-05 19:39:30 +02003991 pairwise = !!mac_addr;
3992 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3993 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003994
Johannes Berge31b8212010-10-05 19:39:30 +02003995 if (kt != NL80211_KEYTYPE_GROUP &&
3996 kt != NL80211_KEYTYPE_PAIRWISE)
3997 return -EINVAL;
3998 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3999 }
4000
Johannes Berg4c476992010-10-04 21:36:35 +02004001 if (!rdev->ops->get_key)
4002 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01004003
Johannes Berg0fa7b392015-01-23 11:10:12 +01004004 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4005 return -ENOENT;
4006
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004007 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004008 if (!msg)
4009 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01004010
Eric W. Biederman15e47302012-09-07 20:12:54 +00004011 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01004012 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03004013 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02004014 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01004015
4016 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02004017 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01004018
David S. Miller9360ffd2012-03-29 04:41:26 -04004019 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4020 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
4021 goto nla_put_failure;
4022 if (mac_addr &&
4023 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
4024 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01004025
Hila Gonene35e4d22012-06-27 17:19:42 +03004026 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
4027 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01004028
4029 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03004030 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01004031
4032 if (cookie.error)
4033 goto nla_put_failure;
4034
4035 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02004036 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01004037
4038 nla_put_failure:
4039 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03004040 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01004041 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01004042 return err;
4043}
4044
4045static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
4046{
Johannes Berg4c476992010-10-04 21:36:35 +02004047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02004048 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01004049 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004050 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01004051
Johannes Bergb9454e82009-07-08 13:29:08 +02004052 err = nl80211_parse_key(info, &key);
4053 if (err)
4054 return err;
4055
4056 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01004057 return -EINVAL;
4058
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004059 /* Only support setting default key and
4060 * Extended Key ID action NL80211_KEY_SET_TX.
4061 */
Jouni Malinen56be3932020-02-22 15:25:43 +02004062 if (!key.def && !key.defmgmt && !key.defbeacon &&
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004063 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01004064 return -EINVAL;
4065
Johannes Bergfffd0932009-07-08 14:22:54 +02004066 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004067
4068 if (key.def) {
4069 if (!rdev->ops->set_default_key) {
4070 err = -EOPNOTSUPP;
4071 goto out;
4072 }
4073
4074 err = nl80211_key_allowed(dev->ieee80211_ptr);
4075 if (err)
4076 goto out;
4077
Hila Gonene35e4d22012-06-27 17:19:42 +03004078 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004079 key.def_uni, key.def_multi);
4080
4081 if (err)
4082 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02004083
Johannes Berg3d23e342009-09-29 23:27:28 +02004084#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004085 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02004086#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004087 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004088 if (key.def_uni || !key.def_multi) {
4089 err = -EINVAL;
4090 goto out;
4091 }
4092
4093 if (!rdev->ops->set_default_mgmt_key) {
4094 err = -EOPNOTSUPP;
4095 goto out;
4096 }
4097
4098 err = nl80211_key_allowed(dev->ieee80211_ptr);
4099 if (err)
4100 goto out;
4101
Hila Gonene35e4d22012-06-27 17:19:42 +03004102 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004103 if (err)
4104 goto out;
4105
4106#ifdef CONFIG_CFG80211_WEXT
4107 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
4108#endif
Jouni Malinen56be3932020-02-22 15:25:43 +02004109 } else if (key.defbeacon) {
4110 if (key.def_uni || !key.def_multi) {
4111 err = -EINVAL;
4112 goto out;
4113 }
4114
4115 if (!rdev->ops->set_default_beacon_key) {
4116 err = -EOPNOTSUPP;
4117 goto out;
4118 }
4119
4120 err = nl80211_key_allowed(dev->ieee80211_ptr);
4121 if (err)
4122 goto out;
4123
4124 err = rdev_set_default_beacon_key(rdev, dev, key.idx);
4125 if (err)
4126 goto out;
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004127 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4128 wiphy_ext_feature_isset(&rdev->wiphy,
4129 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4130 u8 *mac_addr = NULL;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004131
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004132 if (info->attrs[NL80211_ATTR_MAC])
4133 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4134
4135 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4136 err = -EINVAL;
4137 goto out;
4138 }
4139
4140 err = rdev_add_key(rdev, dev, key.idx,
4141 NL80211_KEYTYPE_PAIRWISE,
4142 mac_addr, &key.p);
4143 } else {
4144 err = -EINVAL;
4145 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004146 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02004147 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01004148
Johannes Berg41ade002007-12-19 02:03:29 +01004149 return err;
4150}
4151
4152static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4153{
Johannes Berg4c476992010-10-04 21:36:35 +02004154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02004155 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004156 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02004157 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02004158 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01004159
Johannes Bergb9454e82009-07-08 13:29:08 +02004160 err = nl80211_parse_key(info, &key);
4161 if (err)
4162 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01004163
Jouni Malinenf8af7642020-02-22 15:25:42 +02004164 if (!key.p.key) {
4165 GENL_SET_ERR_MSG(info, "no key");
Johannes Berg41ade002007-12-19 02:03:29 +01004166 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004167 }
Johannes Berg41ade002007-12-19 02:03:29 +01004168
Johannes Berg41ade002007-12-19 02:03:29 +01004169 if (info->attrs[NL80211_ATTR_MAC])
4170 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4171
Johannes Berge31b8212010-10-05 19:39:30 +02004172 if (key.type == -1) {
4173 if (mac_addr)
4174 key.type = NL80211_KEYTYPE_PAIRWISE;
4175 else
4176 key.type = NL80211_KEYTYPE_GROUP;
4177 }
4178
4179 /* for now */
4180 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
Jouni Malinenf8af7642020-02-22 15:25:42 +02004181 key.type != NL80211_KEYTYPE_GROUP) {
4182 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
Johannes Berge31b8212010-10-05 19:39:30 +02004183 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004184 }
Johannes Berge31b8212010-10-05 19:39:30 +02004185
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02004186 if (key.type == NL80211_KEYTYPE_GROUP &&
4187 info->attrs[NL80211_ATTR_VLAN_ID])
4188 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4189
Johannes Berg4c476992010-10-04 21:36:35 +02004190 if (!rdev->ops->add_key)
4191 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004192
Johannes Berge31b8212010-10-05 19:39:30 +02004193 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4194 key.type == NL80211_KEYTYPE_PAIRWISE,
Jouni Malinenf8af7642020-02-22 15:25:42 +02004195 mac_addr)) {
4196 GENL_SET_ERR_MSG(info, "key setting validation failed");
Johannes Berg4c476992010-10-04 21:36:35 +02004197 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004198 }
Johannes Bergfffd0932009-07-08 14:22:54 +02004199
4200 wdev_lock(dev->ieee80211_ptr);
4201 err = nl80211_key_allowed(dev->ieee80211_ptr);
Jouni Malinenf8af7642020-02-22 15:25:42 +02004202 if (err)
4203 GENL_SET_ERR_MSG(info, "key not allowed");
4204 if (!err) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004205 err = rdev_add_key(rdev, dev, key.idx,
4206 key.type == NL80211_KEYTYPE_PAIRWISE,
4207 mac_addr, &key.p);
Jouni Malinenf8af7642020-02-22 15:25:42 +02004208 if (err)
4209 GENL_SET_ERR_MSG(info, "key addition failed");
4210 }
Johannes Bergfffd0932009-07-08 14:22:54 +02004211 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01004212
Johannes Berg41ade002007-12-19 02:03:29 +01004213 return err;
4214}
4215
4216static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4217{
Johannes Berg4c476992010-10-04 21:36:35 +02004218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01004219 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004220 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01004221 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02004222 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01004223
Johannes Bergb9454e82009-07-08 13:29:08 +02004224 err = nl80211_parse_key(info, &key);
4225 if (err)
4226 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01004227
4228 if (info->attrs[NL80211_ATTR_MAC])
4229 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4230
Johannes Berge31b8212010-10-05 19:39:30 +02004231 if (key.type == -1) {
4232 if (mac_addr)
4233 key.type = NL80211_KEYTYPE_PAIRWISE;
4234 else
4235 key.type = NL80211_KEYTYPE_GROUP;
4236 }
4237
4238 /* for now */
4239 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4240 key.type != NL80211_KEYTYPE_GROUP)
4241 return -EINVAL;
4242
Johannes Berg4c476992010-10-04 21:36:35 +02004243 if (!rdev->ops->del_key)
4244 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01004245
Johannes Bergfffd0932009-07-08 14:22:54 +02004246 wdev_lock(dev->ieee80211_ptr);
4247 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02004248
Johannes Berg0fa7b392015-01-23 11:10:12 +01004249 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02004250 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4251 err = -ENOENT;
4252
Johannes Bergfffd0932009-07-08 14:22:54 +02004253 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004254 err = rdev_del_key(rdev, dev, key.idx,
4255 key.type == NL80211_KEYTYPE_PAIRWISE,
4256 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01004257
Johannes Berg3d23e342009-09-29 23:27:28 +02004258#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02004259 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02004260 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02004261 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02004262 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02004263 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
4264 }
4265#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02004266 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02004267
Johannes Berg41ade002007-12-19 02:03:29 +01004268 return err;
4269}
4270
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304271/* This function returns an error or the number of nested attributes */
4272static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4273{
4274 struct nlattr *attr;
4275 int n_entries = 0, tmp;
4276
4277 nla_for_each_nested(attr, nl_attr, tmp) {
4278 if (nla_len(attr) != ETH_ALEN)
4279 return -EINVAL;
4280
4281 n_entries++;
4282 }
4283
4284 return n_entries;
4285}
4286
4287/*
4288 * This function parses ACL information and allocates memory for ACL data.
4289 * On successful return, the calling function is responsible to free the
4290 * ACL buffer returned by this function.
4291 */
4292static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4293 struct genl_info *info)
4294{
4295 enum nl80211_acl_policy acl_policy;
4296 struct nlattr *attr;
4297 struct cfg80211_acl_data *acl;
4298 int i = 0, n_entries, tmp;
4299
4300 if (!wiphy->max_acl_mac_addrs)
4301 return ERR_PTR(-EOPNOTSUPP);
4302
4303 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4304 return ERR_PTR(-EINVAL);
4305
4306 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4307 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4308 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4309 return ERR_PTR(-EINVAL);
4310
4311 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4312 return ERR_PTR(-EINVAL);
4313
4314 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4315 if (n_entries < 0)
4316 return ERR_PTR(n_entries);
4317
4318 if (n_entries > wiphy->max_acl_mac_addrs)
4319 return ERR_PTR(-ENOTSUPP);
4320
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05004321 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304322 if (!acl)
4323 return ERR_PTR(-ENOMEM);
4324
4325 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4326 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4327 i++;
4328 }
4329
4330 acl->n_acl_entries = n_entries;
4331 acl->acl_policy = acl_policy;
4332
4333 return acl;
4334}
4335
4336static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4337{
4338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4339 struct net_device *dev = info->user_ptr[1];
4340 struct cfg80211_acl_data *acl;
4341 int err;
4342
4343 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4344 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4345 return -EOPNOTSUPP;
4346
4347 if (!dev->ieee80211_ptr->beacon_interval)
4348 return -EINVAL;
4349
4350 acl = parse_acl_data(&rdev->wiphy, info);
4351 if (IS_ERR(acl))
4352 return PTR_ERR(acl);
4353
4354 err = rdev_set_mac_acl(rdev, dev, acl);
4355
4356 kfree(acl);
4357
4358 return err;
4359}
4360
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304361static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4362 u8 *rates, u8 rates_len)
4363{
4364 u8 i;
4365 u32 mask = 0;
4366
4367 for (i = 0; i < rates_len; i++) {
4368 int rate = (rates[i] & 0x7f) * 5;
4369 int ridx;
4370
4371 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4372 struct ieee80211_rate *srate =
4373 &sband->bitrates[ridx];
4374 if (rate == srate->bitrate) {
4375 mask |= 1 << ridx;
4376 break;
4377 }
4378 }
4379 if (ridx == sband->n_bitrates)
4380 return 0; /* rate not found */
4381 }
4382
4383 return mask;
4384}
4385
4386static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4387 u8 *rates, u8 rates_len,
4388 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4389{
4390 u8 i;
4391
4392 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4393
4394 for (i = 0; i < rates_len; i++) {
4395 int ridx, rbit;
4396
4397 ridx = rates[i] / 8;
4398 rbit = BIT(rates[i] % 8);
4399
4400 /* check validity */
4401 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4402 return false;
4403
4404 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09004405 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304406 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4407 mcs[ridx] |= rbit;
4408 else
4409 return false;
4410 }
4411
4412 return true;
4413}
4414
4415static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4416{
4417 u16 mcs_mask = 0;
4418
4419 switch (vht_mcs_map) {
4420 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4421 break;
4422 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4423 mcs_mask = 0x00FF;
4424 break;
4425 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4426 mcs_mask = 0x01FF;
4427 break;
4428 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4429 mcs_mask = 0x03FF;
4430 break;
4431 default:
4432 break;
4433 }
4434
4435 return mcs_mask;
4436}
4437
4438static void vht_build_mcs_mask(u16 vht_mcs_map,
4439 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4440{
4441 u8 nss;
4442
4443 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4444 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4445 vht_mcs_map >>= 2;
4446 }
4447}
4448
4449static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4450 struct nl80211_txrate_vht *txrate,
4451 u16 mcs[NL80211_VHT_NSS_MAX])
4452{
4453 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4454 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4455 u8 i;
4456
4457 if (!sband->vht_cap.vht_supported)
4458 return false;
4459
4460 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4461
4462 /* Build vht_mcs_mask from VHT capabilities */
4463 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4464
4465 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4466 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4467 mcs[i] = txrate->mcs[i];
4468 else
4469 return false;
4470 }
4471
4472 return true;
4473}
4474
Miles Hueb89a6a2020-08-04 10:16:29 +02004475static u16 he_mcs_map_to_mcs_mask(u8 he_mcs_map)
4476{
4477 switch (he_mcs_map) {
4478 case IEEE80211_HE_MCS_NOT_SUPPORTED:
4479 return 0;
4480 case IEEE80211_HE_MCS_SUPPORT_0_7:
4481 return 0x00FF;
4482 case IEEE80211_HE_MCS_SUPPORT_0_9:
4483 return 0x03FF;
4484 case IEEE80211_HE_MCS_SUPPORT_0_11:
4485 return 0xFFF;
4486 default:
4487 break;
4488 }
4489 return 0;
4490}
4491
4492static void he_build_mcs_mask(u16 he_mcs_map,
4493 u16 he_mcs_mask[NL80211_HE_NSS_MAX])
4494{
4495 u8 nss;
4496
4497 for (nss = 0; nss < NL80211_HE_NSS_MAX; nss++) {
4498 he_mcs_mask[nss] = he_mcs_map_to_mcs_mask(he_mcs_map & 0x03);
4499 he_mcs_map >>= 2;
4500 }
4501}
4502
4503static u16 he_get_txmcsmap(struct genl_info *info,
4504 const struct ieee80211_sta_he_cap *he_cap)
4505{
4506 struct net_device *dev = info->user_ptr[1];
4507 struct wireless_dev *wdev = dev->ieee80211_ptr;
4508 __le16 tx_mcs;
4509
4510 switch (wdev->chandef.width) {
4511 case NL80211_CHAN_WIDTH_80P80:
4512 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80p80;
4513 break;
4514 case NL80211_CHAN_WIDTH_160:
4515 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_160;
4516 break;
4517 default:
4518 tx_mcs = he_cap->he_mcs_nss_supp.tx_mcs_80;
4519 break;
4520 }
4521 return le16_to_cpu(tx_mcs);
4522}
4523
4524static bool he_set_mcs_mask(struct genl_info *info,
4525 struct wireless_dev *wdev,
4526 struct ieee80211_supported_band *sband,
4527 struct nl80211_txrate_he *txrate,
4528 u16 mcs[NL80211_HE_NSS_MAX])
4529{
4530 const struct ieee80211_sta_he_cap *he_cap;
4531 u16 tx_mcs_mask[NL80211_HE_NSS_MAX] = {};
4532 u16 tx_mcs_map = 0;
4533 u8 i;
4534
4535 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
4536 if (!he_cap)
4537 return false;
4538
4539 memset(mcs, 0, sizeof(u16) * NL80211_HE_NSS_MAX);
4540
4541 tx_mcs_map = he_get_txmcsmap(info, he_cap);
4542
4543 /* Build he_mcs_mask from HE capabilities */
4544 he_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4545
4546 for (i = 0; i < NL80211_HE_NSS_MAX; i++) {
4547 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4548 mcs[i] = txrate->mcs[i];
4549 else
4550 return false;
4551 }
4552
4553 return true;
4554}
4555
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304556static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05304557 struct nlattr *attrs[],
4558 enum nl80211_attrs attr,
Miles Hueb89a6a2020-08-04 10:16:29 +02004559 struct cfg80211_bitrate_mask *mask,
4560 struct net_device *dev)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304561{
4562 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Miles Hueb89a6a2020-08-04 10:16:29 +02004564 struct wireless_dev *wdev = dev->ieee80211_ptr;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304565 int rem, i;
4566 struct nlattr *tx_rates;
4567 struct ieee80211_supported_band *sband;
Miles Hueb89a6a2020-08-04 10:16:29 +02004568 u16 vht_tx_mcs_map, he_tx_mcs_map;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304569
4570 memset(mask, 0, sizeof(*mask));
4571 /* Default to all rates enabled */
4572 for (i = 0; i < NUM_NL80211_BANDS; i++) {
Miles Hueb89a6a2020-08-04 10:16:29 +02004573 const struct ieee80211_sta_he_cap *he_cap;
4574
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304575 sband = rdev->wiphy.bands[i];
4576
4577 if (!sband)
4578 continue;
4579
4580 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4581 memcpy(mask->control[i].ht_mcs,
4582 sband->ht_cap.mcs.rx_mask,
4583 sizeof(mask->control[i].ht_mcs));
4584
4585 if (!sband->vht_cap.vht_supported)
4586 continue;
4587
4588 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4589 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
Miles Hueb89a6a2020-08-04 10:16:29 +02004590
4591 he_cap = ieee80211_get_he_iftype_cap(sband, wdev->iftype);
4592 if (!he_cap)
4593 continue;
4594
4595 he_tx_mcs_map = he_get_txmcsmap(info, he_cap);
4596 he_build_mcs_mask(he_tx_mcs_map, mask->control[i].he_mcs);
4597
4598 mask->control[i].he_gi = 0xFF;
4599 mask->control[i].he_ltf = 0xFF;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304600 }
4601
4602 /* if no rates are given set it back to the defaults */
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05304603 if (!attrs[attr])
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304604 goto out;
4605
4606 /* The nested attribute uses enum nl80211_band as the index. This maps
4607 * directly to the enum nl80211_band values used in cfg80211.
4608 */
4609 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05304610 nla_for_each_nested(tx_rates, attrs[attr], rem) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304611 enum nl80211_band band = nla_type(tx_rates);
4612 int err;
4613
4614 if (band < 0 || band >= NUM_NL80211_BANDS)
4615 return -EINVAL;
4616 sband = rdev->wiphy.bands[band];
4617 if (sband == NULL)
4618 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02004619 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4620 tx_rates,
4621 nl80211_txattr_policy,
4622 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304623 if (err)
4624 return err;
4625 if (tb[NL80211_TXRATE_LEGACY]) {
4626 mask->control[band].legacy = rateset_to_mask(
4627 sband,
4628 nla_data(tb[NL80211_TXRATE_LEGACY]),
4629 nla_len(tb[NL80211_TXRATE_LEGACY]));
4630 if ((mask->control[band].legacy == 0) &&
4631 nla_len(tb[NL80211_TXRATE_LEGACY]))
4632 return -EINVAL;
4633 }
4634 if (tb[NL80211_TXRATE_HT]) {
4635 if (!ht_rateset_to_mask(
4636 sband,
4637 nla_data(tb[NL80211_TXRATE_HT]),
4638 nla_len(tb[NL80211_TXRATE_HT]),
4639 mask->control[band].ht_mcs))
4640 return -EINVAL;
4641 }
4642 if (tb[NL80211_TXRATE_VHT]) {
4643 if (!vht_set_mcs_mask(
4644 sband,
4645 nla_data(tb[NL80211_TXRATE_VHT]),
4646 mask->control[band].vht_mcs))
4647 return -EINVAL;
4648 }
4649 if (tb[NL80211_TXRATE_GI]) {
4650 mask->control[band].gi =
4651 nla_get_u8(tb[NL80211_TXRATE_GI]);
4652 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4653 return -EINVAL;
4654 }
Miles Hueb89a6a2020-08-04 10:16:29 +02004655 if (tb[NL80211_TXRATE_HE] &&
4656 !he_set_mcs_mask(info, wdev, sband,
4657 nla_data(tb[NL80211_TXRATE_HE]),
4658 mask->control[band].he_mcs))
4659 return -EINVAL;
4660 if (tb[NL80211_TXRATE_HE_GI])
4661 mask->control[band].he_gi =
4662 nla_get_u8(tb[NL80211_TXRATE_HE_GI]);
4663 if (tb[NL80211_TXRATE_HE_LTF])
4664 mask->control[band].he_ltf =
4665 nla_get_u8(tb[NL80211_TXRATE_HE_LTF]);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304666
4667 if (mask->control[band].legacy == 0) {
Miles Hueb89a6a2020-08-04 10:16:29 +02004668 /* don't allow empty legacy rates if HT, VHT or HE
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304669 * are not even supported.
4670 */
4671 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
Miles Hueb89a6a2020-08-04 10:16:29 +02004672 rdev->wiphy.bands[band]->vht_cap.vht_supported ||
4673 ieee80211_get_he_iftype_cap(sband, wdev->iftype)))
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304674 return -EINVAL;
4675
4676 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4677 if (mask->control[band].ht_mcs[i])
4678 goto out;
4679
4680 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4681 if (mask->control[band].vht_mcs[i])
4682 goto out;
4683
Miles Hueb89a6a2020-08-04 10:16:29 +02004684 for (i = 0; i < NL80211_HE_NSS_MAX; i++)
4685 if (mask->control[band].he_mcs[i])
4686 goto out;
4687
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304688 /* legacy and mcs rates may not be both empty */
4689 return -EINVAL;
4690 }
4691 }
4692
4693out:
4694 return 0;
4695}
4696
Johannes Berg8564e382016-09-19 09:44:44 +02004697static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4698 enum nl80211_band band,
4699 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304700{
Johannes Berg8564e382016-09-19 09:44:44 +02004701 u32 count_ht, count_vht, i;
4702 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304703
4704 /* Allow only one rate */
4705 if (hweight32(rate) > 1)
4706 return -EINVAL;
4707
4708 count_ht = 0;
4709 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004710 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304711 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004712 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304713 count_ht++;
4714 if (count_ht > 1)
4715 return -EINVAL;
4716 }
4717 if (count_ht && rate)
4718 return -EINVAL;
4719 }
4720
4721 count_vht = 0;
4722 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004723 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304724 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004725 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304726 count_vht++;
4727 if (count_vht > 1)
4728 return -EINVAL;
4729 }
4730 if (count_vht && rate)
4731 return -EINVAL;
4732 }
4733
4734 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4735 return -EINVAL;
4736
Johannes Berg8564e382016-09-19 09:44:44 +02004737 if (rate &&
4738 !wiphy_ext_feature_isset(&rdev->wiphy,
4739 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4740 return -EINVAL;
4741 if (count_ht &&
4742 !wiphy_ext_feature_isset(&rdev->wiphy,
4743 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4744 return -EINVAL;
4745 if (count_vht &&
4746 !wiphy_ext_feature_isset(&rdev->wiphy,
4747 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4748 return -EINVAL;
4749
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304750 return 0;
4751}
4752
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004753static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4754 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004755 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004756{
Johannes Berg88600202012-02-13 15:17:18 +01004757 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004758 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004759
Johannes Berg88600202012-02-13 15:17:18 +01004760 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004761
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004762 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4763 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4764 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004765 if (!bcn->head_len)
4766 return -EINVAL;
4767 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004768 }
4769
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004770 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4771 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4772 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004773 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004774 }
4775
Johannes Berg4c476992010-10-04 21:36:35 +02004776 if (!haveinfo)
4777 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004778
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004779 if (attrs[NL80211_ATTR_IE]) {
4780 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4781 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004782 }
4783
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004784 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004785 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004786 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004787 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004788 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004789 }
4790
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004791 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004792 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004793 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004794 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004795 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004796 }
4797
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004798 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4799 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4800 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004801 }
4802
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004803 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4804 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4805
Johannes Berg8cb08172019-04-26 14:07:28 +02004806 err = nla_parse_nested_deprecated(tb,
4807 NL80211_FTM_RESP_ATTR_MAX,
4808 attrs[NL80211_ATTR_FTM_RESPONDER],
4809 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004810 if (err)
4811 return err;
4812
4813 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4814 wiphy_ext_feature_isset(&rdev->wiphy,
4815 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4816 bcn->ftm_responder = 1;
4817 else
4818 return -EOPNOTSUPP;
4819
4820 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4821 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4822 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4823 }
4824
4825 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4826 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4827 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4828 }
4829 } else {
4830 bcn->ftm_responder = -1;
4831 }
4832
Johannes Berg88600202012-02-13 15:17:18 +01004833 return 0;
4834}
4835
John Crispin796e90f2019-07-30 18:37:00 +02004836static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4837 struct ieee80211_he_obss_pd *he_obss_pd)
4838{
4839 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4840 int err;
4841
4842 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4843 he_obss_pd_policy, NULL);
4844 if (err)
4845 return err;
4846
4847 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] ||
4848 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4849 return -EINVAL;
4850
4851 he_obss_pd->min_offset =
4852 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4853 he_obss_pd->max_offset =
4854 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4855
4856 if (he_obss_pd->min_offset >= he_obss_pd->max_offset)
4857 return -EINVAL;
4858
4859 he_obss_pd->enable = true;
4860
4861 return 0;
4862}
4863
John Crispin5c5e52d2019-12-17 15:19:18 +01004864static int nl80211_parse_he_bss_color(struct nlattr *attrs,
4865 struct cfg80211_he_bss_color *he_bss_color)
4866{
4867 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1];
4868 int err;
4869
4870 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs,
4871 he_bss_color_policy, NULL);
4872 if (err)
4873 return err;
4874
4875 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR])
4876 return -EINVAL;
4877
4878 he_bss_color->color =
4879 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]);
Johannes Berg75e6b592020-07-30 13:00:52 +02004880 he_bss_color->enabled =
4881 !nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
John Crispin5c5e52d2019-12-17 15:19:18 +01004882 he_bss_color->partial =
4883 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
4884
4885 return 0;
4886}
4887
Aloka Dixit291c49d2020-09-11 00:05:29 +00004888static int nl80211_parse_fils_discovery(struct cfg80211_registered_device *rdev,
4889 struct nlattr *attrs,
4890 struct cfg80211_ap_settings *params)
4891{
4892 struct nlattr *tb[NL80211_FILS_DISCOVERY_ATTR_MAX + 1];
4893 int ret;
4894 struct cfg80211_fils_discovery *fd = &params->fils_discovery;
4895
4896 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4897 NL80211_EXT_FEATURE_FILS_DISCOVERY))
4898 return -EINVAL;
4899
4900 ret = nla_parse_nested(tb, NL80211_FILS_DISCOVERY_ATTR_MAX, attrs,
4901 NULL, NULL);
4902 if (ret)
4903 return ret;
4904
4905 if (!tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN] ||
4906 !tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX] ||
4907 !tb[NL80211_FILS_DISCOVERY_ATTR_TMPL])
4908 return -EINVAL;
4909
4910 fd->tmpl_len = nla_len(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
4911 fd->tmpl = nla_data(tb[NL80211_FILS_DISCOVERY_ATTR_TMPL]);
4912 fd->min_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MIN]);
4913 fd->max_interval = nla_get_u32(tb[NL80211_FILS_DISCOVERY_ATTR_INT_MAX]);
4914
4915 return 0;
4916}
4917
Johannes Berg66cd7942017-02-07 22:40:44 +02004918static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4919 const u8 *rates)
4920{
4921 int i;
4922
4923 if (!rates)
4924 return;
4925
4926 for (i = 0; i < rates[1]; i++) {
4927 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4928 params->ht_required = true;
4929 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4930 params->vht_required = true;
Ilan Peer2a392592020-03-26 15:09:35 +02004931 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HE_PHY)
4932 params->he_required = true;
Johannes Berg66cd7942017-02-07 22:40:44 +02004933 }
4934}
4935
4936/*
4937 * Since the nl80211 API didn't include, from the beginning, attributes about
4938 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4939 * benefit of drivers that rebuild IEs in the firmware.
4940 */
4941static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4942{
4943 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004944 size_t ies_len = bcn->tail_len;
4945 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004946 const u8 *rates;
4947 const u8 *cap;
4948
4949 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4950 nl80211_check_ap_rate_selectors(params, rates);
4951
4952 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4953 nl80211_check_ap_rate_selectors(params, rates);
4954
4955 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4956 if (cap && cap[1] >= sizeof(*params->ht_cap))
4957 params->ht_cap = (void *)(cap + 2);
4958 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4959 if (cap && cap[1] >= sizeof(*params->vht_cap))
4960 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004961 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4962 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4963 params->he_cap = (void *)(cap + 3);
Shaul Triebitz7e8d6f12020-01-31 13:12:54 +02004964 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION, ies, ies_len);
4965 if (cap && cap[1] >= sizeof(*params->he_oper) + 1)
4966 params->he_oper = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004967}
4968
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004969static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4970 struct cfg80211_ap_settings *params)
4971{
4972 struct wireless_dev *wdev;
4973 bool ret = false;
4974
Johannes Berg53873f12016-05-03 16:52:04 +03004975 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004976 if (wdev->iftype != NL80211_IFTYPE_AP &&
4977 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4978 continue;
4979
Johannes Berg683b6d32012-11-08 21:25:48 +01004980 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004981 continue;
4982
Johannes Berg683b6d32012-11-08 21:25:48 +01004983 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004984 ret = true;
4985 break;
4986 }
4987
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004988 return ret;
4989}
4990
Jouni Malinene39e5b52012-09-30 19:29:39 +03004991static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4992 enum nl80211_auth_type auth_type,
4993 enum nl80211_commands cmd)
4994{
4995 if (auth_type > NL80211_AUTHTYPE_MAX)
4996 return false;
4997
4998 switch (cmd) {
4999 case NL80211_CMD_AUTHENTICATE:
5000 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
5001 auth_type == NL80211_AUTHTYPE_SAE)
5002 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03005003 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5004 NL80211_EXT_FEATURE_FILS_STA) &&
5005 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5006 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5007 auth_type == NL80211_AUTHTYPE_FILS_PK))
5008 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005009 return true;
5010 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02005011 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00005012 !wiphy_ext_feature_isset(&rdev->wiphy,
5013 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
Srinivas Dasari10773a72018-01-25 17:13:39 +02005014 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03005015 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02005016
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03005017 /* FILS with SK PFS or PK not supported yet */
5018 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5019 auth_type == NL80211_AUTHTYPE_FILS_PK)
5020 return false;
5021 if (!wiphy_ext_feature_isset(
5022 &rdev->wiphy,
5023 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
5024 auth_type == NL80211_AUTHTYPE_FILS_SK)
5025 return false;
5026 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005027 case NL80211_CMD_START_AP:
Chung-Hsien Hsu2831a632020-08-17 02:33:15 -05005028 if (!wiphy_ext_feature_isset(&rdev->wiphy,
5029 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP) &&
5030 auth_type == NL80211_AUTHTYPE_SAE)
Jouni Malinene39e5b52012-09-30 19:29:39 +03005031 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03005032 /* FILS not supported yet */
5033 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
5034 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
5035 auth_type == NL80211_AUTHTYPE_FILS_PK)
5036 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03005037 return true;
5038 default:
5039 return false;
5040 }
5041}
5042
Johannes Berg88600202012-02-13 15:17:18 +01005043static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
5044{
5045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5046 struct net_device *dev = info->user_ptr[1];
5047 struct wireless_dev *wdev = dev->ieee80211_ptr;
5048 struct cfg80211_ap_settings params;
5049 int err;
5050
5051 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5052 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5053 return -EOPNOTSUPP;
5054
5055 if (!rdev->ops->start_ap)
5056 return -EOPNOTSUPP;
5057
5058 if (wdev->beacon_interval)
5059 return -EALREADY;
5060
5061 memset(&params, 0, sizeof(params));
5062
5063 /* these are required for START_AP */
5064 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
5065 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
5066 !info->attrs[NL80211_ATTR_BEACON_HEAD])
5067 return -EINVAL;
5068
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07005069 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01005070 if (err)
5071 return err;
5072
5073 params.beacon_interval =
5074 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
5075 params.dtim_period =
5076 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
5077
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05305078 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
5079 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01005080 if (err)
5081 return err;
5082
5083 /*
5084 * In theory, some of these attributes should be required here
5085 * but since they were not used when the command was originally
5086 * added, keep them optional for old user space programs to let
5087 * them continue to work with drivers that do not need the
5088 * additional information -- drivers must check!
5089 */
5090 if (info->attrs[NL80211_ATTR_SSID]) {
5091 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
5092 params.ssid_len =
5093 nla_len(info->attrs[NL80211_ATTR_SSID]);
Johannes Bergcb9abd42020-08-05 15:47:16 +02005094 if (params.ssid_len == 0)
Johannes Berg88600202012-02-13 15:17:18 +01005095 return -EINVAL;
5096 }
5097
Johannes Bergab0d76f2018-10-02 10:00:07 +02005098 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01005099 params.hidden_ssid = nla_get_u32(
5100 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01005101
5102 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
5103
5104 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
5105 params.auth_type = nla_get_u32(
5106 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03005107 if (!nl80211_valid_auth_type(rdev, params.auth_type,
5108 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01005109 return -EINVAL;
5110 } else
5111 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
5112
5113 err = nl80211_crypto_settings(rdev, info, &params.crypto,
5114 NL80211_MAX_NR_CIPHER_SUITES);
5115 if (err)
5116 return err;
5117
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05305118 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
5119 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
5120 return -EOPNOTSUPP;
5121 params.inactivity_timeout = nla_get_u16(
5122 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
5123 }
5124
Johannes Berg53cabad2012-11-14 15:17:28 +01005125 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
5126 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5127 return -EINVAL;
5128 params.p2p_ctwindow =
5129 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01005130 if (params.p2p_ctwindow != 0 &&
5131 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
5132 return -EINVAL;
5133 }
5134
5135 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
5136 u8 tmp;
5137
5138 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5139 return -EINVAL;
5140 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01005141 params.p2p_opp_ps = tmp;
5142 if (params.p2p_opp_ps != 0 &&
5143 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
5144 return -EINVAL;
5145 }
5146
Johannes Bergaa430da2012-05-16 23:50:18 +02005147 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01005148 err = nl80211_parse_chandef(rdev, info, &params.chandef);
5149 if (err)
5150 return err;
5151 } else if (wdev->preset_chandef.chan) {
5152 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005153 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02005154 return -EINVAL;
5155
Arik Nemtsov923b3522015-07-08 15:41:44 +03005156 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
5157 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02005158 return -EINVAL;
5159
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05305160 if (info->attrs[NL80211_ATTR_TX_RATES]) {
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +05305161 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
5162 NL80211_ATTR_TX_RATES,
Miles Hueb89a6a2020-08-04 10:16:29 +02005163 &params.beacon_rate,
5164 dev);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05305165 if (err)
5166 return err;
5167
Johannes Berg8564e382016-09-19 09:44:44 +02005168 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
5169 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05305170 if (err)
5171 return err;
5172 }
5173
Eliad Peller18998c32014-09-10 14:07:34 +03005174 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
5175 params.smps_mode =
5176 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
5177 switch (params.smps_mode) {
5178 case NL80211_SMPS_OFF:
5179 break;
5180 case NL80211_SMPS_STATIC:
5181 if (!(rdev->wiphy.features &
5182 NL80211_FEATURE_STATIC_SMPS))
5183 return -EINVAL;
5184 break;
5185 case NL80211_SMPS_DYNAMIC:
5186 if (!(rdev->wiphy.features &
5187 NL80211_FEATURE_DYNAMIC_SMPS))
5188 return -EINVAL;
5189 break;
5190 default:
5191 return -EINVAL;
5192 }
5193 } else {
5194 params.smps_mode = NL80211_SMPS_OFF;
5195 }
5196
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05305197 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
5198 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
5199 return -EOPNOTSUPP;
5200
Ola Olsson4baf6be2015-10-29 07:04:58 +01005201 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
5202 params.acl = parse_acl_data(&rdev->wiphy, info);
5203 if (IS_ERR(params.acl))
5204 return PTR_ERR(params.acl);
5205 }
5206
John Crispina0de1ca32019-05-28 13:49:48 +02005207 params.twt_responder =
5208 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
5209
John Crispin796e90f2019-07-30 18:37:00 +02005210 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
5211 err = nl80211_parse_he_obss_pd(
5212 info->attrs[NL80211_ATTR_HE_OBSS_PD],
5213 &params.he_obss_pd);
Luca Coelhobc7a39b2020-06-26 12:49:39 +03005214 if (err)
5215 goto out;
John Crispin796e90f2019-07-30 18:37:00 +02005216 }
5217
John Crispin5c5e52d2019-12-17 15:19:18 +01005218 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) {
5219 err = nl80211_parse_he_bss_color(
5220 info->attrs[NL80211_ATTR_HE_BSS_COLOR],
5221 &params.he_bss_color);
5222 if (err)
Luca Coelho60a01212020-06-26 12:49:40 +03005223 goto out;
John Crispin5c5e52d2019-12-17 15:19:18 +01005224 }
5225
Aloka Dixit291c49d2020-09-11 00:05:29 +00005226 if (info->attrs[NL80211_ATTR_FILS_DISCOVERY]) {
5227 err = nl80211_parse_fils_discovery(rdev,
5228 info->attrs[NL80211_ATTR_FILS_DISCOVERY],
5229 &params);
5230 if (err)
5231 goto out;
5232 }
5233
Johannes Berg66cd7942017-02-07 22:40:44 +02005234 nl80211_calculate_ap_params(&params);
5235
Srinivas Dasarife494372019-01-23 18:06:56 +05305236 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
5237 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
5238
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005239 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03005240 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005241 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01005242 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01005243 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01005244 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01005245 wdev->ssid_len = params.ssid_len;
5246 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05005247
5248 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
5249 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005250 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005251 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05305252
Johannes Berg9951ebf2020-02-21 10:41:43 +01005253out:
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05305254 kfree(params.acl);
5255
Johannes Berg56d18932011-05-09 18:41:15 +02005256 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01005257}
5258
Johannes Berg88600202012-02-13 15:17:18 +01005259static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
5260{
5261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5262 struct net_device *dev = info->user_ptr[1];
5263 struct wireless_dev *wdev = dev->ieee80211_ptr;
5264 struct cfg80211_beacon_data params;
5265 int err;
5266
5267 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5268 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5269 return -EOPNOTSUPP;
5270
5271 if (!rdev->ops->change_beacon)
5272 return -EOPNOTSUPP;
5273
5274 if (!wdev->beacon_interval)
5275 return -EINVAL;
5276
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07005277 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01005278 if (err)
5279 return err;
5280
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005281 wdev_lock(wdev);
5282 err = rdev_change_beacon(rdev, dev, &params);
5283 wdev_unlock(wdev);
5284
5285 return err;
Johannes Berg88600202012-02-13 15:17:18 +01005286}
5287
5288static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01005289{
Johannes Berg4c476992010-10-04 21:36:35 +02005290 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5291 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01005292
Ilan Peer7c8d5e02014-02-25 15:33:38 +02005293 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01005294}
5295
Johannes Berg5727ef12007-12-19 02:03:34 +01005296static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
5297 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
5298 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
5299 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03005300 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07005301 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01005302 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01005303};
5304
Johannes Bergeccb8e82009-05-11 21:57:56 +03005305static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005306 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03005307 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01005308{
5309 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03005310 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01005311 int flag;
5312
Johannes Bergeccb8e82009-05-11 21:57:56 +03005313 /*
5314 * Try parsing the new attribute first so userspace
5315 * can specify both for older kernels.
5316 */
5317 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
5318 if (nla) {
5319 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01005320
Johannes Bergeccb8e82009-05-11 21:57:56 +03005321 sta_flags = nla_data(nla);
5322 params->sta_flags_mask = sta_flags->mask;
5323 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005324 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03005325 if ((params->sta_flags_mask |
5326 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
5327 return -EINVAL;
5328 return 0;
5329 }
5330
5331 /* if present, parse the old attribute */
5332
5333 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01005334 if (!nla)
5335 return 0;
5336
Johannes Berg8cb08172019-04-26 14:07:28 +02005337 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01005338 return -EINVAL;
5339
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005340 /*
5341 * Only allow certain flags for interface types so that
5342 * other attributes are silently ignored. Remember that
5343 * this is backward compatibility code with old userspace
5344 * and shouldn't be hit in other cases anyway.
5345 */
5346 switch (iftype) {
5347 case NL80211_IFTYPE_AP:
5348 case NL80211_IFTYPE_AP_VLAN:
5349 case NL80211_IFTYPE_P2P_GO:
5350 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5351 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5352 BIT(NL80211_STA_FLAG_WME) |
5353 BIT(NL80211_STA_FLAG_MFP);
5354 break;
5355 case NL80211_IFTYPE_P2P_CLIENT:
5356 case NL80211_IFTYPE_STATION:
5357 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5358 BIT(NL80211_STA_FLAG_TDLS_PEER);
5359 break;
5360 case NL80211_IFTYPE_MESH_POINT:
5361 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5362 BIT(NL80211_STA_FLAG_MFP) |
5363 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00005364 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005365 default:
5366 return -EINVAL;
5367 }
Johannes Berg5727ef12007-12-19 02:03:34 +01005368
Johannes Berg3383b5a2012-05-10 20:14:43 +02005369 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
5370 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03005371 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01005372
Johannes Berg3383b5a2012-05-10 20:14:43 +02005373 /* no longer support new API additions in old API */
5374 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
5375 return -EINVAL;
5376 }
5377 }
5378
Johannes Berg5727ef12007-12-19 02:03:34 +01005379 return 0;
5380}
5381
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02005382bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005383{
5384 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03005385 u32 bitrate;
5386 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07005387 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005388
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005389 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005390 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005391 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005392
5393 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5394 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03005395 /* report 16-bit bitrate only if we can */
5396 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005397 if (bitrate > 0 &&
5398 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
5399 return false;
5400 if (bitrate_compat > 0 &&
5401 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
5402 return false;
5403
Johannes Bergb51f3be2015-01-15 16:14:02 +01005404 switch (info->bw) {
5405 case RATE_INFO_BW_5:
5406 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
5407 break;
5408 case RATE_INFO_BW_10:
5409 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
5410 break;
5411 default:
5412 WARN_ON(1);
Miaohe Lin7b506ff2020-08-22 04:23:23 -04005413 fallthrough;
Johannes Bergb51f3be2015-01-15 16:14:02 +01005414 case RATE_INFO_BW_20:
5415 rate_flg = 0;
5416 break;
5417 case RATE_INFO_BW_40:
5418 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
5419 break;
5420 case RATE_INFO_BW_80:
5421 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
5422 break;
5423 case RATE_INFO_BW_160:
5424 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
5425 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005426 case RATE_INFO_BW_HE_RU:
5427 rate_flg = 0;
5428 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01005429 }
5430
5431 if (rate_flg && nla_put_flag(msg, rate_flg))
5432 return false;
5433
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005434 if (info->flags & RATE_INFO_FLAGS_MCS) {
5435 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
5436 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005437 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5438 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5439 return false;
5440 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
5441 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
5442 return false;
5443 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
5444 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005445 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5446 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5447 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005448 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
5449 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
5450 return false;
5451 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
5452 return false;
5453 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
5454 return false;
5455 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
5456 return false;
5457 if (info->bw == RATE_INFO_BW_HE_RU &&
5458 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
5459 info->he_ru_alloc))
5460 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005461 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005462
5463 nla_nest_end(msg, rate);
5464 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005465}
5466
Felix Fietkau119363c2013-04-22 16:29:30 +02005467static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
5468 int id)
5469{
5470 void *attr;
5471 int i = 0;
5472
5473 if (!mask)
5474 return true;
5475
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005476 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02005477 if (!attr)
5478 return false;
5479
5480 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
5481 if (!(mask & BIT(i)))
5482 continue;
5483
5484 if (nla_put_u8(msg, i, signal[i]))
5485 return false;
5486 }
5487
5488 nla_nest_end(msg, attr);
5489
5490 return true;
5491}
5492
Johannes Bergcf5ead82014-11-14 17:14:00 +01005493static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5494 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04005495 struct cfg80211_registered_device *rdev,
5496 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01005497 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005498{
5499 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07005500 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005501
Johannes Bergcf5ead82014-11-14 17:14:00 +01005502 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Andy Strohmanf77bf482019-05-24 23:27:29 -07005503 if (!hdr) {
5504 cfg80211_sinfo_release_content(sinfo);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005505 return -1;
Andy Strohmanf77bf482019-05-24 23:27:29 -07005506 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005507
David S. Miller9360ffd2012-03-29 04:41:26 -04005508 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5509 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5510 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5511 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005512
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005513 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005514 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005515 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005516
5517#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02005518 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03005519 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01005520 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5521 sinfo->memb)) \
5522 goto nla_put_failure; \
5523 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02005524#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03005525 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005526 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5527 sinfo->memb, NL80211_STA_INFO_PAD)) \
5528 goto nla_put_failure; \
5529 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01005530
5531 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5532 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
Ben Greear6c7a0032019-08-09 11:00:00 -07005533 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
Johannes Berg319090b2014-11-17 14:08:11 +01005534
Omer Efrat397c6572018-06-17 13:06:14 +03005535 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5536 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005537 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005538 (u32)sinfo->rx_bytes))
5539 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005540
Omer Efrat397c6572018-06-17 13:06:14 +03005541 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5542 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005543 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5544 (u32)sinfo->tx_bytes))
5545 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005546
Johannes Bergd686b922016-04-26 09:54:11 +02005547 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5548 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01005549 PUT_SINFO(LLID, llid, u16);
5550 PUT_SINFO(PLID, plid, u16);
5551 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02005552 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005553 PUT_SINFO_U64(TX_DURATION, tx_duration);
5554
5555 if (wiphy_ext_feature_isset(&rdev->wiphy,
5556 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5557 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01005558
John W. Linville66266b32012-03-15 13:25:41 -04005559 switch (rdev->wiphy.signal_type) {
5560 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01005561 PUT_SINFO(SIGNAL, signal, u8);
5562 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04005563 break;
5564 default:
5565 break;
5566 }
Omer Efrat397c6572018-06-17 13:06:14 +03005567 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005568 if (!nl80211_put_signal(msg, sinfo->chains,
5569 sinfo->chain_signal,
5570 NL80211_STA_INFO_CHAIN_SIGNAL))
5571 goto nla_put_failure;
5572 }
Omer Efrat397c6572018-06-17 13:06:14 +03005573 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005574 if (!nl80211_put_signal(msg, sinfo->chains,
5575 sinfo->chain_signal_avg,
5576 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5577 goto nla_put_failure;
5578 }
Omer Efrat397c6572018-06-17 13:06:14 +03005579 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005580 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5581 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01005582 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005583 }
Omer Efrat397c6572018-06-17 13:06:14 +03005584 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005585 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5586 NL80211_STA_INFO_RX_BITRATE))
5587 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01005588 }
Johannes Berg319090b2014-11-17 14:08:11 +01005589
5590 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5591 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5592 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5593 PUT_SINFO(TX_FAILED, tx_failed, u32);
5594 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
Narayanraddi Mastiab606332019-02-07 12:16:05 -08005595 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01005596 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5597 PUT_SINFO(LOCAL_PM, local_pm, u32);
5598 PUT_SINFO(PEER_PM, peer_pm, u32);
5599 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04005600 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Markus Theil1303a512020-06-11 16:02:38 +02005601 PUT_SINFO(CONNECTED_TO_AS, connected_to_as, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01005602
Omer Efrat397c6572018-06-17 13:06:14 +03005603 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005604 bss_param = nla_nest_start_noflag(msg,
5605 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07005606 if (!bss_param)
5607 goto nla_put_failure;
5608
David S. Miller9360ffd2012-03-29 04:41:26 -04005609 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5610 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5611 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5612 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5613 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5614 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5615 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5616 sinfo->bss_param.dtim_period) ||
5617 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5618 sinfo->bss_param.beacon_interval))
5619 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07005620
5621 nla_nest_end(msg, bss_param);
5622 }
Omer Efrat397c6572018-06-17 13:06:14 +03005623 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005624 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5625 sizeof(struct nl80211_sta_flag_update),
5626 &sinfo->sta_flags))
5627 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005628
Johannes Bergd686b922016-04-26 09:54:11 +02005629 PUT_SINFO_U64(T_OFFSET, t_offset);
5630 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5631 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01005632 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005633 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5634 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305635 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305636 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5637 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5638 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5639 }
Johannes Berg319090b2014-11-17 14:08:11 +01005640
5641#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005642#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005643
Arend van Spriel8689c052018-05-10 13:50:12 +02005644 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005645 struct nlattr *tidsattr;
5646 int tid;
5647
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005648 tidsattr = nla_nest_start_noflag(msg,
5649 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005650 if (!tidsattr)
5651 goto nla_put_failure;
5652
5653 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5654 struct cfg80211_tid_stats *tidstats;
5655 struct nlattr *tidattr;
5656
5657 tidstats = &sinfo->pertid[tid];
5658
5659 if (!tidstats->filled)
5660 continue;
5661
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005662 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005663 if (!tidattr)
5664 goto nla_put_failure;
5665
Johannes Bergd686b922016-04-26 09:54:11 +02005666#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005667 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005668 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5669 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005670 goto nla_put_failure; \
5671 } while (0)
5672
Johannes Bergd686b922016-04-26 09:54:11 +02005673 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5674 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5675 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5676 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01005677
Johannes Bergd686b922016-04-26 09:54:11 +02005678#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005679 if ((tidstats->filled &
5680 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5681 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5682 NL80211_TID_STATS_TXQ_STATS))
5683 goto nla_put_failure;
5684
Johannes Berg6de39802014-12-19 12:34:00 +01005685 nla_nest_end(msg, tidattr);
5686 }
5687
5688 nla_nest_end(msg, tidsattr);
5689 }
5690
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005691 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005692
Johannes Berg319090b2014-11-17 14:08:11 +01005693 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005694 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5695 sinfo->assoc_req_ies))
5696 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005697
Johannes Berg7ea3e112018-05-18 11:40:44 +02005698 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005699 genlmsg_end(msg, hdr);
5700 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005701
5702 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005703 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005704 genlmsg_cancel(msg, hdr);
5705 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005706}
5707
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005708static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005709 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005710{
Johannes Berg73887fd2018-05-18 09:57:55 +02005711 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005712 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005713 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005714 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005715 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005716 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005717
Johannes Bergea90e0d2017-03-15 14:26:04 +01005718 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005719 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005720 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005721 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005722
Johannes Berg97990a02013-04-19 01:02:55 +02005723 if (!wdev->netdev) {
5724 err = -EINVAL;
5725 goto out_err;
5726 }
5727
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005728 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005729 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005730 goto out_err;
5731 }
5732
Johannes Bergbba95fe2008-07-29 13:22:51 +02005733 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005734 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005735 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005736 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005737 if (err == -ENOENT)
5738 break;
5739 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005740 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005741
Johannes Bergcf5ead82014-11-14 17:14:00 +01005742 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005743 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005744 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005745 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005746 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005747 goto out;
5748
5749 sta_idx++;
5750 }
5751
Johannes Bergbba95fe2008-07-29 13:22:51 +02005752 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005753 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005754 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005755 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005756 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005757
5758 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005759}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005760
Johannes Berg5727ef12007-12-19 02:03:34 +01005761static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5762{
Johannes Berg4c476992010-10-04 21:36:35 +02005763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5764 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005765 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005766 struct sk_buff *msg;
5767 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005768 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005769
Johannes Berg73887fd2018-05-18 09:57:55 +02005770 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005771
Johannes Berg73887fd2018-05-18 09:57:55 +02005772 if (!info->attrs[NL80211_ATTR_MAC])
5773 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005774
5775 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5776
Johannes Berg73887fd2018-05-18 09:57:55 +02005777 if (!rdev->ops->get_station)
5778 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005779
Johannes Berg73887fd2018-05-18 09:57:55 +02005780 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005781 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005782 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005783
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005784 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005785 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005786 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005787 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005788 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005789
Johannes Bergcf5ead82014-11-14 17:14:00 +01005790 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5791 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005792 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005793 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005794 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005795 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005796
Johannes Berg73887fd2018-05-18 09:57:55 +02005797 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005798}
5799
Johannes Berg77ee7c82013-02-15 00:48:33 +01005800int cfg80211_check_station_change(struct wiphy *wiphy,
5801 struct station_parameters *params,
5802 enum cfg80211_station_type statype)
5803{
Ayala Bekere4208422015-10-23 11:20:06 +03005804 if (params->listen_interval != -1 &&
5805 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005806 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005807
Ayala Beker17b94242016-03-17 15:41:38 +02005808 if (params->support_p2p_ps != -1 &&
5809 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5810 return -EINVAL;
5811
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005812 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005813 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5814 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005815 return -EINVAL;
5816
5817 /* When you run into this, adjust the code below for the new flag */
5818 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5819
5820 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005821 case CFG80211_STA_MESH_PEER_KERNEL:
5822 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005823 /*
5824 * No ignoring the TDLS flag here -- the userspace mesh
5825 * code doesn't have the bug of including TDLS in the
5826 * mask everywhere.
5827 */
5828 if (params->sta_flags_mask &
5829 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5830 BIT(NL80211_STA_FLAG_MFP) |
5831 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5832 return -EINVAL;
5833 break;
5834 case CFG80211_STA_TDLS_PEER_SETUP:
5835 case CFG80211_STA_TDLS_PEER_ACTIVE:
5836 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5837 return -EINVAL;
5838 /* ignore since it can't change */
5839 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5840 break;
5841 default:
5842 /* disallow mesh-specific things */
5843 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5844 return -EINVAL;
5845 if (params->local_pm)
5846 return -EINVAL;
5847 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5848 return -EINVAL;
5849 }
5850
5851 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5852 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5853 /* TDLS can't be set, ... */
5854 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5855 return -EINVAL;
5856 /*
5857 * ... but don't bother the driver with it. This works around
5858 * a hostapd/wpa_supplicant issue -- it always includes the
5859 * TLDS_PEER flag in the mask even for AP mode.
5860 */
5861 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5862 }
5863
Ayala Beker47edb112015-09-21 15:49:53 +03005864 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5865 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005866 /* reject other things that can't change */
5867 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5868 return -EINVAL;
5869 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5870 return -EINVAL;
5871 if (params->supported_rates)
5872 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005873 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5874 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005875 return -EINVAL;
5876 }
5877
Ayala Beker47edb112015-09-21 15:49:53 +03005878 if (statype != CFG80211_STA_AP_CLIENT &&
5879 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005880 if (params->vlan)
5881 return -EINVAL;
5882 }
5883
5884 switch (statype) {
5885 case CFG80211_STA_AP_MLME_CLIENT:
5886 /* Use this only for authorizing/unauthorizing a station */
5887 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5888 return -EOPNOTSUPP;
5889 break;
5890 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005891 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005892 /* accept only the listed bits */
5893 if (params->sta_flags_mask &
5894 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5895 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5896 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5897 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5898 BIT(NL80211_STA_FLAG_WME) |
5899 BIT(NL80211_STA_FLAG_MFP)))
5900 return -EINVAL;
5901
5902 /* but authenticated/associated only if driver handles it */
5903 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5904 params->sta_flags_mask &
5905 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5906 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5907 return -EINVAL;
5908 break;
5909 case CFG80211_STA_IBSS:
5910 case CFG80211_STA_AP_STA:
5911 /* reject any changes other than AUTHORIZED */
5912 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5913 return -EINVAL;
5914 break;
5915 case CFG80211_STA_TDLS_PEER_SETUP:
5916 /* reject any changes other than AUTHORIZED or WME */
5917 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5918 BIT(NL80211_STA_FLAG_WME)))
5919 return -EINVAL;
5920 /* force (at least) rates when authorizing */
5921 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5922 !params->supported_rates)
5923 return -EINVAL;
5924 break;
5925 case CFG80211_STA_TDLS_PEER_ACTIVE:
5926 /* reject any changes */
5927 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005928 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005929 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5930 return -EINVAL;
5931 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005932 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005933 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5934 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005935 return -EINVAL;
5936 break;
5937 }
5938
Beni Lev06f7c882016-07-19 19:28:56 +03005939 /*
5940 * Older kernel versions ignored this attribute entirely, so don't
5941 * reject attempts to update it but mark it as unused instead so the
5942 * driver won't look at the data.
5943 */
5944 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5945 statype != CFG80211_STA_TDLS_PEER_SETUP)
5946 params->opmode_notif_used = false;
5947
Johannes Berg77ee7c82013-02-15 00:48:33 +01005948 return 0;
5949}
5950EXPORT_SYMBOL(cfg80211_check_station_change);
5951
Johannes Berg5727ef12007-12-19 02:03:34 +01005952/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005953 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005954 */
Johannes Berg80b99892011-11-18 16:23:01 +01005955static struct net_device *get_vlan(struct genl_info *info,
5956 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005957{
Johannes Berg463d0182009-07-14 00:33:35 +02005958 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005959 struct net_device *v;
5960 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005961
Johannes Berg80b99892011-11-18 16:23:01 +01005962 if (!vlanattr)
5963 return NULL;
5964
5965 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5966 if (!v)
5967 return ERR_PTR(-ENODEV);
5968
5969 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5970 ret = -EINVAL;
5971 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005972 }
Johannes Berg80b99892011-11-18 16:23:01 +01005973
Johannes Berg77ee7c82013-02-15 00:48:33 +01005974 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5975 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5976 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5977 ret = -EINVAL;
5978 goto error;
5979 }
5980
Johannes Berg80b99892011-11-18 16:23:01 +01005981 if (!netif_running(v)) {
5982 ret = -ENETDOWN;
5983 goto error;
5984 }
5985
5986 return v;
5987 error:
5988 dev_put(v);
5989 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005990}
5991
Johannes Berg94e860f2014-01-20 23:58:15 +01005992static const struct nla_policy
5993nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005994 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5995 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5996};
5997
Johannes Bergff276692013-02-15 00:09:01 +01005998static int nl80211_parse_sta_wme(struct genl_info *info,
5999 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02006000{
Jouni Malinendf881292013-02-14 21:10:54 +02006001 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
6002 struct nlattr *nla;
6003 int err;
6004
Jouni Malinendf881292013-02-14 21:10:54 +02006005 /* parse WME attributes if present */
6006 if (!info->attrs[NL80211_ATTR_STA_WME])
6007 return 0;
6008
6009 nla = info->attrs[NL80211_ATTR_STA_WME];
Johannes Berg8cb08172019-04-26 14:07:28 +02006010 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
6011 nl80211_sta_wme_policy,
6012 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02006013 if (err)
6014 return err;
6015
6016 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
6017 params->uapsd_queues = nla_get_u8(
6018 tb[NL80211_STA_WME_UAPSD_QUEUES]);
6019 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
6020 return -EINVAL;
6021
6022 if (tb[NL80211_STA_WME_MAX_SP])
6023 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
6024
6025 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
6026 return -EINVAL;
6027
6028 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
6029
6030 return 0;
6031}
6032
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306033static int nl80211_parse_sta_channel_info(struct genl_info *info,
6034 struct station_parameters *params)
6035{
6036 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
6037 params->supported_channels =
6038 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
6039 params->supported_channels_len =
6040 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
6041 /*
6042 * Need to include at least one (first channel, number of
Johannes Bergcb9abd42020-08-05 15:47:16 +02006043 * channels) tuple for each subband (checked in policy),
6044 * and must have proper tuples for the rest of the data as well.
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306045 */
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306046 if (params->supported_channels_len % 2)
6047 return -EINVAL;
6048 }
6049
6050 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
6051 params->supported_oper_classes =
6052 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
6053 params->supported_oper_classes_len =
6054 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306055 }
6056 return 0;
6057}
6058
Johannes Bergff276692013-02-15 00:09:01 +01006059static int nl80211_set_station_tdls(struct genl_info *info,
6060 struct station_parameters *params)
6061{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306062 int err;
Johannes Bergff276692013-02-15 00:09:01 +01006063 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006064 if (info->attrs[NL80211_ATTR_PEER_AID])
6065 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01006066 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6067 params->ht_capa =
6068 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
6069 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6070 params->vht_capa =
6071 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006072 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6073 params->he_capa =
6074 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6075 params->he_capa_len =
6076 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006077 }
Johannes Bergff276692013-02-15 00:09:01 +01006078
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306079 err = nl80211_parse_sta_channel_info(info, params);
6080 if (err)
6081 return err;
6082
Johannes Bergff276692013-02-15 00:09:01 +01006083 return nl80211_parse_sta_wme(info, params);
6084}
6085
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05306086static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
6087 struct station_parameters *params)
6088{
6089 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6090 int idx;
6091
6092 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
6093 if (!rdev->ops->set_tx_power ||
6094 !wiphy_ext_feature_isset(&rdev->wiphy,
6095 NL80211_EXT_FEATURE_STA_TX_PWR))
6096 return -EOPNOTSUPP;
6097
6098 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
6099 params->txpwr.type = nla_get_u8(info->attrs[idx]);
6100
6101 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
6102 idx = NL80211_ATTR_STA_TX_POWER;
6103
6104 if (info->attrs[idx])
6105 params->txpwr.power =
6106 nla_get_s16(info->attrs[idx]);
6107 else
6108 return -EINVAL;
6109 }
6110 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
6111 }
6112
6113 return 0;
6114}
6115
Johannes Berg5727ef12007-12-19 02:03:34 +01006116static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
6117{
Johannes Berg4c476992010-10-04 21:36:35 +02006118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006119 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01006120 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01006121 u8 *mac_addr;
6122 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01006123
6124 memset(&params, 0, sizeof(params));
6125
Johannes Berg77ee7c82013-02-15 00:48:33 +01006126 if (!rdev->ops->change_station)
6127 return -EOPNOTSUPP;
6128
Ayala Bekere4208422015-10-23 11:20:06 +03006129 /*
6130 * AID and listen_interval properties can be set only for unassociated
6131 * station. Include these parameters here and will check them in
6132 * cfg80211_check_station_change().
6133 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01006134 if (info->attrs[NL80211_ATTR_STA_AID])
6135 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03006136
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02006137 if (info->attrs[NL80211_ATTR_VLAN_ID])
6138 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6139
Ayala Bekere4208422015-10-23 11:20:06 +03006140 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6141 params.listen_interval =
6142 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
6143 else
6144 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01006145
Johannes Bergab0d76f2018-10-02 10:00:07 +02006146 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
6147 params.support_p2p_ps =
6148 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
6149 else
Ayala Beker17b94242016-03-17 15:41:38 +02006150 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02006151
Johannes Berg5727ef12007-12-19 02:03:34 +01006152 if (!info->attrs[NL80211_ATTR_MAC])
6153 return -EINVAL;
6154
6155 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6156
6157 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
6158 params.supported_rates =
6159 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6160 params.supported_rates_len =
6161 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6162 }
6163
Jouni Malinen9d62a982013-02-14 21:10:13 +02006164 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
6165 params.capability =
6166 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
6167 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
6168 }
6169
6170 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
6171 params.ext_capab =
6172 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6173 params.ext_capab_len =
6174 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6175 }
6176
Johannes Bergbdd3ae32012-01-02 13:30:03 +01006177 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01006178 return -EINVAL;
6179
Johannes Bergab0d76f2018-10-02 10:00:07 +02006180 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006181 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006182 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006183
Johannes Bergf8bacc22013-02-14 23:27:01 +01006184 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07006185 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006186 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02006187 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09006188 params.peer_aid = nla_get_u16(
6189 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01006190 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
6191 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07006192
Johannes Bergab0d76f2018-10-02 10:00:07 +02006193 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
6194 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006195 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
6196
Beni Lev06f7c882016-07-19 19:28:56 +03006197 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6198 params.opmode_notif_used = true;
6199 params.opmode_notif =
6200 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6201 }
6202
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006203 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6204 params.he_6ghz_capa =
Johannes Bergfce2ff72020-08-05 15:35:18 +02006205 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006206
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08006207 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6208 params.airtime_weight =
6209 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6210
6211 if (params.airtime_weight &&
6212 !wiphy_ext_feature_isset(&rdev->wiphy,
6213 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6214 return -EOPNOTSUPP;
6215
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05306216 err = nl80211_parse_sta_txpower_setting(info, &params);
6217 if (err)
6218 return err;
6219
Johannes Berg77ee7c82013-02-15 00:48:33 +01006220 /* Include parameters for TDLS peer (will check later) */
6221 err = nl80211_set_station_tdls(info, &params);
6222 if (err)
6223 return err;
6224
6225 params.vlan = get_vlan(info, rdev);
6226 if (IS_ERR(params.vlan))
6227 return PTR_ERR(params.vlan);
6228
Johannes Berga97f4422009-06-18 17:23:43 +02006229 switch (dev->ieee80211_ptr->iftype) {
6230 case NL80211_IFTYPE_AP:
6231 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02006232 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02006233 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02006234 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01006235 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02006236 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02006237 break;
6238 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01006239 err = -EOPNOTSUPP;
6240 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02006241 }
6242
Johannes Berg77ee7c82013-02-15 00:48:33 +01006243 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03006244 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006245
Johannes Berg77ee7c82013-02-15 00:48:33 +01006246 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01006247 if (params.vlan)
6248 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01006249
Johannes Berg5727ef12007-12-19 02:03:34 +01006250 return err;
6251}
6252
6253static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
6254{
Johannes Berg4c476992010-10-04 21:36:35 +02006255 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01006256 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006257 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01006258 struct station_parameters params;
6259 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01006260 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6261 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01006262
6263 memset(&params, 0, sizeof(params));
6264
Johannes Berg984c3112013-02-14 23:43:25 +01006265 if (!rdev->ops->add_station)
6266 return -EOPNOTSUPP;
6267
Johannes Berg5727ef12007-12-19 02:03:34 +01006268 if (!info->attrs[NL80211_ATTR_MAC])
6269 return -EINVAL;
6270
Johannes Berg5727ef12007-12-19 02:03:34 +01006271 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6272 return -EINVAL;
6273
6274 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
6275 return -EINVAL;
6276
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006277 if (!info->attrs[NL80211_ATTR_STA_AID] &&
6278 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02006279 return -EINVAL;
6280
Johannes Berg5727ef12007-12-19 02:03:34 +01006281 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6282 params.supported_rates =
6283 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6284 params.supported_rates_len =
6285 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6286 params.listen_interval =
6287 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02006288
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02006289 if (info->attrs[NL80211_ATTR_VLAN_ID])
6290 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6291
Ayala Beker17b94242016-03-17 15:41:38 +02006292 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02006293 params.support_p2p_ps =
6294 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02006295 } else {
6296 /*
6297 * if not specified, assume it's supported for P2P GO interface,
6298 * and is NOT supported for AP interface
6299 */
6300 params.support_p2p_ps =
6301 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
6302 }
6303
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006304 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006305 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006306 else
6307 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02006308
Jouni Malinen9d62a982013-02-14 21:10:13 +02006309 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
6310 params.capability =
6311 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
6312 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
6313 }
6314
6315 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
6316 params.ext_capab =
6317 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6318 params.ext_capab_len =
6319 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6320 }
6321
Jouni Malinen36aedc92008-08-25 11:58:58 +03006322 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6323 params.ht_capa =
6324 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006325
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00006326 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6327 params.vht_capa =
6328 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6329
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006330 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6331 params.he_capa =
6332 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6333 params.he_capa_len =
6334 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006335 }
6336
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006337 if (info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY])
6338 params.he_6ghz_capa =
6339 nla_data(info->attrs[NL80211_ATTR_HE_6GHZ_CAPABILITY]);
6340
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01006341 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6342 params.opmode_notif_used = true;
6343 params.opmode_notif =
6344 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6345 }
6346
Johannes Bergab0d76f2018-10-02 10:00:07 +02006347 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07006348 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006349 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07006350
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08006351 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6352 params.airtime_weight =
6353 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6354
6355 if (params.airtime_weight &&
6356 !wiphy_ext_feature_isset(&rdev->wiphy,
6357 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6358 return -EOPNOTSUPP;
6359
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05306360 err = nl80211_parse_sta_txpower_setting(info, &params);
6361 if (err)
6362 return err;
6363
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306364 err = nl80211_parse_sta_channel_info(info, &params);
6365 if (err)
6366 return err;
6367
Johannes Bergff276692013-02-15 00:09:01 +01006368 err = nl80211_parse_sta_wme(info, &params);
6369 if (err)
6370 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006371
Johannes Bergbdd3ae32012-01-02 13:30:03 +01006372 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01006373 return -EINVAL;
6374
Johannes Berg496fcc22015-03-12 08:53:27 +02006375 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
6376 * as userspace might just pass through the capabilities from the IEs
6377 * directly, rather than enforcing this restriction and returning an
6378 * error in this case.
6379 */
6380 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
6381 params.ht_capa = NULL;
6382 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006383
6384 /* HE requires WME */
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006385 if (params.he_capa_len || params.he_6ghz_capa)
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006386 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02006387 }
6388
Rajkumar Manoharan43e64bf2020-05-28 21:34:29 +02006389 /* Ensure that HT/VHT capabilities are not set for 6 GHz HE STA */
6390 if (params.he_6ghz_capa && (params.ht_capa || params.vht_capa))
6391 return -EINVAL;
6392
Johannes Berg77ee7c82013-02-15 00:48:33 +01006393 /* When you run into this, adjust the code below for the new flag */
6394 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6395
Johannes Bergbdd90d52011-12-14 12:20:27 +01006396 switch (dev->ieee80211_ptr->iftype) {
6397 case NL80211_IFTYPE_AP:
6398 case NL80211_IFTYPE_AP_VLAN:
6399 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01006400 /* ignore WME attributes if iface/sta is not capable */
6401 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
6402 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
6403 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03006404
Johannes Bergbdd90d52011-12-14 12:20:27 +01006405 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006406 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6407 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02006408 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006409 /* but don't bother the driver with it */
6410 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03006411
Johannes Bergd582cff2012-10-26 17:53:44 +02006412 /* allow authenticated/associated only if driver handles it */
6413 if (!(rdev->wiphy.features &
6414 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01006415 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02006416 return -EINVAL;
6417
Johannes Bergbda95eb2015-11-26 16:26:13 +01006418 /* Older userspace, or userspace wanting to be compatible with
6419 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
6420 * and assoc flags in the mask, but assumes the station will be
6421 * added as associated anyway since this was the required driver
6422 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
6423 * introduced.
6424 * In order to not bother drivers with this quirk in the API
6425 * set the flags in both the mask and set for new stations in
6426 * this case.
6427 */
6428 if (!(params.sta_flags_mask & auth_assoc)) {
6429 params.sta_flags_mask |= auth_assoc;
6430 params.sta_flags_set |= auth_assoc;
6431 }
6432
Johannes Bergbdd90d52011-12-14 12:20:27 +01006433 /* must be last in here for error handling */
6434 params.vlan = get_vlan(info, rdev);
6435 if (IS_ERR(params.vlan))
6436 return PTR_ERR(params.vlan);
6437 break;
6438 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01006439 /* ignore uAPSD data */
6440 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6441
Johannes Bergd582cff2012-10-26 17:53:44 +02006442 /* associated is disallowed */
6443 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
6444 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006445 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006446 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6447 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02006448 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006449 break;
6450 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01006451 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01006452 /* ignore uAPSD data */
6453 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6454
Johannes Berg77ee7c82013-02-15 00:48:33 +01006455 /* these are disallowed */
6456 if (params.sta_flags_mask &
6457 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
6458 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02006459 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006460 /* Only TDLS peers can be added */
6461 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6462 return -EINVAL;
6463 /* Can only add if TDLS ... */
6464 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
6465 return -EOPNOTSUPP;
6466 /* ... with external setup is supported */
6467 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
6468 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01006469 /*
6470 * Older wpa_supplicant versions always mark the TDLS peer
6471 * as authorized, but it shouldn't yet be.
6472 */
6473 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01006474 break;
6475 default:
6476 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03006477 }
6478
Johannes Bergbdd90d52011-12-14 12:20:27 +01006479 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01006480
Hila Gonene35e4d22012-06-27 17:19:42 +03006481 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006482
Johannes Berg5727ef12007-12-19 02:03:34 +01006483 if (params.vlan)
6484 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01006485 return err;
6486}
6487
6488static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6489{
Johannes Berg4c476992010-10-04 21:36:35 +02006490 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6491 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03006492 struct station_del_parameters params;
6493
6494 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01006495
6496 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03006497 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006498
Johannes Berg306b79e2020-03-20 11:38:35 +01006499 switch (dev->ieee80211_ptr->iftype) {
6500 case NL80211_IFTYPE_AP:
6501 case NL80211_IFTYPE_AP_VLAN:
6502 case NL80211_IFTYPE_MESH_POINT:
6503 case NL80211_IFTYPE_P2P_GO:
6504 /* always accept these */
6505 break;
6506 case NL80211_IFTYPE_ADHOC:
6507 /* conditionally accept */
6508 if (wiphy_ext_feature_isset(&rdev->wiphy,
6509 NL80211_EXT_FEATURE_DEL_IBSS_STA))
6510 break;
Nicolas Cavallariedafcf42020-03-05 14:57:53 +01006511 return -EINVAL;
Johannes Berg306b79e2020-03-20 11:38:35 +01006512 default:
Johannes Berg4c476992010-10-04 21:36:35 +02006513 return -EINVAL;
Johannes Berg306b79e2020-03-20 11:38:35 +01006514 }
Johannes Berge80cf852009-05-11 14:43:13 +02006515
Johannes Berg4c476992010-10-04 21:36:35 +02006516 if (!rdev->ops->del_station)
6517 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01006518
Jouni Malinen98856862014-10-20 13:20:45 +03006519 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6520 params.subtype =
6521 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6522 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6523 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6524 return -EINVAL;
6525 } else {
6526 /* Default to Deauthentication frame */
6527 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6528 }
6529
6530 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6531 params.reason_code =
6532 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6533 if (params.reason_code == 0)
6534 return -EINVAL; /* 0 is reserved */
6535 } else {
6536 /* Default to reason code 2 */
6537 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6538 }
6539
Jouni Malinen89c771e2014-10-10 20:52:40 +03006540 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006541}
6542
Eric W. Biederman15e47302012-09-07 20:12:54 +00006543static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006544 int flags, struct net_device *dev,
6545 u8 *dst, u8 *next_hop,
6546 struct mpath_info *pinfo)
6547{
6548 void *hdr;
6549 struct nlattr *pinfoattr;
6550
Henning Rogge1ef4c852014-11-04 16:14:58 +01006551 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006552 if (!hdr)
6553 return -1;
6554
David S. Miller9360ffd2012-03-29 04:41:26 -04006555 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6556 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6557 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6558 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6559 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02006560
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006561 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006562 if (!pinfoattr)
6563 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006564 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6565 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6566 pinfo->frame_qlen))
6567 goto nla_put_failure;
6568 if (((pinfo->filled & MPATH_INFO_SN) &&
6569 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6570 ((pinfo->filled & MPATH_INFO_METRIC) &&
6571 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6572 pinfo->metric)) ||
6573 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6574 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6575 pinfo->exptime)) ||
6576 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6577 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6578 pinfo->flags)) ||
6579 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6580 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6581 pinfo->discovery_timeout)) ||
6582 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6583 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08006584 pinfo->discovery_retries)) ||
6585 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6586 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08006587 pinfo->hop_count)) ||
6588 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6589 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6590 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006591 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006592
6593 nla_nest_end(msg, pinfoattr);
6594
Johannes Berg053c0952015-01-16 22:09:00 +01006595 genlmsg_end(msg, hdr);
6596 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006597
6598 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07006599 genlmsg_cancel(msg, hdr);
6600 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006601}
6602
6603static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006604 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006605{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006606 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006607 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006608 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006609 u8 dst[ETH_ALEN];
6610 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02006611 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006612 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006613
Johannes Bergea90e0d2017-03-15 14:26:04 +01006614 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006615 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006616 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006617 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006618
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006619 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006620 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006621 goto out_err;
6622 }
6623
Johannes Berg97990a02013-04-19 01:02:55 +02006624 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006625 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006626 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006627 }
6628
Johannes Bergbba95fe2008-07-29 13:22:51 +02006629 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006630 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006631 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006632 if (err == -ENOENT)
6633 break;
6634 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006635 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006636
Eric W. Biederman15e47302012-09-07 20:12:54 +00006637 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006638 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006639 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006640 &pinfo) < 0)
6641 goto out;
6642
6643 path_idx++;
6644 }
6645
Johannes Bergbba95fe2008-07-29 13:22:51 +02006646 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006647 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006648 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006649 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006650 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006651 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006652}
6653
6654static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6655{
Johannes Berg4c476992010-10-04 21:36:35 +02006656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006657 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006658 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006659 struct mpath_info pinfo;
6660 struct sk_buff *msg;
6661 u8 *dst = NULL;
6662 u8 next_hop[ETH_ALEN];
6663
6664 memset(&pinfo, 0, sizeof(pinfo));
6665
6666 if (!info->attrs[NL80211_ATTR_MAC])
6667 return -EINVAL;
6668
6669 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6670
Johannes Berg4c476992010-10-04 21:36:35 +02006671 if (!rdev->ops->get_mpath)
6672 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006673
Johannes Berg4c476992010-10-04 21:36:35 +02006674 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6675 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006676
Hila Gonene35e4d22012-06-27 17:19:42 +03006677 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006678 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006679 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006680
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006682 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006683 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006684
Eric W. Biederman15e47302012-09-07 20:12:54 +00006685 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006686 dev, dst, next_hop, &pinfo) < 0) {
6687 nlmsg_free(msg);
6688 return -ENOBUFS;
6689 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006690
Johannes Berg4c476992010-10-04 21:36:35 +02006691 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006692}
6693
6694static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6695{
Johannes Berg4c476992010-10-04 21:36:35 +02006696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6697 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006698 u8 *dst = NULL;
6699 u8 *next_hop = NULL;
6700
6701 if (!info->attrs[NL80211_ATTR_MAC])
6702 return -EINVAL;
6703
6704 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6705 return -EINVAL;
6706
6707 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6708 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6709
Johannes Berg4c476992010-10-04 21:36:35 +02006710 if (!rdev->ops->change_mpath)
6711 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006712
Johannes Berg4c476992010-10-04 21:36:35 +02006713 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6714 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006715
Hila Gonene35e4d22012-06-27 17:19:42 +03006716 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006717}
Johannes Berg4c476992010-10-04 21:36:35 +02006718
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006719static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6720{
Johannes Berg4c476992010-10-04 21:36:35 +02006721 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6722 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006723 u8 *dst = NULL;
6724 u8 *next_hop = NULL;
6725
6726 if (!info->attrs[NL80211_ATTR_MAC])
6727 return -EINVAL;
6728
6729 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6730 return -EINVAL;
6731
6732 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6733 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6734
Johannes Berg4c476992010-10-04 21:36:35 +02006735 if (!rdev->ops->add_mpath)
6736 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006737
Johannes Berg4c476992010-10-04 21:36:35 +02006738 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6739 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006740
Hila Gonene35e4d22012-06-27 17:19:42 +03006741 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006742}
6743
6744static int nl80211_del_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];
6747 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006748 u8 *dst = NULL;
6749
6750 if (info->attrs[NL80211_ATTR_MAC])
6751 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6752
Johannes Berg4c476992010-10-04 21:36:35 +02006753 if (!rdev->ops->del_mpath)
6754 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006755
Miaoqing Panb5014262019-09-26 16:16:50 +08006756 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6757 return -EOPNOTSUPP;
6758
Hila Gonene35e4d22012-06-27 17:19:42 +03006759 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006760}
6761
Henning Rogge66be7d22014-09-12 08:58:49 +02006762static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6763{
6764 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6765 int err;
6766 struct net_device *dev = info->user_ptr[1];
6767 struct mpath_info pinfo;
6768 struct sk_buff *msg;
6769 u8 *dst = NULL;
6770 u8 mpp[ETH_ALEN];
6771
6772 memset(&pinfo, 0, sizeof(pinfo));
6773
6774 if (!info->attrs[NL80211_ATTR_MAC])
6775 return -EINVAL;
6776
6777 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6778
6779 if (!rdev->ops->get_mpp)
6780 return -EOPNOTSUPP;
6781
6782 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6783 return -EOPNOTSUPP;
6784
6785 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6786 if (err)
6787 return err;
6788
6789 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6790 if (!msg)
6791 return -ENOMEM;
6792
6793 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6794 dev, dst, mpp, &pinfo) < 0) {
6795 nlmsg_free(msg);
6796 return -ENOBUFS;
6797 }
6798
6799 return genlmsg_reply(msg, info);
6800}
6801
6802static int nl80211_dump_mpp(struct sk_buff *skb,
6803 struct netlink_callback *cb)
6804{
6805 struct mpath_info pinfo;
6806 struct cfg80211_registered_device *rdev;
6807 struct wireless_dev *wdev;
6808 u8 dst[ETH_ALEN];
6809 u8 mpp[ETH_ALEN];
6810 int path_idx = cb->args[2];
6811 int err;
6812
Johannes Bergea90e0d2017-03-15 14:26:04 +01006813 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006814 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006815 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006816 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006817
6818 if (!rdev->ops->dump_mpp) {
6819 err = -EOPNOTSUPP;
6820 goto out_err;
6821 }
6822
6823 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6824 err = -EOPNOTSUPP;
6825 goto out_err;
6826 }
6827
6828 while (1) {
6829 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6830 mpp, &pinfo);
6831 if (err == -ENOENT)
6832 break;
6833 if (err)
6834 goto out_err;
6835
6836 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6837 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6838 wdev->netdev, dst, mpp,
6839 &pinfo) < 0)
6840 goto out;
6841
6842 path_idx++;
6843 }
6844
6845 out:
6846 cb->args[2] = path_idx;
6847 err = skb->len;
6848 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006849 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006850 return err;
6851}
6852
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006853static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6854{
Johannes Berg4c476992010-10-04 21:36:35 +02006855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6856 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006857 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006858 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006859 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006860
6861 memset(&params, 0, sizeof(params));
6862 /* default to not changing parameters */
6863 params.use_cts_prot = -1;
6864 params.use_short_preamble = -1;
6865 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006866 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006867 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006868 params.p2p_ctwindow = -1;
6869 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006870
6871 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6872 params.use_cts_prot =
6873 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6874 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6875 params.use_short_preamble =
6876 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6877 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6878 params.use_short_slot_time =
6879 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006880 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6881 params.basic_rates =
6882 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6883 params.basic_rates_len =
6884 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6885 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006886 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6887 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006888 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6889 params.ht_opmode =
6890 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006891
Johannes Berg53cabad2012-11-14 15:17:28 +01006892 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6894 return -EINVAL;
6895 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006896 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006897 if (params.p2p_ctwindow != 0 &&
6898 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6899 return -EINVAL;
6900 }
6901
6902 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6903 u8 tmp;
6904
6905 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6906 return -EINVAL;
6907 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006908 params.p2p_opp_ps = tmp;
6909 if (params.p2p_opp_ps &&
6910 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6911 return -EINVAL;
6912 }
6913
Johannes Berg4c476992010-10-04 21:36:35 +02006914 if (!rdev->ops->change_bss)
6915 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006916
Johannes Berg074ac8d2010-09-16 14:58:22 +02006917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006918 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6919 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006920
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006921 wdev_lock(wdev);
6922 err = rdev_change_bss(rdev, dev, &params);
6923 wdev_unlock(wdev);
6924
6925 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006926}
6927
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006928static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6929{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006930 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006931 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006932 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006933 u32 owner_nlportid;
6934
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006935 /*
6936 * You should only get this when cfg80211 hasn't yet initialized
6937 * completely when built-in to the kernel right between the time
6938 * window between nl80211_init() and regulatory_init(), if that is
6939 * even possible.
6940 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006941 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006942 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006943
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006944 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6945 user_reg_hint_type =
6946 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6947 else
6948 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6949
6950 switch (user_reg_hint_type) {
6951 case NL80211_USER_REG_HINT_USER:
6952 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006953 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6954 return -EINVAL;
6955
6956 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6957 return regulatory_hint_user(data, user_reg_hint_type);
6958 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006959 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6960 owner_nlportid = info->snd_portid;
6961 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6962 } else {
6963 owner_nlportid = 0;
6964 is_indoor = true;
6965 }
6966
6967 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006968 default:
6969 return -EINVAL;
6970 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006971}
6972
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006973static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6974{
6975 return reg_reload_regdb();
6976}
6977
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006978static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006979 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006980{
Johannes Berg4c476992010-10-04 21:36:35 +02006981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006982 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006983 struct wireless_dev *wdev = dev->ieee80211_ptr;
6984 struct mesh_config cur_params;
6985 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006986 void *hdr;
6987 struct nlattr *pinfoattr;
6988 struct sk_buff *msg;
6989
Johannes Berg29cbe682010-12-03 09:20:44 +01006990 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6991 return -EOPNOTSUPP;
6992
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006993 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006994 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006995
Johannes Berg29cbe682010-12-03 09:20:44 +01006996 wdev_lock(wdev);
6997 /* If not connected, get default parameters */
6998 if (!wdev->mesh_id_len)
6999 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
7000 else
Hila Gonene35e4d22012-06-27 17:19:42 +03007001 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01007002 wdev_unlock(wdev);
7003
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007004 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02007005 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007006
7007 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07007008 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007009 if (!msg)
7010 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00007011 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007012 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007013 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01007014 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007015 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007016 if (!pinfoattr)
7017 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04007018 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
7019 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
7020 cur_params.dot11MeshRetryTimeout) ||
7021 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
7022 cur_params.dot11MeshConfirmTimeout) ||
7023 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
7024 cur_params.dot11MeshHoldingTimeout) ||
7025 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
7026 cur_params.dot11MeshMaxPeerLinks) ||
7027 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
7028 cur_params.dot11MeshMaxRetries) ||
7029 nla_put_u8(msg, NL80211_MESHCONF_TTL,
7030 cur_params.dot11MeshTTL) ||
7031 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
7032 cur_params.element_ttl) ||
7033 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
7034 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04007035 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
7036 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007037 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
7038 cur_params.dot11MeshHWMPmaxPREQretries) ||
7039 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
7040 cur_params.path_refresh_time) ||
7041 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
7042 cur_params.min_discovery_timeout) ||
7043 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
7044 cur_params.dot11MeshHWMPactivePathTimeout) ||
7045 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
7046 cur_params.dot11MeshHWMPpreqMinInterval) ||
7047 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
7048 cur_params.dot11MeshHWMPperrMinInterval) ||
7049 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
7050 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
7051 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
7052 cur_params.dot11MeshHWMPRootMode) ||
7053 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
7054 cur_params.dot11MeshHWMPRannInterval) ||
7055 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
7056 cur_params.dot11MeshGateAnnouncementProtocol) ||
7057 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
7058 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09007059 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07007060 cur_params.rssi_threshold) ||
7061 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08007062 cur_params.ht_opmode) ||
7063 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7064 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
7065 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08007066 cur_params.dot11MeshHWMProotInterval) ||
7067 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01007068 cur_params.dot11MeshHWMPconfirmationInterval) ||
7069 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
7070 cur_params.power_mode) ||
7071 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07007072 cur_params.dot11MeshAwakeWindowDuration) ||
7073 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04007074 cur_params.plink_timeout) ||
7075 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
Linus Lüssinge3718a62020-06-17 09:30:33 +02007076 cur_params.dot11MeshConnectedToMeshGate) ||
7077 nla_put_u8(msg, NL80211_MESHCONF_NOLEARN,
Markus Theil184eebe2020-06-11 16:02:37 +02007078 cur_params.dot11MeshNolearn) ||
7079 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_AS,
7080 cur_params.dot11MeshConnectedToAuthServer))
David S. Miller9360ffd2012-03-29 04:41:26 -04007081 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007082 nla_nest_end(msg, pinfoattr);
7083 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007084 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007085
Johannes Berg3b858752009-03-12 09:55:09 +01007086 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01007087 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04007088 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02007089 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007090}
7091
Johannes Bergab0d76f2018-10-02 10:00:07 +02007092static const struct nla_policy
7093nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
7094 [NL80211_MESHCONF_RETRY_TIMEOUT] =
7095 NLA_POLICY_RANGE(NLA_U16, 1, 255),
7096 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
7097 NLA_POLICY_RANGE(NLA_U16, 1, 255),
7098 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
7099 NLA_POLICY_RANGE(NLA_U16, 1, 255),
7100 [NL80211_MESHCONF_MAX_PEER_LINKS] =
7101 NLA_POLICY_RANGE(NLA_U16, 0, 255),
7102 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
7103 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
7104 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
7105 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
7106 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
7107 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007108 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
7109 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02007110 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007111 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02007112 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
7113 NLA_POLICY_MIN(NLA_U16, 1),
7114 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
7115 NLA_POLICY_MIN(NLA_U16, 1),
7116 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
7117 NLA_POLICY_MIN(NLA_U16, 1),
7118 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
7119 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
7120 NLA_POLICY_MIN(NLA_U16, 1),
7121 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
7122 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
7123 [NL80211_MESHCONF_RSSI_THRESHOLD] =
7124 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007125 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08007126 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02007127 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
7128 NLA_POLICY_MIN(NLA_U16, 1),
7129 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
7130 NLA_POLICY_MIN(NLA_U16, 1),
7131 [NL80211_MESHCONF_POWER_MODE] =
7132 NLA_POLICY_RANGE(NLA_U32,
7133 NL80211_MESH_POWER_ACTIVE,
7134 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01007135 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07007136 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04007137 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
Linus Lüssinge3718a62020-06-17 09:30:33 +02007138 [NL80211_MESHCONF_NOLEARN] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
Markus Theil184eebe2020-06-11 16:02:37 +02007139 [NL80211_MESHCONF_CONNECTED_TO_AS] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007140};
7141
Javier Cardonac80d5452010-12-16 17:37:49 -08007142static const struct nla_policy
7143 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07007144 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08007145 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
7146 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07007147 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07007148 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007149 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02007150 [NL80211_MESH_SETUP_IE] =
7151 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
7152 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07007153 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08007154};
7155
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007156static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007157 struct mesh_config *cfg,
7158 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007159{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007160 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007161 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09007162 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007163
Johannes Bergab0d76f2018-10-02 10:00:07 +02007164#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
7165do { \
7166 if (tb[attr]) { \
7167 cfg->param = fn(tb[attr]); \
7168 mask |= BIT((attr) - 1); \
7169 } \
Marco Porschea54fba2013-01-07 16:04:48 +01007170} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007171
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007172 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007173 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02007174 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 -07007175 return -EINVAL;
7176
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007177 /* This makes sure that there aren't more than 32 mesh config
7178 * parameters (otherwise our bitfield scheme would not work.) */
7179 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
7180
7181 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02007182 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
7183 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
7184 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
7185 NL80211_MESHCONF_CONFIRM_TIMEOUT,
7186 nla_get_u16);
7187 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
7188 NL80211_MESHCONF_HOLDING_TIMEOUT,
7189 nla_get_u16);
7190 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
7191 NL80211_MESHCONF_MAX_PEER_LINKS,
7192 nla_get_u16);
7193 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
7194 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
7195 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
7196 NL80211_MESHCONF_TTL, nla_get_u8);
7197 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
7198 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
7199 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
7200 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
7201 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01007202 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007203 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007204 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007205 nla_get_u32);
7206 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
7207 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
7208 nla_get_u8);
7209 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
7210 NL80211_MESHCONF_PATH_REFRESH_TIME,
7211 nla_get_u32);
7212 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
7213 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
7214 return -EINVAL;
7215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
7216 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
7217 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01007218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007219 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007220 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007221 nla_get_u32);
7222 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
7223 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
7224 cfg->dot11MeshHWMPactivePathTimeout > 65535))
7225 return -EINVAL;
7226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01007227 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007228 nla_get_u16);
7229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01007230 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007231 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007233 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08007234 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007235 nla_get_u16);
7236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
7237 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
7238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
7239 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
7240 nla_get_u16);
7241 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01007242 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007243 nla_get_u8);
7244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
7245 NL80211_MESHCONF_FORWARDING, nla_get_u8);
7246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
7247 NL80211_MESHCONF_RSSI_THRESHOLD,
7248 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04007249 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
7250 NL80211_MESHCONF_CONNECTED_TO_GATE,
7251 nla_get_u8);
Markus Theil184eebe2020-06-11 16:02:37 +02007252 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToAuthServer, mask,
7253 NL80211_MESHCONF_CONNECTED_TO_AS,
7254 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09007255 /*
7256 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04007257 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09007258 */
7259 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
7260 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
7261
7262 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
7263 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
7264 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
7265 return -EINVAL;
7266
Bob Copeland188f60a2018-06-24 21:10:49 -04007267 /* NON_HT_STA bit is reserved, but some programs set it */
7268 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09007269
Masashi Honma97572352016-08-03 10:07:44 +09007270 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09007271 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09007272 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08007273 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007274 dot11MeshHWMPactivePathToRootTimeout, mask,
7275 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7276 nla_get_u32);
7277 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
7278 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
7279 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
7280 return -EINVAL;
7281 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
7282 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
7283 nla_get_u16);
7284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
7285 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08007286 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007287 nla_get_u16);
7288 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
7289 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
7290 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
7291 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
7292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
7293 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Linus Lüssinge3718a62020-06-17 09:30:33 +02007294 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNolearn, mask,
7295 NL80211_MESHCONF_NOLEARN, nla_get_u8);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007296 if (mask_out)
7297 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08007298
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007299 return 0;
7300
7301#undef FILL_IN_MESH_PARAM_IF_SET
7302}
7303
Javier Cardonac80d5452010-12-16 17:37:49 -08007304static int nl80211_parse_mesh_setup(struct genl_info *info,
7305 struct mesh_setup *setup)
7306{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08007308 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
7309
7310 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
7311 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02007312 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 -08007313 return -EINVAL;
7314
Javier Cardonad299a1f2012-03-31 11:31:33 -07007315 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
7316 setup->sync_method =
7317 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
7318 IEEE80211_SYNC_METHOD_VENDOR :
7319 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
7320
Javier Cardonac80d5452010-12-16 17:37:49 -08007321 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
7322 setup->path_sel_proto =
7323 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
7324 IEEE80211_PATH_PROTOCOL_VENDOR :
7325 IEEE80211_PATH_PROTOCOL_HWMP;
7326
7327 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
7328 setup->path_metric =
7329 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
7330 IEEE80211_PATH_METRIC_VENDOR :
7331 IEEE80211_PATH_METRIC_AIRTIME;
7332
Javier Cardona581a8b02011-04-07 15:08:27 -07007333 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08007334 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07007335 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07007336 setup->ie = nla_data(ieattr);
7337 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08007338 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007339 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
7340 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
7341 return -EINVAL;
7342 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07007343 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
7344 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007345 if (setup->is_secure)
7346 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08007347
Colleen Twitty6e16d902013-05-08 11:45:59 -07007348 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
7349 if (!setup->user_mpm)
7350 return -EINVAL;
7351 setup->auth_id =
7352 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
7353 }
7354
Javier Cardonac80d5452010-12-16 17:37:49 -08007355 return 0;
7356}
7357
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007358static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01007359 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007360{
7361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01007363 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007364 struct mesh_config cfg;
7365 u32 mask;
7366 int err;
7367
Johannes Berg29cbe682010-12-03 09:20:44 +01007368 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7369 return -EOPNOTSUPP;
7370
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007371 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007372 return -EOPNOTSUPP;
7373
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007374 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007375 if (err)
7376 return err;
7377
Johannes Berg29cbe682010-12-03 09:20:44 +01007378 wdev_lock(wdev);
7379 if (!wdev->mesh_id_len)
7380 err = -ENOLINK;
7381
7382 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03007383 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007384
7385 wdev_unlock(wdev);
7386
7387 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007388}
7389
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007390static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
7391 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007392{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007393 struct nlattr *nl_reg_rules;
7394 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007395
Johannes Berg458f4f92012-12-06 15:47:38 +01007396 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
7397 (regdom->dfs_region &&
7398 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007399 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01007400
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007401 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007402 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007403 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007404
Johannes Berg458f4f92012-12-06 15:47:38 +01007405 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007406 struct nlattr *nl_reg_rule;
7407 const struct ieee80211_reg_rule *reg_rule;
7408 const struct ieee80211_freq_range *freq_range;
7409 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01007410 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007411
Johannes Berg458f4f92012-12-06 15:47:38 +01007412 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007413 freq_range = &reg_rule->freq_range;
7414 power_rule = &reg_rule->power_rule;
7415
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007416 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007417 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007418 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007419
Janusz Dziedzic97524822014-01-30 09:52:20 +01007420 max_bandwidth_khz = freq_range->max_bandwidth_khz;
7421 if (!max_bandwidth_khz)
7422 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
7423 reg_rule);
7424
David S. Miller9360ffd2012-03-29 04:41:26 -04007425 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
7426 reg_rule->flags) ||
7427 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
7428 freq_range->start_freq_khz) ||
7429 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
7430 freq_range->end_freq_khz) ||
7431 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01007432 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007433 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
7434 power_rule->max_antenna_gain) ||
7435 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01007436 power_rule->max_eirp) ||
7437 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
7438 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007439 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007440
7441 nla_nest_end(msg, nl_reg_rule);
7442 }
7443
7444 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007445 return 0;
7446
7447nla_put_failure:
7448 return -EMSGSIZE;
7449}
7450
7451static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
7452{
7453 const struct ieee80211_regdomain *regdom = NULL;
7454 struct cfg80211_registered_device *rdev;
7455 struct wiphy *wiphy = NULL;
7456 struct sk_buff *msg;
7457 void *hdr;
7458
7459 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7460 if (!msg)
7461 return -ENOBUFS;
7462
7463 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7464 NL80211_CMD_GET_REG);
7465 if (!hdr)
7466 goto put_failure;
7467
7468 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007469 bool self_managed;
7470
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007471 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7472 if (IS_ERR(rdev)) {
7473 nlmsg_free(msg);
7474 return PTR_ERR(rdev);
7475 }
7476
7477 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007478 self_managed = wiphy->regulatory_flags &
7479 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007480 regdom = get_wiphy_regdom(wiphy);
7481
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007482 /* a self-managed-reg device must have a private regdom */
7483 if (WARN_ON(!regdom && self_managed)) {
7484 nlmsg_free(msg);
7485 return -EINVAL;
7486 }
7487
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007488 if (regdom &&
7489 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7490 goto nla_put_failure;
7491 }
7492
7493 if (!wiphy && reg_last_request_cell_base() &&
7494 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7495 NL80211_USER_REG_HINT_CELL_BASE))
7496 goto nla_put_failure;
7497
7498 rcu_read_lock();
7499
7500 if (!regdom)
7501 regdom = rcu_dereference(cfg80211_regdomain);
7502
7503 if (nl80211_put_regdom(regdom, msg))
7504 goto nla_put_failure_rcu;
7505
7506 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007507
7508 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007509 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007510
Johannes Berg458f4f92012-12-06 15:47:38 +01007511nla_put_failure_rcu:
7512 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007513nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01007514put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04007515 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007516 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007517}
7518
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007519static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
7520 u32 seq, int flags, struct wiphy *wiphy,
7521 const struct ieee80211_regdomain *regdom)
7522{
7523 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7524 NL80211_CMD_GET_REG);
7525
7526 if (!hdr)
7527 return -1;
7528
Michal Kubecek0a833c22017-11-15 13:09:32 +01007529 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007530
7531 if (nl80211_put_regdom(regdom, msg))
7532 goto nla_put_failure;
7533
7534 if (!wiphy && reg_last_request_cell_base() &&
7535 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7536 NL80211_USER_REG_HINT_CELL_BASE))
7537 goto nla_put_failure;
7538
7539 if (wiphy &&
7540 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7541 goto nla_put_failure;
7542
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007543 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7544 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7545 goto nla_put_failure;
7546
Johannes Berg053c0952015-01-16 22:09:00 +01007547 genlmsg_end(msg, hdr);
7548 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007549
7550nla_put_failure:
7551 genlmsg_cancel(msg, hdr);
7552 return -EMSGSIZE;
7553}
7554
7555static int nl80211_get_reg_dump(struct sk_buff *skb,
7556 struct netlink_callback *cb)
7557{
7558 const struct ieee80211_regdomain *regdom = NULL;
7559 struct cfg80211_registered_device *rdev;
7560 int err, reg_idx, start = cb->args[2];
7561
7562 rtnl_lock();
7563
7564 if (cfg80211_regdomain && start == 0) {
7565 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7566 NLM_F_MULTI, NULL,
7567 rtnl_dereference(cfg80211_regdomain));
7568 if (err < 0)
7569 goto out_err;
7570 }
7571
7572 /* the global regdom is idx 0 */
7573 reg_idx = 1;
7574 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7575 regdom = get_wiphy_regdom(&rdev->wiphy);
7576 if (!regdom)
7577 continue;
7578
7579 if (++reg_idx <= start)
7580 continue;
7581
7582 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7583 NLM_F_MULTI, &rdev->wiphy, regdom);
7584 if (err < 0) {
7585 reg_idx--;
7586 break;
7587 }
7588 }
7589
7590 cb->args[2] = reg_idx;
7591 err = skb->len;
7592out_err:
7593 rtnl_unlock();
7594 return err;
7595}
7596
Johannes Bergb6863032015-10-15 09:25:18 +02007597#ifdef CONFIG_CFG80211_CRDA_SUPPORT
7598static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7599 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7600 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7601 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7602 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7603 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7604 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7605 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7606};
7607
7608static int parse_reg_rule(struct nlattr *tb[],
7609 struct ieee80211_reg_rule *reg_rule)
7610{
7611 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
7612 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
7613
7614 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7615 return -EINVAL;
7616 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7617 return -EINVAL;
7618 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7619 return -EINVAL;
7620 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7621 return -EINVAL;
7622 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7623 return -EINVAL;
7624
7625 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7626
7627 freq_range->start_freq_khz =
7628 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7629 freq_range->end_freq_khz =
7630 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7631 freq_range->max_bandwidth_khz =
7632 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7633
7634 power_rule->max_eirp =
7635 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7636
7637 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7638 power_rule->max_antenna_gain =
7639 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7640
7641 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7642 reg_rule->dfs_cac_ms =
7643 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7644
7645 return 0;
7646}
7647
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007648static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7649{
7650 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7651 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01007652 char *alpha2;
7653 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007654 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007655 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007656 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007657
7658 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7659 return -EINVAL;
7660
7661 if (!info->attrs[NL80211_ATTR_REG_RULES])
7662 return -EINVAL;
7663
7664 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7665
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007666 if (info->attrs[NL80211_ATTR_DFS_REGION])
7667 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7668
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007669 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007670 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007671 num_rules++;
7672 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007673 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007674 }
7675
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007676 if (!reg_is_valid_request(alpha2))
7677 return -EINVAL;
7678
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007679 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007680 if (!rd)
7681 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007682
7683 rd->n_reg_rules = num_rules;
7684 rd->alpha2[0] = alpha2[0];
7685 rd->alpha2[1] = alpha2[1];
7686
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007687 /*
7688 * Disable DFS master mode if the DFS region was
7689 * not supported or known on this kernel.
7690 */
7691 if (reg_supported_dfs_region(dfs_region))
7692 rd->dfs_region = dfs_region;
7693
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007694 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007695 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007696 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7697 nl_reg_rule, reg_rule_policy,
7698 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007699 if (r)
7700 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007701 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7702 if (r)
7703 goto bad_reg;
7704
7705 rule_idx++;
7706
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007707 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7708 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007709 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007710 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007711 }
7712
Johannes Berg06627992016-06-09 10:40:09 +02007713 /* set_regdom takes ownership of rd */
7714 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007715 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007716 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007717 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007718}
Johannes Bergb6863032015-10-15 09:25:18 +02007719#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007720
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007721static int validate_scan_freqs(struct nlattr *freqs)
7722{
7723 struct nlattr *attr1, *attr2;
7724 int n_channels = 0, tmp1, tmp2;
7725
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007726 nla_for_each_nested(attr1, freqs, tmp1)
7727 if (nla_len(attr1) != sizeof(u32))
7728 return 0;
7729
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007730 nla_for_each_nested(attr1, freqs, tmp1) {
7731 n_channels++;
7732 /*
7733 * Some hardware has a limited channel list for
7734 * scanning, and it is pretty much nonsensical
7735 * to scan for a channel twice, so disallow that
7736 * and don't require drivers to check that the
7737 * channel list they get isn't longer than what
7738 * they can scan, as long as they can scan all
7739 * the channels they registered at once.
7740 */
7741 nla_for_each_nested(attr2, freqs, tmp2)
7742 if (attr1 != attr2 &&
7743 nla_get_u32(attr1) == nla_get_u32(attr2))
7744 return 0;
7745 }
7746
7747 return n_channels;
7748}
7749
Johannes Berg57fbcce2016-04-12 15:56:15 +02007750static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007751{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007752 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007753}
7754
7755static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7756 struct cfg80211_bss_selection *bss_select)
7757{
7758 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7759 struct nlattr *nest;
7760 int err;
7761 bool found = false;
7762 int i;
7763
7764 /* only process one nested attribute */
7765 nest = nla_data(nla);
7766 if (!nla_ok(nest, nla_len(nest)))
7767 return -EINVAL;
7768
Johannes Berg8cb08172019-04-26 14:07:28 +02007769 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7770 nest, nl80211_bss_select_policy,
7771 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007772 if (err)
7773 return err;
7774
7775 /* only one attribute may be given */
7776 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7777 if (attr[i]) {
7778 if (found)
7779 return -EINVAL;
7780 found = true;
7781 }
7782 }
7783
7784 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7785
7786 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7787 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7788
7789 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7790 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7791 bss_select->param.band_pref =
7792 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7793 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7794 return -EINVAL;
7795 }
7796
7797 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7798 struct nl80211_bss_select_rssi_adjust *adj_param;
7799
7800 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7801 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7802 bss_select->param.adjust.band = adj_param->band;
7803 bss_select->param.adjust.delta = adj_param->delta;
7804 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7805 return -EINVAL;
7806 }
7807
7808 /* user-space did not provide behaviour attribute */
7809 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7810 return -EINVAL;
7811
7812 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7813 return -EINVAL;
7814
7815 return 0;
7816}
7817
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007818int nl80211_parse_random_mac(struct nlattr **attrs,
7819 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007820{
7821 int i;
7822
7823 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007824 eth_zero_addr(mac_addr);
7825 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007826 mac_addr[0] = 0x2;
7827 mac_addr_mask[0] = 0x3;
7828
7829 return 0;
7830 }
7831
7832 /* need both or none */
7833 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7834 return -EINVAL;
7835
7836 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7837 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7838
7839 /* don't allow or configure an mcast address */
7840 if (!is_multicast_ether_addr(mac_addr_mask) ||
7841 is_multicast_ether_addr(mac_addr))
7842 return -EINVAL;
7843
7844 /*
7845 * allow users to pass a MAC address that has bits set outside
7846 * of the mask, but don't bother drivers with having to deal
7847 * with such bits
7848 */
7849 for (i = 0; i < ETH_ALEN; i++)
7850 mac_addr[i] &= mac_addr_mask[i];
7851
7852 return 0;
7853}
7854
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307855static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7856{
7857 ASSERT_WDEV_LOCK(wdev);
7858
7859 if (!cfg80211_beaconing_iface_active(wdev))
7860 return true;
7861
7862 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7863 return true;
7864
7865 return regulatory_pre_cac_allowed(wdev->wiphy);
7866}
7867
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007868static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7869 enum nl80211_ext_feature_index feat)
7870{
7871 if (!(flags & flag))
7872 return true;
7873 if (wiphy_ext_feature_isset(wiphy, feat))
7874 return true;
7875 return false;
7876}
7877
Roee Zamir2d23d072017-08-06 11:38:22 +03007878static int
7879nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7880 void *request, struct nlattr **attrs,
7881 bool is_sched_scan)
7882{
7883 u8 *mac_addr, *mac_addr_mask;
7884 u32 *flags;
7885 enum nl80211_feature_flags randomness_flag;
7886
7887 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7888 return 0;
7889
7890 if (is_sched_scan) {
7891 struct cfg80211_sched_scan_request *req = request;
7892
7893 randomness_flag = wdev ?
7894 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7895 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7896 flags = &req->flags;
7897 mac_addr = req->mac_addr;
7898 mac_addr_mask = req->mac_addr_mask;
7899 } else {
7900 struct cfg80211_scan_request *req = request;
7901
7902 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7903 flags = &req->flags;
7904 mac_addr = req->mac_addr;
7905 mac_addr_mask = req->mac_addr_mask;
7906 }
7907
7908 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7909
Sunil Dutt5037a002018-01-25 17:13:37 +02007910 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7911 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007912 !nl80211_check_scan_feat(wiphy, *flags,
7913 NL80211_SCAN_FLAG_LOW_SPAN,
7914 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7915 !nl80211_check_scan_feat(wiphy, *flags,
7916 NL80211_SCAN_FLAG_LOW_POWER,
7917 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7918 !nl80211_check_scan_feat(wiphy, *flags,
7919 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7920 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7921 !nl80211_check_scan_feat(wiphy, *flags,
7922 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7923 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7924 !nl80211_check_scan_feat(wiphy, *flags,
7925 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7926 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7927 !nl80211_check_scan_feat(wiphy, *flags,
7928 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7929 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7930 !nl80211_check_scan_feat(wiphy, *flags,
7931 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007932 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7933 !nl80211_check_scan_feat(wiphy, *flags,
7934 NL80211_SCAN_FLAG_RANDOM_SN,
7935 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7936 !nl80211_check_scan_feat(wiphy, *flags,
7937 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7938 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007939 return -EOPNOTSUPP;
7940
7941 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7942 int err;
7943
7944 if (!(wiphy->features & randomness_flag) ||
7945 (wdev && wdev->current_bss))
7946 return -EOPNOTSUPP;
7947
7948 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7949 if (err)
7950 return err;
7951 }
7952
Roee Zamir2d23d072017-08-06 11:38:22 +03007953 return 0;
7954}
7955
Johannes Berg2a519312009-02-10 21:25:55 +01007956static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7957{
Johannes Berg4c476992010-10-04 21:36:35 +02007958 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007959 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007960 struct cfg80211_scan_request *request;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07007961 struct nlattr *scan_freqs = NULL;
7962 bool scan_freqs_khz = false;
Johannes Berg2a519312009-02-10 21:25:55 +01007963 struct nlattr *attr;
7964 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007965 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007966 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007967
Johannes Berg79c97e92009-07-07 03:56:12 +02007968 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007969
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007970 if (wdev->iftype == NL80211_IFTYPE_NAN)
7971 return -EOPNOTSUPP;
7972
Johannes Berg4c476992010-10-04 21:36:35 +02007973 if (!rdev->ops->scan)
7974 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007975
Christophe JAILLET83286852020-07-12 19:35:39 +02007976 if (rdev->scan_req || rdev->scan_msg)
7977 return -EBUSY;
Johannes Berg2a519312009-02-10 21:25:55 +01007978
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07007979 if (info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ]) {
7980 if (!wiphy_ext_feature_isset(wiphy,
7981 NL80211_EXT_FEATURE_SCAN_FREQ_KHZ))
7982 return -EOPNOTSUPP;
7983 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQ_KHZ];
7984 scan_freqs_khz = true;
7985 } else if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES])
7986 scan_freqs = info->attrs[NL80211_ATTR_SCAN_FREQUENCIES];
7987
7988 if (scan_freqs) {
7989 n_channels = validate_scan_freqs(scan_freqs);
Christophe JAILLET83286852020-07-12 19:35:39 +02007990 if (!n_channels)
7991 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01007992 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007993 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007994 }
7995
7996 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7997 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7998 n_ssids++;
7999
Christophe JAILLET83286852020-07-12 19:35:39 +02008000 if (n_ssids > wiphy->max_scan_ssids)
8001 return -EINVAL;
Johannes Berg2a519312009-02-10 21:25:55 +01008002
Jouni Malinen70692ad2009-02-16 19:39:13 +02008003 if (info->attrs[NL80211_ATTR_IE])
8004 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
8005 else
8006 ie_len = 0;
8007
Christophe JAILLET83286852020-07-12 19:35:39 +02008008 if (ie_len > wiphy->max_scan_ie_len)
8009 return -EINVAL;
Johannes Berg18a83652009-03-31 12:12:05 +02008010
Johannes Berg2a519312009-02-10 21:25:55 +01008011 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008012 + sizeof(*request->ssids) * n_ssids
8013 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02008014 + ie_len, GFP_KERNEL);
Christophe JAILLET83286852020-07-12 19:35:39 +02008015 if (!request)
8016 return -ENOMEM;
Johannes Berg2a519312009-02-10 21:25:55 +01008017
Johannes Berg2a519312009-02-10 21:25:55 +01008018 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02008019 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01008020 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02008021 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01008022 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02008023 request->ie = (void *)(request->ssids + n_ssids);
8024 else
8025 request->ie = (void *)(request->channels + n_channels);
8026 }
Johannes Berg2a519312009-02-10 21:25:55 +01008027
Johannes Berg584991d2009-11-02 13:32:03 +01008028 i = 0;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008029 if (scan_freqs) {
Johannes Berg2a519312009-02-10 21:25:55 +01008030 /* user specified, bail out if channel not found */
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008031 nla_for_each_nested(attr, scan_freqs, tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01008032 struct ieee80211_channel *chan;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008033 int freq = nla_get_u32(attr);
Johannes Berg584991d2009-11-02 13:32:03 +01008034
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008035 if (!scan_freqs_khz)
8036 freq = MHZ_TO_KHZ(freq);
Johannes Berg584991d2009-11-02 13:32:03 +01008037
Thomas Pedersen2032f3b2020-04-30 10:25:52 -07008038 chan = ieee80211_get_channel_khz(wiphy, freq);
Johannes Berg584991d2009-11-02 13:32:03 +01008039 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01008040 err = -EINVAL;
8041 goto out_free;
8042 }
Johannes Berg584991d2009-11-02 13:32:03 +01008043
8044 /* ignore disabled channels */
8045 if (chan->flags & IEEE80211_CHAN_DISABLED)
8046 continue;
8047
8048 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01008049 i++;
8050 }
8051 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008052 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02008053
Johannes Berg2a519312009-02-10 21:25:55 +01008054 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008055 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01008056 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008057
Johannes Berg2a519312009-02-10 21:25:55 +01008058 if (!wiphy->bands[band])
8059 continue;
8060 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01008061 struct ieee80211_channel *chan;
8062
8063 chan = &wiphy->bands[band]->channels[j];
8064
8065 if (chan->flags & IEEE80211_CHAN_DISABLED)
8066 continue;
8067
8068 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01008069 i++;
8070 }
8071 }
8072 }
8073
Johannes Berg584991d2009-11-02 13:32:03 +01008074 if (!i) {
8075 err = -EINVAL;
8076 goto out_free;
8077 }
8078
8079 request->n_channels = i;
8080
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05308081 wdev_lock(wdev);
8082 if (!cfg80211_off_channel_oper_allowed(wdev)) {
8083 struct ieee80211_channel *chan;
8084
8085 if (request->n_channels != 1) {
8086 wdev_unlock(wdev);
8087 err = -EBUSY;
8088 goto out_free;
8089 }
8090
8091 chan = request->channels[0];
8092 if (chan->center_freq != wdev->chandef.chan->center_freq) {
8093 wdev_unlock(wdev);
8094 err = -EBUSY;
8095 goto out_free;
8096 }
8097 }
8098 wdev_unlock(wdev);
8099
Johannes Berg2a519312009-02-10 21:25:55 +01008100 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01008101 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01008102 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008103 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01008104 err = -EINVAL;
8105 goto out_free;
8106 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008107 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01008108 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01008109 i++;
8110 }
8111 }
8112
Jouni Malinen70692ad2009-02-16 19:39:13 +02008113 if (info->attrs[NL80211_ATTR_IE]) {
8114 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02008115 memcpy((void *)request->ie,
8116 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02008117 request->ie_len);
8118 }
8119
Johannes Berg57fbcce2016-04-12 15:56:15 +02008120 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02008121 if (wiphy->bands[i])
8122 request->rates[i] =
8123 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02008124
8125 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
8126 nla_for_each_nested(attr,
8127 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
8128 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02008129 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02008130
Johannes Berg57fbcce2016-04-12 15:56:15 +02008131 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02008132 err = -EINVAL;
8133 goto out_free;
8134 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01008135
8136 if (!wiphy->bands[band])
8137 continue;
8138
Johannes Berg34850ab2011-07-18 18:08:35 +02008139 err = ieee80211_get_ratemask(wiphy->bands[band],
8140 nla_data(attr),
8141 nla_len(attr),
8142 &request->rates[band]);
8143 if (err)
8144 goto out_free;
8145 }
8146 }
8147
Avraham Stern1d762502016-07-05 17:10:13 +03008148 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
8149 if (!wiphy_ext_feature_isset(wiphy,
8150 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
8151 err = -EOPNOTSUPP;
8152 goto out_free;
8153 }
8154
8155 request->duration =
8156 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
8157 request->duration_mandatory =
8158 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
8159 }
8160
Roee Zamir2d23d072017-08-06 11:38:22 +03008161 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
8162 false);
8163 if (err)
8164 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008165
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308166 request->no_cck =
8167 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
8168
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02008169 /* Initial implementation used NL80211_ATTR_MAC to set the specific
8170 * BSSID to scan for. This was problematic because that same attribute
8171 * was already used for another purpose (local random MAC address). The
8172 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
8173 * compatibility with older userspace components, also use the
8174 * NL80211_ATTR_MAC value here if it can be determined to be used for
8175 * the specific BSSID use case instead of the random MAC address
8176 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
8177 */
8178 if (info->attrs[NL80211_ATTR_BSSID])
8179 memcpy(request->bssid,
8180 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
8181 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
8182 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02008183 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
8184 ETH_ALEN);
8185 else
8186 eth_broadcast_addr(request->bssid);
8187
Johannes Bergfd014282012-06-18 19:17:03 +02008188 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02008189 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07008190 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01008191
Johannes Berg79c97e92009-07-07 03:56:12 +02008192 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03008193 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01008194
Christophe JAILLET504776b2020-07-12 19:35:51 +02008195 if (err)
8196 goto out_free;
8197
8198 nl80211_send_scan_start(rdev, wdev);
8199 if (wdev->netdev)
8200 dev_hold(wdev->netdev);
8201
8202 return 0;
8203
Johannes Berg2a519312009-02-10 21:25:55 +01008204 out_free:
Christophe JAILLET504776b2020-07-12 19:35:51 +02008205 rdev->scan_req = NULL;
8206 kfree(request);
Johannes Berg3b858752009-03-12 09:55:09 +01008207
Johannes Berg2a519312009-02-10 21:25:55 +01008208 return err;
8209}
8210
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05308211static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
8212{
8213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8214 struct wireless_dev *wdev = info->user_ptr[1];
8215
8216 if (!rdev->ops->abort_scan)
8217 return -EOPNOTSUPP;
8218
8219 if (rdev->scan_msg)
8220 return 0;
8221
8222 if (!rdev->scan_req)
8223 return -ENOENT;
8224
8225 rdev_abort_scan(rdev, wdev);
8226 return 0;
8227}
8228
Avraham Stern3b06d272015-10-12 09:51:34 +03008229static int
8230nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
8231 struct cfg80211_sched_scan_request *request,
8232 struct nlattr **attrs)
8233{
8234 int tmp, err, i = 0;
8235 struct nlattr *attr;
8236
8237 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8238 u32 interval;
8239
8240 /*
8241 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00008242 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03008243 * case one scan plan will be set with the specified scan
8244 * interval and infinite number of iterations.
8245 */
Avraham Stern3b06d272015-10-12 09:51:34 +03008246 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
8247 if (!interval)
8248 return -EINVAL;
8249
8250 request->scan_plans[0].interval =
8251 DIV_ROUND_UP(interval, MSEC_PER_SEC);
8252 if (!request->scan_plans[0].interval)
8253 return -EINVAL;
8254
8255 if (request->scan_plans[0].interval >
8256 wiphy->max_sched_scan_plan_interval)
8257 request->scan_plans[0].interval =
8258 wiphy->max_sched_scan_plan_interval;
8259
8260 return 0;
8261 }
8262
8263 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
8264 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
8265
8266 if (WARN_ON(i >= n_plans))
8267 return -EINVAL;
8268
Johannes Berg8cb08172019-04-26 14:07:28 +02008269 err = nla_parse_nested_deprecated(plan,
8270 NL80211_SCHED_SCAN_PLAN_MAX,
8271 attr, nl80211_plan_policy,
8272 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03008273 if (err)
8274 return err;
8275
8276 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
8277 return -EINVAL;
8278
8279 request->scan_plans[i].interval =
8280 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
8281 if (!request->scan_plans[i].interval ||
8282 request->scan_plans[i].interval >
8283 wiphy->max_sched_scan_plan_interval)
8284 return -EINVAL;
8285
8286 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
8287 request->scan_plans[i].iterations =
8288 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
8289 if (!request->scan_plans[i].iterations ||
8290 (request->scan_plans[i].iterations >
8291 wiphy->max_sched_scan_plan_iterations))
8292 return -EINVAL;
8293 } else if (i < n_plans - 1) {
8294 /*
8295 * All scan plans but the last one must specify
8296 * a finite number of iterations
8297 */
8298 return -EINVAL;
8299 }
8300
8301 i++;
8302 }
8303
8304 /*
8305 * The last scan plan must not specify the number of
8306 * iterations, it is supposed to run infinitely
8307 */
8308 if (request->scan_plans[n_plans - 1].iterations)
8309 return -EINVAL;
8310
8311 return 0;
8312}
8313
vamsi krishna1e1b11b2019-02-01 18:34:51 +05308314static int
8315nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
8316 struct cfg80211_match_set *match_sets,
8317 struct nlattr *tb_band_rssi,
8318 s32 rssi_thold)
8319{
8320 struct nlattr *attr;
8321 int i, tmp, ret = 0;
8322
8323 if (!wiphy_ext_feature_isset(wiphy,
8324 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
8325 if (tb_band_rssi)
8326 ret = -EOPNOTSUPP;
8327 else
8328 for (i = 0; i < NUM_NL80211_BANDS; i++)
8329 match_sets->per_band_rssi_thold[i] =
8330 NL80211_SCAN_RSSI_THOLD_OFF;
8331 return ret;
8332 }
8333
8334 for (i = 0; i < NUM_NL80211_BANDS; i++)
8335 match_sets->per_band_rssi_thold[i] = rssi_thold;
8336
8337 nla_for_each_nested(attr, tb_band_rssi, tmp) {
8338 enum nl80211_band band = nla_type(attr);
8339
8340 if (band < 0 || band >= NUM_NL80211_BANDS)
8341 return -EINVAL;
8342
8343 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
8344 }
8345
8346 return 0;
8347}
8348
Luciano Coelho256da022014-11-10 16:13:46 +02008349static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02008350nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008351 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008352{
8353 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008354 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03008355 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02008356 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008357 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008358 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01008359 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008360
Luciano Coelho256da022014-11-10 16:13:46 +02008361 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008362 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02008363 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008364 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02008365 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008366 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02008367 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008368 }
8369
Luciano Coelho256da022014-11-10 16:13:46 +02008370 if (attrs[NL80211_ATTR_SCAN_SSIDS])
8371 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008372 tmp)
8373 n_ssids++;
8374
Luciano Coelho93b6aa62011-07-13 14:57:28 +03008375 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02008376 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008377
Johannes Bergea73cbc2014-01-24 10:53:53 +01008378 /*
8379 * First, count the number of 'real' matchsets. Due to an issue with
8380 * the old implementation, matchsets containing only the RSSI attribute
8381 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
8382 * RSSI for all matchsets, rather than their own matchset for reporting
8383 * all APs with a strong RSSI. This is needed to be compatible with
8384 * older userspace that treated a matchset with only the RSSI as the
8385 * global RSSI for all other matchsets - if there are other matchsets.
8386 */
Luciano Coelho256da022014-11-10 16:13:46 +02008387 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008388 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008389 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01008390 tmp) {
8391 struct nlattr *rssi;
8392
Johannes Berg8cb08172019-04-26 14:07:28 +02008393 err = nla_parse_nested_deprecated(tb,
8394 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8395 attr,
8396 nl80211_match_policy,
8397 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01008398 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02008399 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01008400
8401 /* SSID and BSSID are mutually exclusive */
8402 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
8403 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
8404 return ERR_PTR(-EINVAL);
8405
Johannes Bergea73cbc2014-01-24 10:53:53 +01008406 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01008407 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
8408 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01008409 n_match_sets++;
8410 continue;
8411 }
8412 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8413 if (rssi)
8414 default_match_rssi = nla_get_s32(rssi);
8415 }
8416 }
8417
8418 /* However, if there's no other matchset, add the RSSI one */
8419 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
8420 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008421
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008422 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02008423 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008424
Luciano Coelho256da022014-11-10 16:13:46 +02008425 if (attrs[NL80211_ATTR_IE])
8426 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008427 else
8428 ie_len = 0;
8429
Luciano Coelho5a865ba2011-07-13 14:57:29 +03008430 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02008431 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03008432
Avraham Stern3b06d272015-10-12 09:51:34 +03008433 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8434 /*
8435 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
8436 * each scan plan already specifies its own interval
8437 */
8438 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8439 return ERR_PTR(-EINVAL);
8440
8441 nla_for_each_nested(attr,
8442 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
8443 n_plans++;
8444 } else {
8445 /*
8446 * The scan interval attribute is kept for backward
8447 * compatibility. If no scan plans are specified and sched scan
8448 * interval is specified, one scan plan will be set with this
8449 * scan interval and infinite number of iterations.
8450 */
8451 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8452 return ERR_PTR(-EINVAL);
8453
8454 n_plans = 1;
8455 }
8456
8457 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
8458 return ERR_PTR(-EINVAL);
8459
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008460 if (!wiphy_ext_feature_isset(
8461 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
8462 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
8463 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
8464 return ERR_PTR(-EINVAL);
8465
Luciano Coelho807f8a82011-05-11 17:09:35 +03008466 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008467 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008468 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03008469 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008470 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03008471 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02008472 if (!request)
8473 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008474
8475 if (n_ssids)
8476 request->ssids = (void *)&request->channels[n_channels];
8477 request->n_ssids = n_ssids;
8478 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01008479 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008480 request->ie = (void *)(request->ssids + n_ssids);
8481 else
8482 request->ie = (void *)(request->channels + n_channels);
8483 }
8484
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008485 if (n_match_sets) {
8486 if (request->ie)
8487 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01008488 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008489 request->match_sets =
8490 (void *)(request->ssids + n_ssids);
8491 else
8492 request->match_sets =
8493 (void *)(request->channels + n_channels);
8494 }
8495 request->n_match_sets = n_match_sets;
8496
Avraham Stern3b06d272015-10-12 09:51:34 +03008497 if (n_match_sets)
8498 request->scan_plans = (void *)(request->match_sets +
8499 n_match_sets);
8500 else if (request->ie)
8501 request->scan_plans = (void *)(request->ie + ie_len);
8502 else if (n_ssids)
8503 request->scan_plans = (void *)(request->ssids + n_ssids);
8504 else
8505 request->scan_plans = (void *)(request->channels + n_channels);
8506
8507 request->n_scan_plans = n_plans;
8508
Luciano Coelho807f8a82011-05-11 17:09:35 +03008509 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008510 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008511 /* user specified, bail out if channel not found */
8512 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008513 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008514 tmp) {
8515 struct ieee80211_channel *chan;
8516
8517 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
8518
8519 if (!chan) {
8520 err = -EINVAL;
8521 goto out_free;
8522 }
8523
8524 /* ignore disabled channels */
8525 if (chan->flags & IEEE80211_CHAN_DISABLED)
8526 continue;
8527
8528 request->channels[i] = chan;
8529 i++;
8530 }
8531 } else {
8532 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008533 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008534 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008535
Luciano Coelho807f8a82011-05-11 17:09:35 +03008536 if (!wiphy->bands[band])
8537 continue;
8538 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8539 struct ieee80211_channel *chan;
8540
8541 chan = &wiphy->bands[band]->channels[j];
8542
8543 if (chan->flags & IEEE80211_CHAN_DISABLED)
8544 continue;
8545
8546 request->channels[i] = chan;
8547 i++;
8548 }
8549 }
8550 }
8551
8552 if (!i) {
8553 err = -EINVAL;
8554 goto out_free;
8555 }
8556
8557 request->n_channels = i;
8558
8559 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01008560 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02008561 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008562 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008563 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008564 err = -EINVAL;
8565 goto out_free;
8566 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008567 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008568 memcpy(request->ssids[i].ssid, nla_data(attr),
8569 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03008570 i++;
8571 }
8572 }
8573
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008574 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008575 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008576 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008577 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008578 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01008579 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008580
Johannes Berg8cb08172019-04-26 14:07:28 +02008581 err = nla_parse_nested_deprecated(tb,
8582 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8583 attr,
8584 nl80211_match_policy,
8585 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01008586 if (err)
8587 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02008588 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01008589 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02008590
8591 if (!ssid && !bssid) {
8592 i++;
8593 continue;
8594 }
8595
8596 if (WARN_ON(i >= n_match_sets)) {
8597 /* this indicates a programming error,
8598 * the loop above should have verified
8599 * things properly
8600 */
8601 err = -EINVAL;
8602 goto out_free;
8603 }
8604
8605 if (ssid) {
Johannes Bergd39f3b42019-04-08 13:40:47 +02008606 memcpy(request->match_sets[i].ssid.ssid,
8607 nla_data(ssid), nla_len(ssid));
8608 request->match_sets[i].ssid.ssid_len =
8609 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008610 }
Johannes Bergcb9abd42020-08-05 15:47:16 +02008611 if (bssid)
Johannes Bergd39f3b42019-04-08 13:40:47 +02008612 memcpy(request->match_sets[i].bssid,
8613 nla_data(bssid), ETH_ALEN);
Johannes Bergd39f3b42019-04-08 13:40:47 +02008614
8615 /* special attribute - old implementation w/a */
8616 request->match_sets[i].rssi_thold = default_match_rssi;
8617 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8618 if (rssi)
8619 request->match_sets[i].rssi_thold =
8620 nla_get_s32(rssi);
vamsi krishna1e1b11b2019-02-01 18:34:51 +05308621
8622 /* Parse per band RSSI attribute */
8623 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8624 &request->match_sets[i],
8625 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8626 request->match_sets[i].rssi_thold);
8627 if (err)
8628 goto out_free;
8629
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008630 i++;
8631 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01008632
8633 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02008634 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008635 request->match_sets[0].rssi_thold = default_match_rssi;
8636
8637 request->min_rssi_thold = INT_MAX;
8638 for (i = 0; i < n_match_sets; i++)
8639 request->min_rssi_thold =
8640 min(request->match_sets[i].rssi_thold,
8641 request->min_rssi_thold);
8642 } else {
8643 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008644 }
8645
Johannes Berg9900e482014-02-04 21:01:25 +01008646 if (ie_len) {
8647 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008648 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008649 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008650 request->ie_len);
8651 }
8652
Roee Zamir2d23d072017-08-06 11:38:22 +03008653 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8654 if (err)
8655 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008656
Luciano Coelho9c748932015-01-16 16:04:09 +02008657 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8658 request->delay =
8659 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8660
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008661 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8662 request->relative_rssi = nla_get_s8(
8663 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8664 request->relative_rssi_set = true;
8665 }
8666
8667 if (request->relative_rssi_set &&
8668 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8669 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8670
8671 rssi_adjust = nla_data(
8672 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8673 request->rssi_adjust.band = rssi_adjust->band;
8674 request->rssi_adjust.delta = rssi_adjust->delta;
8675 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8676 err = -EINVAL;
8677 goto out_free;
8678 }
8679 }
8680
Avraham Stern3b06d272015-10-12 09:51:34 +03008681 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8682 if (err)
8683 goto out_free;
8684
Sam Leffler15d60302012-10-11 21:03:34 -07008685 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008686
Luciano Coelho256da022014-11-10 16:13:46 +02008687 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008688
8689out_free:
8690 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008691 return ERR_PTR(err);
8692}
8693
8694static int nl80211_start_sched_scan(struct sk_buff *skb,
8695 struct genl_info *info)
8696{
8697 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8698 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02008699 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008700 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008701 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008702 int err;
8703
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008704 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008705 return -EOPNOTSUPP;
8706
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008707 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8708 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8709 if (err)
8710 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02008711
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008712 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008713 info->attrs,
8714 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008715
8716 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008717 if (err)
8718 goto out_err;
8719
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008720 /* leave request id zero for legacy request
8721 * or if driver does not support multi-scheduled scan
8722 */
Denis Kenzior2fd351a2019-10-08 11:43:50 -05008723 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
8724 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008725
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008726 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008727 if (err)
8728 goto out_free;
8729
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008730 sched_scan_req->dev = dev;
8731 sched_scan_req->wiphy = &rdev->wiphy;
8732
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008733 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8734 sched_scan_req->owner_nlportid = info->snd_portid;
8735
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008736 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008737
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008738 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008739 return 0;
8740
8741out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008742 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008743out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008744 return err;
8745}
8746
8747static int nl80211_stop_sched_scan(struct sk_buff *skb,
8748 struct genl_info *info)
8749{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008750 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008751 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008752 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008753
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008754 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008755 return -EOPNOTSUPP;
8756
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008757 if (info->attrs[NL80211_ATTR_COOKIE]) {
8758 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8759 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8760 }
8761
8762 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8763 struct cfg80211_sched_scan_request,
8764 list);
8765 if (!req || req->reqid ||
8766 (req->owner_nlportid &&
8767 req->owner_nlportid != info->snd_portid))
8768 return -ENOENT;
8769
8770 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008771}
8772
Simon Wunderlich04f39042013-02-08 18:16:19 +01008773static int nl80211_start_radar_detection(struct sk_buff *skb,
8774 struct genl_info *info)
8775{
8776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8777 struct net_device *dev = info->user_ptr[1];
8778 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008779 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008780 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008781 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008782 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008783 int err;
8784
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008785 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008786 if (dfs_region == NL80211_DFS_UNSET)
8787 return -EINVAL;
8788
Simon Wunderlich04f39042013-02-08 18:16:19 +01008789 err = nl80211_parse_chandef(rdev, info, &chandef);
8790 if (err)
8791 return err;
8792
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008793 if (netif_carrier_ok(dev))
8794 return -EBUSY;
8795
Simon Wunderlich04f39042013-02-08 18:16:19 +01008796 if (wdev->cac_started)
8797 return -EBUSY;
8798
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008799 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008800 if (err < 0)
8801 return err;
8802
8803 if (err == 0)
8804 return -EINVAL;
8805
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008806 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008807 return -EINVAL;
8808
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008809 /* CAC start is offloaded to HW and can't be started manually */
8810 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8811 return -EOPNOTSUPP;
8812
Simon Wunderlich04f39042013-02-08 18:16:19 +01008813 if (!rdev->ops->start_radar_detection)
8814 return -EOPNOTSUPP;
8815
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008816 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8817 if (WARN_ON(!cac_time_ms))
8818 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8819
Ilan Peera1056b1b2015-10-22 22:27:46 +03008820 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008821 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008822 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008823 wdev->cac_started = true;
8824 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008825 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008826 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008827 return err;
8828}
8829
Sriram R30c63112018-12-04 17:46:52 +05308830static int nl80211_notify_radar_detection(struct sk_buff *skb,
8831 struct genl_info *info)
8832{
8833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8834 struct net_device *dev = info->user_ptr[1];
8835 struct wireless_dev *wdev = dev->ieee80211_ptr;
8836 struct wiphy *wiphy = wdev->wiphy;
8837 struct cfg80211_chan_def chandef;
8838 enum nl80211_dfs_regions dfs_region;
8839 int err;
8840
8841 dfs_region = reg_get_dfs_region(wiphy);
8842 if (dfs_region == NL80211_DFS_UNSET) {
8843 GENL_SET_ERR_MSG(info,
8844 "DFS Region is not set. Unexpected Radar indication");
8845 return -EINVAL;
8846 }
8847
8848 err = nl80211_parse_chandef(rdev, info, &chandef);
8849 if (err) {
8850 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8851 return err;
8852 }
8853
8854 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8855 if (err < 0) {
8856 GENL_SET_ERR_MSG(info, "chandef is invalid");
8857 return err;
8858 }
8859
8860 if (err == 0) {
8861 GENL_SET_ERR_MSG(info,
8862 "Unexpected Radar indication for chandef/iftype");
8863 return -EINVAL;
8864 }
8865
8866 /* Do not process this notification if radar is already detected
8867 * by kernel on this channel, and return success.
8868 */
8869 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8870 return 0;
8871
8872 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8873
8874 cfg80211_sched_dfs_chan_update(rdev);
8875
Luca Coelhoa680fe42019-04-17 09:34:40 +03008876 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308877
8878 /* Propagate this notification to other radios as well */
8879 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8880
8881 return 0;
8882}
8883
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008884static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8885{
8886 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8887 struct net_device *dev = info->user_ptr[1];
8888 struct wireless_dev *wdev = dev->ieee80211_ptr;
8889 struct cfg80211_csa_settings params;
8890 /* csa_attrs is defined static to avoid waste of stack size - this
8891 * function is called under RTNL lock, so this should not be a problem.
8892 */
8893 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008894 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008895 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008896 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008897 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008898 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008899
8900 if (!rdev->ops->channel_switch ||
8901 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8902 return -EOPNOTSUPP;
8903
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008904 switch (dev->ieee80211_ptr->iftype) {
8905 case NL80211_IFTYPE_AP:
8906 case NL80211_IFTYPE_P2P_GO:
8907 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008908 /* For all modes except AP the handle_dfs flag needs to be
8909 * supplied to tell the kernel that userspace will handle radar
8910 * events when they happen. Otherwise a switch to a channel
8911 * requiring DFS will be rejected.
8912 */
8913 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008914
8915 /* useless if AP is not running */
8916 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008917 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008918 break;
8919 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008920 if (!wdev->ssid_len)
8921 return -ENOTCONN;
8922 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008923 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008924 if (!wdev->mesh_id_len)
8925 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008926 break;
8927 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008928 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008929 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008930
8931 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008932 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008933
8934 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8935 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8936 return -EINVAL;
8937
8938 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008939 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008940 return -EINVAL;
8941
Luciano Coelho252e07c2014-10-08 09:48:34 +03008942 /* Even though the attribute is u32, the specification says
8943 * u8, so let's make sure we don't overflow.
8944 */
8945 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8946 if (cs_count > 255)
8947 return -EINVAL;
8948
8949 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008950
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008951 if (!need_new_beacon)
8952 goto skip_beacons;
8953
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008954 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008955 if (err)
8956 return err;
8957
Johannes Berg8cb08172019-04-26 14:07:28 +02008958 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8959 info->attrs[NL80211_ATTR_CSA_IES],
8960 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008961 if (err)
8962 return err;
8963
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008964 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008965 if (err)
8966 return err;
8967
John Crispin00c207e2020-08-11 10:01:03 +02008968 if (!csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008969 return -EINVAL;
8970
John Crispin00c207e2020-08-11 10:01:03 +02008971 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008972 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008973 return -EINVAL;
8974
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008975 params.n_counter_offsets_beacon = len / sizeof(u16);
8976 if (rdev->wiphy.max_num_csa_counters &&
8977 (params.n_counter_offsets_beacon >
8978 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008979 return -EINVAL;
8980
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008981 params.counter_offsets_beacon =
John Crispin00c207e2020-08-11 10:01:03 +02008982 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_BEACON]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008983
8984 /* sanity checks - counters should fit and be the same */
8985 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8986 u16 offset = params.counter_offsets_beacon[i];
8987
8988 if (offset >= params.beacon_csa.tail_len)
8989 return -EINVAL;
8990
8991 if (params.beacon_csa.tail[offset] != params.count)
8992 return -EINVAL;
8993 }
8994
John Crispin00c207e2020-08-11 10:01:03 +02008995 if (csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]) {
8996 len = nla_len(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008997 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008998 return -EINVAL;
8999
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009000 params.n_counter_offsets_presp = len / sizeof(u16);
9001 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02009002 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009003 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009004 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009005
9006 params.counter_offsets_presp =
John Crispin00c207e2020-08-11 10:01:03 +02009007 nla_data(csa_attrs[NL80211_ATTR_CNTDWN_OFFS_PRESP]);
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03009008
9009 /* sanity checks - counters should fit and be the same */
9010 for (i = 0; i < params.n_counter_offsets_presp; i++) {
9011 u16 offset = params.counter_offsets_presp[i];
9012
9013 if (offset >= params.beacon_csa.probe_resp_len)
9014 return -EINVAL;
9015
9016 if (params.beacon_csa.probe_resp[offset] !=
9017 params.count)
9018 return -EINVAL;
9019 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009020 }
9021
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02009022skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009023 err = nl80211_parse_chandef(rdev, info, &params.chandef);
9024 if (err)
9025 return err;
9026
Arik Nemtsov923b3522015-07-08 15:41:44 +03009027 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
9028 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009029 return -EINVAL;
9030
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02009031 err = cfg80211_chandef_dfs_required(wdev->wiphy,
9032 &params.chandef,
9033 wdev->iftype);
9034 if (err < 0)
9035 return err;
9036
Benjamin Berg8d9de162017-05-16 11:23:12 +02009037 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02009038 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02009039 if (need_handle_dfs_flag &&
9040 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
9041 return -EINVAL;
9042 }
9043 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009044
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009045 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
9046 params.block_tx = true;
9047
Simon Wunderlichc56589e2013-11-21 18:19:49 +01009048 wdev_lock(wdev);
9049 err = rdev_channel_switch(rdev, dev, &params);
9050 wdev_unlock(wdev);
9051
9052 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02009053}
9054
Johannes Berg9720bb32011-06-21 09:45:33 +02009055static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
9056 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01009057 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02009058 struct wireless_dev *wdev,
9059 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01009060{
Johannes Berg48ab9052009-07-10 18:42:31 +02009061 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01009062 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01009063 void *hdr;
9064 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02009065
9066 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009067
Eric W. Biederman15e47302012-09-07 20:12:54 +00009068 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01009069 NL80211_CMD_NEW_SCAN_RESULTS);
9070 if (!hdr)
9071 return -1;
9072
Michal Kubecek0a833c22017-11-15 13:09:32 +01009073 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02009074
Johannes Berg97990a02013-04-19 01:02:55 +02009075 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
9076 goto nla_put_failure;
9077 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009078 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
9079 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009080 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
9081 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02009082 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009083
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009084 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01009085 if (!bss)
9086 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04009087 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01009088 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04009089 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01009090
9091 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02009092 /* indicate whether we have probe response data or not */
9093 if (rcu_access_pointer(res->proberesp_ies) &&
9094 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
9095 goto fail_unlock_rcu;
9096
9097 /* this pointer prefers to be pointed to probe response data
9098 * but is always valid
9099 */
Johannes Berg9caf0362012-11-29 01:25:20 +01009100 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01009101 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009102 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
9103 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01009104 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01009105 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
9106 ies->len, ies->data))
9107 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01009108 }
Johannes Berg0e227082014-08-12 20:34:30 +02009109
9110 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01009111 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02009112 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009113 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
9114 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01009115 goto fail_unlock_rcu;
9116 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
9117 ies->len, ies->data))
9118 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01009119 }
9120 rcu_read_unlock();
9121
David S. Miller9360ffd2012-03-29 04:41:26 -04009122 if (res->beacon_interval &&
9123 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
9124 goto nla_put_failure;
9125 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
9126 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Thomas Pedersen942ba882020-04-30 10:25:51 -07009127 nla_put_u32(msg, NL80211_BSS_FREQUENCY_OFFSET,
9128 res->channel->freq_offset) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02009129 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04009130 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
9131 jiffies_to_msecs(jiffies - intbss->ts)))
9132 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009133
Avraham Stern1d762502016-07-05 17:10:13 +03009134 if (intbss->parent_tsf &&
9135 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
9136 intbss->parent_tsf, NL80211_BSS_PAD) ||
9137 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
9138 intbss->parent_bssid)))
9139 goto nla_put_failure;
9140
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02009141 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009142 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
9143 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02009144 goto nla_put_failure;
9145
Sunil Dutt983dafa2017-12-13 19:51:36 +02009146 if (!nl80211_put_signal(msg, intbss->pub.chains,
9147 intbss->pub.chain_signal,
9148 NL80211_BSS_CHAIN_SIGNAL))
9149 goto nla_put_failure;
9150
Johannes Berg77965c972009-02-18 18:45:06 +01009151 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01009152 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04009153 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
9154 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009155 break;
9156 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04009157 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
9158 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01009159 break;
9160 default:
9161 break;
9162 }
9163
Johannes Berg48ab9052009-07-10 18:42:31 +02009164 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02009165 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02009166 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04009167 if (intbss == wdev->current_bss &&
9168 nla_put_u32(msg, NL80211_BSS_STATUS,
9169 NL80211_BSS_STATUS_ASSOCIATED))
9170 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02009171 break;
9172 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04009173 if (intbss == wdev->current_bss &&
9174 nla_put_u32(msg, NL80211_BSS_STATUS,
9175 NL80211_BSS_STATUS_IBSS_JOINED))
9176 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02009177 break;
9178 default:
9179 break;
9180 }
9181
Johannes Berg2a519312009-02-10 21:25:55 +01009182 nla_nest_end(msg, bss);
9183
Johannes Berg053c0952015-01-16 22:09:00 +01009184 genlmsg_end(msg, hdr);
9185 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01009186
Johannes Berg8cef2c92013-02-05 16:54:31 +01009187 fail_unlock_rcu:
9188 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01009189 nla_put_failure:
9190 genlmsg_cancel(msg, hdr);
9191 return -EMSGSIZE;
9192}
9193
Johannes Berg97990a02013-04-19 01:02:55 +02009194static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01009195{
Johannes Berg48ab9052009-07-10 18:42:31 +02009196 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01009197 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02009198 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02009199 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01009200 int err;
9201
Johannes Bergea90e0d2017-03-15 14:26:04 +01009202 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02009203 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01009204 if (err) {
9205 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02009206 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01009207 }
Johannes Berg2a519312009-02-10 21:25:55 +01009208
Johannes Berg48ab9052009-07-10 18:42:31 +02009209 wdev_lock(wdev);
9210 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05009211
9212 /*
9213 * dump_scan will be called multiple times to break up the scan results
9214 * into multiple messages. It is unlikely that any more bss-es will be
9215 * expired after the first call, so only call only call this on the
9216 * first dump_scan invocation.
9217 */
9218 if (start == 0)
9219 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02009220
Johannes Berg9720bb32011-06-21 09:45:33 +02009221 cb->seq = rdev->bss_generation;
9222
Johannes Berg48ab9052009-07-10 18:42:31 +02009223 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01009224 if (++idx <= start)
9225 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02009226 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01009227 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02009228 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01009229 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02009230 break;
Johannes Berg2a519312009-02-10 21:25:55 +01009231 }
9232 }
9233
Johannes Berg48ab9052009-07-10 18:42:31 +02009234 spin_unlock_bh(&rdev->bss_lock);
9235 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01009236
Johannes Berg97990a02013-04-19 01:02:55 +02009237 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01009238 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01009239
Johannes Berg67748892010-10-04 21:14:06 +02009240 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01009241}
9242
Eric W. Biederman15e47302012-09-07 20:12:54 +00009243static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01009244 int flags, struct net_device *dev,
9245 bool allow_radio_stats,
9246 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01009247{
9248 void *hdr;
9249 struct nlattr *infoattr;
9250
Johannes Berg11f78ac2014-11-14 16:43:50 +01009251 /* skip radio stats if userspace didn't request them */
9252 if (!survey->channel && !allow_radio_stats)
9253 return 0;
9254
Eric W. Biederman15e47302012-09-07 20:12:54 +00009255 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01009256 NL80211_CMD_NEW_SURVEY_RESULTS);
9257 if (!hdr)
9258 return -ENOMEM;
9259
David S. Miller9360ffd2012-03-29 04:41:26 -04009260 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
9261 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01009262
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009263 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01009264 if (!infoattr)
9265 goto nla_put_failure;
9266
Johannes Berg11f78ac2014-11-14 16:43:50 +01009267 if (survey->channel &&
9268 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04009269 survey->channel->center_freq))
9270 goto nla_put_failure;
9271
9272 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
9273 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
9274 goto nla_put_failure;
9275 if ((survey->filled & SURVEY_INFO_IN_USE) &&
9276 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
9277 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009278 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009279 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
9280 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009281 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009282 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009283 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
9284 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009285 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009286 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009287 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
9288 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009289 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009290 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009291 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
9292 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009293 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009294 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009295 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
9296 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009297 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01009298 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009299 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
9300 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01009301 goto nla_put_failure;
Felix Fietkauc8cd6e72019-08-28 12:20:42 +02009302 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
9303 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
9304 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
9305 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01009306
9307 nla_nest_end(msg, infoattr);
9308
Johannes Berg053c0952015-01-16 22:09:00 +01009309 genlmsg_end(msg, hdr);
9310 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01009311
9312 nla_put_failure:
9313 genlmsg_cancel(msg, hdr);
9314 return -EMSGSIZE;
9315}
9316
Johannes Berg11f78ac2014-11-14 16:43:50 +01009317static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01009318{
Johannes Berg50508d92019-07-29 16:31:09 +02009319 struct nlattr **attrbuf;
Holger Schurig61fa7132009-11-11 12:25:40 +01009320 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009321 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02009322 struct wireless_dev *wdev;
9323 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01009324 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01009325 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01009326
Johannes Berg50508d92019-07-29 16:31:09 +02009327 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
9328 if (!attrbuf)
9329 return -ENOMEM;
9330
Johannes Bergea90e0d2017-03-15 14:26:04 +01009331 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02009332 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02009333 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01009334 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01009335
Johannes Berg11f78ac2014-11-14 16:43:50 +01009336 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02009337 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01009338
Johannes Berg97990a02013-04-19 01:02:55 +02009339 if (!wdev->netdev) {
9340 res = -EINVAL;
9341 goto out_err;
9342 }
9343
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009344 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01009345 res = -EOPNOTSUPP;
9346 goto out_err;
9347 }
9348
9349 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009350 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01009351 if (res == -ENOENT)
9352 break;
9353 if (res)
9354 goto out_err;
9355
Johannes Berg11f78ac2014-11-14 16:43:50 +01009356 /* don't send disabled channels, but do send non-channel data */
9357 if (survey.channel &&
9358 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07009359 survey_idx++;
9360 continue;
9361 }
9362
Holger Schurig61fa7132009-11-11 12:25:40 +01009363 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009364 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01009365 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01009366 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01009367 goto out;
9368 survey_idx++;
9369 }
9370
9371 out:
Johannes Berg97990a02013-04-19 01:02:55 +02009372 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01009373 res = skb->len;
9374 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02009375 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +01009376 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01009377 return res;
9378}
9379
Samuel Ortizb23aa672009-07-01 21:26:54 +02009380static bool nl80211_valid_wpa_versions(u32 wpa_versions)
9381{
9382 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
Chung-Hsien Hsucc3e14c2019-05-09 09:49:05 +00009383 NL80211_WPA_VERSION_2 |
9384 NL80211_WPA_VERSION_3));
Samuel Ortizb23aa672009-07-01 21:26:54 +02009385}
9386
Jouni Malinen636a5d32009-03-19 13:39:22 +02009387static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
9388{
Johannes Berg4c476992010-10-04 21:36:35 +02009389 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9390 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009391 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009392 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
9393 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02009394 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02009395 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009396 bool local_state_change;
Thomas Pedersen942ba882020-04-30 10:25:51 -07009397 u32 freq;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009398
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009399 if (!info->attrs[NL80211_ATTR_MAC])
9400 return -EINVAL;
9401
Jouni Malinen17780922009-03-27 20:52:47 +02009402 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
9403 return -EINVAL;
9404
Johannes Berg19957bb2009-07-02 17:20:43 +02009405 if (!info->attrs[NL80211_ATTR_SSID])
9406 return -EINVAL;
9407
9408 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9409 return -EINVAL;
9410
Johannes Bergfffd0932009-07-08 14:22:54 +02009411 err = nl80211_parse_key(info, &key);
9412 if (err)
9413 return err;
9414
9415 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02009416 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
9417 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02009418 if (!key.p.key || !key.p.key_len)
9419 return -EINVAL;
9420 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
9421 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
9422 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
9423 key.p.key_len != WLAN_KEY_LEN_WEP104))
9424 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02009425 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02009426 return -EINVAL;
9427 } else {
9428 key.p.key_len = 0;
9429 key.p.key = NULL;
9430 }
9431
Johannes Bergafea0b72010-08-10 09:46:42 +02009432 if (key.idx >= 0) {
9433 int i;
9434 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009435
Johannes Bergafea0b72010-08-10 09:46:42 +02009436 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
9437 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
9438 ok = true;
9439 break;
9440 }
9441 }
Johannes Berg4c476992010-10-04 21:36:35 +02009442 if (!ok)
9443 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02009444 }
9445
Johannes Berg4c476992010-10-04 21:36:35 +02009446 if (!rdev->ops->auth)
9447 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009448
Johannes Berg074ac8d2010-09-16 14:58:22 +02009449 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009450 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9451 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009452
Johannes Berg19957bb2009-07-02 17:20:43 +02009453 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Thomas Pedersen942ba882020-04-30 10:25:51 -07009454 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
9455 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
9456 freq +=
9457 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
9458
9459 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
Jouni Malinen664834d2014-01-15 00:01:44 +02009460 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009461 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009462
Johannes Berg19957bb2009-07-02 17:20:43 +02009463 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9464 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9465
9466 if (info->attrs[NL80211_ATTR_IE]) {
9467 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9468 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9469 }
9470
9471 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009472 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02009473 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02009474
Jouni Malinen63181062016-10-27 00:42:02 +03009475 if ((auth_type == NL80211_AUTHTYPE_SAE ||
9476 auth_type == NL80211_AUTHTYPE_FILS_SK ||
9477 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
9478 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009479 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03009480 return -EINVAL;
9481
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009482 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03009483 if (auth_type != NL80211_AUTHTYPE_SAE &&
9484 auth_type != NL80211_AUTHTYPE_FILS_SK &&
9485 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
9486 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03009487 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009488 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
9489 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009490 }
9491
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009492 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9493
Johannes Berg95de8172012-01-20 13:55:25 +01009494 /*
9495 * Since we no longer track auth state, ignore
9496 * requests to only change local state.
9497 */
9498 if (local_state_change)
9499 return 0;
9500
Johannes Berg91bf9b22013-05-15 17:44:01 +02009501 wdev_lock(dev->ieee80211_ptr);
9502 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
9503 ssid, ssid_len, ie, ie_len,
9504 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009505 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009506 wdev_unlock(dev->ieee80211_ptr);
9507 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009508}
9509
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009510static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
9511 struct genl_info *info)
9512{
9513 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9514 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
9515 return -EINVAL;
9516 }
9517
9518 if (!rdev->ops->tx_control_port ||
9519 !wiphy_ext_feature_isset(&rdev->wiphy,
9520 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
9521 return -EOPNOTSUPP;
9522
9523 return 0;
9524}
9525
Johannes Bergc0692b82010-08-27 14:26:53 +03009526static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9527 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009528 struct cfg80211_crypto_settings *settings,
9529 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009530{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02009531 memset(settings, 0, sizeof(*settings));
9532
Samuel Ortizb23aa672009-07-01 21:26:54 +02009533 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9534
Johannes Bergc0692b82010-08-27 14:26:53 +03009535 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9536 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009537
Johannes Bergc0692b82010-08-27 14:26:53 +03009538 proto = nla_get_u16(
9539 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9540 settings->control_port_ethertype = cpu_to_be16(proto);
9541 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9542 proto != ETH_P_PAE)
9543 return -EINVAL;
9544 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9545 settings->control_port_no_encrypt = true;
9546 } else
9547 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9548
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009549 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9550 int r = validate_pae_over_nl80211(rdev, info);
9551
9552 if (r < 0)
9553 return r;
9554
9555 settings->control_port_over_nl80211 = true;
Markus Theil7f3f96c2020-03-12 10:10:54 +01009556
9557 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_PREAUTH])
9558 settings->control_port_no_preauth = true;
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009559 }
9560
Samuel Ortizb23aa672009-07-01 21:26:54 +02009561 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9562 void *data;
9563 int len, i;
9564
9565 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9566 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9567 settings->n_ciphers_pairwise = len / sizeof(u32);
9568
9569 if (len % sizeof(u32))
9570 return -EINVAL;
9571
Johannes Berg3dc27d22009-07-02 21:36:37 +02009572 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009573 return -EINVAL;
9574
9575 memcpy(settings->ciphers_pairwise, data, len);
9576
9577 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009578 if (!cfg80211_supported_cipher_suite(
9579 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009580 settings->ciphers_pairwise[i]))
9581 return -EINVAL;
9582 }
9583
9584 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9585 settings->cipher_group =
9586 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009587 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9588 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009589 return -EINVAL;
9590 }
9591
9592 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9593 settings->wpa_versions =
9594 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9595 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9596 return -EINVAL;
9597 }
9598
9599 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9600 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03009601 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009602
9603 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9604 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9605 settings->n_akm_suites = len / sizeof(u32);
9606
9607 if (len % sizeof(u32))
9608 return -EINVAL;
9609
Jouni Malinen1b9ca022011-09-21 16:13:07 +03009610 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9611 return -EINVAL;
9612
Samuel Ortizb23aa672009-07-01 21:26:54 +02009613 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009614 }
9615
Eliad Peller91b5ab62017-06-09 13:08:42 +01009616 if (info->attrs[NL80211_ATTR_PMK]) {
9617 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9618 return -EINVAL;
9619 if (!wiphy_ext_feature_isset(&rdev->wiphy,
Chung-Hsien Hsuf9662272020-06-23 08:49:35 -05009620 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK) &&
9621 !wiphy_ext_feature_isset(&rdev->wiphy,
9622 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_AP_PSK))
Eliad Peller91b5ab62017-06-09 13:08:42 +01009623 return -EINVAL;
9624 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9625 }
9626
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009627 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9628 if (!wiphy_ext_feature_isset(&rdev->wiphy,
Chung-Hsien Hsu2831a632020-08-17 02:33:15 -05009629 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
9630 !wiphy_ext_feature_isset(&rdev->wiphy,
9631 NL80211_EXT_FEATURE_SAE_OFFLOAD_AP))
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009632 return -EINVAL;
9633 settings->sae_pwd =
9634 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9635 settings->sae_pwd_len =
9636 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9637 }
9638
Samuel Ortizb23aa672009-07-01 21:26:54 +02009639 return 0;
9640}
9641
Jouni Malinen636a5d32009-03-19 13:39:22 +02009642static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9643{
Johannes Berg4c476992010-10-04 21:36:35 +02009644 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9645 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02009646 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01009647 struct cfg80211_assoc_request req = {};
9648 const u8 *bssid, *ssid;
9649 int err, ssid_len = 0;
Thomas Pedersen942ba882020-04-30 10:25:51 -07009650 u32 freq;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009651
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009652 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9653 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9654 return -EPERM;
9655
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009656 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02009657 !info->attrs[NL80211_ATTR_SSID] ||
9658 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009659 return -EINVAL;
9660
Johannes Berg4c476992010-10-04 21:36:35 +02009661 if (!rdev->ops->assoc)
9662 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009663
Johannes Berg074ac8d2010-09-16 14:58:22 +02009664 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009665 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9666 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009667
Johannes Berg19957bb2009-07-02 17:20:43 +02009668 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009669
Thomas Pedersen942ba882020-04-30 10:25:51 -07009670 freq = MHZ_TO_KHZ(nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
9671 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
9672 freq +=
9673 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
9674 chan = nl80211_get_valid_chan(&rdev->wiphy, freq);
Jouni Malinen664834d2014-01-15 00:01:44 +02009675 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009676 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009677
Johannes Berg19957bb2009-07-02 17:20:43 +02009678 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9679 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009680
9681 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009682 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9683 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009684 }
9685
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009686 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009687 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009688 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009689 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009690 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009691 else if (mfp != NL80211_MFP_NO)
9692 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009693 }
9694
Johannes Berg3e5d7642009-07-07 14:37:26 +02009695 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009696 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009697
Ben Greear7e7c8922011-11-18 11:31:59 -08009698 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009699 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009700
9701 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009702 memcpy(&req.ht_capa_mask,
9703 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9704 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009705
9706 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009707 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009708 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009709 memcpy(&req.ht_capa,
9710 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9711 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009712 }
9713
Johannes Bergee2aca32013-02-21 17:36:01 +01009714 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009715 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009716
9717 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009718 memcpy(&req.vht_capa_mask,
9719 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9720 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009721
9722 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009723 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009724 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009725 memcpy(&req.vht_capa,
9726 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9727 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009728 }
9729
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009730 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009731 if (!((rdev->wiphy.features &
9732 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9733 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9734 !wiphy_ext_feature_isset(&rdev->wiphy,
9735 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009736 return -EINVAL;
9737 req.flags |= ASSOC_REQ_USE_RRM;
9738 }
9739
Jouni Malinen348bd452016-10-27 00:42:03 +03009740 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9741 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9742 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9743 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9744 return -EINVAL;
9745 req.fils_nonces =
9746 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9747 }
9748
Johannes Bergf62fab72013-02-21 20:09:09 +01009749 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009750 if (!err) {
9751 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009752
Johannes Bergf62fab72013-02-21 20:09:09 +01009753 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9754 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009755
9756 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9757 dev->ieee80211_ptr->conn_owner_nlportid =
9758 info->snd_portid;
9759 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9760 bssid, ETH_ALEN);
9761 }
9762
Johannes Berg91bf9b22013-05-15 17:44:01 +02009763 wdev_unlock(dev->ieee80211_ptr);
9764 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009765
Jouni Malinen636a5d32009-03-19 13:39:22 +02009766 return err;
9767}
9768
9769static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9770{
Johannes Berg4c476992010-10-04 21:36:35 +02009771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9772 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009773 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009774 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009775 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009776 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009777
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009778 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9779 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9780 return -EPERM;
9781
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009782 if (!info->attrs[NL80211_ATTR_MAC])
9783 return -EINVAL;
9784
9785 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9786 return -EINVAL;
9787
Johannes Berg4c476992010-10-04 21:36:35 +02009788 if (!rdev->ops->deauth)
9789 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009790
Johannes Berg074ac8d2010-09-16 14:58:22 +02009791 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009792 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9793 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009794
Johannes Berg19957bb2009-07-02 17:20:43 +02009795 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009796
Johannes Berg19957bb2009-07-02 17:20:43 +02009797 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9798 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009799 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009800 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009801 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009802
9803 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009804 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9805 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009806 }
9807
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009808 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9809
Johannes Berg91bf9b22013-05-15 17:44:01 +02009810 wdev_lock(dev->ieee80211_ptr);
9811 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9812 local_state_change);
9813 wdev_unlock(dev->ieee80211_ptr);
9814 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009815}
9816
9817static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9818{
Johannes Berg4c476992010-10-04 21:36:35 +02009819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9820 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009821 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009822 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009823 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009824 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009825
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009826 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9827 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9828 return -EPERM;
9829
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009830 if (!info->attrs[NL80211_ATTR_MAC])
9831 return -EINVAL;
9832
9833 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9834 return -EINVAL;
9835
Johannes Berg4c476992010-10-04 21:36:35 +02009836 if (!rdev->ops->disassoc)
9837 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009838
Johannes Berg074ac8d2010-09-16 14:58:22 +02009839 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009840 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9841 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009842
Johannes Berg19957bb2009-07-02 17:20:43 +02009843 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009844
Johannes Berg19957bb2009-07-02 17:20:43 +02009845 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9846 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009847 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009848 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009849 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009850
9851 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009852 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9853 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009854 }
9855
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009856 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9857
Johannes Berg91bf9b22013-05-15 17:44:01 +02009858 wdev_lock(dev->ieee80211_ptr);
9859 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9860 local_state_change);
9861 wdev_unlock(dev->ieee80211_ptr);
9862 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009863}
9864
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009865static bool
9866nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009867 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009868 int rateval)
9869{
9870 struct wiphy *wiphy = &rdev->wiphy;
9871 bool found = false;
9872 int band, i;
9873
Johannes Berg57fbcce2016-04-12 15:56:15 +02009874 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009875 struct ieee80211_supported_band *sband;
9876
9877 sband = wiphy->bands[band];
9878 if (!sband)
9879 continue;
9880
9881 for (i = 0; i < sband->n_bitrates; i++) {
9882 if (sband->bitrates[i].bitrate == rateval) {
9883 mcast_rate[band] = i + 1;
9884 found = true;
9885 break;
9886 }
9887 }
9888 }
9889
9890 return found;
9891}
9892
Johannes Berg04a773a2009-04-19 21:24:32 +02009893static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9894{
Johannes Berg4c476992010-10-04 21:36:35 +02009895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9896 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009897 struct cfg80211_ibss_params ibss;
9898 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009899 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009900 int err;
9901
Johannes Berg8e30bc52009-04-22 17:45:38 +02009902 memset(&ibss, 0, sizeof(ibss));
9903
Johannes Berg683b6d32012-11-08 21:25:48 +01009904 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009905 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9906 return -EINVAL;
9907
Johannes Berg8e30bc52009-04-22 17:45:38 +02009908 ibss.beacon_interval = 100;
9909
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309910 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009911 ibss.beacon_interval =
9912 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309913
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309914 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9915 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309916 if (err)
9917 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009918
Johannes Berg4c476992010-10-04 21:36:35 +02009919 if (!rdev->ops->join_ibss)
9920 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009921
Johannes Berg4c476992010-10-04 21:36:35 +02009922 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9923 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009924
Johannes Berg79c97e92009-07-07 03:56:12 +02009925 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009926
Johannes Berg39193492011-09-16 13:45:25 +02009927 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009928 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009929
9930 if (!is_valid_ether_addr(ibss.bssid))
9931 return -EINVAL;
9932 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009933 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9934 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9935
9936 if (info->attrs[NL80211_ATTR_IE]) {
9937 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9938 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9939 }
9940
Johannes Berg683b6d32012-11-08 21:25:48 +01009941 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9942 if (err)
9943 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009944
Ilan Peer174e0cd2014-02-23 09:13:01 +02009945 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9946 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009947 return -EINVAL;
9948
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009949 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009950 case NL80211_CHAN_WIDTH_5:
9951 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009952 case NL80211_CHAN_WIDTH_20_NOHT:
9953 break;
9954 case NL80211_CHAN_WIDTH_20:
9955 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009956 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9957 return -EINVAL;
9958 break;
9959 case NL80211_CHAN_WIDTH_80:
9960 case NL80211_CHAN_WIDTH_80P80:
9961 case NL80211_CHAN_WIDTH_160:
9962 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9963 return -EINVAL;
9964 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9965 NL80211_EXT_FEATURE_VHT_IBSS))
9966 return -EINVAL;
9967 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009968 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009969 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009970 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009971
Johannes Berg04a773a2009-04-19 21:24:32 +02009972 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009973 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009974
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009975 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9976 u8 *rates =
9977 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9978 int n_rates =
9979 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9980 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009981 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009982
Johannes Berg34850ab2011-07-18 18:08:35 +02009983 err = ieee80211_get_ratemask(sband, rates, n_rates,
9984 &ibss.basic_rates);
9985 if (err)
9986 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009987 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009988
Simon Wunderlich803768f2013-06-28 10:39:58 +02009989 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9990 memcpy(&ibss.ht_capa_mask,
9991 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9992 sizeof(ibss.ht_capa_mask));
9993
9994 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9995 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9996 return -EINVAL;
9997 memcpy(&ibss.ht_capa,
9998 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9999 sizeof(ibss.ht_capa));
10000 }
10001
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +010010002 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
10003 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
10004 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
10005 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +030010006
Johannes Berg4c476992010-10-04 21:36:35 +020010007 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +053010008 bool no_ht = false;
10009
Johannes Berg768075e2017-11-13 15:35:06 +010010010 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +020010011 if (IS_ERR(connkeys))
10012 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +053010013
Johannes Berg3d9d1d62012-11-08 23:14:50 +010010014 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
10015 no_ht) {
Waiman Long453431a2020-08-06 23:18:13 -070010016 kfree_sensitive(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +053010017 return -EINVAL;
10018 }
Johannes Berg4c476992010-10-04 21:36:35 +020010019 }
Johannes Berg04a773a2009-04-19 21:24:32 +020010020
Antonio Quartulli267335d2012-01-31 20:25:47 +010010021 ibss.control_port =
10022 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
10023
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -050010024 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
10025 int r = validate_pae_over_nl80211(rdev, info);
10026
Johannes Bergd350a0f2018-12-15 11:03:22 +020010027 if (r < 0) {
Waiman Long453431a2020-08-06 23:18:13 -070010028 kfree_sensitive(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -050010029 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +020010030 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -050010031
10032 ibss.control_port_over_nl80211 = true;
10033 }
10034
Simon Wunderlich5336fa82013-10-07 18:41:05 +020010035 ibss.userspace_handles_dfs =
10036 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
10037
Denis Kenziorf8d16d32018-03-26 12:52:45 -050010038 wdev_lock(dev->ieee80211_ptr);
10039 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +020010040 if (err)
Waiman Long453431a2020-08-06 23:18:13 -070010041 kfree_sensitive(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -050010042 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
10043 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10044 wdev_unlock(dev->ieee80211_ptr);
10045
Johannes Berg04a773a2009-04-19 21:24:32 +020010046 return err;
10047}
10048
10049static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
10050{
Johannes Berg4c476992010-10-04 21:36:35 +020010051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10052 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +020010053
Johannes Berg4c476992010-10-04 21:36:35 +020010054 if (!rdev->ops->leave_ibss)
10055 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +020010056
Johannes Berg4c476992010-10-04 21:36:35 +020010057 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
10058 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +020010059
Johannes Berg4c476992010-10-04 21:36:35 +020010060 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +020010061}
10062
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010063static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
10064{
10065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10066 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +020010067 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010068 u32 nla_rate;
10069 int err;
10070
10071 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +020010072 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
10073 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010074 return -EOPNOTSUPP;
10075
10076 if (!rdev->ops->set_mcast_rate)
10077 return -EOPNOTSUPP;
10078
10079 memset(mcast_rate, 0, sizeof(mcast_rate));
10080
10081 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
10082 return -EINVAL;
10083
10084 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
10085 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
10086 return -EINVAL;
10087
Ilan Peera1056b1b2015-10-22 22:27:46 +030010088 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010089
10090 return err;
10091}
10092
Johannes Bergad7e7182013-11-13 13:37:47 +010010093static struct sk_buff *
10094__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010095 struct wireless_dev *wdev, int approxlen,
10096 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +010010097 enum nl80211_attrs attr,
10098 const struct nl80211_vendor_cmd_info *info,
10099 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +010010100{
10101 struct sk_buff *skb;
10102 void *hdr;
10103 struct nlattr *data;
10104
10105 skb = nlmsg_new(approxlen + 100, gfp);
10106 if (!skb)
10107 return NULL;
10108
10109 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
10110 if (!hdr) {
10111 kfree_skb(skb);
10112 return NULL;
10113 }
10114
10115 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
10116 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +010010117
10118 if (info) {
10119 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
10120 info->vendor_id))
10121 goto nla_put_failure;
10122 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
10123 info->subcmd))
10124 goto nla_put_failure;
10125 }
10126
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010127 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010128 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
10129 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010130 goto nla_put_failure;
10131 if (wdev->netdev &&
10132 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
10133 wdev->netdev->ifindex))
10134 goto nla_put_failure;
10135 }
10136
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010137 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +020010138 if (!data)
10139 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +010010140
10141 ((void **)skb->cb)[0] = rdev;
10142 ((void **)skb->cb)[1] = hdr;
10143 ((void **)skb->cb)[2] = data;
10144
10145 return skb;
10146
10147 nla_put_failure:
10148 kfree_skb(skb);
10149 return NULL;
10150}
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010151
Johannes Berge03ad6e2014-01-01 17:22:30 +010010152struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010153 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +010010154 enum nl80211_commands cmd,
10155 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010156 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +010010157 int vendor_event_idx,
10158 int approxlen, gfp_t gfp)
10159{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010160 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +010010161 const struct nl80211_vendor_cmd_info *info;
10162
10163 switch (cmd) {
10164 case NL80211_CMD_TESTMODE:
10165 if (WARN_ON(vendor_event_idx != -1))
10166 return NULL;
10167 info = NULL;
10168 break;
10169 case NL80211_CMD_VENDOR:
10170 if (WARN_ON(vendor_event_idx < 0 ||
10171 vendor_event_idx >= wiphy->n_vendor_events))
10172 return NULL;
10173 info = &wiphy->vendor_events[vendor_event_idx];
10174 break;
10175 default:
10176 WARN_ON(1);
10177 return NULL;
10178 }
10179
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010180 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +010010181 cmd, attr, info, gfp);
10182}
10183EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
10184
10185void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
10186{
10187 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10188 void *hdr = ((void **)skb->cb)[1];
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010189 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +010010190 struct nlattr *data = ((void **)skb->cb)[2];
10191 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
10192
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010193 /* clear CB data for netlink core to own from now on */
10194 memset(skb->cb, 0, sizeof(skb->cb));
10195
Johannes Berge03ad6e2014-01-01 17:22:30 +010010196 nla_nest_end(skb, data);
10197 genlmsg_end(skb, hdr);
10198
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010199 if (nlhdr->nlmsg_pid) {
10200 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
10201 nlhdr->nlmsg_pid);
10202 } else {
10203 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
10204 mcgrp = NL80211_MCGRP_VENDOR;
Johannes Berge03ad6e2014-01-01 17:22:30 +010010205
Johannes Berg55c1fdf2019-02-06 13:17:19 +020010206 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
10207 skb, 0, mcgrp, gfp);
10208 }
Johannes Berge03ad6e2014-01-01 17:22:30 +010010209}
10210EXPORT_SYMBOL(__cfg80211_send_event_skb);
10211
Johannes Bergaff89a92009-07-01 21:26:51 +020010212#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +020010213static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
10214{
Johannes Berg4c476992010-10-04 21:36:35 +020010215 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +030010216 struct wireless_dev *wdev =
10217 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +020010218 int err;
10219
David Spinadelfc73f112013-07-31 18:04:15 +030010220 if (!rdev->ops->testmode_cmd)
10221 return -EOPNOTSUPP;
10222
10223 if (IS_ERR(wdev)) {
10224 err = PTR_ERR(wdev);
10225 if (err != -EINVAL)
10226 return err;
10227 wdev = NULL;
10228 } else if (wdev->wiphy != &rdev->wiphy) {
10229 return -EINVAL;
10230 }
10231
Johannes Bergaff89a92009-07-01 21:26:51 +020010232 if (!info->attrs[NL80211_ATTR_TESTDATA])
10233 return -EINVAL;
10234
Johannes Bergad7e7182013-11-13 13:37:47 +010010235 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +030010236 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +020010237 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
10238 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +010010239 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +020010240
Johannes Bergaff89a92009-07-01 21:26:51 +020010241 return err;
10242}
10243
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010244static int nl80211_testmode_dump(struct sk_buff *skb,
10245 struct netlink_callback *cb)
10246{
Johannes Berg00918d32011-12-13 17:22:05 +010010247 struct cfg80211_registered_device *rdev;
Johannes Berg50508d92019-07-29 16:31:09 +020010248 struct nlattr **attrbuf = NULL;
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010249 int err;
10250 long phy_idx;
10251 void *data = NULL;
10252 int data_len = 0;
10253
Johannes Berg5fe231e2013-05-08 21:45:15 +020010254 rtnl_lock();
10255
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010256 if (cb->args[0]) {
10257 /*
10258 * 0 is a valid index, but not valid for args[0],
10259 * so we need to offset by 1.
10260 */
10261 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +020010262
10263 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
10264 if (!rdev) {
10265 err = -ENOENT;
10266 goto out_err;
10267 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010268 } else {
Johannes Berg50508d92019-07-29 16:31:09 +020010269 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
10270 GFP_KERNEL);
10271 if (!attrbuf) {
10272 err = -ENOMEM;
10273 goto out_err;
10274 }
Johannes Bergc90c39d2016-10-24 14:40:01 +020010275
Johannes Berg8cb08172019-04-26 14:07:28 +020010276 err = nlmsg_parse_deprecated(cb->nlh,
10277 GENL_HDRLEN + nl80211_fam.hdrsize,
10278 attrbuf, nl80211_fam.maxattr,
10279 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010280 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +020010281 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +010010282
Johannes Bergc90c39d2016-10-24 14:40:01 +020010283 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +020010284 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010285 err = PTR_ERR(rdev);
10286 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +010010287 }
Johannes Berg2bd7e352012-06-15 14:23:16 +020010288 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +020010289
Johannes Bergc90c39d2016-10-24 14:40:01 +020010290 if (attrbuf[NL80211_ATTR_TESTDATA])
10291 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010292 }
10293
10294 if (cb->args[1]) {
10295 data = nla_data((void *)cb->args[1]);
10296 data_len = nla_len((void *)cb->args[1]);
10297 }
10298
Johannes Berg00918d32011-12-13 17:22:05 +010010299 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010300 err = -EOPNOTSUPP;
10301 goto out_err;
10302 }
10303
10304 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000010305 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010306 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10307 NL80211_CMD_TESTMODE);
10308 struct nlattr *tmdata;
10309
Dan Carpentercb35fba2013-08-14 14:50:01 +030010310 if (!hdr)
10311 break;
10312
David S. Miller9360ffd2012-03-29 04:41:26 -040010313 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010314 genlmsg_cancel(skb, hdr);
10315 break;
10316 }
10317
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010318 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010319 if (!tmdata) {
10320 genlmsg_cancel(skb, hdr);
10321 break;
10322 }
Hila Gonene35e4d22012-06-27 17:19:42 +030010323 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010324 nla_nest_end(skb, tmdata);
10325
10326 if (err == -ENOBUFS || err == -ENOENT) {
10327 genlmsg_cancel(skb, hdr);
10328 break;
10329 } else if (err) {
10330 genlmsg_cancel(skb, hdr);
10331 goto out_err;
10332 }
10333
10334 genlmsg_end(skb, hdr);
10335 }
10336
10337 err = skb->len;
10338 /* see above */
10339 cb->args[0] = phy_idx + 1;
10340 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +020010341 kfree(attrbuf);
Johannes Berg5fe231e2013-05-08 21:45:15 +020010342 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010343 return err;
10344}
Johannes Bergaff89a92009-07-01 21:26:51 +020010345#endif
10346
Samuel Ortizb23aa672009-07-01 21:26:54 +020010347static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
10348{
Johannes Berg4c476992010-10-04 21:36:35 +020010349 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10350 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010351 struct cfg80211_connect_params connect;
10352 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +020010353 struct cfg80211_cached_keys *connkeys = NULL;
Thomas Pedersen942ba882020-04-30 10:25:51 -070010354 u32 freq = 0;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010355 int err;
10356
10357 memset(&connect, 0, sizeof(connect));
10358
Samuel Ortizb23aa672009-07-01 21:26:54 +020010359 if (!info->attrs[NL80211_ATTR_SSID] ||
10360 !nla_len(info->attrs[NL80211_ATTR_SSID]))
10361 return -EINVAL;
10362
10363 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10364 connect.auth_type =
10365 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +030010366 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
10367 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +020010368 return -EINVAL;
10369 } else
10370 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
10371
10372 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
10373
Avraham Stern3a00df52017-06-09 13:08:43 +010010374 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
10375 !wiphy_ext_feature_isset(&rdev->wiphy,
10376 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
10377 return -EINVAL;
10378 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
10379
Johannes Bergc0692b82010-08-27 14:26:53 +030010380 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +020010381 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010382 if (err)
10383 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010384
Johannes Berg074ac8d2010-09-16 14:58:22 +020010385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010386 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10387 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010388
Johannes Berg79c97e92009-07-07 03:56:12 +020010389 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010390
Bala Shanmugam4486ea92012-03-07 17:27:12 +053010391 connect.bg_scan_period = -1;
10392 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
10393 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
10394 connect.bg_scan_period =
10395 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
10396 }
10397
Samuel Ortizb23aa672009-07-01 21:26:54 +020010398 if (info->attrs[NL80211_ATTR_MAC])
10399 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +020010400 else if (info->attrs[NL80211_ATTR_MAC_HINT])
10401 connect.bssid_hint =
10402 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010403 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10404 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10405
10406 if (info->attrs[NL80211_ATTR_IE]) {
10407 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10408 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10409 }
10410
Jouni Malinencee00a92013-01-15 17:15:57 +020010411 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10412 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +030010413 if (connect.mfp == NL80211_MFP_OPTIONAL &&
10414 !wiphy_ext_feature_isset(&rdev->wiphy,
10415 NL80211_EXT_FEATURE_MFP_OPTIONAL))
10416 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +020010417 } else {
10418 connect.mfp = NL80211_MFP_NO;
10419 }
10420
Jouni Malinenba6fbac2016-03-29 13:53:27 +030010421 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10422 connect.prev_bssid =
10423 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10424
Thomas Pedersen942ba882020-04-30 10:25:51 -070010425 if (info->attrs[NL80211_ATTR_WIPHY_FREQ])
10426 freq = MHZ_TO_KHZ(nla_get_u32(
10427 info->attrs[NL80211_ATTR_WIPHY_FREQ]));
10428 if (info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET])
10429 freq +=
10430 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_OFFSET]);
10431
10432 if (freq) {
10433 connect.channel = nl80211_get_valid_chan(wiphy, freq);
Jouni Malinen664834d2014-01-15 00:01:44 +020010434 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +020010435 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +020010436 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Thomas Pedersen942ba882020-04-30 10:25:51 -070010437 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
10438 freq = MHZ_TO_KHZ(freq);
10439 connect.channel_hint = nl80211_get_valid_chan(wiphy, freq);
Jouni Malinen664834d2014-01-15 00:01:44 +020010440 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +020010441 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010442 }
10443
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +030010444 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
10445 connect.edmg.channels =
10446 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
10447
10448 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
10449 connect.edmg.bw_config =
10450 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
10451 }
10452
Johannes Bergfffd0932009-07-08 14:22:54 +020010453 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +010010454 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +020010455 if (IS_ERR(connkeys))
10456 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +020010457 }
10458
Ben Greear7e7c8922011-11-18 11:31:59 -080010459 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
10460 connect.flags |= ASSOC_REQ_DISABLE_HT;
10461
10462 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10463 memcpy(&connect.ht_capa_mask,
10464 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
10465 sizeof(connect.ht_capa_mask));
10466
10467 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +080010468 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Waiman Long453431a2020-08-06 23:18:13 -070010469 kfree_sensitive(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -080010470 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +080010471 }
Ben Greear7e7c8922011-11-18 11:31:59 -080010472 memcpy(&connect.ht_capa,
10473 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10474 sizeof(connect.ht_capa));
10475 }
10476
Johannes Bergee2aca32013-02-21 17:36:01 +010010477 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
10478 connect.flags |= ASSOC_REQ_DISABLE_VHT;
10479
10480 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10481 memcpy(&connect.vht_capa_mask,
10482 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
10483 sizeof(connect.vht_capa_mask));
10484
10485 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
10486 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Waiman Long453431a2020-08-06 23:18:13 -070010487 kfree_sensitive(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +010010488 return -EINVAL;
10489 }
10490 memcpy(&connect.vht_capa,
10491 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
10492 sizeof(connect.vht_capa));
10493 }
10494
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010495 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +020010496 if (!((rdev->wiphy.features &
10497 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
10498 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
10499 !wiphy_ext_feature_isset(&rdev->wiphy,
10500 NL80211_EXT_FEATURE_RRM)) {
Waiman Long453431a2020-08-06 23:18:13 -070010501 kfree_sensitive(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010502 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +010010503 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010504 connect.flags |= ASSOC_REQ_USE_RRM;
10505 }
10506
Lior David34d50512016-01-28 10:58:25 +020010507 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +020010508 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Waiman Long453431a2020-08-06 23:18:13 -070010509 kfree_sensitive(connkeys);
Lior David34d50512016-01-28 10:58:25 +020010510 return -EOPNOTSUPP;
10511 }
10512
Arend van Spriel38de03d2016-03-02 20:37:18 +010010513 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10514 /* bss selection makes no sense if bssid is set */
10515 if (connect.bssid) {
Waiman Long453431a2020-08-06 23:18:13 -070010516 kfree_sensitive(connkeys);
Arend van Spriel38de03d2016-03-02 20:37:18 +010010517 return -EINVAL;
10518 }
10519
10520 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10521 wiphy, &connect.bss_select);
10522 if (err) {
Waiman Long453431a2020-08-06 23:18:13 -070010523 kfree_sensitive(connkeys);
Arend van Spriel38de03d2016-03-02 20:37:18 +010010524 return err;
10525 }
10526 }
10527
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010528 if (wiphy_ext_feature_isset(&rdev->wiphy,
10529 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10530 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10531 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10532 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10533 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10534 connect.fils_erp_username =
10535 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10536 connect.fils_erp_username_len =
10537 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10538 connect.fils_erp_realm =
10539 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10540 connect.fils_erp_realm_len =
10541 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10542 connect.fils_erp_next_seq_num =
10543 nla_get_u16(
10544 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10545 connect.fils_erp_rrk =
10546 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10547 connect.fils_erp_rrk_len =
10548 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10549 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10550 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10551 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10552 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
Waiman Long453431a2020-08-06 23:18:13 -070010553 kfree_sensitive(connkeys);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010554 return -EINVAL;
10555 }
10556
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010557 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10558 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Waiman Long453431a2020-08-06 23:18:13 -070010559 kfree_sensitive(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010560 GENL_SET_ERR_MSG(info,
10561 "external auth requires connection ownership");
10562 return -EINVAL;
10563 }
10564 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10565 }
10566
Johannes Berg83739b02013-05-15 17:44:01 +020010567 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010568
Jouni Malinen4ce2bd92016-03-29 13:53:28 +030010569 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10570 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +020010571 if (err)
Waiman Long453431a2020-08-06 23:18:13 -070010572 kfree_sensitive(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010573
10574 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10575 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10576 if (connect.bssid)
10577 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10578 connect.bssid, ETH_ALEN);
10579 else
Miaohe Lin3b1648f2020-08-01 17:15:49 +080010580 eth_zero_addr(dev->ieee80211_ptr->disconnect_bssid);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010581 }
10582
10583 wdev_unlock(dev->ieee80211_ptr);
10584
Samuel Ortizb23aa672009-07-01 21:26:54 +020010585 return err;
10586}
10587
vamsi krishna088e8df2016-10-27 16:51:11 +030010588static int nl80211_update_connect_params(struct sk_buff *skb,
10589 struct genl_info *info)
10590{
10591 struct cfg80211_connect_params connect = {};
10592 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10593 struct net_device *dev = info->user_ptr[1];
10594 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010595 bool fils_sk_offload;
10596 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +030010597 u32 changed = 0;
10598 int ret;
10599
10600 if (!rdev->ops->update_connect_params)
10601 return -EOPNOTSUPP;
10602
10603 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +030010604 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10605 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10606 changed |= UPDATE_ASSOC_IES;
10607 }
10608
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010609 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10610 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10611
10612 /*
10613 * when driver supports fils-sk offload all attributes must be
10614 * provided. So the else covers "fils-sk-not-all" and
10615 * "no-fils-sk-any".
10616 */
10617 if (fils_sk_offload &&
10618 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10619 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10620 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10621 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10622 connect.fils_erp_username =
10623 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10624 connect.fils_erp_username_len =
10625 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10626 connect.fils_erp_realm =
10627 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10628 connect.fils_erp_realm_len =
10629 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10630 connect.fils_erp_next_seq_num =
10631 nla_get_u16(
10632 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10633 connect.fils_erp_rrk =
10634 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10635 connect.fils_erp_rrk_len =
10636 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10637 changed |= UPDATE_FILS_ERP_INFO;
10638 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10639 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10640 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10641 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10642 return -EINVAL;
10643 }
10644
10645 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10646 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10647 if (!nl80211_valid_auth_type(rdev, auth_type,
10648 NL80211_CMD_CONNECT))
10649 return -EINVAL;
10650
10651 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10652 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10653 return -EINVAL;
10654
10655 connect.auth_type = auth_type;
10656 changed |= UPDATE_AUTH_TYPE;
10657 }
10658
vamsi krishna088e8df2016-10-27 16:51:11 +030010659 wdev_lock(dev->ieee80211_ptr);
10660 if (!wdev->current_bss)
10661 ret = -ENOLINK;
10662 else
10663 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10664 wdev_unlock(dev->ieee80211_ptr);
10665
10666 return ret;
10667}
10668
Samuel Ortizb23aa672009-07-01 21:26:54 +020010669static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10670{
Johannes Berg4c476992010-10-04 21:36:35 +020010671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10672 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010673 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +020010674 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010675
Andrew Zaborowskibad29292018-05-22 02:46:02 +020010676 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10677 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10678 return -EPERM;
10679
Samuel Ortizb23aa672009-07-01 21:26:54 +020010680 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10681 reason = WLAN_REASON_DEAUTH_LEAVING;
10682 else
10683 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10684
10685 if (reason == 0)
10686 return -EINVAL;
10687
Johannes Berg074ac8d2010-09-16 14:58:22 +020010688 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010689 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10690 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010691
Johannes Berg83739b02013-05-15 17:44:01 +020010692 wdev_lock(dev->ieee80211_ptr);
10693 ret = cfg80211_disconnect(rdev, dev, reason, true);
10694 wdev_unlock(dev->ieee80211_ptr);
10695 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010696}
10697
Johannes Berg463d0182009-07-14 00:33:35 +020010698static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10699{
Johannes Berg4c476992010-10-04 21:36:35 +020010700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010701 struct net *net;
10702 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010703
Vadim Kochan4b681c82015-01-12 16:34:05 +020010704 if (info->attrs[NL80211_ATTR_PID]) {
10705 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10706
10707 net = get_net_ns_by_pid(pid);
10708 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10709 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10710
10711 net = get_net_ns_by_fd(fd);
10712 } else {
Johannes Berg463d0182009-07-14 00:33:35 +020010713 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010714 }
Johannes Berg463d0182009-07-14 00:33:35 +020010715
Johannes Berg4c476992010-10-04 21:36:35 +020010716 if (IS_ERR(net))
10717 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010718
10719 err = 0;
10720
10721 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010722 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10723 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010724
Johannes Berg463d0182009-07-14 00:33:35 +020010725 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010726 return err;
10727}
10728
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010729static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10730{
Johannes Berg4c476992010-10-04 21:36:35 +020010731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010732 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10733 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010734 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010735 struct cfg80211_pmksa pmksa;
10736
10737 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10738
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010739 if (!info->attrs[NL80211_ATTR_PMKID])
10740 return -EINVAL;
10741
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010742 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010743
10744 if (info->attrs[NL80211_ATTR_MAC]) {
10745 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10746 } else if (info->attrs[NL80211_ATTR_SSID] &&
10747 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10748 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10749 info->attrs[NL80211_ATTR_PMK])) {
10750 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10751 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10752 pmksa.cache_id =
10753 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10754 } else {
10755 return -EINVAL;
10756 }
10757 if (info->attrs[NL80211_ATTR_PMK]) {
10758 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10759 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10760 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010761
Veerendranath Jakkam7fc82af2020-03-13 01:59:03 +020010762 if (info->attrs[NL80211_ATTR_PMK_LIFETIME])
10763 pmksa.pmk_lifetime =
10764 nla_get_u32(info->attrs[NL80211_ATTR_PMK_LIFETIME]);
10765
10766 if (info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD])
10767 pmksa.pmk_reauth_threshold =
10768 nla_get_u8(
10769 info->attrs[NL80211_ATTR_PMK_REAUTH_THRESHOLD]);
10770
Johannes Berg074ac8d2010-09-16 14:58:22 +020010771 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010772 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10773 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10774 wiphy_ext_feature_isset(&rdev->wiphy,
10775 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
Johannes Berg4c476992010-10-04 21:36:35 +020010776 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010777
10778 switch (info->genlhdr->cmd) {
10779 case NL80211_CMD_SET_PMKSA:
10780 rdev_ops = rdev->ops->set_pmksa;
10781 break;
10782 case NL80211_CMD_DEL_PMKSA:
10783 rdev_ops = rdev->ops->del_pmksa;
10784 break;
10785 default:
10786 WARN_ON(1);
10787 break;
10788 }
10789
Johannes Berg4c476992010-10-04 21:36:35 +020010790 if (!rdev_ops)
10791 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010792
Johannes Berg4c476992010-10-04 21:36:35 +020010793 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010794}
10795
10796static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10797{
Johannes Berg4c476992010-10-04 21:36:35 +020010798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10799 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010800
Johannes Berg074ac8d2010-09-16 14:58:22 +020010801 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010802 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10803 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010804
Johannes Berg4c476992010-10-04 21:36:35 +020010805 if (!rdev->ops->flush_pmksa)
10806 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010807
Hila Gonene35e4d22012-06-27 17:19:42 +030010808 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010809}
10810
Arik Nemtsov109086c2011-09-28 14:12:50 +030010811static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10812{
10813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10814 struct net_device *dev = info->user_ptr[1];
10815 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010816 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010817 u16 status_code;
10818 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010819 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010820
10821 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10822 !rdev->ops->tdls_mgmt)
10823 return -EOPNOTSUPP;
10824
10825 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10826 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10827 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10828 !info->attrs[NL80211_ATTR_IE] ||
10829 !info->attrs[NL80211_ATTR_MAC])
10830 return -EINVAL;
10831
10832 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10833 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10834 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10835 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010836 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010837 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10838 peer_capability =
10839 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010840
Hila Gonene35e4d22012-06-27 17:19:42 +030010841 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010842 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010843 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010844 nla_data(info->attrs[NL80211_ATTR_IE]),
10845 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010846}
10847
10848static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10849{
10850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10851 struct net_device *dev = info->user_ptr[1];
10852 enum nl80211_tdls_operation operation;
10853 u8 *peer;
10854
10855 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10856 !rdev->ops->tdls_oper)
10857 return -EOPNOTSUPP;
10858
10859 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10860 !info->attrs[NL80211_ATTR_MAC])
10861 return -EINVAL;
10862
10863 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10864 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10865
Hila Gonene35e4d22012-06-27 17:19:42 +030010866 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010867}
10868
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010869static int nl80211_remain_on_channel(struct sk_buff *skb,
10870 struct genl_info *info)
10871{
Johannes Berg4c476992010-10-04 21:36:35 +020010872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010873 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010874 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010875 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010876 struct sk_buff *msg;
10877 void *hdr;
10878 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010879 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010880 int err;
10881
10882 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10883 !info->attrs[NL80211_ATTR_DURATION])
10884 return -EINVAL;
10885
10886 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10887
Johannes Berg7c4ef712011-11-18 15:33:48 +010010888 if (!rdev->ops->remain_on_channel ||
10889 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010890 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010891
Johannes Bergebf348f2012-06-01 12:50:54 +020010892 /*
10893 * We should be on that channel for at least a minimum amount of
10894 * time (10ms) but no longer than the driver supports.
10895 */
10896 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10897 duration > rdev->wiphy.max_remain_on_channel_duration)
10898 return -EINVAL;
10899
Johannes Berg683b6d32012-11-08 21:25:48 +010010900 err = nl80211_parse_chandef(rdev, info, &chandef);
10901 if (err)
10902 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010903
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010904 wdev_lock(wdev);
10905 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10906 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10907 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10908 &chandef);
10909 if (compat_chandef != &chandef) {
10910 wdev_unlock(wdev);
10911 return -EBUSY;
10912 }
10913 }
10914 wdev_unlock(wdev);
10915
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010916 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010917 if (!msg)
10918 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010919
Eric W. Biederman15e47302012-09-07 20:12:54 +000010920 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010921 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010922 if (!hdr) {
10923 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010924 goto free_msg;
10925 }
10926
Johannes Berg683b6d32012-11-08 21:25:48 +010010927 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10928 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010929
10930 if (err)
10931 goto free_msg;
10932
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010933 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10934 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010935 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010936
10937 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010938
10939 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010940
10941 nla_put_failure:
10942 err = -ENOBUFS;
10943 free_msg:
10944 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010945 return err;
10946}
10947
10948static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10949 struct genl_info *info)
10950{
Johannes Berg4c476992010-10-04 21:36:35 +020010951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010952 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010953 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010954
10955 if (!info->attrs[NL80211_ATTR_COOKIE])
10956 return -EINVAL;
10957
Johannes Berg4c476992010-10-04 21:36:35 +020010958 if (!rdev->ops->cancel_remain_on_channel)
10959 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010960
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010961 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10962
Hila Gonene35e4d22012-06-27 17:19:42 +030010963 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010964}
10965
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010966static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10967 struct genl_info *info)
10968{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010969 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010970 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010971 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010972 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010973
Johannes Berg4c476992010-10-04 21:36:35 +020010974 if (!rdev->ops->set_bitrate_mask)
10975 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010976
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053010977 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
Miles Hueb89a6a2020-08-04 10:16:29 +020010978 NL80211_ATTR_TX_RATES, &mask,
10979 dev);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010980 if (err)
10981 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010982
Hila Gonene35e4d22012-06-27 17:19:42 +030010983 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010984}
10985
Johannes Berg2e161f782010-08-12 15:38:38 +020010986static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010987{
Johannes Berg4c476992010-10-04 21:36:35 +020010988 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010989 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010990 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010991
10992 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10993 return -EINVAL;
10994
Johannes Berg2e161f782010-08-12 15:38:38 +020010995 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10996 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010997
Johannes Berg71bbc992012-06-15 15:30:18 +020010998 switch (wdev->iftype) {
10999 case NL80211_IFTYPE_STATION:
11000 case NL80211_IFTYPE_ADHOC:
11001 case NL80211_IFTYPE_P2P_CLIENT:
11002 case NL80211_IFTYPE_AP:
11003 case NL80211_IFTYPE_AP_VLAN:
11004 case NL80211_IFTYPE_MESH_POINT:
11005 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020011006 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020011007 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011008 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020011009 default:
Johannes Berg4c476992010-10-04 21:36:35 +020011010 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020011011 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011012
11013 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020011014 if (!rdev->ops->mgmt_tx)
11015 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020011016
Johannes Berg9dba48a2020-04-17 12:40:15 +020011017 if (info->attrs[NL80211_ATTR_RECEIVE_MULTICAST] &&
11018 !wiphy_ext_feature_isset(&rdev->wiphy,
11019 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS)) {
11020 GENL_SET_ERR_MSG(info,
11021 "multicast RX registrations are not supported");
11022 return -EOPNOTSUPP;
11023 }
11024
Eric W. Biederman15e47302012-09-07 20:12:54 +000011025 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Ilan Peerff74c512020-01-31 13:45:29 +020011026 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
11027 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
Johannes Berg9dba48a2020-04-17 12:40:15 +020011028 info->attrs[NL80211_ATTR_RECEIVE_MULTICAST],
Ilan Peerff74c512020-01-31 13:45:29 +020011029 info->extack);
Jouni Malinen026331c2010-02-15 12:53:10 +020011030}
11031
Johannes Berg2e161f782010-08-12 15:38:38 +020011032static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020011033{
Johannes Berg4c476992010-10-04 21:36:35 +020011034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020011035 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010011036 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020011037 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010011038 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020011039 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010011040 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011041 struct cfg80211_mgmt_tx_params params = {
11042 .dont_wait_for_ack =
11043 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
11044 };
Jouni Malinen026331c2010-02-15 12:53:10 +020011045
Johannes Berg683b6d32012-11-08 21:25:48 +010011046 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020011047 return -EINVAL;
11048
Johannes Berg4c476992010-10-04 21:36:35 +020011049 if (!rdev->ops->mgmt_tx)
11050 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020011051
Johannes Berg71bbc992012-06-15 15:30:18 +020011052 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020011053 case NL80211_IFTYPE_P2P_DEVICE:
11054 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
11055 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020011056 case NL80211_IFTYPE_STATION:
11057 case NL80211_IFTYPE_ADHOC:
11058 case NL80211_IFTYPE_P2P_CLIENT:
11059 case NL80211_IFTYPE_AP:
11060 case NL80211_IFTYPE_AP_VLAN:
11061 case NL80211_IFTYPE_MESH_POINT:
11062 case NL80211_IFTYPE_P2P_GO:
11063 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011064 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020011065 default:
Johannes Berg4c476992010-10-04 21:36:35 +020011066 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020011067 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011068
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011069 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010011070 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011071 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011072 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020011073
11074 /*
11075 * We should wait on the channel for at least a minimum amount
11076 * of time (10ms) but no longer than the driver supports.
11077 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011078 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
11079 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020011080 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011081 }
11082
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011083 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011084
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011085 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010011086 return -EINVAL;
11087
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011088 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053011089
Antonio Quartulliea141b752013-06-11 14:20:03 +020011090 /* get the channel if any has been specified, otherwise pass NULL to
11091 * the driver. The latter will use the current one
11092 */
11093 chandef.chan = NULL;
11094 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
11095 err = nl80211_parse_chandef(rdev, info, &chandef);
11096 if (err)
11097 return err;
11098 }
11099
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011100 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020011101 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020011102
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053011103 wdev_lock(wdev);
11104 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
11105 wdev_unlock(wdev);
11106 return -EBUSY;
11107 }
11108 wdev_unlock(wdev);
11109
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030011110 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
11111 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
11112
11113 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
11114 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
11115 int i;
11116
11117 if (len % sizeof(u16))
11118 return -EINVAL;
11119
11120 params.n_csa_offsets = len / sizeof(u16);
11121 params.csa_offsets =
11122 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
11123
11124 /* check that all the offsets fit the frame */
11125 for (i = 0; i < params.n_csa_offsets; i++) {
11126 if (params.csa_offsets[i] >= params.len)
11127 return -EINVAL;
11128 }
11129 }
11130
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011131 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010011132 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11133 if (!msg)
11134 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020011135
Eric W. Biederman15e47302012-09-07 20:12:54 +000011136 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010011137 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030011138 if (!hdr) {
11139 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010011140 goto free_msg;
11141 }
Jouni Malinen026331c2010-02-15 12:53:10 +020011142 }
Johannes Berge247bd902011-11-04 11:18:21 +010011143
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020011144 params.chan = chandef.chan;
11145 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020011146 if (err)
11147 goto free_msg;
11148
Johannes Berge247bd902011-11-04 11:18:21 +010011149 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020011150 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
11151 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040011152 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011153
Johannes Berge247bd902011-11-04 11:18:21 +010011154 genlmsg_end(msg, hdr);
11155 return genlmsg_reply(msg, info);
11156 }
11157
11158 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020011159
11160 nla_put_failure:
11161 err = -ENOBUFS;
11162 free_msg:
11163 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020011164 return err;
11165}
11166
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011167static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
11168{
11169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020011170 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011171 u64 cookie;
11172
11173 if (!info->attrs[NL80211_ATTR_COOKIE])
11174 return -EINVAL;
11175
11176 if (!rdev->ops->mgmt_tx_cancel_wait)
11177 return -EOPNOTSUPP;
11178
Johannes Berg71bbc992012-06-15 15:30:18 +020011179 switch (wdev->iftype) {
11180 case NL80211_IFTYPE_STATION:
11181 case NL80211_IFTYPE_ADHOC:
11182 case NL80211_IFTYPE_P2P_CLIENT:
11183 case NL80211_IFTYPE_AP:
11184 case NL80211_IFTYPE_AP_VLAN:
11185 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020011186 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020011187 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030011188 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020011189 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011190 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020011191 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011192
11193 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
11194
Hila Gonene35e4d22012-06-27 17:19:42 +030011195 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011196}
11197
Kalle Valoffb9eb32010-02-17 17:58:10 +020011198static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
11199{
Johannes Berg4c476992010-10-04 21:36:35 +020011200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011201 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011202 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011203 u8 ps_state;
11204 bool state;
11205 int err;
11206
Johannes Berg4c476992010-10-04 21:36:35 +020011207 if (!info->attrs[NL80211_ATTR_PS_STATE])
11208 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011209
11210 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
11211
Kalle Valoffb9eb32010-02-17 17:58:10 +020011212 wdev = dev->ieee80211_ptr;
11213
Johannes Berg4c476992010-10-04 21:36:35 +020011214 if (!rdev->ops->set_power_mgmt)
11215 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011216
11217 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
11218
11219 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020011220 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011221
Hila Gonene35e4d22012-06-27 17:19:42 +030011222 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020011223 if (!err)
11224 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011225 return err;
11226}
11227
11228static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
11229{
Johannes Berg4c476992010-10-04 21:36:35 +020011230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011231 enum nl80211_ps_state ps_state;
11232 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020011233 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020011234 struct sk_buff *msg;
11235 void *hdr;
11236 int err;
11237
Kalle Valoffb9eb32010-02-17 17:58:10 +020011238 wdev = dev->ieee80211_ptr;
11239
Johannes Berg4c476992010-10-04 21:36:35 +020011240 if (!rdev->ops->set_power_mgmt)
11241 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011242
11243 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020011244 if (!msg)
11245 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011246
Eric W. Biederman15e47302012-09-07 20:12:54 +000011247 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011248 NL80211_CMD_GET_POWER_SAVE);
11249 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020011250 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011251 goto free_msg;
11252 }
11253
11254 if (wdev->ps)
11255 ps_state = NL80211_PS_ENABLED;
11256 else
11257 ps_state = NL80211_PS_DISABLED;
11258
David S. Miller9360ffd2012-03-29 04:41:26 -040011259 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
11260 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020011261
11262 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020011263 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020011264
Johannes Berg4c476992010-10-04 21:36:35 +020011265 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020011266 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020011267 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020011268 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020011269 return err;
11270}
11271
Johannes Berg94e860f2014-01-20 23:58:15 +010011272static const struct nla_policy
11273nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011274 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011275 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
11276 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070011277 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
11278 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
11279 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010011280 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011281};
11282
Thomas Pedersen84f10702012-07-12 16:17:33 -070011283static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010011284 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011285{
11286 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070011287 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011288 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070011289
Johannes Bergd9d8b012012-11-26 12:51:52 +010011290 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070011291 return -EINVAL;
11292
Thomas Pedersen84f10702012-07-12 16:17:33 -070011293 if (!rdev->ops->set_cqm_txe_config)
11294 return -EOPNOTSUPP;
11295
11296 if (wdev->iftype != NL80211_IFTYPE_STATION &&
11297 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11298 return -EOPNOTSUPP;
11299
Hila Gonene35e4d22012-06-27 17:19:42 +030011300 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070011301}
11302
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011303static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
11304 struct net_device *dev)
11305{
11306 struct wireless_dev *wdev = dev->ieee80211_ptr;
11307 s32 last, low, high;
11308 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090011309 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011310 int err;
11311
11312 /* RSSI reporting disabled? */
11313 if (!wdev->cqm_config)
11314 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
11315
11316 /*
11317 * Obtain current RSSI value if possible, if not and no RSSI threshold
11318 * event has been received yet, we should receive an event after a
11319 * connection is established and enough beacons received to calculate
11320 * the average.
11321 */
11322 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
11323 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020011324 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011325 u8 *mac_addr;
11326
11327 mac_addr = wdev->current_bss->pub.bssid;
11328
Johannes Berg73887fd2018-05-18 09:57:55 +020011329 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
11330 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011331 return err;
11332
Felix Fietkaudf167372020-01-08 18:06:30 +010011333 cfg80211_sinfo_release_content(&sinfo);
Omer Efrat397c6572018-06-17 13:06:14 +030011334 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011335 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020011336 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011337 }
11338
11339 last = wdev->cqm_config->last_rssi_event_value;
11340 hyst = wdev->cqm_config->rssi_hyst;
11341 n = wdev->cqm_config->n_rssi_thresholds;
11342
Masashi Honma4b2c5a12019-09-08 09:56:53 +090011343 for (i = 0; i < n; i++) {
11344 i = array_index_nospec(i, n);
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011345 if (last < wdev->cqm_config->rssi_thresholds[i])
11346 break;
Masashi Honma4b2c5a12019-09-08 09:56:53 +090011347 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011348
Masashi Honma1222a162018-09-25 11:15:01 +090011349 low_index = i - 1;
11350 if (low_index >= 0) {
11351 low_index = array_index_nospec(low_index, n);
11352 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
11353 } else {
11354 low = S32_MIN;
11355 }
11356 if (i < n) {
11357 i = array_index_nospec(i, n);
11358 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
11359 } else {
11360 high = S32_MAX;
11361 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011362
11363 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
11364}
11365
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011366static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011367 const s32 *thresholds, int n_thresholds,
11368 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011369{
Johannes Berg4c476992010-10-04 21:36:35 +020011370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020011371 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011372 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011373 int i, err;
11374 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011375
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011376 /* Check all values negative and sorted */
11377 for (i = 0; i < n_thresholds; i++) {
11378 if (thresholds[i] > 0 || thresholds[i] <= prev)
11379 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011380
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011381 prev = thresholds[i];
11382 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011383
Johannes Berg074ac8d2010-09-16 14:58:22 +020011384 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020011385 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11386 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011387
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011388 wdev_lock(wdev);
11389 cfg80211_cqm_config_free(wdev);
11390 wdev_unlock(wdev);
11391
11392 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
11393 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
11394 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
11395
11396 return rdev_set_cqm_rssi_config(rdev, dev,
11397 thresholds[0], hysteresis);
11398 }
11399
11400 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11401 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
11402 return -EOPNOTSUPP;
11403
11404 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
11405 n_thresholds = 0;
11406
11407 wdev_lock(wdev);
11408 if (n_thresholds) {
11409 struct cfg80211_cqm_config *cqm_config;
11410
11411 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
11412 n_thresholds * sizeof(s32), GFP_KERNEL);
11413 if (!cqm_config) {
11414 err = -ENOMEM;
11415 goto unlock;
11416 }
11417
11418 cqm_config->rssi_hyst = hysteresis;
11419 cqm_config->n_rssi_thresholds = n_thresholds;
11420 memcpy(cqm_config->rssi_thresholds, thresholds,
11421 n_thresholds * sizeof(s32));
11422
11423 wdev->cqm_config = cqm_config;
11424 }
11425
11426 err = cfg80211_cqm_rssi_update(rdev, dev);
11427
11428unlock:
11429 wdev_unlock(wdev);
11430
11431 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011432}
11433
11434static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
11435{
11436 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
11437 struct nlattr *cqm;
11438 int err;
11439
11440 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011441 if (!cqm)
11442 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011443
Johannes Berg8cb08172019-04-26 14:07:28 +020011444 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
11445 nl80211_attr_cqm_policy,
11446 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011447 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011448 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011449
11450 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
11451 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011452 const s32 *thresholds =
11453 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11454 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011455 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011456
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011457 if (len % 4)
11458 return -EINVAL;
11459
11460 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
11461 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011462 }
11463
11464 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
11465 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
11466 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
11467 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
11468 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
11469 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
11470
11471 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
11472 }
11473
11474 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011475}
11476
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011477static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
11478{
11479 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11480 struct net_device *dev = info->user_ptr[1];
11481 struct ocb_setup setup = {};
11482 int err;
11483
11484 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11485 if (err)
11486 return err;
11487
11488 return cfg80211_join_ocb(rdev, dev, &setup);
11489}
11490
11491static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
11492{
11493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11494 struct net_device *dev = info->user_ptr[1];
11495
11496 return cfg80211_leave_ocb(rdev, dev);
11497}
11498
Johannes Berg29cbe682010-12-03 09:20:44 +010011499static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
11500{
11501 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11502 struct net_device *dev = info->user_ptr[1];
11503 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080011504 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010011505 int err;
11506
11507 /* start with default */
11508 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080011509 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010011510
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011511 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010011512 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011513 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010011514 if (err)
11515 return err;
11516 }
11517
11518 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
11519 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
11520 return -EINVAL;
11521
Javier Cardonac80d5452010-12-16 17:37:49 -080011522 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
11523 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
11524
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080011525 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11526 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
11527 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11528 return -EINVAL;
11529
Marco Porsch9bdbf042013-01-07 16:04:51 +010011530 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
11531 setup.beacon_interval =
11532 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011533
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053011534 err = cfg80211_validate_beacon_int(rdev,
11535 NL80211_IFTYPE_MESH_POINT,
11536 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011537 if (err)
11538 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010011539 }
11540
11541 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
11542 setup.dtim_period =
11543 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
11544 if (setup.dtim_period < 1 || setup.dtim_period > 100)
11545 return -EINVAL;
11546 }
11547
Javier Cardonac80d5452010-12-16 17:37:49 -080011548 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
11549 /* parse additional setup parameters if given */
11550 err = nl80211_parse_mesh_setup(info, &setup);
11551 if (err)
11552 return err;
11553 }
11554
Thomas Pedersend37bb182013-03-04 13:06:13 -080011555 if (setup.user_mpm)
11556 cfg.auto_open_plinks = false;
11557
Johannes Bergcc1d2802012-05-16 23:50:20 +020011558 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010011559 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11560 if (err)
11561 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011562 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050011563 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010011564 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011565 }
11566
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070011567 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11568 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11569 int n_rates =
11570 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11571 struct ieee80211_supported_band *sband;
11572
11573 if (!setup.chandef.chan)
11574 return -EINVAL;
11575
11576 sband = rdev->wiphy.bands[setup.chandef.chan->band];
11577
11578 err = ieee80211_get_ratemask(sband, rates, n_rates,
11579 &setup.basic_rates);
11580 if (err)
11581 return err;
11582 }
11583
Johannes Berg8564e382016-09-19 09:44:44 +020011584 if (info->attrs[NL80211_ATTR_TX_RATES]) {
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053011585 err = nl80211_parse_tx_bitrate_mask(info, info->attrs,
11586 NL80211_ATTR_TX_RATES,
Miles Hueb89a6a2020-08-04 10:16:29 +020011587 &setup.beacon_rate,
11588 dev);
Johannes Berg8564e382016-09-19 09:44:44 +020011589 if (err)
11590 return err;
11591
Johannes Berg265698d2017-09-18 22:46:36 +020011592 if (!setup.chandef.chan)
11593 return -EINVAL;
11594
Johannes Berg8564e382016-09-19 09:44:44 +020011595 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11596 &setup.beacon_rate);
11597 if (err)
11598 return err;
11599 }
11600
Benjamin Bergd37d49c2017-05-16 11:23:11 +020011601 setup.userspace_handles_dfs =
11602 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11603
Denis Kenzior1224f582018-03-26 12:52:49 -050011604 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11605 int r = validate_pae_over_nl80211(rdev, info);
11606
11607 if (r < 0)
11608 return r;
11609
11610 setup.control_port_over_nl80211 = true;
11611 }
11612
Denis Kenzior188c1b32018-03-26 12:52:46 -050011613 wdev_lock(dev->ieee80211_ptr);
11614 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11615 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11616 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11617 wdev_unlock(dev->ieee80211_ptr);
11618
11619 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010011620}
11621
11622static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11623{
11624 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11625 struct net_device *dev = info->user_ptr[1];
11626
11627 return cfg80211_leave_mesh(rdev, dev);
11628}
11629
Johannes Bergdfb89c52012-06-27 09:23:48 +020011630#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011631static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11632 struct cfg80211_registered_device *rdev)
11633{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011634 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011635 struct nlattr *nl_pats, *nl_pat;
11636 int i, pat_len;
11637
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011638 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011639 return 0;
11640
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011641 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011642 if (!nl_pats)
11643 return -ENOBUFS;
11644
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011645 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011646 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011647 if (!nl_pat)
11648 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011649 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011650 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011651 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011652 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11653 wowlan->patterns[i].pattern) ||
11654 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011655 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011656 return -ENOBUFS;
11657 nla_nest_end(msg, nl_pat);
11658 }
11659 nla_nest_end(msg, nl_pats);
11660
11661 return 0;
11662}
11663
Johannes Berg2a0e0472013-01-23 22:57:40 +010011664static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11665 struct cfg80211_wowlan_tcp *tcp)
11666{
11667 struct nlattr *nl_tcp;
11668
11669 if (!tcp)
11670 return 0;
11671
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011672 nl_tcp = nla_nest_start_noflag(msg,
11673 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011674 if (!nl_tcp)
11675 return -ENOBUFS;
11676
Jiri Benc930345e2015-03-29 16:59:25 +020011677 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11678 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010011679 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11680 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11681 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11682 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11683 tcp->payload_len, tcp->payload) ||
11684 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11685 tcp->data_interval) ||
11686 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11687 tcp->wake_len, tcp->wake_data) ||
11688 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11689 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11690 return -ENOBUFS;
11691
11692 if (tcp->payload_seq.len &&
11693 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11694 sizeof(tcp->payload_seq), &tcp->payload_seq))
11695 return -ENOBUFS;
11696
11697 if (tcp->payload_tok.len &&
11698 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11699 sizeof(tcp->payload_tok) + tcp->tokens_size,
11700 &tcp->payload_tok))
11701 return -ENOBUFS;
11702
Johannes Berge248ad32013-05-16 10:24:28 +020011703 nla_nest_end(msg, nl_tcp);
11704
Johannes Berg2a0e0472013-01-23 22:57:40 +010011705 return 0;
11706}
11707
Luciano Coelho75453cc2015-01-09 14:06:37 +020011708static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11709 struct cfg80211_sched_scan_request *req)
11710{
Avraham Stern3b06d272015-10-12 09:51:34 +030011711 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011712 int i;
11713
11714 if (!req)
11715 return 0;
11716
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011717 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011718 if (!nd)
11719 return -ENOBUFS;
11720
Avraham Stern3b06d272015-10-12 09:51:34 +030011721 if (req->n_scan_plans == 1 &&
11722 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11723 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011724 return -ENOBUFS;
11725
Luciano Coelho21fea562015-03-17 16:36:01 +020011726 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11727 return -ENOBUFS;
11728
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011729 if (req->relative_rssi_set) {
11730 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11731
11732 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11733 req->relative_rssi))
11734 return -ENOBUFS;
11735
11736 rssi_adjust.band = req->rssi_adjust.band;
11737 rssi_adjust.delta = req->rssi_adjust.delta;
11738 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11739 sizeof(rssi_adjust), &rssi_adjust))
11740 return -ENOBUFS;
11741 }
11742
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011743 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011744 if (!freqs)
11745 return -ENOBUFS;
11746
Johannes Berg53b18982016-09-14 09:59:21 +020011747 for (i = 0; i < req->n_channels; i++) {
11748 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11749 return -ENOBUFS;
11750 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020011751
11752 nla_nest_end(msg, freqs);
11753
11754 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011755 matches = nla_nest_start_noflag(msg,
11756 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011757 if (!matches)
11758 return -ENOBUFS;
11759
Luciano Coelho75453cc2015-01-09 14:06:37 +020011760 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011761 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011762 if (!match)
11763 return -ENOBUFS;
11764
Johannes Berg53b18982016-09-14 09:59:21 +020011765 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11766 req->match_sets[i].ssid.ssid_len,
11767 req->match_sets[i].ssid.ssid))
11768 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011769 nla_nest_end(msg, match);
11770 }
11771 nla_nest_end(msg, matches);
11772 }
11773
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011774 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011775 if (!scan_plans)
11776 return -ENOBUFS;
11777
11778 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011779 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011780 if (!scan_plan)
11781 return -ENOBUFS;
11782
Colin Ian King67626962018-09-06 10:58:44 +010011783 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011784 req->scan_plans[i].interval) ||
11785 (req->scan_plans[i].iterations &&
11786 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11787 req->scan_plans[i].iterations)))
11788 return -ENOBUFS;
11789 nla_nest_end(msg, scan_plan);
11790 }
11791 nla_nest_end(msg, scan_plans);
11792
Luciano Coelho75453cc2015-01-09 14:06:37 +020011793 nla_nest_end(msg, nd);
11794
11795 return 0;
11796}
11797
Johannes Bergff1b6e62011-05-04 15:37:28 +020011798static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11799{
11800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11801 struct sk_buff *msg;
11802 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011803 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011804
Johannes Berg964dc9e2013-06-03 17:25:34 +020011805 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011806 return -EOPNOTSUPP;
11807
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011808 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011809 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011810 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11811 rdev->wiphy.wowlan_config->tcp->payload_len +
11812 rdev->wiphy.wowlan_config->tcp->wake_len +
11813 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011814 }
11815
11816 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011817 if (!msg)
11818 return -ENOMEM;
11819
Eric W. Biederman15e47302012-09-07 20:12:54 +000011820 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011821 NL80211_CMD_GET_WOWLAN);
11822 if (!hdr)
11823 goto nla_put_failure;
11824
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011825 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011826 struct nlattr *nl_wowlan;
11827
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011828 nl_wowlan = nla_nest_start_noflag(msg,
11829 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011830 if (!nl_wowlan)
11831 goto nla_put_failure;
11832
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011833 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011834 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011835 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011836 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011837 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011838 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011839 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011840 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011841 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011842 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011843 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011844 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011845 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011846 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11847 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011848
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011849 if (nl80211_send_wowlan_patterns(msg, rdev))
11850 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011851
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011852 if (nl80211_send_wowlan_tcp(msg,
11853 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011854 goto nla_put_failure;
11855
Luciano Coelho75453cc2015-01-09 14:06:37 +020011856 if (nl80211_send_wowlan_nd(
11857 msg,
11858 rdev->wiphy.wowlan_config->nd_config))
11859 goto nla_put_failure;
11860
Johannes Bergff1b6e62011-05-04 15:37:28 +020011861 nla_nest_end(msg, nl_wowlan);
11862 }
11863
11864 genlmsg_end(msg, hdr);
11865 return genlmsg_reply(msg, info);
11866
11867nla_put_failure:
11868 nlmsg_free(msg);
11869 return -ENOBUFS;
11870}
11871
Johannes Berg2a0e0472013-01-23 22:57:40 +010011872static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11873 struct nlattr *attr,
11874 struct cfg80211_wowlan *trig)
11875{
11876 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11877 struct cfg80211_wowlan_tcp *cfg;
11878 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11879 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11880 u32 size;
11881 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11882 int err, port;
11883
Johannes Berg964dc9e2013-06-03 17:25:34 +020011884 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011885 return -EINVAL;
11886
Johannes Berg8cb08172019-04-26 14:07:28 +020011887 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11888 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011889 if (err)
11890 return err;
11891
11892 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11893 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11894 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11895 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11896 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11897 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11898 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11899 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11900 return -EINVAL;
11901
11902 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011903 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011904 return -EINVAL;
11905
11906 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011907 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011908 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011909 return -EINVAL;
11910
11911 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011912 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011913 return -EINVAL;
11914
11915 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11916 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11917 return -EINVAL;
11918
11919 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11920 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11921
11922 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11923 tokens_size = tokln - sizeof(*tok);
11924
11925 if (!tok->len || tokens_size % tok->len)
11926 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011927 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011928 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011929 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011930 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011931 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011932 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011933 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011934 return -EINVAL;
11935 if (tok->offset + tok->len > data_size)
11936 return -EINVAL;
11937 }
11938
11939 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11940 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011941 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011942 return -EINVAL;
11943 if (seq->len == 0 || seq->len > 4)
11944 return -EINVAL;
11945 if (seq->len + seq->offset > data_size)
11946 return -EINVAL;
11947 }
11948
11949 size = sizeof(*cfg);
11950 size += data_size;
11951 size += wake_size + wake_mask_size;
11952 size += tokens_size;
11953
11954 cfg = kzalloc(size, GFP_KERNEL);
11955 if (!cfg)
11956 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011957 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11958 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011959 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11960 ETH_ALEN);
11961 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11962 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11963 else
11964 port = 0;
11965#ifdef CONFIG_INET
11966 /* allocate a socket and port for it and use it */
11967 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11968 IPPROTO_TCP, &cfg->sock, 1);
11969 if (err) {
11970 kfree(cfg);
11971 return err;
11972 }
11973 if (inet_csk_get_port(cfg->sock->sk, port)) {
11974 sock_release(cfg->sock);
11975 kfree(cfg);
11976 return -EADDRINUSE;
11977 }
11978 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11979#else
11980 if (!port) {
11981 kfree(cfg);
11982 return -EINVAL;
11983 }
11984 cfg->src_port = port;
11985#endif
11986
11987 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11988 cfg->payload_len = data_size;
11989 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11990 memcpy((void *)cfg->payload,
11991 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11992 data_size);
11993 if (seq)
11994 cfg->payload_seq = *seq;
11995 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11996 cfg->wake_len = wake_size;
11997 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11998 memcpy((void *)cfg->wake_data,
11999 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
12000 wake_size);
12001 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
12002 data_size + wake_size;
12003 memcpy((void *)cfg->wake_mask,
12004 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
12005 wake_mask_size);
12006 if (tok) {
12007 cfg->tokens_size = tokens_size;
12008 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
12009 }
12010
12011 trig->tcp = cfg;
12012
12013 return 0;
12014}
12015
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012016static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
12017 const struct wiphy_wowlan_support *wowlan,
12018 struct nlattr *attr,
12019 struct cfg80211_wowlan *trig)
12020{
12021 struct nlattr **tb;
12022 int err;
12023
Kees Cook6396bb22018-06-12 14:03:40 -070012024 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012025 if (!tb)
12026 return -ENOMEM;
12027
12028 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
12029 err = -EOPNOTSUPP;
12030 goto out;
12031 }
12032
Johannes Berg8cb08172019-04-26 14:07:28 +020012033 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
12034 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012035 if (err)
12036 goto out;
12037
Arend Van Sprielaad1e812017-01-27 12:27:44 +000012038 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
12039 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012040 err = PTR_ERR_OR_ZERO(trig->nd_config);
12041 if (err)
12042 trig->nd_config = NULL;
12043
12044out:
12045 kfree(tb);
12046 return err;
12047}
12048
Johannes Bergff1b6e62011-05-04 15:37:28 +020012049static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
12050{
12051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12052 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020012053 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020012054 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020012055 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012056 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012057 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020012058 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012059
Johannes Berg964dc9e2013-06-03 17:25:34 +020012060 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020012061 return -EOPNOTSUPP;
12062
Johannes Bergae33bd82012-07-12 16:25:02 +020012063 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
12064 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012065 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020012066 goto set_wakeup;
12067 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020012068
Johannes Berg8cb08172019-04-26 14:07:28 +020012069 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
12070 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
12071 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020012072 if (err)
12073 return err;
12074
12075 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
12076 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
12077 return -EINVAL;
12078 new_triggers.any = true;
12079 }
12080
12081 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
12082 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
12083 return -EINVAL;
12084 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020012085 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012086 }
12087
12088 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
12089 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
12090 return -EINVAL;
12091 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020012092 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012093 }
12094
Johannes Berg77dbbb12011-07-13 10:48:55 +020012095 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
12096 return -EINVAL;
12097
12098 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
12099 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
12100 return -EINVAL;
12101 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020012102 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012103 }
12104
12105 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
12106 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
12107 return -EINVAL;
12108 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020012109 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012110 }
12111
12112 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
12113 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
12114 return -EINVAL;
12115 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020012116 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012117 }
12118
12119 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
12120 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
12121 return -EINVAL;
12122 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020012123 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020012124 }
12125
Johannes Bergff1b6e62011-05-04 15:37:28 +020012126 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
12127 struct nlattr *pat;
12128 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080012129 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012130 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020012131
Johannes Berg98fc4382015-03-01 09:10:13 +020012132 regular = true;
12133
Johannes Bergff1b6e62011-05-04 15:37:28 +020012134 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
12135 rem)
12136 n_patterns++;
12137 if (n_patterns > wowlan->n_patterns)
12138 return -EINVAL;
12139
12140 new_triggers.patterns = kcalloc(n_patterns,
12141 sizeof(new_triggers.patterns[0]),
12142 GFP_KERNEL);
12143 if (!new_triggers.patterns)
12144 return -ENOMEM;
12145
12146 new_triggers.n_patterns = n_patterns;
12147 i = 0;
12148
12149 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
12150 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020012151 u8 *mask_pat;
12152
Johannes Berg8cb08172019-04-26 14:07:28 +020012153 err = nla_parse_nested_deprecated(pat_tb,
12154 MAX_NL80211_PKTPAT,
12155 pat,
12156 nl80211_packet_pattern_policy,
12157 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020012158 if (err)
12159 goto error;
12160
Johannes Bergff1b6e62011-05-04 15:37:28 +020012161 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012162 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12163 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020012164 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012165 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020012166 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012167 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020012168 goto error;
12169 if (pat_len > wowlan->pattern_max_len ||
12170 pat_len < wowlan->pattern_min_len)
12171 goto error;
12172
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012173 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080012174 pkt_offset = 0;
12175 else
12176 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012177 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080012178 if (pkt_offset > wowlan->max_pkt_offset)
12179 goto error;
12180 new_triggers.patterns[i].pkt_offset = pkt_offset;
12181
Johannes Berg922bd802014-05-19 17:59:50 +020012182 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12183 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020012184 err = -ENOMEM;
12185 goto error;
12186 }
Johannes Berg922bd802014-05-19 17:59:50 +020012187 new_triggers.patterns[i].mask = mask_pat;
12188 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020012189 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020012190 mask_pat += mask_len;
12191 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012192 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020012193 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070012194 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020012195 pat_len);
12196 i++;
12197 }
12198 }
12199
Johannes Berg2a0e0472013-01-23 22:57:40 +010012200 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020012201 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012202 err = nl80211_parse_wowlan_tcp(
12203 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
12204 &new_triggers);
12205 if (err)
12206 goto error;
12207 }
12208
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012209 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020012210 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012211 err = nl80211_parse_wowlan_nd(
12212 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
12213 &new_triggers);
12214 if (err)
12215 goto error;
12216 }
12217
Johannes Berg98fc4382015-03-01 09:10:13 +020012218 /* The 'any' trigger means the device continues operating more or less
12219 * as in its normal operation mode and wakes up the host on most of the
12220 * normal interrupts (like packet RX, ...)
12221 * It therefore makes little sense to combine with the more constrained
12222 * wakeup trigger modes.
12223 */
12224 if (new_triggers.any && regular) {
12225 err = -EINVAL;
12226 goto error;
12227 }
12228
Johannes Bergae33bd82012-07-12 16:25:02 +020012229 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
12230 if (!ntrig) {
12231 err = -ENOMEM;
12232 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012233 }
Johannes Bergae33bd82012-07-12 16:25:02 +020012234 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012235 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020012236
Johannes Bergae33bd82012-07-12 16:25:02 +020012237 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020012238 if (rdev->ops->set_wakeup &&
12239 prev_enabled != !!rdev->wiphy.wowlan_config)
12240 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020012241
Johannes Bergff1b6e62011-05-04 15:37:28 +020012242 return 0;
12243 error:
12244 for (i = 0; i < new_triggers.n_patterns; i++)
12245 kfree(new_triggers.patterns[i].mask);
12246 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010012247 if (new_triggers.tcp && new_triggers.tcp->sock)
12248 sock_release(new_triggers.tcp->sock);
12249 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010012250 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020012251 return err;
12252}
Johannes Bergdfb89c52012-06-27 09:23:48 +020012253#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020012254
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012255static int nl80211_send_coalesce_rules(struct sk_buff *msg,
12256 struct cfg80211_registered_device *rdev)
12257{
12258 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
12259 int i, j, pat_len;
12260 struct cfg80211_coalesce_rules *rule;
12261
12262 if (!rdev->coalesce->n_rules)
12263 return 0;
12264
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012265 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012266 if (!nl_rules)
12267 return -ENOBUFS;
12268
12269 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012270 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012271 if (!nl_rule)
12272 return -ENOBUFS;
12273
12274 rule = &rdev->coalesce->rules[i];
12275 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
12276 rule->delay))
12277 return -ENOBUFS;
12278
12279 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
12280 rule->condition))
12281 return -ENOBUFS;
12282
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012283 nl_pats = nla_nest_start_noflag(msg,
12284 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012285 if (!nl_pats)
12286 return -ENOBUFS;
12287
12288 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012289 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012290 if (!nl_pat)
12291 return -ENOBUFS;
12292 pat_len = rule->patterns[j].pattern_len;
12293 if (nla_put(msg, NL80211_PKTPAT_MASK,
12294 DIV_ROUND_UP(pat_len, 8),
12295 rule->patterns[j].mask) ||
12296 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
12297 rule->patterns[j].pattern) ||
12298 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
12299 rule->patterns[j].pkt_offset))
12300 return -ENOBUFS;
12301 nla_nest_end(msg, nl_pat);
12302 }
12303 nla_nest_end(msg, nl_pats);
12304 nla_nest_end(msg, nl_rule);
12305 }
12306 nla_nest_end(msg, nl_rules);
12307
12308 return 0;
12309}
12310
12311static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
12312{
12313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12314 struct sk_buff *msg;
12315 void *hdr;
12316
12317 if (!rdev->wiphy.coalesce)
12318 return -EOPNOTSUPP;
12319
12320 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12321 if (!msg)
12322 return -ENOMEM;
12323
12324 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12325 NL80211_CMD_GET_COALESCE);
12326 if (!hdr)
12327 goto nla_put_failure;
12328
12329 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
12330 goto nla_put_failure;
12331
12332 genlmsg_end(msg, hdr);
12333 return genlmsg_reply(msg, info);
12334
12335nla_put_failure:
12336 nlmsg_free(msg);
12337 return -ENOBUFS;
12338}
12339
12340void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
12341{
12342 struct cfg80211_coalesce *coalesce = rdev->coalesce;
12343 int i, j;
12344 struct cfg80211_coalesce_rules *rule;
12345
12346 if (!coalesce)
12347 return;
12348
12349 for (i = 0; i < coalesce->n_rules; i++) {
12350 rule = &coalesce->rules[i];
12351 for (j = 0; j < rule->n_patterns; j++)
12352 kfree(rule->patterns[j].mask);
12353 kfree(rule->patterns);
12354 }
12355 kfree(coalesce->rules);
12356 kfree(coalesce);
12357 rdev->coalesce = NULL;
12358}
12359
12360static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
12361 struct nlattr *rule,
12362 struct cfg80211_coalesce_rules *new_rule)
12363{
12364 int err, i;
12365 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12366 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
12367 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
12368 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
12369
Johannes Berg8cb08172019-04-26 14:07:28 +020012370 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
12371 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012372 if (err)
12373 return err;
12374
12375 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
12376 new_rule->delay =
12377 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
12378 if (new_rule->delay > coalesce->max_delay)
12379 return -EINVAL;
12380
12381 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
12382 new_rule->condition =
12383 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012384
12385 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
12386 return -EINVAL;
12387
12388 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12389 rem)
12390 n_patterns++;
12391 if (n_patterns > coalesce->n_patterns)
12392 return -EINVAL;
12393
12394 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
12395 GFP_KERNEL);
12396 if (!new_rule->patterns)
12397 return -ENOMEM;
12398
12399 new_rule->n_patterns = n_patterns;
12400 i = 0;
12401
12402 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12403 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020012404 u8 *mask_pat;
12405
Johannes Berg8cb08172019-04-26 14:07:28 +020012406 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
12407 pat,
12408 nl80211_packet_pattern_policy,
12409 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020012410 if (err)
12411 return err;
12412
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012413 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12414 !pat_tb[NL80211_PKTPAT_PATTERN])
12415 return -EINVAL;
12416 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
12417 mask_len = DIV_ROUND_UP(pat_len, 8);
12418 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
12419 return -EINVAL;
12420 if (pat_len > coalesce->pattern_max_len ||
12421 pat_len < coalesce->pattern_min_len)
12422 return -EINVAL;
12423
12424 if (!pat_tb[NL80211_PKTPAT_OFFSET])
12425 pkt_offset = 0;
12426 else
12427 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
12428 if (pkt_offset > coalesce->max_pkt_offset)
12429 return -EINVAL;
12430 new_rule->patterns[i].pkt_offset = pkt_offset;
12431
Johannes Berg922bd802014-05-19 17:59:50 +020012432 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12433 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012434 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020012435
12436 new_rule->patterns[i].mask = mask_pat;
12437 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
12438 mask_len);
12439
12440 mask_pat += mask_len;
12441 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012442 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020012443 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12444 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012445 i++;
12446 }
12447
12448 return 0;
12449}
12450
12451static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
12452{
12453 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12454 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12455 struct cfg80211_coalesce new_coalesce = {};
12456 struct cfg80211_coalesce *n_coalesce;
12457 int err, rem_rule, n_rules = 0, i, j;
12458 struct nlattr *rule;
12459 struct cfg80211_coalesce_rules *tmp_rule;
12460
12461 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
12462 return -EOPNOTSUPP;
12463
12464 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
12465 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030012466 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012467 return 0;
12468 }
12469
12470 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12471 rem_rule)
12472 n_rules++;
12473 if (n_rules > coalesce->n_rules)
12474 return -EINVAL;
12475
12476 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
12477 GFP_KERNEL);
12478 if (!new_coalesce.rules)
12479 return -ENOMEM;
12480
12481 new_coalesce.n_rules = n_rules;
12482 i = 0;
12483
12484 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12485 rem_rule) {
12486 err = nl80211_parse_coalesce_rule(rdev, rule,
12487 &new_coalesce.rules[i]);
12488 if (err)
12489 goto error;
12490
12491 i++;
12492 }
12493
Ilan Peera1056b1b2015-10-22 22:27:46 +030012494 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012495 if (err)
12496 goto error;
12497
12498 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
12499 if (!n_coalesce) {
12500 err = -ENOMEM;
12501 goto error;
12502 }
12503 cfg80211_rdev_free_coalesce(rdev);
12504 rdev->coalesce = n_coalesce;
12505
12506 return 0;
12507error:
12508 for (i = 0; i < new_coalesce.n_rules; i++) {
12509 tmp_rule = &new_coalesce.rules[i];
12510 for (j = 0; j < tmp_rule->n_patterns; j++)
12511 kfree(tmp_rule->patterns[j].mask);
12512 kfree(tmp_rule->patterns);
12513 }
12514 kfree(new_coalesce.rules);
12515
12516 return err;
12517}
12518
Johannes Berge5497d72011-07-05 16:35:40 +020012519static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
12520{
12521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12522 struct net_device *dev = info->user_ptr[1];
12523 struct wireless_dev *wdev = dev->ieee80211_ptr;
12524 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
12525 struct cfg80211_gtk_rekey_data rekey_data;
12526 int err;
12527
12528 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
12529 return -EINVAL;
12530
Johannes Berg8cb08172019-04-26 14:07:28 +020012531 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
12532 info->attrs[NL80211_ATTR_REKEY_DATA],
12533 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020012534 if (err)
12535 return err;
12536
Vladis Dronove785fa02017-09-13 00:21:21 +020012537 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12538 !tb[NL80211_REKEY_DATA_KCK])
12539 return -EINVAL;
Nathan Errera093a48d2020-05-28 21:22:38 +020012540 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN &&
12541 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
12542 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KEK_EXT_LEN))
Johannes Berge5497d72011-07-05 16:35:40 +020012543 return -ERANGE;
Nathan Errera093a48d2020-05-28 21:22:38 +020012544 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN &&
12545 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK &&
12546 nla_len(tb[NL80211_REKEY_DATA_KEK]) == NL80211_KCK_EXT_LEN))
Johannes Berge5497d72011-07-05 16:35:40 +020012547 return -ERANGE;
12548
Johannes Berg78f686c2014-09-10 22:28:06 +030012549 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
12550 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
12551 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Nathan Errera093a48d2020-05-28 21:22:38 +020012552 rekey_data.kek_len = nla_len(tb[NL80211_REKEY_DATA_KEK]);
12553 rekey_data.kck_len = nla_len(tb[NL80211_REKEY_DATA_KCK]);
12554 if (tb[NL80211_REKEY_DATA_AKM])
12555 rekey_data.akm = nla_get_u32(tb[NL80211_REKEY_DATA_AKM]);
Johannes Berge5497d72011-07-05 16:35:40 +020012556
12557 wdev_lock(wdev);
12558 if (!wdev->current_bss) {
12559 err = -ENOTCONN;
12560 goto out;
12561 }
12562
12563 if (!rdev->ops->set_rekey_data) {
12564 err = -EOPNOTSUPP;
12565 goto out;
12566 }
12567
Hila Gonene35e4d22012-06-27 17:19:42 +030012568 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020012569 out:
12570 wdev_unlock(wdev);
12571 return err;
12572}
12573
Johannes Berg28946da2011-11-04 11:18:12 +010012574static int nl80211_register_unexpected_frame(struct sk_buff *skb,
12575 struct genl_info *info)
12576{
12577 struct net_device *dev = info->user_ptr[1];
12578 struct wireless_dev *wdev = dev->ieee80211_ptr;
12579
12580 if (wdev->iftype != NL80211_IFTYPE_AP &&
12581 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12582 return -EINVAL;
12583
Eric W. Biederman15e47302012-09-07 20:12:54 +000012584 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012585 return -EBUSY;
12586
Eric W. Biederman15e47302012-09-07 20:12:54 +000012587 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010012588 return 0;
12589}
12590
Johannes Berg7f6cf312011-11-04 11:18:15 +010012591static int nl80211_probe_client(struct sk_buff *skb,
12592 struct genl_info *info)
12593{
12594 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12595 struct net_device *dev = info->user_ptr[1];
12596 struct wireless_dev *wdev = dev->ieee80211_ptr;
12597 struct sk_buff *msg;
12598 void *hdr;
12599 const u8 *addr;
12600 u64 cookie;
12601 int err;
12602
12603 if (wdev->iftype != NL80211_IFTYPE_AP &&
12604 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12605 return -EOPNOTSUPP;
12606
12607 if (!info->attrs[NL80211_ATTR_MAC])
12608 return -EINVAL;
12609
12610 if (!rdev->ops->probe_client)
12611 return -EOPNOTSUPP;
12612
12613 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12614 if (!msg)
12615 return -ENOMEM;
12616
Eric W. Biederman15e47302012-09-07 20:12:54 +000012617 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010012618 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030012619 if (!hdr) {
12620 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012621 goto free_msg;
12622 }
12623
12624 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12625
Hila Gonene35e4d22012-06-27 17:19:42 +030012626 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012627 if (err)
12628 goto free_msg;
12629
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012630 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12631 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012632 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012633
12634 genlmsg_end(msg, hdr);
12635
12636 return genlmsg_reply(msg, info);
12637
12638 nla_put_failure:
12639 err = -ENOBUFS;
12640 free_msg:
12641 nlmsg_free(msg);
12642 return err;
12643}
12644
Johannes Berg5e760232011-11-04 11:18:17 +010012645static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12646{
12647 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070012648 struct cfg80211_beacon_registration *reg, *nreg;
12649 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012650
12651 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12652 return -EOPNOTSUPP;
12653
Ben Greear37c73b52012-10-26 14:49:25 -070012654 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12655 if (!nreg)
12656 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010012657
Ben Greear37c73b52012-10-26 14:49:25 -070012658 /* First, check if already registered. */
12659 spin_lock_bh(&rdev->beacon_registrations_lock);
12660 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12661 if (reg->nlportid == info->snd_portid) {
12662 rv = -EALREADY;
12663 goto out_err;
12664 }
12665 }
12666 /* Add it to the list */
12667 nreg->nlportid = info->snd_portid;
12668 list_add(&nreg->list, &rdev->beacon_registrations);
12669
12670 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012671
12672 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070012673out_err:
12674 spin_unlock_bh(&rdev->beacon_registrations_lock);
12675 kfree(nreg);
12676 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012677}
12678
Johannes Berg98104fde2012-06-16 00:19:54 +020012679static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12680{
12681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12682 struct wireless_dev *wdev = info->user_ptr[1];
12683 int err;
12684
12685 if (!rdev->ops->start_p2p_device)
12686 return -EOPNOTSUPP;
12687
12688 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12689 return -EOPNOTSUPP;
12690
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012691 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020012692 return 0;
12693
Luciano Coelhob6a55012014-02-27 11:07:21 +020012694 if (rfkill_blocked(rdev->rfkill))
12695 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020012696
Johannes Bergeeb126e2012-10-23 15:16:50 +020012697 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012698 if (err)
12699 return err;
12700
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012701 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020012702 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020012703
12704 return 0;
12705}
12706
12707static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12708{
12709 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12710 struct wireless_dev *wdev = info->user_ptr[1];
12711
12712 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12713 return -EOPNOTSUPP;
12714
12715 if (!rdev->ops->stop_p2p_device)
12716 return -EOPNOTSUPP;
12717
Johannes Bergf9f47522013-03-19 15:04:07 +010012718 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012719
12720 return 0;
12721}
12722
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012723static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12724{
12725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12726 struct wireless_dev *wdev = info->user_ptr[1];
12727 struct cfg80211_nan_conf conf = {};
12728 int err;
12729
12730 if (wdev->iftype != NL80211_IFTYPE_NAN)
12731 return -EOPNOTSUPP;
12732
Johannes Bergeeb04a92016-11-21 13:55:48 +010012733 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012734 return -EEXIST;
12735
12736 if (rfkill_blocked(rdev->rfkill))
12737 return -ERFKILL;
12738
12739 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12740 return -EINVAL;
12741
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012742 conf.master_pref =
12743 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012744
Luca Coelho85859892017-02-08 15:00:34 +020012745 if (info->attrs[NL80211_ATTR_BANDS]) {
12746 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12747
12748 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12749 return -EOPNOTSUPP;
12750
12751 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12752 return -EINVAL;
12753
12754 conf.bands = bands;
12755 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012756
12757 err = rdev_start_nan(rdev, wdev, &conf);
12758 if (err)
12759 return err;
12760
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012761 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012762 rdev->opencount++;
12763
12764 return 0;
12765}
12766
12767static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12768{
12769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12770 struct wireless_dev *wdev = info->user_ptr[1];
12771
12772 if (wdev->iftype != NL80211_IFTYPE_NAN)
12773 return -EOPNOTSUPP;
12774
12775 cfg80211_stop_nan(rdev, wdev);
12776
12777 return 0;
12778}
12779
Ayala Bekera442b762016-09-20 17:31:15 +030012780static int validate_nan_filter(struct nlattr *filter_attr)
12781{
12782 struct nlattr *attr;
12783 int len = 0, n_entries = 0, rem;
12784
12785 nla_for_each_nested(attr, filter_attr, rem) {
12786 len += nla_len(attr);
12787 n_entries++;
12788 }
12789
12790 if (len >= U8_MAX)
12791 return -EINVAL;
12792
12793 return n_entries;
12794}
12795
12796static int handle_nan_filter(struct nlattr *attr_filter,
12797 struct cfg80211_nan_func *func,
12798 bool tx)
12799{
12800 struct nlattr *attr;
12801 int n_entries, rem, i;
12802 struct cfg80211_nan_func_filter *filter;
12803
12804 n_entries = validate_nan_filter(attr_filter);
12805 if (n_entries < 0)
12806 return n_entries;
12807
12808 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12809
12810 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12811 if (!filter)
12812 return -ENOMEM;
12813
12814 i = 0;
12815 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020012816 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012817 filter[i].len = nla_len(attr);
12818 i++;
12819 }
12820 if (tx) {
12821 func->num_tx_filters = n_entries;
12822 func->tx_filters = filter;
12823 } else {
12824 func->num_rx_filters = n_entries;
12825 func->rx_filters = filter;
12826 }
12827
12828 return 0;
12829}
12830
12831static int nl80211_nan_add_func(struct sk_buff *skb,
12832 struct genl_info *info)
12833{
12834 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12835 struct wireless_dev *wdev = info->user_ptr[1];
12836 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12837 struct cfg80211_nan_func *func;
12838 struct sk_buff *msg = NULL;
12839 void *hdr = NULL;
12840 int err = 0;
12841
12842 if (wdev->iftype != NL80211_IFTYPE_NAN)
12843 return -EOPNOTSUPP;
12844
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012845 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012846 return -ENOTCONN;
12847
12848 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12849 return -EINVAL;
12850
Johannes Berg8cb08172019-04-26 14:07:28 +020012851 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12852 info->attrs[NL80211_ATTR_NAN_FUNC],
12853 nl80211_nan_func_policy,
12854 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012855 if (err)
12856 return err;
12857
12858 func = kzalloc(sizeof(*func), GFP_KERNEL);
12859 if (!func)
12860 return -ENOMEM;
12861
Johannes Bergb60ad342018-10-01 11:52:07 +020012862 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012863
Johannes Bergcb9abd42020-08-05 15:47:16 +020012864 if (!tb[NL80211_NAN_FUNC_TYPE]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012865 err = -EINVAL;
12866 goto out;
12867 }
12868
12869
12870 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12871
12872 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12873 err = -EINVAL;
12874 goto out;
12875 }
12876
12877 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12878 sizeof(func->service_id));
12879
12880 func->close_range =
12881 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12882
12883 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12884 func->serv_spec_info_len =
12885 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12886 func->serv_spec_info =
12887 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12888 func->serv_spec_info_len,
12889 GFP_KERNEL);
12890 if (!func->serv_spec_info) {
12891 err = -ENOMEM;
12892 goto out;
12893 }
12894 }
12895
12896 if (tb[NL80211_NAN_FUNC_TTL])
12897 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12898
12899 switch (func->type) {
12900 case NL80211_NAN_FUNC_PUBLISH:
12901 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12902 err = -EINVAL;
12903 goto out;
12904 }
12905
12906 func->publish_type =
12907 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12908 func->publish_bcast =
12909 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12910
12911 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12912 func->publish_bcast) {
12913 err = -EINVAL;
12914 goto out;
12915 }
12916 break;
12917 case NL80211_NAN_FUNC_SUBSCRIBE:
12918 func->subscribe_active =
12919 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12920 break;
12921 case NL80211_NAN_FUNC_FOLLOW_UP:
12922 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012923 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12924 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012925 err = -EINVAL;
12926 goto out;
12927 }
12928
12929 func->followup_id =
12930 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12931 func->followup_reqid =
12932 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12933 memcpy(func->followup_dest.addr,
12934 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12935 sizeof(func->followup_dest.addr));
12936 if (func->ttl) {
12937 err = -EINVAL;
12938 goto out;
12939 }
12940 break;
12941 default:
12942 err = -EINVAL;
12943 goto out;
12944 }
12945
12946 if (tb[NL80211_NAN_FUNC_SRF]) {
12947 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12948
Johannes Berg8cb08172019-04-26 14:07:28 +020012949 err = nla_parse_nested_deprecated(srf_tb,
12950 NL80211_NAN_SRF_ATTR_MAX,
12951 tb[NL80211_NAN_FUNC_SRF],
12952 nl80211_nan_srf_policy,
12953 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012954 if (err)
12955 goto out;
12956
12957 func->srf_include =
12958 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12959
12960 if (srf_tb[NL80211_NAN_SRF_BF]) {
12961 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12962 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12963 err = -EINVAL;
12964 goto out;
12965 }
12966
12967 func->srf_bf_len =
12968 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12969 func->srf_bf =
12970 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12971 func->srf_bf_len, GFP_KERNEL);
12972 if (!func->srf_bf) {
12973 err = -ENOMEM;
12974 goto out;
12975 }
12976
12977 func->srf_bf_idx =
12978 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12979 } else {
12980 struct nlattr *attr, *mac_attr =
12981 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12982 int n_entries, rem, i = 0;
12983
12984 if (!mac_attr) {
12985 err = -EINVAL;
12986 goto out;
12987 }
12988
12989 n_entries = validate_acl_mac_addrs(mac_attr);
12990 if (n_entries <= 0) {
12991 err = -EINVAL;
12992 goto out;
12993 }
12994
12995 func->srf_num_macs = n_entries;
12996 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012997 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012998 GFP_KERNEL);
12999 if (!func->srf_macs) {
13000 err = -ENOMEM;
13001 goto out;
13002 }
13003
13004 nla_for_each_nested(attr, mac_attr, rem)
13005 memcpy(func->srf_macs[i++].addr, nla_data(attr),
13006 sizeof(*func->srf_macs));
13007 }
13008 }
13009
13010 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
13011 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
13012 func, true);
13013 if (err)
13014 goto out;
13015 }
13016
13017 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
13018 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
13019 func, false);
13020 if (err)
13021 goto out;
13022 }
13023
13024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13025 if (!msg) {
13026 err = -ENOMEM;
13027 goto out;
13028 }
13029
13030 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13031 NL80211_CMD_ADD_NAN_FUNCTION);
13032 /* This can't really happen - we just allocated 4KB */
13033 if (WARN_ON(!hdr)) {
13034 err = -ENOMEM;
13035 goto out;
13036 }
13037
13038 err = rdev_add_nan_func(rdev, wdev, func);
13039out:
13040 if (err < 0) {
13041 cfg80211_free_nan_func(func);
13042 nlmsg_free(msg);
13043 return err;
13044 }
13045
13046 /* propagate the instance id and cookie to userspace */
13047 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
13048 NL80211_ATTR_PAD))
13049 goto nla_put_failure;
13050
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013051 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030013052 if (!func_attr)
13053 goto nla_put_failure;
13054
13055 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
13056 func->instance_id))
13057 goto nla_put_failure;
13058
13059 nla_nest_end(msg, func_attr);
13060
13061 genlmsg_end(msg, hdr);
13062 return genlmsg_reply(msg, info);
13063
13064nla_put_failure:
13065 nlmsg_free(msg);
13066 return -ENOBUFS;
13067}
13068
13069static int nl80211_nan_del_func(struct sk_buff *skb,
13070 struct genl_info *info)
13071{
13072 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13073 struct wireless_dev *wdev = info->user_ptr[1];
13074 u64 cookie;
13075
13076 if (wdev->iftype != NL80211_IFTYPE_NAN)
13077 return -EOPNOTSUPP;
13078
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013079 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030013080 return -ENOTCONN;
13081
13082 if (!info->attrs[NL80211_ATTR_COOKIE])
13083 return -EINVAL;
13084
Ayala Bekera442b762016-09-20 17:31:15 +030013085 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
13086
13087 rdev_del_nan_func(rdev, wdev, cookie);
13088
13089 return 0;
13090}
13091
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013092static int nl80211_nan_change_config(struct sk_buff *skb,
13093 struct genl_info *info)
13094{
13095 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13096 struct wireless_dev *wdev = info->user_ptr[1];
13097 struct cfg80211_nan_conf conf = {};
13098 u32 changed = 0;
13099
13100 if (wdev->iftype != NL80211_IFTYPE_NAN)
13101 return -EOPNOTSUPP;
13102
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013103 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013104 return -ENOTCONN;
13105
13106 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
13107 conf.master_pref =
13108 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
13109 if (conf.master_pref <= 1 || conf.master_pref == 255)
13110 return -EINVAL;
13111
13112 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
13113 }
13114
Luca Coelho85859892017-02-08 15:00:34 +020013115 if (info->attrs[NL80211_ATTR_BANDS]) {
13116 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
13117
13118 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
13119 return -EOPNOTSUPP;
13120
13121 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
13122 return -EINVAL;
13123
13124 conf.bands = bands;
13125 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030013126 }
13127
13128 if (!changed)
13129 return -EINVAL;
13130
13131 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
13132}
13133
Ayala Beker50bcd312016-09-20 17:31:17 +030013134void cfg80211_nan_match(struct wireless_dev *wdev,
13135 struct cfg80211_nan_match_params *match, gfp_t gfp)
13136{
13137 struct wiphy *wiphy = wdev->wiphy;
13138 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13139 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
13140 struct sk_buff *msg;
13141 void *hdr;
13142
13143 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
13144 return;
13145
13146 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13147 if (!msg)
13148 return;
13149
13150 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
13151 if (!hdr) {
13152 nlmsg_free(msg);
13153 return;
13154 }
13155
13156 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13157 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13158 wdev->netdev->ifindex)) ||
13159 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13160 NL80211_ATTR_PAD))
13161 goto nla_put_failure;
13162
13163 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
13164 NL80211_ATTR_PAD) ||
13165 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
13166 goto nla_put_failure;
13167
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013168 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030013169 if (!match_attr)
13170 goto nla_put_failure;
13171
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013172 local_func_attr = nla_nest_start_noflag(msg,
13173 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030013174 if (!local_func_attr)
13175 goto nla_put_failure;
13176
13177 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
13178 goto nla_put_failure;
13179
13180 nla_nest_end(msg, local_func_attr);
13181
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013182 peer_func_attr = nla_nest_start_noflag(msg,
13183 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030013184 if (!peer_func_attr)
13185 goto nla_put_failure;
13186
13187 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
13188 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
13189 goto nla_put_failure;
13190
13191 if (match->info && match->info_len &&
13192 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
13193 match->info))
13194 goto nla_put_failure;
13195
13196 nla_nest_end(msg, peer_func_attr);
13197 nla_nest_end(msg, match_attr);
13198 genlmsg_end(msg, hdr);
13199
13200 if (!wdev->owner_nlportid)
13201 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
13202 msg, 0, NL80211_MCGRP_NAN, gfp);
13203 else
13204 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
13205 wdev->owner_nlportid);
13206
13207 return;
13208
13209nla_put_failure:
13210 nlmsg_free(msg);
13211}
13212EXPORT_SYMBOL(cfg80211_nan_match);
13213
Ayala Beker368e5a72016-09-20 17:31:18 +030013214void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
13215 u8 inst_id,
13216 enum nl80211_nan_func_term_reason reason,
13217 u64 cookie, gfp_t gfp)
13218{
13219 struct wiphy *wiphy = wdev->wiphy;
13220 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13221 struct sk_buff *msg;
13222 struct nlattr *func_attr;
13223 void *hdr;
13224
13225 if (WARN_ON(!inst_id))
13226 return;
13227
13228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13229 if (!msg)
13230 return;
13231
13232 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
13233 if (!hdr) {
13234 nlmsg_free(msg);
13235 return;
13236 }
13237
13238 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13239 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13240 wdev->netdev->ifindex)) ||
13241 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
13242 NL80211_ATTR_PAD))
13243 goto nla_put_failure;
13244
13245 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
13246 NL80211_ATTR_PAD))
13247 goto nla_put_failure;
13248
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013249 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030013250 if (!func_attr)
13251 goto nla_put_failure;
13252
13253 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
13254 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
13255 goto nla_put_failure;
13256
13257 nla_nest_end(msg, func_attr);
13258 genlmsg_end(msg, hdr);
13259
13260 if (!wdev->owner_nlportid)
13261 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
13262 msg, 0, NL80211_MCGRP_NAN, gfp);
13263 else
13264 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
13265 wdev->owner_nlportid);
13266
13267 return;
13268
13269nla_put_failure:
13270 nlmsg_free(msg);
13271}
13272EXPORT_SYMBOL(cfg80211_nan_func_terminated);
13273
Johannes Berg3713b4e2013-02-14 16:19:38 +010013274static int nl80211_get_protocol_features(struct sk_buff *skb,
13275 struct genl_info *info)
13276{
13277 void *hdr;
13278 struct sk_buff *msg;
13279
13280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13281 if (!msg)
13282 return -ENOMEM;
13283
13284 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13285 NL80211_CMD_GET_PROTOCOL_FEATURES);
13286 if (!hdr)
13287 goto nla_put_failure;
13288
13289 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
13290 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
13291 goto nla_put_failure;
13292
13293 genlmsg_end(msg, hdr);
13294 return genlmsg_reply(msg, info);
13295
13296 nla_put_failure:
13297 kfree_skb(msg);
13298 return -ENOBUFS;
13299}
13300
Jouni Malinen355199e2013-02-27 17:14:27 +020013301static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
13302{
13303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13304 struct cfg80211_update_ft_ies_params ft_params;
13305 struct net_device *dev = info->user_ptr[1];
13306
13307 if (!rdev->ops->update_ft_ies)
13308 return -EOPNOTSUPP;
13309
13310 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020013311 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020013312 return -EINVAL;
13313
13314 memset(&ft_params, 0, sizeof(ft_params));
13315 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
13316 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13317 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13318
13319 return rdev_update_ft_ies(rdev, dev, &ft_params);
13320}
13321
Arend van Spriel5de17982013-04-18 15:49:00 +020013322static int nl80211_crit_protocol_start(struct sk_buff *skb,
13323 struct genl_info *info)
13324{
13325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13326 struct wireless_dev *wdev = info->user_ptr[1];
13327 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
13328 u16 duration;
13329 int ret;
13330
13331 if (!rdev->ops->crit_proto_start)
13332 return -EOPNOTSUPP;
13333
13334 if (WARN_ON(!rdev->ops->crit_proto_stop))
13335 return -EINVAL;
13336
13337 if (rdev->crit_proto_nlportid)
13338 return -EBUSY;
13339
13340 /* determine protocol if provided */
13341 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
13342 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
13343
13344 if (proto >= NUM_NL80211_CRIT_PROTO)
13345 return -EINVAL;
13346
13347 /* timeout must be provided */
13348 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
13349 return -EINVAL;
13350
13351 duration =
13352 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
13353
Arend van Spriel5de17982013-04-18 15:49:00 +020013354 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
13355 if (!ret)
13356 rdev->crit_proto_nlportid = info->snd_portid;
13357
13358 return ret;
13359}
13360
13361static int nl80211_crit_protocol_stop(struct sk_buff *skb,
13362 struct genl_info *info)
13363{
13364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13365 struct wireless_dev *wdev = info->user_ptr[1];
13366
13367 if (!rdev->ops->crit_proto_stop)
13368 return -EOPNOTSUPP;
13369
13370 if (rdev->crit_proto_nlportid) {
13371 rdev->crit_proto_nlportid = 0;
13372 rdev_crit_proto_stop(rdev, wdev);
13373 }
13374 return 0;
13375}
13376
Johannes Berg901bb982019-05-28 10:56:03 +020013377static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
13378 struct nlattr *attr,
13379 struct netlink_ext_ack *extack)
13380{
13381 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
13382 if (attr->nla_type & NLA_F_NESTED) {
13383 NL_SET_ERR_MSG_ATTR(extack, attr,
13384 "unexpected nested data");
13385 return -EINVAL;
13386 }
13387
13388 return 0;
13389 }
13390
13391 if (!(attr->nla_type & NLA_F_NESTED)) {
13392 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
13393 return -EINVAL;
13394 }
13395
Michal Kubecek32d51092019-12-11 10:58:19 +010013396 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
Johannes Berg901bb982019-05-28 10:56:03 +020013397}
13398
Johannes Bergad7e7182013-11-13 13:37:47 +010013399static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
13400{
13401 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13402 struct wireless_dev *wdev =
13403 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
13404 int i, err;
13405 u32 vid, subcmd;
13406
13407 if (!rdev->wiphy.vendor_commands)
13408 return -EOPNOTSUPP;
13409
13410 if (IS_ERR(wdev)) {
13411 err = PTR_ERR(wdev);
13412 if (err != -EINVAL)
13413 return err;
13414 wdev = NULL;
13415 } else if (wdev->wiphy != &rdev->wiphy) {
13416 return -EINVAL;
13417 }
13418
13419 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
13420 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
13421 return -EINVAL;
13422
13423 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
13424 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
13425 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
13426 const struct wiphy_vendor_command *vcmd;
13427 void *data = NULL;
13428 int len = 0;
13429
13430 vcmd = &rdev->wiphy.vendor_commands[i];
13431
13432 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13433 continue;
13434
13435 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13436 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13437 if (!wdev)
13438 return -EINVAL;
13439 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13440 !wdev->netdev)
13441 return -EINVAL;
13442
13443 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013444 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010013445 return -ENETDOWN;
13446 }
13447 } else {
13448 wdev = NULL;
13449 }
13450
Julian Squires4052d3d2020-07-06 17:13:53 -040013451 if (!vcmd->doit)
13452 return -EOPNOTSUPP;
13453
Johannes Bergad7e7182013-11-13 13:37:47 +010013454 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
13455 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
13456 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020013457
13458 err = nl80211_vendor_check_policy(vcmd,
13459 info->attrs[NL80211_ATTR_VENDOR_DATA],
13460 info->extack);
13461 if (err)
13462 return err;
Johannes Bergad7e7182013-11-13 13:37:47 +010013463 }
13464
13465 rdev->cur_cmd_info = info;
Johannes Berg901bb982019-05-28 10:56:03 +020013466 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
Johannes Bergad7e7182013-11-13 13:37:47 +010013467 rdev->cur_cmd_info = NULL;
13468 return err;
13469 }
13470
13471 return -EOPNOTSUPP;
13472}
13473
Johannes Berg7bdbe402015-08-15 22:39:49 +030013474static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
13475 struct netlink_callback *cb,
13476 struct cfg80211_registered_device **rdev,
13477 struct wireless_dev **wdev)
13478{
Johannes Berg50508d92019-07-29 16:31:09 +020013479 struct nlattr **attrbuf;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013480 u32 vid, subcmd;
13481 unsigned int i;
13482 int vcmd_idx = -1;
13483 int err;
13484 void *data = NULL;
13485 unsigned int data_len = 0;
13486
Johannes Berg7bdbe402015-08-15 22:39:49 +030013487 if (cb->args[0]) {
13488 /* subtract the 1 again here */
13489 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
13490 struct wireless_dev *tmp;
13491
Johannes Bergea90e0d2017-03-15 14:26:04 +010013492 if (!wiphy)
13493 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013494 *rdev = wiphy_to_rdev(wiphy);
13495 *wdev = NULL;
13496
13497 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030013498 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013499 if (tmp->identifier == cb->args[1] - 1) {
13500 *wdev = tmp;
13501 break;
13502 }
13503 }
13504 }
13505
13506 /* keep rtnl locked in successful case */
13507 return 0;
13508 }
13509
Johannes Berg50508d92019-07-29 16:31:09 +020013510 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
13511 if (!attrbuf)
13512 return -ENOMEM;
13513
Johannes Berg8cb08172019-04-26 14:07:28 +020013514 err = nlmsg_parse_deprecated(cb->nlh,
13515 GENL_HDRLEN + nl80211_fam.hdrsize,
13516 attrbuf, nl80211_fam.maxattr,
13517 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013518 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020013519 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013520
Johannes Bergc90c39d2016-10-24 14:40:01 +020013521 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg50508d92019-07-29 16:31:09 +020013522 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
13523 err = -EINVAL;
13524 goto out;
13525 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013526
Johannes Bergc90c39d2016-10-24 14:40:01 +020013527 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013528 if (IS_ERR(*wdev))
13529 *wdev = NULL;
13530
Johannes Bergc90c39d2016-10-24 14:40:01 +020013531 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg50508d92019-07-29 16:31:09 +020013532 if (IS_ERR(*rdev)) {
13533 err = PTR_ERR(*rdev);
13534 goto out;
13535 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013536
Johannes Bergc90c39d2016-10-24 14:40:01 +020013537 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
13538 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013539
13540 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
13541 const struct wiphy_vendor_command *vcmd;
13542
13543 vcmd = &(*rdev)->wiphy.vendor_commands[i];
13544
13545 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13546 continue;
13547
Johannes Berg50508d92019-07-29 16:31:09 +020013548 if (!vcmd->dumpit) {
13549 err = -EOPNOTSUPP;
13550 goto out;
13551 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013552
13553 vcmd_idx = i;
13554 break;
13555 }
13556
Johannes Berg50508d92019-07-29 16:31:09 +020013557 if (vcmd_idx < 0) {
13558 err = -EOPNOTSUPP;
13559 goto out;
13560 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013561
Johannes Bergc90c39d2016-10-24 14:40:01 +020013562 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
13563 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13564 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020013565
13566 err = nl80211_vendor_check_policy(
13567 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
13568 attrbuf[NL80211_ATTR_VENDOR_DATA],
13569 cb->extack);
13570 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020013571 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013572 }
13573
13574 /* 0 is the first index - add 1 to parse only once */
13575 cb->args[0] = (*rdev)->wiphy_idx + 1;
13576 /* add 1 to know if it was NULL */
13577 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
13578 cb->args[2] = vcmd_idx;
13579 cb->args[3] = (unsigned long)data;
13580 cb->args[4] = data_len;
13581
13582 /* keep rtnl locked in successful case */
Johannes Berg50508d92019-07-29 16:31:09 +020013583 err = 0;
13584out:
13585 kfree(attrbuf);
13586 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013587}
13588
13589static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13590 struct netlink_callback *cb)
13591{
13592 struct cfg80211_registered_device *rdev;
13593 struct wireless_dev *wdev;
13594 unsigned int vcmd_idx;
13595 const struct wiphy_vendor_command *vcmd;
13596 void *data;
13597 int data_len;
13598 int err;
13599 struct nlattr *vendor_data;
13600
Johannes Bergea90e0d2017-03-15 14:26:04 +010013601 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030013602 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13603 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010013604 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013605
13606 vcmd_idx = cb->args[2];
13607 data = (void *)cb->args[3];
13608 data_len = cb->args[4];
13609 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13610
13611 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13612 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013613 if (!wdev) {
13614 err = -EINVAL;
13615 goto out;
13616 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013617 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010013618 !wdev->netdev) {
13619 err = -EINVAL;
13620 goto out;
13621 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013622
13623 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013624 if (!wdev_running(wdev)) {
13625 err = -ENETDOWN;
13626 goto out;
13627 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013628 }
13629 }
13630
13631 while (1) {
13632 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13633 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13634 NL80211_CMD_VENDOR);
13635 if (!hdr)
13636 break;
13637
13638 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013639 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13640 wdev_id(wdev),
13641 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013642 genlmsg_cancel(skb, hdr);
13643 break;
13644 }
13645
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013646 vendor_data = nla_nest_start_noflag(skb,
13647 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013648 if (!vendor_data) {
13649 genlmsg_cancel(skb, hdr);
13650 break;
13651 }
13652
13653 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13654 (unsigned long *)&cb->args[5]);
13655 nla_nest_end(skb, vendor_data);
13656
13657 if (err == -ENOBUFS || err == -ENOENT) {
13658 genlmsg_cancel(skb, hdr);
13659 break;
Julian Squires9c167b22020-07-20 12:20:35 -023013660 } else if (err <= 0) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013661 genlmsg_cancel(skb, hdr);
13662 goto out;
13663 }
13664
13665 genlmsg_end(skb, hdr);
13666 }
13667
13668 err = skb->len;
13669 out:
13670 rtnl_unlock();
13671 return err;
13672}
13673
Johannes Bergad7e7182013-11-13 13:37:47 +010013674struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13675 enum nl80211_commands cmd,
13676 enum nl80211_attrs attr,
13677 int approxlen)
13678{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013679 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010013680
13681 if (WARN_ON(!rdev->cur_cmd_info))
13682 return NULL;
13683
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020013684 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010013685 rdev->cur_cmd_info->snd_portid,
13686 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010013687 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010013688}
13689EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13690
13691int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13692{
13693 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13694 void *hdr = ((void **)skb->cb)[1];
13695 struct nlattr *data = ((void **)skb->cb)[2];
13696
Johannes Bergbd8c78e2014-07-30 14:55:26 +020013697 /* clear CB data for netlink core to own from now on */
13698 memset(skb->cb, 0, sizeof(skb->cb));
13699
Johannes Bergad7e7182013-11-13 13:37:47 +010013700 if (WARN_ON(!rdev->cur_cmd_info)) {
13701 kfree_skb(skb);
13702 return -EINVAL;
13703 }
13704
13705 nla_nest_end(skb, data);
13706 genlmsg_end(skb, hdr);
13707 return genlmsg_reply(skb, rdev->cur_cmd_info);
13708}
13709EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13710
Johannes Berg55c1fdf2019-02-06 13:17:19 +020013711unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13712{
13713 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13714
13715 if (WARN_ON(!rdev->cur_cmd_info))
13716 return 0;
13717
13718 return rdev->cur_cmd_info->snd_portid;
13719}
13720EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13721
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013722static int nl80211_set_qos_map(struct sk_buff *skb,
13723 struct genl_info *info)
13724{
13725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13726 struct cfg80211_qos_map *qos_map = NULL;
13727 struct net_device *dev = info->user_ptr[1];
13728 u8 *pos, len, num_des, des_len, des;
13729 int ret;
13730
13731 if (!rdev->ops->set_qos_map)
13732 return -EOPNOTSUPP;
13733
13734 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13735 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13736 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13737
Johannes Bergc8b82802020-08-19 08:56:43 +020013738 if (len % 2)
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013739 return -EINVAL;
13740
13741 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13742 if (!qos_map)
13743 return -ENOMEM;
13744
13745 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13746 if (num_des) {
13747 des_len = num_des *
13748 sizeof(struct cfg80211_dscp_exception);
13749 memcpy(qos_map->dscp_exception, pos, des_len);
13750 qos_map->num_des = num_des;
13751 for (des = 0; des < num_des; des++) {
13752 if (qos_map->dscp_exception[des].up > 7) {
13753 kfree(qos_map);
13754 return -EINVAL;
13755 }
13756 }
13757 pos += des_len;
13758 }
13759 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13760 }
13761
13762 wdev_lock(dev->ieee80211_ptr);
13763 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13764 if (!ret)
13765 ret = rdev_set_qos_map(rdev, dev, qos_map);
13766 wdev_unlock(dev->ieee80211_ptr);
13767
13768 kfree(qos_map);
13769 return ret;
13770}
13771
Johannes Berg960d01a2014-09-09 22:55:35 +030013772static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13773{
13774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13775 struct net_device *dev = info->user_ptr[1];
13776 struct wireless_dev *wdev = dev->ieee80211_ptr;
13777 const u8 *peer;
13778 u8 tsid, up;
13779 u16 admitted_time = 0;
13780 int err;
13781
Johannes Berg723e73a2014-10-22 09:25:06 +020013782 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013783 return -EOPNOTSUPP;
13784
13785 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13786 !info->attrs[NL80211_ATTR_USER_PRIO])
13787 return -EINVAL;
13788
13789 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013790 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013791
13792 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013793 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013794 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013795 * need more attributes for that (e.g. BA session requirement);
13796 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013797 */
13798 return -EINVAL;
13799 }
13800
13801 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13802
13803 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13804 admitted_time =
13805 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13806 if (!admitted_time)
13807 return -EINVAL;
13808 }
13809
13810 wdev_lock(wdev);
13811 switch (wdev->iftype) {
13812 case NL80211_IFTYPE_STATION:
13813 case NL80211_IFTYPE_P2P_CLIENT:
13814 if (wdev->current_bss)
13815 break;
13816 err = -ENOTCONN;
13817 goto out;
13818 default:
13819 err = -EOPNOTSUPP;
13820 goto out;
13821 }
13822
13823 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13824
13825 out:
13826 wdev_unlock(wdev);
13827 return err;
13828}
13829
13830static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13831{
13832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13833 struct net_device *dev = info->user_ptr[1];
13834 struct wireless_dev *wdev = dev->ieee80211_ptr;
13835 const u8 *peer;
13836 u8 tsid;
13837 int err;
13838
13839 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13840 return -EINVAL;
13841
13842 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13843 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13844
13845 wdev_lock(wdev);
13846 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13847 wdev_unlock(wdev);
13848
13849 return err;
13850}
13851
Arik Nemtsov1057d352014-11-19 12:54:26 +020013852static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13853 struct genl_info *info)
13854{
13855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13856 struct net_device *dev = info->user_ptr[1];
13857 struct wireless_dev *wdev = dev->ieee80211_ptr;
13858 struct cfg80211_chan_def chandef = {};
13859 const u8 *addr;
13860 u8 oper_class;
13861 int err;
13862
13863 if (!rdev->ops->tdls_channel_switch ||
13864 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13865 return -EOPNOTSUPP;
13866
13867 switch (dev->ieee80211_ptr->iftype) {
13868 case NL80211_IFTYPE_STATION:
13869 case NL80211_IFTYPE_P2P_CLIENT:
13870 break;
13871 default:
13872 return -EOPNOTSUPP;
13873 }
13874
13875 if (!info->attrs[NL80211_ATTR_MAC] ||
13876 !info->attrs[NL80211_ATTR_OPER_CLASS])
13877 return -EINVAL;
13878
13879 err = nl80211_parse_chandef(rdev, info, &chandef);
13880 if (err)
13881 return err;
13882
13883 /*
13884 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13885 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13886 * specification is not defined for them.
13887 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020013888 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020013889 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13890 chandef.width != NL80211_CHAN_WIDTH_20)
13891 return -EINVAL;
13892
13893 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030013894 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13895 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020013896 return -EINVAL;
13897
13898 /* don't allow switching to DFS channels */
13899 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13900 return -EINVAL;
13901
13902 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13903 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13904
13905 wdev_lock(wdev);
13906 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13907 wdev_unlock(wdev);
13908
13909 return err;
13910}
13911
13912static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13913 struct genl_info *info)
13914{
13915 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13916 struct net_device *dev = info->user_ptr[1];
13917 struct wireless_dev *wdev = dev->ieee80211_ptr;
13918 const u8 *addr;
13919
13920 if (!rdev->ops->tdls_channel_switch ||
13921 !rdev->ops->tdls_cancel_channel_switch ||
13922 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13923 return -EOPNOTSUPP;
13924
13925 switch (dev->ieee80211_ptr->iftype) {
13926 case NL80211_IFTYPE_STATION:
13927 case NL80211_IFTYPE_P2P_CLIENT:
13928 break;
13929 default:
13930 return -EOPNOTSUPP;
13931 }
13932
13933 if (!info->attrs[NL80211_ATTR_MAC])
13934 return -EINVAL;
13935
13936 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13937
13938 wdev_lock(wdev);
13939 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13940 wdev_unlock(wdev);
13941
13942 return 0;
13943}
13944
Michael Braunce0ce132016-10-10 19:12:22 +020013945static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13946 struct genl_info *info)
13947{
13948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13949 struct net_device *dev = info->user_ptr[1];
13950 struct wireless_dev *wdev = dev->ieee80211_ptr;
13951 const struct nlattr *nla;
13952 bool enabled;
13953
Michael Braunce0ce132016-10-10 19:12:22 +020013954 if (!rdev->ops->set_multicast_to_unicast)
13955 return -EOPNOTSUPP;
13956
13957 if (wdev->iftype != NL80211_IFTYPE_AP &&
13958 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13959 return -EOPNOTSUPP;
13960
13961 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13962 enabled = nla_get_flag(nla);
13963
13964 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13965}
13966
Avraham Stern3a00df52017-06-09 13:08:43 +010013967static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13968{
13969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13970 struct net_device *dev = info->user_ptr[1];
13971 struct wireless_dev *wdev = dev->ieee80211_ptr;
13972 struct cfg80211_pmk_conf pmk_conf = {};
13973 int ret;
13974
13975 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13976 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13977 return -EOPNOTSUPP;
13978
13979 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13980 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13981 return -EOPNOTSUPP;
13982
13983 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13984 return -EINVAL;
13985
13986 wdev_lock(wdev);
13987 if (!wdev->current_bss) {
13988 ret = -ENOTCONN;
13989 goto out;
13990 }
13991
13992 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13993 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13994 ret = -EINVAL;
13995 goto out;
13996 }
13997
13998 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13999 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
14000 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
14001 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
14002 ret = -EINVAL;
14003 goto out;
14004 }
14005
Johannes Bergcb9abd42020-08-05 15:47:16 +020014006 if (info->attrs[NL80211_ATTR_PMKR0_NAME])
Avraham Stern3a00df52017-06-09 13:08:43 +010014007 pmk_conf.pmk_r0_name =
14008 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
Avraham Stern3a00df52017-06-09 13:08:43 +010014009
14010 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
14011out:
14012 wdev_unlock(wdev);
14013 return ret;
14014}
14015
14016static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
14017{
14018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14019 struct net_device *dev = info->user_ptr[1];
14020 struct wireless_dev *wdev = dev->ieee80211_ptr;
14021 const u8 *aa;
14022 int ret;
14023
14024 if (wdev->iftype != NL80211_IFTYPE_STATION &&
14025 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
14026 return -EOPNOTSUPP;
14027
14028 if (!wiphy_ext_feature_isset(&rdev->wiphy,
14029 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
14030 return -EOPNOTSUPP;
14031
14032 if (!info->attrs[NL80211_ATTR_MAC])
14033 return -EINVAL;
14034
14035 wdev_lock(wdev);
14036 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
14037 ret = rdev_del_pmk(rdev, dev, aa);
14038 wdev_unlock(wdev);
14039
14040 return ret;
14041}
14042
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014043static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
14044{
14045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14046 struct net_device *dev = info->user_ptr[1];
14047 struct cfg80211_external_auth_params params;
14048
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020014049 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014050 return -EOPNOTSUPP;
14051
Srinivas Dasarife494372019-01-23 18:06:56 +053014052 if (!info->attrs[NL80211_ATTR_SSID] &&
14053 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
14054 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014055 return -EINVAL;
14056
14057 if (!info->attrs[NL80211_ATTR_BSSID])
14058 return -EINVAL;
14059
14060 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
14061 return -EINVAL;
14062
14063 memset(&params, 0, sizeof(params));
14064
Srinivas Dasarife494372019-01-23 18:06:56 +053014065 if (info->attrs[NL80211_ATTR_SSID]) {
14066 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Johannes Bergcb9abd42020-08-05 15:47:16 +020014067 if (params.ssid.ssid_len == 0)
Srinivas Dasarife494372019-01-23 18:06:56 +053014068 return -EINVAL;
14069 memcpy(params.ssid.ssid,
14070 nla_data(info->attrs[NL80211_ATTR_SSID]),
14071 params.ssid.ssid_len);
14072 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014073
14074 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
14075 ETH_ALEN);
14076
14077 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
14078
Srinivas Dasarife494372019-01-23 18:06:56 +053014079 if (info->attrs[NL80211_ATTR_PMKID])
14080 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
14081
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014082 return rdev_external_auth(rdev, dev, &params);
14083}
14084
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014085static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
14086{
Markus Theildca9ca22020-05-08 16:42:00 +020014087 bool dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK];
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014088 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14089 struct net_device *dev = info->user_ptr[1];
14090 struct wireless_dev *wdev = dev->ieee80211_ptr;
14091 const u8 *buf;
14092 size_t len;
14093 u8 *dest;
14094 u16 proto;
14095 bool noencrypt;
Markus Theildca9ca22020-05-08 16:42:00 +020014096 u64 cookie = 0;
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014097 int err;
14098
14099 if (!wiphy_ext_feature_isset(&rdev->wiphy,
14100 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
14101 return -EOPNOTSUPP;
14102
14103 if (!rdev->ops->tx_control_port)
14104 return -EOPNOTSUPP;
14105
14106 if (!info->attrs[NL80211_ATTR_FRAME] ||
14107 !info->attrs[NL80211_ATTR_MAC] ||
14108 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
14109 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
14110 return -EINVAL;
14111 }
14112
14113 wdev_lock(wdev);
14114
14115 switch (wdev->iftype) {
14116 case NL80211_IFTYPE_AP:
14117 case NL80211_IFTYPE_P2P_GO:
14118 case NL80211_IFTYPE_MESH_POINT:
14119 break;
14120 case NL80211_IFTYPE_ADHOC:
14121 case NL80211_IFTYPE_STATION:
14122 case NL80211_IFTYPE_P2P_CLIENT:
14123 if (wdev->current_bss)
14124 break;
14125 err = -ENOTCONN;
14126 goto out;
14127 default:
14128 err = -EOPNOTSUPP;
14129 goto out;
14130 }
14131
14132 wdev_unlock(wdev);
14133
14134 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
14135 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
14136 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
14137 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
14138 noencrypt =
14139 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
14140
Markus Theildca9ca22020-05-08 16:42:00 +020014141 err = rdev_tx_control_port(rdev, dev, buf, len,
14142 dest, cpu_to_be16(proto), noencrypt,
14143 dont_wait_for_ack ? NULL : &cookie);
14144 if (!err && !dont_wait_for_ack)
14145 nl_set_extack_cookie_u64(info->extack, cookie);
14146 return err;
Denis Kenzior2576a9a2018-03-26 12:52:42 -050014147 out:
14148 wdev_unlock(wdev);
14149 return err;
14150}
14151
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014152static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
14153 struct genl_info *info)
14154{
14155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14156 struct net_device *dev = info->user_ptr[1];
14157 struct wireless_dev *wdev = dev->ieee80211_ptr;
14158 struct cfg80211_ftm_responder_stats ftm_stats = {};
14159 struct sk_buff *msg;
14160 void *hdr;
14161 struct nlattr *ftm_stats_attr;
14162 int err;
14163
14164 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
14165 return -EOPNOTSUPP;
14166
14167 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
14168 if (err)
14169 return err;
14170
14171 if (!ftm_stats.filled)
14172 return -ENODATA;
14173
14174 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
14175 if (!msg)
14176 return -ENOMEM;
14177
14178 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
14179 NL80211_CMD_GET_FTM_RESPONDER_STATS);
14180 if (!hdr)
Navid Emamdoost1399c592019-10-04 14:42:19 -050014181 goto nla_put_failure;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014182
14183 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
14184 goto nla_put_failure;
14185
Michal Kubecekae0be8d2019-04-26 11:13:06 +020014186 ftm_stats_attr = nla_nest_start_noflag(msg,
14187 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070014188 if (!ftm_stats_attr)
14189 goto nla_put_failure;
14190
14191#define SET_FTM(field, name, type) \
14192 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14193 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
14194 ftm_stats.field)) \
14195 goto nla_put_failure; } while (0)
14196#define SET_FTM_U64(field, name) \
14197 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
14198 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
14199 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
14200 goto nla_put_failure; } while (0)
14201
14202 SET_FTM(success_num, SUCCESS_NUM, u32);
14203 SET_FTM(partial_num, PARTIAL_NUM, u32);
14204 SET_FTM(failed_num, FAILED_NUM, u32);
14205 SET_FTM(asap_num, ASAP_NUM, u32);
14206 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
14207 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
14208 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
14209 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
14210 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
14211#undef SET_FTM
14212
14213 nla_nest_end(msg, ftm_stats_attr);
14214
14215 genlmsg_end(msg, hdr);
14216 return genlmsg_reply(msg, info);
14217
14218nla_put_failure:
14219 nlmsg_free(msg);
14220 return -ENOBUFS;
14221}
14222
Sunil Duttcb74e972019-02-20 16:18:07 +053014223static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
14224{
14225 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14226 struct cfg80211_update_owe_info owe_info;
14227 struct net_device *dev = info->user_ptr[1];
14228
14229 if (!rdev->ops->update_owe_info)
14230 return -EOPNOTSUPP;
14231
14232 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
14233 !info->attrs[NL80211_ATTR_MAC])
14234 return -EINVAL;
14235
14236 memset(&owe_info, 0, sizeof(owe_info));
14237 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
14238 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
14239
14240 if (info->attrs[NL80211_ATTR_IE]) {
14241 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
14242 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
14243 }
14244
14245 return rdev_update_owe_info(rdev, dev, &owe_info);
14246}
14247
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014248static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
14249{
14250 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14251 struct net_device *dev = info->user_ptr[1];
14252 struct wireless_dev *wdev = dev->ieee80211_ptr;
14253 struct station_info sinfo = {};
14254 const u8 *buf;
14255 size_t len;
14256 u8 *dest;
14257 int err;
14258
14259 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
14260 return -EOPNOTSUPP;
14261
14262 if (!info->attrs[NL80211_ATTR_MAC] ||
14263 !info->attrs[NL80211_ATTR_FRAME]) {
14264 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
14265 return -EINVAL;
14266 }
14267
14268 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
14269 return -EOPNOTSUPP;
14270
14271 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
14272 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
14273 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
14274
14275 if (len < sizeof(struct ethhdr))
14276 return -EINVAL;
14277
14278 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
14279 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
14280 return -EINVAL;
14281
14282 err = rdev_get_station(rdev, dev, dest, &sinfo);
14283 if (err)
14284 return err;
14285
Felix Fietkau2a279b342020-01-08 18:06:29 +010014286 cfg80211_sinfo_release_content(&sinfo);
14287
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070014288 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
14289}
14290
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014291static int parse_tid_conf(struct cfg80211_registered_device *rdev,
14292 struct nlattr *attrs[], struct net_device *dev,
Johannes Berg3710a8a2020-02-24 11:34:25 +010014293 struct cfg80211_tid_cfg *tid_conf,
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014294 struct genl_info *info, const u8 *peer)
14295{
14296 struct netlink_ext_ack *extack = info->extack;
Johannes Berg3710a8a2020-02-24 11:34:25 +010014297 u64 mask;
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014298 int err;
14299
14300 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
14301 return -EINVAL;
14302
14303 tid_conf->config_override =
14304 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
Johannes Berg3710a8a2020-02-24 11:34:25 +010014305 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014306
14307 if (tid_conf->config_override) {
14308 if (rdev->ops->reset_tid_config) {
14309 err = rdev_reset_tid_config(rdev, dev, peer,
Johannes Berg3710a8a2020-02-24 11:34:25 +010014310 tid_conf->tids);
Sergey Matyukevichc0336952020-04-24 14:29:04 +030014311 if (err)
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014312 return err;
14313 } else {
14314 return -EINVAL;
14315 }
14316 }
14317
14318 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
Johannes Berg3710a8a2020-02-24 11:34:25 +010014319 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014320 tid_conf->noack =
14321 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
14322 }
14323
Tamizh chelvam6a21d162020-01-20 13:21:23 +053014324 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]) {
14325 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_SHORT);
14326 tid_conf->retry_short =
14327 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_SHORT]);
14328
14329 if (tid_conf->retry_short > rdev->wiphy.max_data_retry_count)
14330 return -EINVAL;
14331 }
14332
14333 if (attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]) {
14334 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RETRY_LONG);
14335 tid_conf->retry_long =
14336 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RETRY_LONG]);
14337
14338 if (tid_conf->retry_long > rdev->wiphy.max_data_retry_count)
14339 return -EINVAL;
14340 }
14341
Tamizh chelvamade274b2020-01-20 13:21:24 +053014342 if (attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]) {
14343 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMPDU_CTRL);
14344 tid_conf->ampdu =
14345 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMPDU_CTRL]);
14346 }
14347
Tamizh chelvam04f7d142020-01-20 13:21:25 +053014348 if (attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]) {
14349 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL);
14350 tid_conf->rtscts =
14351 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_RTSCTS_CTRL]);
14352 }
14353
Sergey Matyukevich33462e62020-04-24 14:29:03 +030014354 if (attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]) {
14355 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_AMSDU_CTRL);
14356 tid_conf->amsdu =
14357 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_AMSDU_CTRL]);
14358 }
14359
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053014360 if (attrs[NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE]) {
14361 u32 idx = NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE, attr;
14362
14363 tid_conf->txrate_type = nla_get_u8(attrs[idx]);
14364
14365 if (tid_conf->txrate_type != NL80211_TX_RATE_AUTOMATIC) {
14366 attr = NL80211_TID_CONFIG_ATTR_TX_RATE;
14367 err = nl80211_parse_tx_bitrate_mask(info, attrs, attr,
Miles Hueb89a6a2020-08-04 10:16:29 +020014368 &tid_conf->txrate_mask, dev);
Tamizh Chelvam9a5f6482020-05-13 13:41:44 +053014369 if (err)
14370 return err;
14371
14372 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE);
14373 }
14374 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_TX_RATE_TYPE);
14375 }
14376
Johannes Berg3710a8a2020-02-24 11:34:25 +010014377 if (peer)
14378 mask = rdev->wiphy.tid_config_support.peer;
14379 else
14380 mask = rdev->wiphy.tid_config_support.vif;
14381
14382 if (tid_conf->mask & ~mask) {
14383 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
14384 return -ENOTSUPP;
14385 }
14386
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014387 return 0;
14388}
14389
14390static int nl80211_set_tid_config(struct sk_buff *skb,
14391 struct genl_info *info)
14392{
14393 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14394 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
14395 struct net_device *dev = info->user_ptr[1];
Johannes Berg3710a8a2020-02-24 11:34:25 +010014396 struct cfg80211_tid_config *tid_config;
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014397 struct nlattr *tid;
14398 int conf_idx = 0, rem_conf;
14399 int ret = -EINVAL;
14400 u32 num_conf = 0;
14401
14402 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
14403 return -EINVAL;
14404
14405 if (!rdev->ops->set_tid_config)
14406 return -EOPNOTSUPP;
14407
14408 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14409 rem_conf)
14410 num_conf++;
14411
14412 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
14413 GFP_KERNEL);
14414 if (!tid_config)
14415 return -ENOMEM;
14416
14417 tid_config->n_tid_conf = num_conf;
14418
14419 if (info->attrs[NL80211_ATTR_MAC])
14420 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
14421
14422 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14423 rem_conf) {
14424 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
14425 tid, NULL, NULL);
14426
14427 if (ret)
14428 goto bad_tid_conf;
14429
14430 ret = parse_tid_conf(rdev, attrs, dev,
14431 &tid_config->tid_conf[conf_idx],
14432 info, tid_config->peer);
14433 if (ret)
14434 goto bad_tid_conf;
14435
14436 conf_idx++;
14437 }
14438
14439 ret = rdev_set_tid_config(rdev, dev, tid_config);
14440
14441bad_tid_conf:
14442 kfree(tid_config);
14443 return ret;
14444}
14445
Johannes Berg4c476992010-10-04 21:36:35 +020014446#define NL80211_FLAG_NEED_WIPHY 0x01
14447#define NL80211_FLAG_NEED_NETDEV 0x02
14448#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020014449#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
14450#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
14451 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020014452#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020014453/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020014454#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14455 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030014456#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020014457
Johannes Bergf84f7712013-11-14 17:14:45 +010014458static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020014459 struct genl_info *info)
14460{
14461 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020014462 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020014463 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020014464 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
14465
14466 if (rtnl)
14467 rtnl_lock();
14468
14469 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020014470 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020014471 if (IS_ERR(rdev)) {
14472 if (rtnl)
14473 rtnl_unlock();
14474 return PTR_ERR(rdev);
14475 }
14476 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020014477 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
14478 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020014479 ASSERT_RTNL();
14480
Johannes Berg89a54e42012-06-15 14:33:17 +020014481 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
14482 info->attrs);
14483 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020014484 if (rtnl)
14485 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020014486 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020014487 }
Johannes Berg89a54e42012-06-15 14:33:17 +020014488
Johannes Berg89a54e42012-06-15 14:33:17 +020014489 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014490 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020014491
Johannes Berg1bf614e2012-06-15 15:23:36 +020014492 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
14493 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020014494 if (rtnl)
14495 rtnl_unlock();
14496 return -EINVAL;
14497 }
14498
14499 info->user_ptr[1] = dev;
14500 } else {
14501 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020014502 }
Johannes Berg89a54e42012-06-15 14:33:17 +020014503
Arend Van Spriel73c7da32016-10-20 20:08:22 +010014504 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
14505 !wdev_running(wdev)) {
14506 if (rtnl)
14507 rtnl_unlock();
14508 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020014509 }
14510
Arend Van Spriel73c7da32016-10-20 20:08:22 +010014511 if (dev)
14512 dev_hold(dev);
14513
Johannes Berg4c476992010-10-04 21:36:35 +020014514 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020014515 }
14516
14517 return 0;
14518}
14519
Johannes Bergf84f7712013-11-14 17:14:45 +010014520static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020014521 struct genl_info *info)
14522{
Johannes Berg1bf614e2012-06-15 15:23:36 +020014523 if (info->user_ptr[1]) {
14524 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
14525 struct wireless_dev *wdev = info->user_ptr[1];
14526
14527 if (wdev->netdev)
14528 dev_put(wdev->netdev);
14529 } else {
14530 dev_put(info->user_ptr[1]);
14531 }
14532 }
Johannes Berg5393b912014-09-10 15:00:16 +030014533
Johannes Berg4c476992010-10-04 21:36:35 +020014534 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
14535 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030014536
14537 /* If needed, clear the netlink message payload from the SKB
14538 * as it might contain key data that shouldn't stick around on
14539 * the heap after the SKB is freed. The netlink message header
14540 * is still needed for further processing, so leave it intact.
14541 */
14542 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
14543 struct nlmsghdr *nlh = nlmsg_hdr(skb);
14544
14545 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
14546 }
Johannes Berg4c476992010-10-04 21:36:35 +020014547}
14548
Johannes Berg4534de82013-11-14 17:14:46 +010014549static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040014550 {
14551 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014552 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014553 .doit = nl80211_get_wiphy,
14554 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020014555 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040014556 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020014557 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14558 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014559 },
14560 {
14561 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014562 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014563 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014564 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014565 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014566 },
14567 {
14568 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014569 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014570 .doit = nl80211_get_interface,
14571 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040014572 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020014573 .internal_flags = NL80211_FLAG_NEED_WDEV |
14574 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014575 },
14576 {
14577 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014578 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014579 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014580 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014581 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14582 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014583 },
14584 {
14585 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014586 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014587 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014588 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014589 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14590 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014591 },
14592 {
14593 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014594 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014595 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014596 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020014597 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014598 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014599 },
Johannes Berg41ade002007-12-19 02:03:29 +010014600 {
14601 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014602 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014603 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014604 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014605 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014606 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010014607 },
14608 {
14609 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014610 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014611 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014612 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014613 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014614 NL80211_FLAG_NEED_RTNL |
14615 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010014616 },
14617 {
14618 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014619 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014620 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014621 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014623 NL80211_FLAG_NEED_RTNL |
14624 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010014625 },
14626 {
14627 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014628 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014629 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014630 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014631 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014632 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010014633 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010014634 {
14635 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020014636 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014637 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014638 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014639 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014640 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014641 },
14642 {
Johannes Berg88600202012-02-13 15:17:18 +010014643 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014644 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014645 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014646 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014647 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014648 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014649 },
14650 {
Johannes Berg88600202012-02-13 15:17:18 +010014651 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014652 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014653 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014654 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014655 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014656 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014657 },
Johannes Berg5727ef12007-12-19 02:03:34 +010014658 {
14659 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014660 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014661 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014662 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020014663 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14664 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014665 },
14666 {
14667 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014668 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014669 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014670 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014672 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014673 },
14674 {
14675 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014676 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014677 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014678 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014680 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014681 },
14682 {
14683 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014684 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014685 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014686 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014688 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014689 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014690 {
14691 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014692 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014693 .doit = nl80211_get_mpath,
14694 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014695 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014696 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014697 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014698 },
14699 {
Henning Rogge66be7d22014-09-12 08:58:49 +020014700 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014701 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020014702 .doit = nl80211_get_mpp,
14703 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020014704 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020014705 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14706 NL80211_FLAG_NEED_RTNL,
14707 },
14708 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014709 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014710 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014711 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014712 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014713 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014714 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014715 },
14716 {
14717 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014718 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014719 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014720 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014721 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014722 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014723 },
14724 {
14725 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014726 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014727 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014728 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014729 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014730 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014731 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014732 {
14733 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014734 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014735 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014736 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014737 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014738 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014739 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014740 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014741 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014742 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014743 .doit = nl80211_get_reg_do,
14744 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014745 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014746 /* can be retrieved by unprivileged users */
14747 },
Johannes Bergb6863032015-10-15 09:25:18 +020014748#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014749 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014750 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014751 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014752 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014753 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014754 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014755 },
Johannes Bergb6863032015-10-15 09:25:18 +020014756#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014757 {
14758 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014759 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014760 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014761 .flags = GENL_ADMIN_PERM,
14762 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014763 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014764 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014765 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014766 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014767 .flags = GENL_ADMIN_PERM,
14768 },
14769 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014770 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014771 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014772 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014773 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014774 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014775 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014776 },
14777 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014778 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014779 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014780 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020014781 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014782 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014783 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014784 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020014785 {
Johannes Berg2a519312009-02-10 21:25:55 +010014786 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014787 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014788 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014789 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020014790 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014791 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010014792 },
14793 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014794 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014795 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014796 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014797 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014798 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14799 NL80211_FLAG_NEED_RTNL,
14800 },
14801 {
Johannes Berg2a519312009-02-10 21:25:55 +010014802 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014803 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014804 .dumpit = nl80211_dump_scan,
14805 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020014806 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014807 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014808 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014809 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014810 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014811 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14812 NL80211_FLAG_NEED_RTNL,
14813 },
14814 {
14815 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014816 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014817 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014818 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014819 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14820 NL80211_FLAG_NEED_RTNL,
14821 },
14822 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020014823 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014824 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014825 .doit = nl80211_authenticate,
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 Berg5393b912014-09-10 15:00:16 +030014828 NL80211_FLAG_NEED_RTNL |
14829 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014830 },
14831 {
14832 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014833 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014834 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014835 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014836 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014837 NL80211_FLAG_NEED_RTNL |
14838 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014839 },
14840 {
14841 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014842 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014843 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014844 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014845 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014846 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014847 },
14848 {
14849 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014850 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014851 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014852 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014853 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014854 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014855 },
Johannes Berg04a773a2009-04-19 21:24:32 +020014856 {
14857 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014858 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014859 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014860 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014862 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014863 },
14864 {
14865 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014866 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014867 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014868 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014869 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014870 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014871 },
Johannes Bergaff89a92009-07-01 21:26:51 +020014872#ifdef CONFIG_NL80211_TESTMODE
14873 {
14874 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014875 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020014876 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070014877 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014878 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014879 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14880 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020014881 },
14882#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020014883 {
14884 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014885 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014886 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014887 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014888 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014889 NL80211_FLAG_NEED_RTNL |
14890 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014891 },
14892 {
vamsi krishna088e8df2016-10-27 16:51:11 +030014893 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014894 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030014895 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030014896 .flags = GENL_ADMIN_PERM,
14897 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014898 NL80211_FLAG_NEED_RTNL |
14899 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030014900 },
14901 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020014902 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014903 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014904 .doit = nl80211_disconnect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014905 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014906 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014907 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014908 },
Johannes Berg463d0182009-07-14 00:33:35 +020014909 {
14910 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014911 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020014912 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020014913 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014914 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14915 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020014916 },
Holger Schurig61fa7132009-11-11 12:25:40 +010014917 {
14918 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014919 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010014920 .dumpit = nl80211_dump_survey,
14921 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014922 {
14923 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014924 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014925 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014926 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014927 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014928 NL80211_FLAG_NEED_RTNL |
14929 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014930 },
14931 {
14932 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014933 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014934 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014935 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014936 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014937 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014938 },
14939 {
14940 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014941 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014942 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014943 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014945 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014946 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014947 {
14948 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014949 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014950 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014951 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014952 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014953 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014954 },
14955 {
14956 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014957 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014958 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014959 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014960 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014961 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014962 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014963 {
14964 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014965 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014966 .doit = nl80211_set_tx_bitrate_mask,
Martin Willi5617c6c2016-05-09 18:33:58 +020014967 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014968 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14969 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014970 },
Jouni Malinen026331c2010-02-15 12:53:10 +020014971 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014972 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014973 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014974 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014975 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014976 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014977 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014978 },
14979 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014980 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014981 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014982 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014983 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014984 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014985 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014986 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020014987 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014988 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014989 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014990 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020014991 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014992 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014993 NL80211_FLAG_NEED_RTNL,
14994 },
14995 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020014996 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014997 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014998 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020014999 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015000 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15001 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015002 },
15003 {
15004 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015005 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015006 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015007 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020015008 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15009 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020015010 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015011 {
15012 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020015013 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015014 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020015015 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015016 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15017 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020015018 },
Johannes Bergf444de02010-05-05 15:25:02 +020015019 {
15020 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015021 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020015022 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020015023 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020015024 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15025 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020015026 },
Bill Jordane8347eb2010-10-01 13:54:28 -040015027 {
15028 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020015029 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040015030 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020015031 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020015032 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15033 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040015034 },
Johannes Berg29cbe682010-12-03 09:20:44 +010015035 {
15036 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015037 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010015038 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020015039 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010015040 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15041 NL80211_FLAG_NEED_RTNL,
15042 },
15043 {
15044 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015045 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010015046 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020015047 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010015048 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15049 NL80211_FLAG_NEED_RTNL,
15050 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015051 {
15052 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020015053 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015054 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020015055 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015056 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15057 NL80211_FLAG_NEED_RTNL,
15058 },
15059 {
15060 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020015061 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015062 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020015063 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010015064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15065 NL80211_FLAG_NEED_RTNL,
15066 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020015067#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020015068 {
15069 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020015070 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015071 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015072 /* can be retrieved by unprivileged users */
15073 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15074 NL80211_FLAG_NEED_RTNL,
15075 },
15076 {
15077 .cmd = NL80211_CMD_SET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020015078 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015079 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020015080 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020015081 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15082 NL80211_FLAG_NEED_RTNL,
15083 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020015084#endif
Johannes Berge5497d72011-07-05 16:35:40 +020015085 {
15086 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020015087 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020015088 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020015089 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020015090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030015091 NL80211_FLAG_NEED_RTNL |
15092 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020015093 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030015094 {
15095 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015096 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015097 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020015098 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015099 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15100 NL80211_FLAG_NEED_RTNL,
15101 },
15102 {
15103 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020015104 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015105 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020015106 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030015107 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15108 NL80211_FLAG_NEED_RTNL,
15109 },
Johannes Berg28946da2011-11-04 11:18:12 +010015110 {
15111 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015112 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010015113 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020015114 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010015115 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15116 NL80211_FLAG_NEED_RTNL,
15117 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010015118 {
15119 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015120 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010015121 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020015122 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020015123 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010015124 NL80211_FLAG_NEED_RTNL,
15125 },
Johannes Berg5e760232011-11-04 11:18:17 +010015126 {
15127 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015128 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010015129 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020015130 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010015131 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15132 NL80211_FLAG_NEED_RTNL,
15133 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010015134 {
15135 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020015136 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010015137 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020015138 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010015139 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15140 NL80211_FLAG_NEED_RTNL,
15141 },
Johannes Berg98104fde2012-06-16 00:19:54 +020015142 {
15143 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015144 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020015145 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020015146 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020015147 .internal_flags = NL80211_FLAG_NEED_WDEV |
15148 NL80211_FLAG_NEED_RTNL,
15149 },
15150 {
15151 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015152 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020015153 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020015154 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020015155 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15156 NL80211_FLAG_NEED_RTNL,
15157 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015158 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015159 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020015160 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015161 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015162 .flags = GENL_ADMIN_PERM,
15163 .internal_flags = NL80211_FLAG_NEED_WDEV |
15164 NL80211_FLAG_NEED_RTNL,
15165 },
15166 {
15167 .cmd = NL80211_CMD_STOP_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020015168 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015169 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030015170 .flags = GENL_ADMIN_PERM,
15171 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15172 NL80211_FLAG_NEED_RTNL,
15173 },
15174 {
Ayala Bekera442b762016-09-20 17:31:15 +030015175 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020015176 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030015177 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030015178 .flags = GENL_ADMIN_PERM,
15179 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15180 NL80211_FLAG_NEED_RTNL,
15181 },
15182 {
15183 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020015184 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030015185 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030015186 .flags = GENL_ADMIN_PERM,
15187 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15188 NL80211_FLAG_NEED_RTNL,
15189 },
15190 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030015191 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020015192 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030015193 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030015194 .flags = GENL_ADMIN_PERM,
15195 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15196 NL80211_FLAG_NEED_RTNL,
15197 },
15198 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015199 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015200 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015201 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020015202 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010015203 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15204 NL80211_FLAG_NEED_RTNL,
15205 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053015206 {
15207 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020015208 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053015209 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020015210 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053015211 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15212 NL80211_FLAG_NEED_RTNL,
15213 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010015214 {
15215 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020015216 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015217 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020015218 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010015219 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15220 NL80211_FLAG_NEED_RTNL,
15221 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010015222 {
15223 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020015224 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010015225 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010015226 },
Jouni Malinen355199e2013-02-27 17:14:27 +020015227 {
15228 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020015229 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020015230 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020015231 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020015232 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15233 NL80211_FLAG_NEED_RTNL,
15234 },
Arend van Spriel5de17982013-04-18 15:49:00 +020015235 {
15236 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020015237 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020015238 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020015239 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020015240 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15241 NL80211_FLAG_NEED_RTNL,
15242 },
15243 {
15244 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020015245 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020015246 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020015247 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020015248 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15249 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015250 },
15251 {
15252 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015253 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015254 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015255 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15256 NL80211_FLAG_NEED_RTNL,
15257 },
15258 {
15259 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020015260 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015261 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020015262 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070015263 .internal_flags = NL80211_FLAG_NEED_WIPHY |
15264 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020015265 },
15266 {
15267 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015268 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020015269 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020015270 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020015271 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15272 NL80211_FLAG_NEED_RTNL,
15273 },
Johannes Bergad7e7182013-11-13 13:37:47 +010015274 {
15275 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020015276 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010015277 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030015278 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020015279 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010015280 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015281 NL80211_FLAG_NEED_RTNL |
15282 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010015283 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080015284 {
15285 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020015286 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080015287 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020015288 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080015289 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15290 NL80211_FLAG_NEED_RTNL,
15291 },
Johannes Berg960d01a2014-09-09 22:55:35 +030015292 {
15293 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015294 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030015295 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020015296 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030015297 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15298 NL80211_FLAG_NEED_RTNL,
15299 },
15300 {
15301 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015302 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030015303 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020015304 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030015305 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15306 NL80211_FLAG_NEED_RTNL,
15307 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020015308 {
15309 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015310 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015311 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020015312 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015313 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15314 NL80211_FLAG_NEED_RTNL,
15315 },
15316 {
15317 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015318 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015319 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020015320 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020015321 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15322 NL80211_FLAG_NEED_RTNL,
15323 },
Michael Braunce0ce132016-10-10 19:12:22 +020015324 {
15325 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020015326 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020015327 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020015328 .flags = GENL_UNS_ADMIN_PERM,
15329 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15330 NL80211_FLAG_NEED_RTNL,
15331 },
Avraham Stern3a00df52017-06-09 13:08:43 +010015332 {
15333 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020015334 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010015335 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010015336 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053015337 NL80211_FLAG_NEED_RTNL |
15338 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010015339 },
15340 {
15341 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020015342 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010015343 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010015344 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15345 NL80211_FLAG_NEED_RTNL,
15346 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015347 {
15348 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020015349 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015350 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020015351 .flags = GENL_ADMIN_PERM,
15352 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15353 NL80211_FLAG_NEED_RTNL,
15354 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015355 {
15356 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015357 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015358 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015359 .flags = GENL_UNS_ADMIN_PERM,
15360 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15361 NL80211_FLAG_NEED_RTNL,
15362 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015363 {
15364 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015365 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015366 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015367 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15368 NL80211_FLAG_NEED_RTNL,
15369 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015370 {
15371 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020015372 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015373 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015374 .flags = GENL_UNS_ADMIN_PERM,
15375 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15376 NL80211_FLAG_NEED_RTNL,
15377 },
Sriram R30c63112018-12-04 17:46:52 +053015378 {
15379 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020015380 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053015381 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053015382 .flags = GENL_UNS_ADMIN_PERM,
15383 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15384 NL80211_FLAG_NEED_RTNL,
15385 },
Sunil Duttcb74e972019-02-20 16:18:07 +053015386 {
15387 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
15388 .doit = nl80211_update_owe_info,
15389 .flags = GENL_ADMIN_PERM,
15390 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15391 NL80211_FLAG_NEED_RTNL,
15392 },
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070015393 {
15394 .cmd = NL80211_CMD_PROBE_MESH_LINK,
15395 .doit = nl80211_probe_mesh_link,
15396 .flags = GENL_UNS_ADMIN_PERM,
15397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15398 NL80211_FLAG_NEED_RTNL,
15399 },
Tamizh chelvam77f576d2020-01-20 13:21:22 +053015400 {
15401 .cmd = NL80211_CMD_SET_TID_CONFIG,
15402 .doit = nl80211_set_tid_config,
15403 .flags = GENL_UNS_ADMIN_PERM,
15404 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15405 NL80211_FLAG_NEED_RTNL,
15406 },
Johannes Berg55682962007-09-20 13:09:35 -040015407};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015408
Johannes Berg56989f62016-10-24 14:40:05 +020015409static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020015410 .name = NL80211_GENL_NAME, /* have users key off the name instead */
15411 .hdrsize = 0, /* no private header */
15412 .version = 1, /* no particular meaning now */
15413 .maxattr = NL80211_ATTR_MAX,
Johannes Berg3b0f31f2019-03-21 22:51:02 +010015414 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020015415 .netnsok = true,
15416 .pre_doit = nl80211_pre_doit,
15417 .post_doit = nl80211_post_doit,
15418 .module = THIS_MODULE,
15419 .ops = nl80211_ops,
15420 .n_ops = ARRAY_SIZE(nl80211_ops),
15421 .mcgrps = nl80211_mcgrps,
15422 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
Johannes Berg50508d92019-07-29 16:31:09 +020015423 .parallel_ops = true,
Johannes Berg489111e2016-10-24 14:40:03 +020015424};
15425
Johannes Berg55682962007-09-20 13:09:35 -040015426/* notification functions */
15427
Johannes Berg3bb20552014-05-26 13:52:25 +020015428void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
15429 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040015430{
15431 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020015432 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040015433
Johannes Berg3bb20552014-05-26 13:52:25 +020015434 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
15435 cmd != NL80211_CMD_DEL_WIPHY);
15436
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015437 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040015438 if (!msg)
15439 return;
15440
Johannes Berg3bb20552014-05-26 13:52:25 +020015441 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040015442 nlmsg_free(msg);
15443 return;
15444 }
15445
Johannes Berg68eb5502013-11-19 15:19:38 +010015446 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015447 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040015448}
15449
Denis Kenzior896ff062016-08-03 16:58:33 -050015450void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
15451 struct wireless_dev *wdev,
15452 enum nl80211_commands cmd)
15453{
15454 struct sk_buff *msg;
15455
Denis Kenzior896ff062016-08-03 16:58:33 -050015456 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15457 if (!msg)
15458 return;
15459
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020015460 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050015461 nlmsg_free(msg);
15462 return;
15463 }
15464
15465 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15466 NL80211_MCGRP_CONFIG, GFP_KERNEL);
15467}
15468
Johannes Berg362a4152009-05-24 16:43:15 +020015469static int nl80211_add_scan_req(struct sk_buff *msg,
15470 struct cfg80211_registered_device *rdev)
15471{
15472 struct cfg80211_scan_request *req = rdev->scan_req;
15473 struct nlattr *nest;
15474 int i;
15475
15476 if (WARN_ON(!req))
15477 return 0;
15478
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015479 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020015480 if (!nest)
15481 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040015482 for (i = 0; i < req->n_ssids; i++) {
15483 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
15484 goto nla_put_failure;
15485 }
Johannes Berg362a4152009-05-24 16:43:15 +020015486 nla_nest_end(msg, nest);
15487
Thomas Pedersen2032f3b2020-04-30 10:25:52 -070015488 if (req->flags & NL80211_SCAN_FLAG_FREQ_KHZ) {
15489 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQ_KHZ);
15490 if (!nest)
David S. Miller9360ffd2012-03-29 04:41:26 -040015491 goto nla_put_failure;
Thomas Pedersen2032f3b2020-04-30 10:25:52 -070015492 for (i = 0; i < req->n_channels; i++) {
15493 if (nla_put_u32(msg, i,
15494 ieee80211_channel_to_khz(req->channels[i])))
15495 goto nla_put_failure;
15496 }
15497 nla_nest_end(msg, nest);
15498 } else {
15499 nest = nla_nest_start_noflag(msg,
15500 NL80211_ATTR_SCAN_FREQUENCIES);
15501 if (!nest)
15502 goto nla_put_failure;
15503 for (i = 0; i < req->n_channels; i++) {
15504 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
15505 goto nla_put_failure;
15506 }
15507 nla_nest_end(msg, nest);
David S. Miller9360ffd2012-03-29 04:41:26 -040015508 }
Johannes Berg362a4152009-05-24 16:43:15 +020015509
David S. Miller9360ffd2012-03-29 04:41:26 -040015510 if (req->ie &&
15511 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
15512 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020015513
Johannes Bergae917c92013-10-25 11:05:22 +020015514 if (req->flags &&
15515 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
15516 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070015517
Avraham Stern1d762502016-07-05 17:10:13 +030015518 if (req->info.scan_start_tsf &&
15519 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
15520 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
15521 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
15522 req->info.tsf_bssid)))
15523 goto nla_put_failure;
15524
Johannes Berg362a4152009-05-24 16:43:15 +020015525 return 0;
15526 nla_put_failure:
15527 return -ENOBUFS;
15528}
15529
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015530static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020015531 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020015532 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015533 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020015534 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010015535{
15536 void *hdr;
15537
Eric W. Biederman15e47302012-09-07 20:12:54 +000015538 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010015539 if (!hdr)
15540 return -1;
15541
David S. Miller9360ffd2012-03-29 04:41:26 -040015542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020015543 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15544 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015545 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15546 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015547 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010015548
Johannes Berg362a4152009-05-24 16:43:15 +020015549 /* ignore errors and send incomplete event anyway */
15550 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010015551
Johannes Berg053c0952015-01-16 22:09:00 +010015552 genlmsg_end(msg, hdr);
15553 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010015554
15555 nla_put_failure:
15556 genlmsg_cancel(msg, hdr);
15557 return -EMSGSIZE;
15558}
15559
Luciano Coelho807f8a82011-05-11 17:09:35 +030015560static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015561nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015562 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030015563{
15564 void *hdr;
15565
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015566 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015567 if (!hdr)
15568 return -1;
15569
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015570 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
15571 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
15572 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
15573 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
15574 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015575 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030015576
Johannes Berg053c0952015-01-16 22:09:00 +010015577 genlmsg_end(msg, hdr);
15578 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030015579
15580 nla_put_failure:
15581 genlmsg_cancel(msg, hdr);
15582 return -EMSGSIZE;
15583}
15584
Johannes Berga538e2d2009-06-16 19:56:42 +020015585void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020015586 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020015587{
15588 struct sk_buff *msg;
15589
Thomas Graf58050fc2012-06-28 03:57:45 +000015590 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020015591 if (!msg)
15592 return;
15593
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015594 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020015595 NL80211_CMD_TRIGGER_SCAN) < 0) {
15596 nlmsg_free(msg);
15597 return;
15598 }
15599
Johannes Berg68eb5502013-11-19 15:19:38 +010015600 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015601 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020015602}
15603
Johannes Bergf9d15d12014-01-22 11:14:19 +020015604struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
15605 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010015606{
15607 struct sk_buff *msg;
15608
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015609 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010015610 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020015611 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010015612
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015613 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020015614 aborted ? NL80211_CMD_SCAN_ABORTED :
15615 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010015616 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020015617 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010015618 }
15619
Johannes Bergf9d15d12014-01-22 11:14:19 +020015620 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010015621}
15622
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015623/* send message created by nl80211_build_scan_msg() */
15624void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
15625 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010015626{
Johannes Berg2a519312009-02-10 21:25:55 +010015627 if (!msg)
15628 return;
15629
Johannes Berg68eb5502013-11-19 15:19:38 +010015630 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015631 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010015632}
15633
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015634void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030015635{
15636 struct sk_buff *msg;
15637
Thomas Graf58050fc2012-06-28 03:57:45 +000015638 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015639 if (!msg)
15640 return;
15641
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015642 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030015643 nlmsg_free(msg);
15644 return;
15645 }
15646
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015647 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015648 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015649}
15650
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015651static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
15652 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015653{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015654 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040015655 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
15656 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015657
David S. Miller9360ffd2012-03-29 04:41:26 -040015658 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
15659 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15660 NL80211_REGDOM_TYPE_WORLD))
15661 goto nla_put_failure;
15662 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
15663 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15664 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
15665 goto nla_put_failure;
15666 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
15667 request->intersect) {
15668 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15669 NL80211_REGDOM_TYPE_INTERSECTION))
15670 goto nla_put_failure;
15671 } else {
15672 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15673 NL80211_REGDOM_TYPE_COUNTRY) ||
15674 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
15675 request->alpha2))
15676 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015677 }
15678
Arik Nemtsovad30ca22014-12-15 19:25:59 +020015679 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
15680 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
15681
15682 if (wiphy &&
15683 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
15684 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020015685
15686 if (wiphy &&
15687 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
15688 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
15689 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020015690 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015691
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015692 return true;
15693
15694nla_put_failure:
15695 return false;
15696}
15697
15698/*
15699 * This can happen on global regulatory changes or device specific settings
15700 * based on custom regulatory domains.
15701 */
15702void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
15703 struct regulatory_request *request)
15704{
15705 struct sk_buff *msg;
15706 void *hdr;
15707
15708 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15709 if (!msg)
15710 return;
15711
15712 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
zhong jiang24f6d762019-09-05 12:25:37 +080015713 if (!hdr)
15714 goto nla_put_failure;
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015715
zhong jiang24f6d762019-09-05 12:25:37 +080015716 if (!nl80211_reg_change_event_fill(msg, request))
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015717 goto nla_put_failure;
15718
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015719 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015720
Johannes Bergbc43b282009-07-25 10:54:13 +020015721 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015722 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015723 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020015724 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015725
15726 return;
15727
15728nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015729 nlmsg_free(msg);
15730}
15731
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015732static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15733 struct net_device *netdev,
15734 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015735 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015736 int uapsd_queues, const u8 *req_ies,
15737 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015738{
15739 struct sk_buff *msg;
15740 void *hdr;
15741
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015742 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015743 if (!msg)
15744 return;
15745
15746 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15747 if (!hdr) {
15748 nlmsg_free(msg);
15749 return;
15750 }
15751
David S. Miller9360ffd2012-03-29 04:41:26 -040015752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15753 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015754 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15755 (req_ies &&
15756 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015757 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015758
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015759 if (uapsd_queues >= 0) {
15760 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015761 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015762 if (!nla_wmm)
15763 goto nla_put_failure;
15764
15765 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15766 uapsd_queues))
15767 goto nla_put_failure;
15768
15769 nla_nest_end(msg, nla_wmm);
15770 }
15771
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015772 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015773
Johannes Berg68eb5502013-11-19 15:19:38 +010015774 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015775 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015776 return;
15777
15778 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015779 nlmsg_free(msg);
15780}
15781
15782void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015783 struct net_device *netdev, const u8 *buf,
15784 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015785{
15786 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015787 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015788}
15789
15790void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15791 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015792 size_t len, gfp_t gfp, int uapsd_queues,
15793 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015794{
Johannes Berge6d6e342009-07-01 21:26:47 +020015795 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015796 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15797 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015798}
15799
Jouni Malinen53b46b82009-03-27 20:53:56 +020015800void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015801 struct net_device *netdev, const u8 *buf,
15802 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015803{
15804 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015805 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015806}
15807
Jouni Malinen53b46b82009-03-27 20:53:56 +020015808void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15809 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020015810 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015811{
15812 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015813 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015814}
15815
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015816void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15817 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020015818{
Johannes Berg947add32013-02-22 22:05:20 +010015819 struct wireless_dev *wdev = dev->ieee80211_ptr;
15820 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015821 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015822 const struct ieee80211_mgmt *mgmt = (void *)buf;
15823 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020015824
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015825 if (WARN_ON(len < 2))
15826 return;
15827
Jouni Malinen4d797fc2020-04-01 17:25:47 +030015828 if (ieee80211_is_deauth(mgmt->frame_control)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015829 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
Jouni Malinen4d797fc2020-04-01 17:25:47 +030015830 } else if (ieee80211_is_disassoc(mgmt->frame_control)) {
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015831 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
Jouni Malinen4d797fc2020-04-01 17:25:47 +030015832 } else if (ieee80211_is_beacon(mgmt->frame_control)) {
15833 if (wdev->unprot_beacon_reported &&
15834 elapsed_jiffies_msecs(wdev->unprot_beacon_reported) < 10000)
15835 return;
15836 cmd = NL80211_CMD_UNPROT_BEACON;
15837 wdev->unprot_beacon_reported = jiffies;
15838 } else {
15839 return;
15840 }
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015841
15842 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015843 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15844 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015845}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015846EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015847
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040015848static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15849 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020015850 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015851{
15852 struct sk_buff *msg;
15853 void *hdr;
15854
Johannes Berge6d6e342009-07-01 21:26:47 +020015855 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015856 if (!msg)
15857 return;
15858
15859 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15860 if (!hdr) {
15861 nlmsg_free(msg);
15862 return;
15863 }
15864
David S. Miller9360ffd2012-03-29 04:41:26 -040015865 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15866 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15867 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15868 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15869 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030015870
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015871 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030015872
Johannes Berg68eb5502013-11-19 15:19:38 +010015873 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015874 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015875 return;
15876
15877 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030015878 nlmsg_free(msg);
15879}
15880
15881void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015882 struct net_device *netdev, const u8 *addr,
15883 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015884{
15885 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020015886 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015887}
15888
15889void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015890 struct net_device *netdev, const u8 *addr,
15891 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015892{
Johannes Berge6d6e342009-07-01 21:26:47 +020015893 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
15894 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015895}
15896
Samuel Ortizb23aa672009-07-01 21:26:54 +020015897void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015898 struct net_device *netdev,
15899 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015900 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015901{
15902 struct sk_buff *msg;
15903 void *hdr;
15904
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015905 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020015906 cr->fils.kek_len + cr->fils.pmk_len +
15907 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015908 if (!msg)
15909 return;
15910
15911 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15912 if (!hdr) {
15913 nlmsg_free(msg);
15914 return;
15915 }
15916
David S. Miller9360ffd2012-03-29 04:41:26 -040015917 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15918 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015919 (cr->bssid &&
15920 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030015921 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015922 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15923 cr->status) ||
15924 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015925 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015926 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15927 cr->timeout_reason))) ||
15928 (cr->req_ie &&
15929 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15930 (cr->resp_ie &&
15931 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015932 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020015933 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015934 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020015935 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015936 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020015937 ((cr->fils.kek &&
15938 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15939 cr->fils.kek)) ||
15940 (cr->fils.pmk &&
15941 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15942 (cr->fils.pmkid &&
15943 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040015944 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015945
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015946 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015947
Johannes Berg68eb5502013-11-19 15:19:38 +010015948 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015949 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015950 return;
15951
15952 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015953 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015954}
15955
15956void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015957 struct net_device *netdev,
15958 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015959{
15960 struct sk_buff *msg;
15961 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015962 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015963
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015964 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15965 info->fils.kek_len + info->fils.pmk_len +
15966 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015967 if (!msg)
15968 return;
15969
15970 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15971 if (!hdr) {
15972 nlmsg_free(msg);
15973 return;
15974 }
15975
David S. Miller9360ffd2012-03-29 04:41:26 -040015976 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15977 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15978 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015979 (info->req_ie &&
15980 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15981 info->req_ie)) ||
15982 (info->resp_ie &&
15983 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015984 info->resp_ie)) ||
15985 (info->fils.update_erp_next_seq_num &&
15986 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15987 info->fils.erp_next_seq_num)) ||
15988 (info->fils.kek &&
15989 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15990 info->fils.kek)) ||
15991 (info->fils.pmk &&
15992 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15993 (info->fils.pmkid &&
15994 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015995 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015996
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015997 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015998
Johannes Berg68eb5502013-11-19 15:19:38 +010015999 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016000 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016001 return;
16002
16003 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020016004 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016005}
16006
Avraham Stern503c1fb2017-09-29 14:21:49 +020016007void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
16008 struct net_device *netdev, const u8 *bssid)
16009{
16010 struct sk_buff *msg;
16011 void *hdr;
16012
16013 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
16014 if (!msg)
16015 return;
16016
16017 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
16018 if (!hdr) {
16019 nlmsg_free(msg);
16020 return;
16021 }
16022
Chung-Hsien Hsuf4d75992019-05-09 09:48:25 +000016023 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16024 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16025 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
Avraham Stern503c1fb2017-09-29 14:21:49 +020016026 goto nla_put_failure;
16027
16028 genlmsg_end(msg, hdr);
16029
16030 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16031 NL80211_MCGRP_MLME, GFP_KERNEL);
16032 return;
16033
16034 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020016035 nlmsg_free(msg);
16036}
16037
Samuel Ortizb23aa672009-07-01 21:26:54 +020016038void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
16039 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020016040 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020016041{
16042 struct sk_buff *msg;
16043 void *hdr;
16044
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016045 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016046 if (!msg)
16047 return;
16048
16049 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
16050 if (!hdr) {
16051 nlmsg_free(msg);
16052 return;
16053 }
16054
David S. Miller9360ffd2012-03-29 04:41:26 -040016055 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020016057 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040016058 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
16059 (from_ap &&
16060 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
16061 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
16062 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020016063
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016064 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016065
Johannes Berg68eb5502013-11-19 15:19:38 +010016066 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016067 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016068 return;
16069
16070 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020016071 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020016072}
16073
Johannes Berg04a773a2009-04-19 21:24:32 +020016074void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
16075 struct net_device *netdev, const u8 *bssid,
16076 gfp_t gfp)
16077{
16078 struct sk_buff *msg;
16079 void *hdr;
16080
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070016081 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020016082 if (!msg)
16083 return;
16084
16085 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
16086 if (!hdr) {
16087 nlmsg_free(msg);
16088 return;
16089 }
16090
David S. Miller9360ffd2012-03-29 04:41:26 -040016091 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16092 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16093 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16094 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020016095
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016096 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020016097
Johannes Berg68eb5502013-11-19 15:19:38 +010016098 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016099 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020016100 return;
16101
16102 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020016103 nlmsg_free(msg);
16104}
16105
Johannes Berg947add32013-02-22 22:05:20 +010016106void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040016107 const u8 *ie, u8 ie_len,
16108 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070016109{
Johannes Berg947add32013-02-22 22:05:20 +010016110 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016111 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016112 struct sk_buff *msg;
16113 void *hdr;
16114
Johannes Berg947add32013-02-22 22:05:20 +010016115 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
16116 return;
16117
16118 trace_cfg80211_notify_new_peer_candidate(dev, addr);
16119
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016120 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016121 if (!msg)
16122 return;
16123
16124 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
16125 if (!hdr) {
16126 nlmsg_free(msg);
16127 return;
16128 }
16129
David S. Miller9360ffd2012-03-29 04:41:26 -040016130 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010016131 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16132 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016133 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040016134 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
16135 (sig_dbm &&
16136 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016137 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070016138
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016139 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016140
Johannes Berg68eb5502013-11-19 15:19:38 +010016141 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016142 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016143 return;
16144
16145 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070016146 nlmsg_free(msg);
16147}
Johannes Berg947add32013-02-22 22:05:20 +010016148EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070016149
Jouni Malinena3b8b052009-03-27 21:59:49 +020016150void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
16151 struct net_device *netdev, const u8 *addr,
16152 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020016153 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020016154{
16155 struct sk_buff *msg;
16156 void *hdr;
16157
Johannes Berge6d6e342009-07-01 21:26:47 +020016158 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020016159 if (!msg)
16160 return;
16161
16162 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
16163 if (!hdr) {
16164 nlmsg_free(msg);
16165 return;
16166 }
16167
David S. Miller9360ffd2012-03-29 04:41:26 -040016168 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16169 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16170 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
16171 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
16172 (key_id != -1 &&
16173 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
16174 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
16175 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020016176
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016177 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020016178
Johannes Berg68eb5502013-11-19 15:19:38 +010016179 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016180 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020016181 return;
16182
16183 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020016184 nlmsg_free(msg);
16185}
16186
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016187void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
16188 struct ieee80211_channel *channel_before,
16189 struct ieee80211_channel *channel_after)
16190{
16191 struct sk_buff *msg;
16192 void *hdr;
16193 struct nlattr *nl_freq;
16194
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070016195 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016196 if (!msg)
16197 return;
16198
16199 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
16200 if (!hdr) {
16201 nlmsg_free(msg);
16202 return;
16203 }
16204
16205 /*
16206 * Since we are applying the beacon hint to a wiphy we know its
16207 * wiphy_idx is valid
16208 */
David S. Miller9360ffd2012-03-29 04:41:26 -040016209 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
16210 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016211
16212 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016213 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016214 if (!nl_freq)
16215 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030016216
16217 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016218 goto nla_put_failure;
16219 nla_nest_end(msg, nl_freq);
16220
16221 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016222 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016223 if (!nl_freq)
16224 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030016225
16226 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016227 goto nla_put_failure;
16228 nla_nest_end(msg, nl_freq);
16229
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016230 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016231
Johannes Berg463d0182009-07-14 00:33:35 +020016232 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010016233 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016234 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020016235 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016236
16237 return;
16238
16239nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040016240 nlmsg_free(msg);
16241}
16242
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016243static void nl80211_send_remain_on_chan_event(
16244 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020016245 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016246 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016247 unsigned int duration, gfp_t gfp)
16248{
16249 struct sk_buff *msg;
16250 void *hdr;
16251
16252 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16253 if (!msg)
16254 return;
16255
16256 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
16257 if (!hdr) {
16258 nlmsg_free(msg);
16259 return;
16260 }
16261
David S. Miller9360ffd2012-03-29 04:41:26 -040016262 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016263 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16264 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016265 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16266 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016267 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010016268 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
16269 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016270 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16271 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040016272 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016273
David S. Miller9360ffd2012-03-29 04:41:26 -040016274 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
16275 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
16276 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016277
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016278 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016279
Johannes Berg68eb5502013-11-19 15:19:38 +010016280 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016281 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016282 return;
16283
16284 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016285 nlmsg_free(msg);
16286}
16287
Johannes Berg947add32013-02-22 22:05:20 +010016288void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
16289 struct ieee80211_channel *chan,
16290 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016291{
Johannes Berg947add32013-02-22 22:05:20 +010016292 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016293 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016294
16295 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016296 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020016297 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010016298 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016299}
Johannes Berg947add32013-02-22 22:05:20 +010016300EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016301
Johannes Berg947add32013-02-22 22:05:20 +010016302void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
16303 struct ieee80211_channel *chan,
16304 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016305{
Johannes Berg947add32013-02-22 22:05:20 +010016306 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016307 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016308
16309 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016310 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010016311 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016312}
Johannes Berg947add32013-02-22 22:05:20 +010016313EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010016314
James Prestwood1c38c7f2019-06-12 12:35:09 -070016315void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
16316 struct ieee80211_channel *chan,
16317 gfp_t gfp)
16318{
16319 struct wiphy *wiphy = wdev->wiphy;
16320 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16321
16322 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
16323 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
16324 rdev, wdev, cookie, chan, 0, gfp);
16325}
16326EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
16327
Johannes Berg947add32013-02-22 22:05:20 +010016328void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
16329 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010016330{
Johannes Berg947add32013-02-22 22:05:20 +010016331 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016332 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010016333 struct sk_buff *msg;
16334
Johannes Berg947add32013-02-22 22:05:20 +010016335 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
16336
Thomas Graf58050fc2012-06-28 03:57:45 +000016337 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010016338 if (!msg)
16339 return;
16340
Johannes Bergcf5ead82014-11-14 17:14:00 +010016341 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040016342 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010016343 nlmsg_free(msg);
16344 return;
16345 }
16346
Johannes Berg68eb5502013-11-19 15:19:38 +010016347 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016348 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010016349}
Johannes Berg947add32013-02-22 22:05:20 +010016350EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010016351
Johannes Bergcf5ead82014-11-14 17:14:00 +010016352void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
16353 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020016354{
Johannes Berg947add32013-02-22 22:05:20 +010016355 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016356 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020016357 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020016358 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010016359
Johannes Berg73887fd2018-05-18 09:57:55 +020016360 if (!sinfo)
16361 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020016362
Johannes Berg947add32013-02-22 22:05:20 +010016363 trace_cfg80211_del_sta(dev, mac_addr);
16364
Thomas Graf58050fc2012-06-28 03:57:45 +000016365 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020016366 if (!msg) {
16367 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020016368 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020016369 }
Jouni Malinenec15e682011-03-23 15:29:52 +020016370
Johannes Bergcf5ead82014-11-14 17:14:00 +010016371 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010016372 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020016373 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020016374 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020016375 }
16376
Johannes Berg68eb5502013-11-19 15:19:38 +010016377 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016378 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020016379}
Johannes Bergcf5ead82014-11-14 17:14:00 +010016380EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020016381
Johannes Berg947add32013-02-22 22:05:20 +010016382void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
16383 enum nl80211_connect_failed_reason reason,
16384 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016385{
Johannes Berg947add32013-02-22 22:05:20 +010016386 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016387 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016388 struct sk_buff *msg;
16389 void *hdr;
16390
16391 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
16392 if (!msg)
16393 return;
16394
16395 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
16396 if (!hdr) {
16397 nlmsg_free(msg);
16398 return;
16399 }
16400
16401 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16402 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
16403 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
16404 goto nla_put_failure;
16405
16406 genlmsg_end(msg, hdr);
16407
Johannes Berg68eb5502013-11-19 15:19:38 +010016408 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016409 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016410 return;
16411
16412 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016413 nlmsg_free(msg);
16414}
Johannes Berg947add32013-02-22 22:05:20 +010016415EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016416
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016417static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
16418 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010016419{
16420 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016421 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010016422 struct sk_buff *msg;
16423 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070016424 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010016425
Eric W. Biederman15e47302012-09-07 20:12:54 +000016426 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010016427 return false;
16428
16429 msg = nlmsg_new(100, gfp);
16430 if (!msg)
16431 return true;
16432
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016433 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010016434 if (!hdr) {
16435 nlmsg_free(msg);
16436 return true;
16437 }
16438
David S. Miller9360ffd2012-03-29 04:41:26 -040016439 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16440 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16441 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
16442 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010016443
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016444 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000016445 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010016446 return true;
16447
16448 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010016449 nlmsg_free(msg);
16450 return true;
16451}
16452
Johannes Berg947add32013-02-22 22:05:20 +010016453bool cfg80211_rx_spurious_frame(struct net_device *dev,
16454 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016455{
Johannes Berg947add32013-02-22 22:05:20 +010016456 struct wireless_dev *wdev = dev->ieee80211_ptr;
16457 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016458
Johannes Berg947add32013-02-22 22:05:20 +010016459 trace_cfg80211_rx_spurious_frame(dev, addr);
16460
16461 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16462 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
16463 trace_cfg80211_return_bool(false);
16464 return false;
16465 }
16466 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
16467 addr, gfp);
16468 trace_cfg80211_return_bool(ret);
16469 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016470}
Johannes Berg947add32013-02-22 22:05:20 +010016471EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
16472
16473bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
16474 const u8 *addr, gfp_t gfp)
16475{
16476 struct wireless_dev *wdev = dev->ieee80211_ptr;
16477 bool ret;
16478
16479 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
16480
16481 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16482 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
16483 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
16484 trace_cfg80211_return_bool(false);
16485 return false;
16486 }
16487 ret = __nl80211_unexpected_frame(dev,
16488 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
16489 addr, gfp);
16490 trace_cfg80211_return_bool(ret);
16491 return ret;
16492}
16493EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016494
Johannes Berg2e161f782010-08-12 15:38:38 +020016495int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000016496 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010016497 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030016498 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020016499{
Johannes Berg71bbc992012-06-15 15:30:18 +020016500 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020016501 struct sk_buff *msg;
16502 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020016503
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016504 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016505 if (!msg)
16506 return -ENOMEM;
16507
Johannes Berg2e161f782010-08-12 15:38:38 +020016508 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020016509 if (!hdr) {
16510 nlmsg_free(msg);
16511 return -ENOMEM;
16512 }
16513
David S. Miller9360ffd2012-03-29 04:41:26 -040016514 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016515 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16516 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016517 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16518 NL80211_ATTR_PAD) ||
Thomas Pedersene76fede2020-04-30 10:25:50 -070016519 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, KHZ_TO_MHZ(freq)) ||
Thomas Pedersen942ba882020-04-30 10:25:51 -070016520 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET, freq % 1000) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016521 (sig_dbm &&
16522 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030016523 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16524 (flags &&
16525 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016526 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020016527
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016528 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020016529
Eric W. Biederman15e47302012-09-07 20:12:54 +000016530 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020016531
16532 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020016533 nlmsg_free(msg);
16534 return -ENOBUFS;
16535}
16536
Markus Theildca9ca22020-05-08 16:42:00 +020016537static void nl80211_frame_tx_status(struct wireless_dev *wdev, u64 cookie,
16538 const u8 *buf, size_t len, bool ack,
16539 gfp_t gfp, enum nl80211_commands command)
Jouni Malinen026331c2010-02-15 12:53:10 +020016540{
Johannes Berg947add32013-02-22 22:05:20 +010016541 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016542 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020016543 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020016544 struct sk_buff *msg;
16545 void *hdr;
16546
Markus Theildca9ca22020-05-08 16:42:00 +020016547 if (command == NL80211_CMD_FRAME_TX_STATUS)
16548 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
16549 else
16550 trace_cfg80211_control_port_tx_status(wdev, cookie, ack);
Johannes Berg947add32013-02-22 22:05:20 +010016551
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016552 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016553 if (!msg)
16554 return;
16555
Markus Theildca9ca22020-05-08 16:42:00 +020016556 hdr = nl80211hdr_put(msg, 0, 0, 0, command);
Jouni Malinen026331c2010-02-15 12:53:10 +020016557 if (!hdr) {
16558 nlmsg_free(msg);
16559 return;
16560 }
16561
David S. Miller9360ffd2012-03-29 04:41:26 -040016562 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016563 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16564 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016565 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16566 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016567 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016568 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16569 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016570 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
16571 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020016572
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016573 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020016574
Johannes Berg68eb5502013-11-19 15:19:38 +010016575 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016576 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016577 return;
16578
Markus Theildca9ca22020-05-08 16:42:00 +020016579nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020016580 nlmsg_free(msg);
16581}
Markus Theildca9ca22020-05-08 16:42:00 +020016582
16583void cfg80211_control_port_tx_status(struct wireless_dev *wdev, u64 cookie,
16584 const u8 *buf, size_t len, bool ack,
16585 gfp_t gfp)
16586{
16587 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp,
16588 NL80211_CMD_CONTROL_PORT_FRAME_TX_STATUS);
16589}
16590EXPORT_SYMBOL(cfg80211_control_port_tx_status);
16591
16592void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
16593 const u8 *buf, size_t len, bool ack, gfp_t gfp)
16594{
16595 nl80211_frame_tx_status(wdev, cookie, buf, len, ack, gfp,
16596 NL80211_CMD_FRAME_TX_STATUS);
16597}
Johannes Berg947add32013-02-22 22:05:20 +010016598EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020016599
Denis Kenzior6a671a52018-03-26 12:52:41 -050016600static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050016601 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050016602 bool unencrypted, gfp_t gfp)
16603{
16604 struct wireless_dev *wdev = dev->ieee80211_ptr;
16605 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050016606 struct ethhdr *ehdr = eth_hdr(skb);
Johannes Berg8d74a622020-02-24 10:19:12 +010016607 const u8 *addr = ehdr->h_source;
Denis Kenziora948f712018-07-03 15:05:48 -050016608 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016609 struct sk_buff *msg;
16610 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050016611 struct nlattr *frame;
16612
Denis Kenzior6a671a52018-03-26 12:52:41 -050016613 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
16614
16615 if (!nlportid)
16616 return -ENOENT;
16617
Denis Kenziora948f712018-07-03 15:05:48 -050016618 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016619 if (!msg)
16620 return -ENOMEM;
16621
16622 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
16623 if (!hdr) {
16624 nlmsg_free(msg);
16625 return -ENOBUFS;
16626 }
16627
16628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16629 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16630 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16631 NL80211_ATTR_PAD) ||
Johannes Berg8d74a622020-02-24 10:19:12 +010016632 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050016633 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
16634 (unencrypted && nla_put_flag(msg,
16635 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
16636 goto nla_put_failure;
16637
Denis Kenziora948f712018-07-03 15:05:48 -050016638 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
16639 if (!frame)
16640 goto nla_put_failure;
16641
16642 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016643 genlmsg_end(msg, hdr);
16644
16645 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16646
16647 nla_put_failure:
16648 nlmsg_free(msg);
16649 return -ENOBUFS;
16650}
16651
16652bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050016653 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050016654{
16655 int ret;
16656
Denis Kenziora948f712018-07-03 15:05:48 -050016657 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
16658 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016659 trace_cfg80211_return_bool(ret == 0);
16660 return ret == 0;
16661}
16662EXPORT_SYMBOL(cfg80211_rx_control_port);
16663
Johannes Berg5b97f492014-11-26 12:37:43 +010016664static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
16665 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016666{
Johannes Berg947add32013-02-22 22:05:20 +010016667 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010016668 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16669 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16670 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016671
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016672 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010016673 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016674
Johannes Berg5b97f492014-11-26 12:37:43 +010016675 cb = (void **)msg->cb;
16676
16677 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
16678 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016679 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010016680 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016681 }
16682
David S. Miller9360ffd2012-03-29 04:41:26 -040016683 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010016684 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040016685 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016686
Johannes Berg5b97f492014-11-26 12:37:43 +010016687 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016688 goto nla_put_failure;
16689
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016690 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010016691 if (!cb[1])
16692 goto nla_put_failure;
16693
16694 cb[2] = rdev;
16695
16696 return msg;
16697 nla_put_failure:
16698 nlmsg_free(msg);
16699 return NULL;
16700}
16701
16702static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
16703{
16704 void **cb = (void **)msg->cb;
16705 struct cfg80211_registered_device *rdev = cb[2];
16706
16707 nla_nest_end(msg, cb[1]);
16708 genlmsg_end(msg, cb[0]);
16709
16710 memset(msg->cb, 0, sizeof(msg->cb));
16711
16712 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16713 NL80211_MCGRP_MLME, gfp);
16714}
16715
16716void cfg80211_cqm_rssi_notify(struct net_device *dev,
16717 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016718 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010016719{
16720 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010016721 struct wireless_dev *wdev = dev->ieee80211_ptr;
16722 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010016723
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016724 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010016725
Johannes Berg98f03342014-11-26 12:42:02 +010016726 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
16727 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
16728 return;
16729
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010016730 if (wdev->cqm_config) {
16731 wdev->cqm_config->last_rssi_event_value = rssi_level;
16732
16733 cfg80211_cqm_rssi_update(rdev, dev);
16734
16735 if (rssi_level == 0)
16736 rssi_level = wdev->cqm_config->last_rssi_event_value;
16737 }
16738
Johannes Berg5b97f492014-11-26 12:37:43 +010016739 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16740 if (!msg)
16741 return;
16742
David S. Miller9360ffd2012-03-29 04:41:26 -040016743 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16744 rssi_event))
16745 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016746
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016747 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16748 rssi_level))
16749 goto nla_put_failure;
16750
Johannes Berg5b97f492014-11-26 12:37:43 +010016751 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016752
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016753 return;
16754
16755 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016756 nlmsg_free(msg);
16757}
Johannes Berg947add32013-02-22 22:05:20 +010016758EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016759
Johannes Berg5b97f492014-11-26 12:37:43 +010016760void cfg80211_cqm_txe_notify(struct net_device *dev,
16761 const u8 *peer, u32 num_packets,
16762 u32 rate, u32 intvl, gfp_t gfp)
16763{
16764 struct sk_buff *msg;
16765
16766 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16767 if (!msg)
16768 return;
16769
16770 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
16771 goto nla_put_failure;
16772
16773 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
16774 goto nla_put_failure;
16775
16776 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
16777 goto nla_put_failure;
16778
16779 cfg80211_send_cqm(msg, gfp);
16780 return;
16781
16782 nla_put_failure:
16783 nlmsg_free(msg);
16784}
16785EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16786
16787void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16788 const u8 *peer, u32 num_packets, gfp_t gfp)
16789{
16790 struct sk_buff *msg;
16791
16792 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16793
16794 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16795 if (!msg)
16796 return;
16797
16798 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16799 goto nla_put_failure;
16800
16801 cfg80211_send_cqm(msg, gfp);
16802 return;
16803
16804 nla_put_failure:
16805 nlmsg_free(msg);
16806}
16807EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16808
Johannes Berg98f03342014-11-26 12:42:02 +010016809void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16810{
16811 struct sk_buff *msg;
16812
16813 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16814 if (!msg)
16815 return;
16816
16817 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16818 goto nla_put_failure;
16819
16820 cfg80211_send_cqm(msg, gfp);
16821 return;
16822
16823 nla_put_failure:
16824 nlmsg_free(msg);
16825}
16826EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16827
Johannes Berg947add32013-02-22 22:05:20 +010016828static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16829 struct net_device *netdev, const u8 *bssid,
16830 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020016831{
16832 struct sk_buff *msg;
16833 struct nlattr *rekey_attr;
16834 void *hdr;
16835
Thomas Graf58050fc2012-06-28 03:57:45 +000016836 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016837 if (!msg)
16838 return;
16839
16840 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16841 if (!hdr) {
16842 nlmsg_free(msg);
16843 return;
16844 }
16845
David S. Miller9360ffd2012-03-29 04:41:26 -040016846 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16847 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16848 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16849 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016850
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016851 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020016852 if (!rekey_attr)
16853 goto nla_put_failure;
16854
David S. Miller9360ffd2012-03-29 04:41:26 -040016855 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16856 NL80211_REPLAY_CTR_LEN, replay_ctr))
16857 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016858
16859 nla_nest_end(msg, rekey_attr);
16860
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016861 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020016862
Johannes Berg68eb5502013-11-19 15:19:38 +010016863 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016864 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016865 return;
16866
16867 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020016868 nlmsg_free(msg);
16869}
16870
Johannes Berg947add32013-02-22 22:05:20 +010016871void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16872 const u8 *replay_ctr, gfp_t gfp)
16873{
16874 struct wireless_dev *wdev = dev->ieee80211_ptr;
16875 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016876 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016877
16878 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16879 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16880}
16881EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
16882
16883static void
16884nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
16885 struct net_device *netdev, int index,
16886 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016887{
16888 struct sk_buff *msg;
16889 struct nlattr *attr;
16890 void *hdr;
16891
Thomas Graf58050fc2012-06-28 03:57:45 +000016892 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016893 if (!msg)
16894 return;
16895
16896 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
16897 if (!hdr) {
16898 nlmsg_free(msg);
16899 return;
16900 }
16901
David S. Miller9360ffd2012-03-29 04:41:26 -040016902 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16903 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16904 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016905
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016906 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016907 if (!attr)
16908 goto nla_put_failure;
16909
David S. Miller9360ffd2012-03-29 04:41:26 -040016910 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
16911 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
16912 (preauth &&
16913 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
16914 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016915
16916 nla_nest_end(msg, attr);
16917
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016918 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016919
Johannes Berg68eb5502013-11-19 15:19:38 +010016920 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016921 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016922 return;
16923
16924 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016925 nlmsg_free(msg);
16926}
16927
Johannes Berg947add32013-02-22 22:05:20 +010016928void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16929 const u8 *bssid, bool preauth, gfp_t gfp)
16930{
16931 struct wireless_dev *wdev = dev->ieee80211_ptr;
16932 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016933 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016934
16935 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16936 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16937}
16938EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16939
16940static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16941 struct net_device *netdev,
16942 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020016943 gfp_t gfp,
16944 enum nl80211_commands notif,
16945 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070016946{
16947 struct sk_buff *msg;
16948 void *hdr;
16949
Thomas Graf58050fc2012-06-28 03:57:45 +000016950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016951 if (!msg)
16952 return;
16953
Luciano Coelhof8d75522014-11-07 14:31:35 +020016954 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070016955 if (!hdr) {
16956 nlmsg_free(msg);
16957 return;
16958 }
16959
Johannes Berg683b6d32012-11-08 21:25:48 +010016960 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16961 goto nla_put_failure;
16962
16963 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040016964 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070016965
Luciano Coelhof8d75522014-11-07 14:31:35 +020016966 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16967 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16968 goto nla_put_failure;
16969
Thomas Pedersen53145262012-04-06 13:35:47 -070016970 genlmsg_end(msg, hdr);
16971
Johannes Berg68eb5502013-11-19 15:19:38 +010016972 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016973 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016974 return;
16975
16976 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070016977 nlmsg_free(msg);
16978}
16979
Johannes Berg947add32013-02-22 22:05:20 +010016980void cfg80211_ch_switch_notify(struct net_device *dev,
16981 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070016982{
Johannes Berg947add32013-02-22 22:05:20 +010016983 struct wireless_dev *wdev = dev->ieee80211_ptr;
16984 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016985 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016986
Simon Wunderliche487eae2013-11-21 18:19:51 +010016987 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010016988
Simon Wunderliche487eae2013-11-21 18:19:51 +010016989 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010016990
Michal Kazior9e0e2962014-01-29 14:22:27 +010016991 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010016992 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016993
16994 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16995 !WARN_ON(!wdev->current_bss))
Sergey Matyukevich0afd4252019-07-26 16:39:34 +000016996 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016997
Michael Vassernisd34990b2019-07-29 06:01:16 +000016998 cfg80211_sched_dfs_chan_update(rdev);
16999
Luciano Coelhof8d75522014-11-07 14:31:35 +020017000 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
17001 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010017002}
17003EXPORT_SYMBOL(cfg80211_ch_switch_notify);
17004
Luciano Coelhof8d75522014-11-07 14:31:35 +020017005void cfg80211_ch_switch_started_notify(struct net_device *dev,
17006 struct cfg80211_chan_def *chandef,
17007 u8 count)
17008{
17009 struct wireless_dev *wdev = dev->ieee80211_ptr;
17010 struct wiphy *wiphy = wdev->wiphy;
17011 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17012
17013 trace_cfg80211_ch_switch_started_notify(dev, chandef);
17014
17015 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
17016 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
17017}
17018EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
17019
Thomas Pedersen84f10702012-07-12 16:17:33 -070017020void
Simon Wunderlich04f39042013-02-08 18:16:19 +010017021nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010017022 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010017023 enum nl80211_radar_event event,
17024 struct net_device *netdev, gfp_t gfp)
17025{
17026 struct sk_buff *msg;
17027 void *hdr;
17028
17029 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17030 if (!msg)
17031 return;
17032
17033 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
17034 if (!hdr) {
17035 nlmsg_free(msg);
17036 return;
17037 }
17038
17039 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
17040 goto nla_put_failure;
17041
17042 /* NOP and radar events don't need a netdev parameter */
17043 if (netdev) {
17044 struct wireless_dev *wdev = netdev->ieee80211_ptr;
17045
17046 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017047 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17048 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010017049 goto nla_put_failure;
17050 }
17051
17052 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
17053 goto nla_put_failure;
17054
17055 if (nl80211_send_chandef(msg, chandef))
17056 goto nla_put_failure;
17057
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017058 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010017059
Johannes Berg68eb5502013-11-19 15:19:38 +010017060 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017061 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010017062 return;
17063
17064 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010017065 nlmsg_free(msg);
17066}
17067
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053017068void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
17069 struct sta_opmode_info *sta_opmode,
17070 gfp_t gfp)
17071{
17072 struct sk_buff *msg;
17073 struct wireless_dev *wdev = dev->ieee80211_ptr;
17074 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17075 void *hdr;
17076
17077 if (WARN_ON(!mac))
17078 return;
17079
17080 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17081 if (!msg)
17082 return;
17083
17084 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
17085 if (!hdr) {
17086 nlmsg_free(msg);
17087 return;
17088 }
17089
17090 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
17091 goto nla_put_failure;
17092
17093 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
17094 goto nla_put_failure;
17095
17096 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
17097 goto nla_put_failure;
17098
17099 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
17100 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
17101 goto nla_put_failure;
17102
17103 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
Johannes Berg0016d322020-03-25 09:05:32 +010017104 nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053017105 goto nla_put_failure;
17106
17107 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
17108 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
17109 goto nla_put_failure;
17110
17111 genlmsg_end(msg, hdr);
17112
17113 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17114 NL80211_MCGRP_MLME, gfp);
17115
17116 return;
17117
17118nla_put_failure:
17119 nlmsg_free(msg);
17120}
17121EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
17122
Johannes Berg7f6cf312011-11-04 11:18:15 +010017123void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053017124 u64 cookie, bool acked, s32 ack_signal,
17125 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010017126{
17127 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017128 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010017129 struct sk_buff *msg;
17130 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010017131
Beni Lev4ee3e062012-08-27 12:49:39 +030017132 trace_cfg80211_probe_status(dev, addr, cookie, acked);
17133
Thomas Graf58050fc2012-06-28 03:57:45 +000017134 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030017135
Johannes Berg7f6cf312011-11-04 11:18:15 +010017136 if (!msg)
17137 return;
17138
17139 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
17140 if (!hdr) {
17141 nlmsg_free(msg);
17142 return;
17143 }
17144
David S. Miller9360ffd2012-03-29 04:41:26 -040017145 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17146 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17147 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017148 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
17149 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053017150 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
17151 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
17152 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040017153 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010017154
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017155 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010017156
Johannes Berg68eb5502013-11-19 15:19:38 +010017157 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017158 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010017159 return;
17160
17161 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010017162 nlmsg_free(msg);
17163}
17164EXPORT_SYMBOL(cfg80211_probe_status);
17165
Thomas Pedersene76fede2020-04-30 10:25:50 -070017166void cfg80211_report_obss_beacon_khz(struct wiphy *wiphy, const u8 *frame,
17167 size_t len, int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010017168{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017169 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010017170 struct sk_buff *msg;
17171 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070017172 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010017173
Beni Lev4ee3e062012-08-27 12:49:39 +030017174 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
17175
Ben Greear37c73b52012-10-26 14:49:25 -070017176 spin_lock_bh(&rdev->beacon_registrations_lock);
17177 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
17178 msg = nlmsg_new(len + 100, GFP_ATOMIC);
17179 if (!msg) {
17180 spin_unlock_bh(&rdev->beacon_registrations_lock);
17181 return;
17182 }
Johannes Berg5e760232011-11-04 11:18:17 +010017183
Ben Greear37c73b52012-10-26 14:49:25 -070017184 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
17185 if (!hdr)
17186 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010017187
Ben Greear37c73b52012-10-26 14:49:25 -070017188 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17189 (freq &&
Thomas Pedersen942ba882020-04-30 10:25:51 -070017190 (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
17191 KHZ_TO_MHZ(freq)) ||
17192 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_OFFSET,
17193 freq % 1000))) ||
Ben Greear37c73b52012-10-26 14:49:25 -070017194 (sig_dbm &&
17195 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
17196 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
17197 goto nla_put_failure;
17198
17199 genlmsg_end(msg, hdr);
17200
17201 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010017202 }
Ben Greear37c73b52012-10-26 14:49:25 -070017203 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017204 return;
17205
17206 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070017207 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017208 nlmsg_free(msg);
17209}
Thomas Pedersene76fede2020-04-30 10:25:50 -070017210EXPORT_SYMBOL(cfg80211_report_obss_beacon_khz);
Johannes Berg5e760232011-11-04 11:18:17 +010017211
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017212#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017213static int cfg80211_net_detect_results(struct sk_buff *msg,
17214 struct cfg80211_wowlan_wakeup *wakeup)
17215{
17216 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
17217 struct nlattr *nl_results, *nl_match, *nl_freqs;
17218 int i, j;
17219
Michal Kubecekae0be8d2019-04-26 11:13:06 +020017220 nl_results = nla_nest_start_noflag(msg,
17221 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017222 if (!nl_results)
17223 return -EMSGSIZE;
17224
17225 for (i = 0; i < nd->n_matches; i++) {
17226 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
17227
Michal Kubecekae0be8d2019-04-26 11:13:06 +020017228 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017229 if (!nl_match)
17230 break;
17231
17232 /* The SSID attribute is optional in nl80211, but for
17233 * simplicity reasons it's always present in the
17234 * cfg80211 structure. If a driver can't pass the
17235 * SSID, that needs to be changed. A zero length SSID
17236 * is still a valid SSID (wildcard), so it cannot be
17237 * used for this purpose.
17238 */
17239 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
17240 match->ssid.ssid)) {
17241 nla_nest_cancel(msg, nl_match);
17242 goto out;
17243 }
17244
17245 if (match->n_channels) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020017246 nl_freqs = nla_nest_start_noflag(msg,
17247 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017248 if (!nl_freqs) {
17249 nla_nest_cancel(msg, nl_match);
17250 goto out;
17251 }
17252
17253 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020017254 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017255 nla_nest_cancel(msg, nl_freqs);
17256 nla_nest_cancel(msg, nl_match);
17257 goto out;
17258 }
17259 }
17260
17261 nla_nest_end(msg, nl_freqs);
17262 }
17263
17264 nla_nest_end(msg, nl_match);
17265 }
17266
17267out:
17268 nla_nest_end(msg, nl_results);
17269 return 0;
17270}
17271
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017272void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
17273 struct cfg80211_wowlan_wakeup *wakeup,
17274 gfp_t gfp)
17275{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017276 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017277 struct sk_buff *msg;
17278 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017279 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017280
17281 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
17282
17283 if (wakeup)
17284 size += wakeup->packet_present_len;
17285
17286 msg = nlmsg_new(size, gfp);
17287 if (!msg)
17288 return;
17289
17290 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
17291 if (!hdr)
17292 goto free_msg;
17293
17294 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017295 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17296 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017297 goto free_msg;
17298
17299 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
17300 wdev->netdev->ifindex))
17301 goto free_msg;
17302
17303 if (wakeup) {
17304 struct nlattr *reasons;
17305
Michal Kubecekae0be8d2019-04-26 11:13:06 +020017306 reasons = nla_nest_start_noflag(msg,
17307 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020017308 if (!reasons)
17309 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017310
17311 if (wakeup->disconnect &&
17312 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
17313 goto free_msg;
17314 if (wakeup->magic_pkt &&
17315 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
17316 goto free_msg;
17317 if (wakeup->gtk_rekey_failure &&
17318 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
17319 goto free_msg;
17320 if (wakeup->eap_identity_req &&
17321 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
17322 goto free_msg;
17323 if (wakeup->four_way_handshake &&
17324 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
17325 goto free_msg;
17326 if (wakeup->rfkill_release &&
17327 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
17328 goto free_msg;
17329
17330 if (wakeup->pattern_idx >= 0 &&
17331 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
17332 wakeup->pattern_idx))
17333 goto free_msg;
17334
Johannes Bergae917c92013-10-25 11:05:22 +020017335 if (wakeup->tcp_match &&
17336 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
17337 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010017338
Johannes Bergae917c92013-10-25 11:05:22 +020017339 if (wakeup->tcp_connlost &&
17340 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
17341 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010017342
Johannes Bergae917c92013-10-25 11:05:22 +020017343 if (wakeup->tcp_nomoretokens &&
17344 nla_put_flag(msg,
17345 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
17346 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010017347
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017348 if (wakeup->packet) {
17349 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
17350 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
17351
17352 if (!wakeup->packet_80211) {
17353 pkt_attr =
17354 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
17355 len_attr =
17356 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
17357 }
17358
17359 if (wakeup->packet_len &&
17360 nla_put_u32(msg, len_attr, wakeup->packet_len))
17361 goto free_msg;
17362
17363 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
17364 wakeup->packet))
17365 goto free_msg;
17366 }
17367
Luciano Coelho8cd4d452014-09-17 11:55:28 +030017368 if (wakeup->net_detect &&
17369 cfg80211_net_detect_results(msg, wakeup))
17370 goto free_msg;
17371
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017372 nla_nest_end(msg, reasons);
17373 }
17374
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017375 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017376
Johannes Berg68eb5502013-11-19 15:19:38 +010017377 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017378 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010017379 return;
17380
17381 free_msg:
17382 nlmsg_free(msg);
17383}
17384EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
17385#endif
17386
Jouni Malinen3475b092012-11-16 22:49:57 +020017387void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
17388 enum nl80211_tdls_operation oper,
17389 u16 reason_code, gfp_t gfp)
17390{
17391 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017392 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020017393 struct sk_buff *msg;
17394 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020017395
17396 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
17397 reason_code);
17398
17399 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17400 if (!msg)
17401 return;
17402
17403 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
17404 if (!hdr) {
17405 nlmsg_free(msg);
17406 return;
17407 }
17408
17409 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17410 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17411 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
17412 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
17413 (reason_code > 0 &&
17414 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
17415 goto nla_put_failure;
17416
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017417 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020017418
Johannes Berg68eb5502013-11-19 15:19:38 +010017419 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017420 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020017421 return;
17422
17423 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020017424 nlmsg_free(msg);
17425}
17426EXPORT_SYMBOL(cfg80211_tdls_oper_request);
17427
Jouni Malinen026331c2010-02-15 12:53:10 +020017428static int nl80211_netlink_notify(struct notifier_block * nb,
17429 unsigned long state,
17430 void *_notify)
17431{
17432 struct netlink_notify *notify = _notify;
17433 struct cfg80211_registered_device *rdev;
17434 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070017435 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020017436
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030017437 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020017438 return NOTIFY_DONE;
17439
17440 rcu_read_lock();
17441
Johannes Berg5e760232011-11-04 11:18:17 +010017442 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017443 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020017444
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017445 list_for_each_entry_rcu(sched_scan_req,
17446 &rdev->sched_scan_req_list,
17447 list) {
17448 if (sched_scan_req->owner_nlportid == notify->portid) {
17449 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010017450 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017451 }
Johannes Berg753aacf2017-01-05 10:57:14 +010017452 }
Johannes Berg78f22b62014-03-24 17:57:27 +010017453
Johannes Berg53873f12016-05-03 16:52:04 +030017454 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000017455 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070017456
Johannes Bergab810072017-04-26 07:43:41 +020017457 if (wdev->owner_nlportid == notify->portid) {
17458 wdev->nl_owner_dead = true;
17459 schedule_work(&rdev->destroy_work);
17460 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050017461 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020017462 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020017463
17464 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010017465 }
17466
Ben Greear37c73b52012-10-26 14:49:25 -070017467 spin_lock_bh(&rdev->beacon_registrations_lock);
17468 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
17469 list) {
17470 if (reg->nlportid == notify->portid) {
17471 list_del(&reg->list);
17472 kfree(reg);
17473 break;
17474 }
17475 }
17476 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017477 }
Jouni Malinen026331c2010-02-15 12:53:10 +020017478
17479 rcu_read_unlock();
17480
Ilan peer05050752015-03-04 00:32:06 -050017481 /*
17482 * It is possible that the user space process that is controlling the
17483 * indoor setting disappeared, so notify the regulatory core.
17484 */
17485 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080017486 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020017487}
17488
17489static struct notifier_block nl80211_netlink_notifier = {
17490 .notifier_call = nl80211_netlink_notify,
17491};
17492
Jouni Malinen355199e2013-02-27 17:14:27 +020017493void cfg80211_ft_event(struct net_device *netdev,
17494 struct cfg80211_ft_event_params *ft_event)
17495{
17496 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017497 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020017498 struct sk_buff *msg;
17499 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020017500
17501 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
17502
17503 if (!ft_event->target_ap)
17504 return;
17505
Dedy Lansky1039d082018-05-17 16:25:03 +030017506 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
17507 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020017508 if (!msg)
17509 return;
17510
17511 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020017512 if (!hdr)
17513 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020017514
Johannes Bergae917c92013-10-25 11:05:22 +020017515 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17516 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17517 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
17518 goto out;
17519
17520 if (ft_event->ies &&
17521 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
17522 goto out;
17523 if (ft_event->ric_ies &&
17524 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
17525 ft_event->ric_ies))
17526 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020017527
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017528 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020017529
Johannes Berg68eb5502013-11-19 15:19:38 +010017530 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017531 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020017532 return;
17533 out:
17534 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020017535}
17536EXPORT_SYMBOL(cfg80211_ft_event);
17537
Arend van Spriel5de17982013-04-18 15:49:00 +020017538void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
17539{
17540 struct cfg80211_registered_device *rdev;
17541 struct sk_buff *msg;
17542 void *hdr;
17543 u32 nlportid;
17544
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017545 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020017546 if (!rdev->crit_proto_nlportid)
17547 return;
17548
17549 nlportid = rdev->crit_proto_nlportid;
17550 rdev->crit_proto_nlportid = 0;
17551
17552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17553 if (!msg)
17554 return;
17555
17556 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
17557 if (!hdr)
17558 goto nla_put_failure;
17559
17560 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017561 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17562 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020017563 goto nla_put_failure;
17564
17565 genlmsg_end(msg, hdr);
17566
17567 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
17568 return;
17569
17570 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020017571 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020017572}
17573EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
17574
Johannes Berg348baf02014-01-24 14:06:29 +010017575void nl80211_send_ap_stopped(struct wireless_dev *wdev)
17576{
17577 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017578 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010017579 struct sk_buff *msg;
17580 void *hdr;
17581
17582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17583 if (!msg)
17584 return;
17585
17586 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
17587 if (!hdr)
17588 goto out;
17589
17590 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17591 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017592 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17593 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010017594 goto out;
17595
17596 genlmsg_end(msg, hdr);
17597
17598 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
17599 NL80211_MCGRP_MLME, GFP_KERNEL);
17600 return;
17601 out:
17602 nlmsg_free(msg);
17603}
17604
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020017605int cfg80211_external_auth_request(struct net_device *dev,
17606 struct cfg80211_external_auth_params *params,
17607 gfp_t gfp)
17608{
17609 struct wireless_dev *wdev = dev->ieee80211_ptr;
17610 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17611 struct sk_buff *msg;
17612 void *hdr;
17613
17614 if (!wdev->conn_owner_nlportid)
17615 return -EINVAL;
17616
17617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17618 if (!msg)
17619 return -ENOMEM;
17620
17621 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
17622 if (!hdr)
17623 goto nla_put_failure;
17624
17625 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17626 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17627 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
17628 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
17629 params->action) ||
17630 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
17631 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
17632 params->ssid.ssid))
17633 goto nla_put_failure;
17634
17635 genlmsg_end(msg, hdr);
17636 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
17637 wdev->conn_owner_nlportid);
17638 return 0;
17639
17640 nla_put_failure:
17641 nlmsg_free(msg);
17642 return -ENOBUFS;
17643}
17644EXPORT_SYMBOL(cfg80211_external_auth_request);
17645
Sunil Duttcb74e972019-02-20 16:18:07 +053017646void cfg80211_update_owe_info_event(struct net_device *netdev,
17647 struct cfg80211_update_owe_info *owe_info,
17648 gfp_t gfp)
17649{
17650 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
17651 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17652 struct sk_buff *msg;
17653 void *hdr;
17654
17655 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
17656
17657 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17658 if (!msg)
17659 return;
17660
17661 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
17662 if (!hdr)
17663 goto nla_put_failure;
17664
17665 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17666 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17667 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
17668 goto nla_put_failure;
17669
17670 if (!owe_info->ie_len ||
17671 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
17672 goto nla_put_failure;
17673
17674 genlmsg_end(msg, hdr);
17675
17676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17677 NL80211_MCGRP_MLME, gfp);
17678 return;
17679
17680nla_put_failure:
17681 genlmsg_cancel(msg, hdr);
17682 nlmsg_free(msg);
17683}
17684EXPORT_SYMBOL(cfg80211_update_owe_info_event);
17685
Johannes Berg55682962007-09-20 13:09:35 -040017686/* initialisation/exit functions */
17687
Johannes Berg56989f62016-10-24 14:40:05 +020017688int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040017689{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000017690 int err;
Johannes Berg55682962007-09-20 13:09:35 -040017691
Johannes Berg489111e2016-10-24 14:40:03 +020017692 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040017693 if (err)
17694 return err;
17695
Jouni Malinen026331c2010-02-15 12:53:10 +020017696 err = netlink_register_notifier(&nl80211_netlink_notifier);
17697 if (err)
17698 goto err_out;
17699
Johannes Berg55682962007-09-20 13:09:35 -040017700 return 0;
17701 err_out:
17702 genl_unregister_family(&nl80211_fam);
17703 return err;
17704}
17705
17706void nl80211_exit(void)
17707{
Jouni Malinen026331c2010-02-15 12:53:10 +020017708 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040017709 genl_unregister_family(&nl80211_fam);
17710}