blob: 56ac851ccee16b047293b062e8eb2e1613d58c2a [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
Johannes Berg55c1fdf2019-02-06 13:17:19 +02008 * Copyright (C) 2018-2019 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 Berg463d0182009-07-14 00:33:35 +020023#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include <net/genetlink.h>
25#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020026#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010027#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040028#include "core.h"
29#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070030#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030031#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040032
Jouni Malinen5fb628e2011-08-10 23:54:35 +030033static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
34 struct genl_info *info,
35 struct cfg80211_crypto_settings *settings,
36 int cipher_limit);
37
Johannes Berg55682962007-09-20 13:09:35 -040038/* the netlink family */
Johannes Berg489111e2016-10-24 14:40:03 +020039static struct genl_family nl80211_fam;
Johannes Berg55682962007-09-20 13:09:35 -040040
Johannes Berg2a94fe42013-11-19 15:19:39 +010041/* multicast groups */
42enum nl80211_multicast_groups {
43 NL80211_MCGRP_CONFIG,
44 NL80211_MCGRP_SCAN,
45 NL80211_MCGRP_REGULATORY,
46 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010047 NL80211_MCGRP_VENDOR,
Ayala Beker50bcd312016-09-20 17:31:17 +030048 NL80211_MCGRP_NAN,
Johannes Berg2a94fe42013-11-19 15:19:39 +010049 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
50};
51
52static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010053 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
54 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
55 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
56 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
57 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Ayala Beker50bcd312016-09-20 17:31:17 +030058 [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN },
Johannes Berg2a94fe42013-11-19 15:19:39 +010059#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010060 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010061#endif
62};
63
Johannes Berg89a54e42012-06-15 14:33:17 +020064/* returns ERR_PTR values */
65static struct wireless_dev *
66__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040067{
Johannes Berg89a54e42012-06-15 14:33:17 +020068 struct cfg80211_registered_device *rdev;
69 struct wireless_dev *result = NULL;
70 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
71 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
72 u64 wdev_id;
73 int wiphy_idx = -1;
74 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040075
Johannes Berg5fe231e2013-05-08 21:45:15 +020076 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040077
Johannes Berg89a54e42012-06-15 14:33:17 +020078 if (!have_ifidx && !have_wdev_id)
79 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040080
Johannes Berg89a54e42012-06-15 14:33:17 +020081 if (have_ifidx)
82 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
83 if (have_wdev_id) {
84 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
85 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040086 }
87
Johannes Berg89a54e42012-06-15 14:33:17 +020088 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
89 struct wireless_dev *wdev;
90
91 if (wiphy_net(&rdev->wiphy) != netns)
92 continue;
93
94 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
95 continue;
96
Johannes Berg53873f12016-05-03 16:52:04 +030097 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +020098 if (have_ifidx && wdev->netdev &&
99 wdev->netdev->ifindex == ifidx) {
100 result = wdev;
101 break;
102 }
103 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
104 result = wdev;
105 break;
106 }
107 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200108
109 if (result)
110 break;
111 }
112
113 if (result)
114 return result;
115 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400116}
117
Johannes Berga9455402012-06-15 13:32:49 +0200118static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200119__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200120{
Johannes Berg7fee47782012-06-15 14:09:58 +0200121 struct cfg80211_registered_device *rdev = NULL, *tmp;
122 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200123
Johannes Berg5fe231e2013-05-08 21:45:15 +0200124 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200125
Johannes Berg878d9ec2012-06-15 14:18:32 +0200126 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200127 !attrs[NL80211_ATTR_IFINDEX] &&
128 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200129 return ERR_PTR(-EINVAL);
130
Johannes Berg878d9ec2012-06-15 14:18:32 +0200131 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200132 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200133 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 if (attrs[NL80211_ATTR_WDEV]) {
136 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
137 struct wireless_dev *wdev;
138 bool found = false;
139
140 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
141 if (tmp) {
142 /* make sure wdev exists */
Johannes Berg53873f12016-05-03 16:52:04 +0300143 list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) {
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (wdev->identifier != (u32)wdev_id)
145 continue;
146 found = true;
147 break;
148 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200149
150 if (!found)
151 tmp = NULL;
152
153 if (rdev && tmp != rdev)
154 return ERR_PTR(-EINVAL);
155 rdev = tmp;
156 }
157 }
158
Johannes Berg878d9ec2012-06-15 14:18:32 +0200159 if (attrs[NL80211_ATTR_IFINDEX]) {
160 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -0700161
Ying Xue7f2b8562014-01-15 10:23:45 +0800162 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200163 if (netdev) {
164 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800165 tmp = wiphy_to_rdev(
166 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200167 else
168 tmp = NULL;
169
Johannes Berg7fee47782012-06-15 14:09:58 +0200170 /* not wireless device -- return error */
171 if (!tmp)
172 return ERR_PTR(-EINVAL);
173
174 /* mismatch -- return error */
175 if (rdev && tmp != rdev)
176 return ERR_PTR(-EINVAL);
177
178 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200179 }
Johannes Berga9455402012-06-15 13:32:49 +0200180 }
181
Johannes Berg4f7eff12012-06-15 14:14:22 +0200182 if (!rdev)
183 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200184
Johannes Berg4f7eff12012-06-15 14:14:22 +0200185 if (netns != wiphy_net(&rdev->wiphy))
186 return ERR_PTR(-ENODEV);
187
188 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200189}
190
191/*
192 * This function returns a pointer to the driver
193 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200194 *
195 * The result of this can be a PTR_ERR and hence must
196 * be checked with IS_ERR() for errors.
197 */
198static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200199cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200200{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200201 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200202}
203
Johannes Bergf88eb7c2019-09-20 21:54:17 +0200204static int validate_beacon_head(const struct nlattr *attr,
205 struct netlink_ext_ack *extack)
206{
207 const u8 *data = nla_data(attr);
208 unsigned int len = nla_len(attr);
209 const struct element *elem;
210 const struct ieee80211_mgmt *mgmt = (void *)data;
211 unsigned int fixedlen = offsetof(struct ieee80211_mgmt,
212 u.beacon.variable);
213
214 if (len < fixedlen)
215 goto err;
216
217 if (ieee80211_hdrlen(mgmt->frame_control) !=
218 offsetof(struct ieee80211_mgmt, u.beacon))
219 goto err;
220
221 data += fixedlen;
222 len -= fixedlen;
223
224 for_each_element(elem, data, len) {
225 /* nothing */
226 }
227
228 if (for_each_element_completed(elem, data, len))
229 return 0;
230
231err:
232 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed beacon head");
233 return -EINVAL;
234}
235
Johannes Berg3d7af872018-10-02 10:00:08 +0200236static int validate_ie_attr(const struct nlattr *attr,
237 struct netlink_ext_ack *extack)
238{
Johannes Berg9f308612019-02-07 23:39:19 +0100239 const u8 *data = nla_data(attr);
240 unsigned int len = nla_len(attr);
Jouni Malinen7388afe2019-02-11 16:29:04 +0200241 const struct element *elem;
Johannes Berg3d7af872018-10-02 10:00:08 +0200242
Johannes Berg9f308612019-02-07 23:39:19 +0100243 for_each_element(elem, data, len) {
244 /* nothing */
Johannes Berg3d7af872018-10-02 10:00:08 +0200245 }
246
Johannes Berg9f308612019-02-07 23:39:19 +0100247 if (for_each_element_completed(elem, data, len))
248 return 0;
249
Johannes Berg3d7af872018-10-02 10:00:08 +0200250 NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
251 return -EINVAL;
252}
253
Johannes Berg55682962007-09-20 13:09:35 -0400254/* policy for the attributes */
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700255static const struct nla_policy
256nl80211_ftm_responder_policy[NL80211_FTM_RESP_ATTR_MAX + 1] = {
257 [NL80211_FTM_RESP_ATTR_ENABLED] = { .type = NLA_FLAG, },
258 [NL80211_FTM_RESP_ATTR_LCI] = { .type = NLA_BINARY,
259 .len = U8_MAX },
260 [NL80211_FTM_RESP_ATTR_CIVICLOC] = { .type = NLA_BINARY,
261 .len = U8_MAX },
262};
263
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200264static const struct nla_policy
265nl80211_pmsr_ftm_req_attr_policy[NL80211_PMSR_FTM_REQ_ATTR_MAX + 1] = {
266 [NL80211_PMSR_FTM_REQ_ATTR_ASAP] = { .type = NLA_FLAG },
267 [NL80211_PMSR_FTM_REQ_ATTR_PREAMBLE] = { .type = NLA_U32 },
268 [NL80211_PMSR_FTM_REQ_ATTR_NUM_BURSTS_EXP] =
269 NLA_POLICY_MAX(NLA_U8, 15),
270 [NL80211_PMSR_FTM_REQ_ATTR_BURST_PERIOD] = { .type = NLA_U16 },
271 [NL80211_PMSR_FTM_REQ_ATTR_BURST_DURATION] =
272 NLA_POLICY_MAX(NLA_U8, 15),
273 [NL80211_PMSR_FTM_REQ_ATTR_FTMS_PER_BURST] =
Aviya Erenfeldea187092019-02-06 13:17:08 +0200274 NLA_POLICY_MAX(NLA_U8, 31),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200275 [NL80211_PMSR_FTM_REQ_ATTR_NUM_FTMR_RETRIES] = { .type = NLA_U8 },
276 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_LCI] = { .type = NLA_FLAG },
277 [NL80211_PMSR_FTM_REQ_ATTR_REQUEST_CIVICLOC] = { .type = NLA_FLAG },
278};
279
280static const struct nla_policy
281nl80211_pmsr_req_data_policy[NL80211_PMSR_TYPE_MAX + 1] = {
282 [NL80211_PMSR_TYPE_FTM] =
Johannes Berg23323282019-01-25 10:08:28 +0100283 NLA_POLICY_NESTED(nl80211_pmsr_ftm_req_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200284};
285
286static const struct nla_policy
287nl80211_pmsr_req_attr_policy[NL80211_PMSR_REQ_ATTR_MAX + 1] = {
288 [NL80211_PMSR_REQ_ATTR_DATA] =
Johannes Berg23323282019-01-25 10:08:28 +0100289 NLA_POLICY_NESTED(nl80211_pmsr_req_data_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200290 [NL80211_PMSR_REQ_ATTR_GET_AP_TSF] = { .type = NLA_FLAG },
291};
292
293static const struct nla_policy
294nl80211_psmr_peer_attr_policy[NL80211_PMSR_PEER_ATTR_MAX + 1] = {
295 [NL80211_PMSR_PEER_ATTR_ADDR] = NLA_POLICY_ETH_ADDR,
296 /*
297 * we could specify this again to be the top-level policy,
298 * but that would open us up to recursion problems ...
299 */
300 [NL80211_PMSR_PEER_ATTR_CHAN] = { .type = NLA_NESTED },
301 [NL80211_PMSR_PEER_ATTR_REQ] =
Johannes Berg23323282019-01-25 10:08:28 +0100302 NLA_POLICY_NESTED(nl80211_pmsr_req_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200303 [NL80211_PMSR_PEER_ATTR_RESP] = { .type = NLA_REJECT },
304};
305
306static const struct nla_policy
307nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {
308 [NL80211_PMSR_ATTR_MAX_PEERS] = { .type = NLA_REJECT },
309 [NL80211_PMSR_ATTR_REPORT_AP_TSF] = { .type = NLA_REJECT },
310 [NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR] = { .type = NLA_REJECT },
311 [NL80211_PMSR_ATTR_TYPE_CAPA] = { .type = NLA_REJECT },
312 [NL80211_PMSR_ATTR_PEERS] =
Johannes Berg23323282019-01-25 10:08:28 +0100313 NLA_POLICY_NESTED_ARRAY(nl80211_psmr_peer_attr_policy),
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200314};
315
John Crispin796e90f2019-07-30 18:37:00 +0200316static const struct nla_policy
317he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX + 1] = {
318 [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] =
319 NLA_POLICY_RANGE(NLA_U8, 1, 20),
320 [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET] =
321 NLA_POLICY_RANGE(NLA_U8, 1, 20),
322};
323
John Crispin5c5e52d2019-12-17 15:19:18 +0100324static const struct nla_policy
325he_bss_color_policy[NL80211_HE_BSS_COLOR_ATTR_MAX + 1] = {
326 [NL80211_HE_BSS_COLOR_ATTR_COLOR] = NLA_POLICY_RANGE(NLA_U8, 1, 63),
327 [NL80211_HE_BSS_COLOR_ATTR_DISABLED] = { .type = NLA_FLAG },
328 [NL80211_HE_BSS_COLOR_ATTR_PARTIAL] = { .type = NLA_FLAG },
329};
330
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530331static const struct nla_policy
332nl80211_tid_config_attr_policy[NL80211_TID_CONFIG_ATTR_MAX + 1] = {
Johannes Berg3710a8a2020-02-24 11:34:25 +0100333 [NL80211_TID_CONFIG_ATTR_VIF_SUPP] = { .type = NLA_U64 },
334 [NL80211_TID_CONFIG_ATTR_PEER_SUPP] = { .type = NLA_U64 },
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530335 [NL80211_TID_CONFIG_ATTR_OVERRIDE] = { .type = NLA_FLAG },
Johannes Berg3710a8a2020-02-24 11:34:25 +0100336 [NL80211_TID_CONFIG_ATTR_TIDS] = NLA_POLICY_RANGE(NLA_U16, 1, 0xff),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530337 [NL80211_TID_CONFIG_ATTR_NOACK] =
338 NLA_POLICY_MAX(NLA_U8, NL80211_TID_CONFIG_DISABLE),
339};
340
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200341const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg6d4dd4e2019-07-31 10:58:20 +0200342 [0] = { .strict_start_type = NL80211_ATTR_HE_OBSS_PD },
Johannes Berg55682962007-09-20 13:09:35 -0400343 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
344 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700345 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200346 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100347
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200348 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530349 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +0300350 [NL80211_ATTR_WIPHY_EDMG_CHANNELS] = NLA_POLICY_RANGE(NLA_U8,
351 NL80211_EDMG_CHANNELS_MIN,
352 NL80211_EDMG_CHANNELS_MAX),
353 [NL80211_ATTR_WIPHY_EDMG_BW_CONFIG] = NLA_POLICY_RANGE(NLA_U8,
354 NL80211_EDMG_BW_CONFIG_MIN,
355 NL80211_EDMG_BW_CONFIG_MAX),
356
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100357 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
358 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
359 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
360
Johannes Bergab0d76f2018-10-02 10:00:07 +0200361 [NL80211_ATTR_WIPHY_RETRY_SHORT] = NLA_POLICY_MIN(NLA_U8, 1),
362 [NL80211_ATTR_WIPHY_RETRY_LONG] = NLA_POLICY_MIN(NLA_U8, 1),
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200363 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
364 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100365 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200366 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400367
Johannes Bergab0d76f2018-10-02 10:00:07 +0200368 [NL80211_ATTR_IFTYPE] = NLA_POLICY_MAX(NLA_U32, NL80211_IFTYPE_MAX),
Johannes Berg55682962007-09-20 13:09:35 -0400369 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
370 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100371
Johannes Berg1a28ed22019-05-28 14:18:07 +0200372 [NL80211_ATTR_MAC] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
373 [NL80211_ATTR_PREV_BSSID] = {
374 .type = NLA_EXACT_LEN_WARN,
375 .len = ETH_ALEN
376 },
Johannes Berg41ade002007-12-19 02:03:29 +0100377
Johannes Bergb9454e82009-07-08 13:29:08 +0200378 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100379 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
380 .len = WLAN_MAX_KEY_LEN },
Jouni Malinen56be3932020-02-22 15:25:43 +0200381 [NL80211_ATTR_KEY_IDX] = NLA_POLICY_MAX(NLA_U8, 7),
Johannes Berg41ade002007-12-19 02:03:29 +0100382 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
383 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200384 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200385 [NL80211_ATTR_KEY_TYPE] =
386 NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES),
Johannes Berged1b6cc2007-12-19 02:03:32 +0100387
388 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
389 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
Johannes Bergf88eb7c2019-09-20 21:54:17 +0200390 [NL80211_ATTR_BEACON_HEAD] =
391 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_beacon_head,
392 IEEE80211_MAX_DATA_LEN),
Johannes Berg3d7af872018-10-02 10:00:08 +0200393 [NL80211_ATTR_BEACON_TAIL] =
394 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
395 IEEE80211_MAX_DATA_LEN),
Johannes Bergab0d76f2018-10-02 10:00:07 +0200396 [NL80211_ATTR_STA_AID] =
397 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Johannes Berg5727ef12007-12-19 02:03:34 +0100398 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
399 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
400 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
401 .len = NL80211_MAX_SUPP_RATES },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200402 [NL80211_ATTR_STA_PLINK_ACTION] =
403 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_ACTIONS - 1),
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +0530404 [NL80211_ATTR_STA_TX_POWER_SETTING] =
405 NLA_POLICY_RANGE(NLA_U8,
406 NL80211_TX_POWER_AUTOMATIC,
407 NL80211_TX_POWER_FIXED),
408 [NL80211_ATTR_STA_TX_POWER] = { .type = NLA_S16 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100409 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200410 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100411 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800412 .len = IEEE80211_MAX_MESH_ID_LEN },
Markus Theil1fab1b82019-10-29 10:30:03 +0100413 [NL80211_ATTR_MPATH_NEXT_HOP] = NLA_POLICY_ETH_ADDR_COMPAT,
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300414
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700415 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
416 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
417
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300418 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
419 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
420 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200421 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
422 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100423 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300424
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800425 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700426 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700427
Johannes Berg1a28ed22019-05-28 14:18:07 +0200428 [NL80211_ATTR_HT_CAPABILITY] = {
429 .type = NLA_EXACT_LEN_WARN,
430 .len = NL80211_HT_CAPABILITY_LEN
431 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200432
433 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
Johannes Berg3d7af872018-10-02 10:00:08 +0200434 [NL80211_ATTR_IE] = NLA_POLICY_VALIDATE_FN(NLA_BINARY,
435 validate_ie_attr,
436 IEEE80211_MAX_DATA_LEN),
Johannes Berg2a519312009-02-10 21:25:55 +0100437 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
438 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200439
440 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
441 .len = IEEE80211_MAX_SSID_LEN },
442 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
443 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200444 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300445 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200446 [NL80211_ATTR_USE_MFP] = NLA_POLICY_RANGE(NLA_U32,
447 NL80211_MFP_NO,
448 NL80211_MFP_OPTIONAL),
Johannes Bergeccb8e82009-05-11 21:57:56 +0300449 [NL80211_ATTR_STA_FLAGS2] = {
450 .len = sizeof(struct nl80211_sta_flag_update),
451 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300452 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300453 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
454 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Denis Kenzior64bf3d42018-03-26 12:52:43 -0500455 [NL80211_ATTR_CONTROL_PORT_OVER_NL80211] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200456 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
Sergey Matyukevichea750802020-02-13 13:16:16 +0000457 [NL80211_ATTR_STATUS_CODE] = { .type = NLA_U16 },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200458 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
459 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200460 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100461 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200462 [NL80211_ATTR_PMKID] = {
463 .type = NLA_EXACT_LEN_WARN,
464 .len = WLAN_PMKID_LEN
465 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100466 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
467 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200468 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200469 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
470 .len = IEEE80211_MAX_DATA_LEN },
471 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200472 [NL80211_ATTR_PS_STATE] = NLA_POLICY_RANGE(NLA_U32,
473 NL80211_PS_DISABLED,
474 NL80211_PS_ENABLED),
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200475 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300476 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200477 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300478 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
479 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200480 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900481 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
482 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100483 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100484 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100485 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200486 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200487 [NL80211_ATTR_STA_PLINK_STATE] =
488 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_PLINK_STATES - 1),
489 [NL80211_ATTR_MESH_PEER_AID] =
490 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300491 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200492 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200493 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200494 [NL80211_ATTR_HIDDEN_SSID] =
495 NLA_POLICY_RANGE(NLA_U32,
496 NL80211_HIDDEN_SSID_NOT_IN_USE,
497 NL80211_HIDDEN_SSID_ZERO_CONTENTS),
Johannes Berg3d7af872018-10-02 10:00:08 +0200498 [NL80211_ATTR_IE_PROBE_RESP] =
499 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
500 IEEE80211_MAX_DATA_LEN),
501 [NL80211_ATTR_IE_ASSOC_RESP] =
502 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
503 IEEE80211_MAX_DATA_LEN),
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530504 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300505 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530506 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300507 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
508 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
509 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
510 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
511 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300512 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100513 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200514 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
515 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700516 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800517 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
518 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
519 .len = NL80211_HT_CAPABILITY_LEN
520 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100521 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530522 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530523 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200524 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700525 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinen11b6b5a2016-10-27 00:41:58 +0300526 [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200527 [NL80211_ATTR_VHT_CAPABILITY] = {
528 .type = NLA_EXACT_LEN_WARN,
529 .len = NL80211_VHT_CAPABILITY_LEN
530 },
Sam Lefflered4737712012-10-11 21:03:31 -0700531 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200532 [NL80211_ATTR_P2P_CTWINDOW] = NLA_POLICY_MAX(NLA_U8, 127),
533 [NL80211_ATTR_P2P_OPPPS] = NLA_POLICY_MAX(NLA_U8, 1),
534 [NL80211_ATTR_LOCAL_MESH_POWER_MODE] =
535 NLA_POLICY_RANGE(NLA_U32,
536 NL80211_MESH_POWER_UNKNOWN + 1,
537 NL80211_MESH_POWER_MAX),
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530538 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
539 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200540 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
541 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100542 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100543 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
544 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
545 .len = NL80211_VHT_CAPABILITY_LEN,
546 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200547 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
548 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
549 .len = IEEE80211_MAX_DATA_LEN },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200550 [NL80211_ATTR_PEER_AID] =
551 NLA_POLICY_RANGE(NLA_U16, 1, IEEE80211_MAX_AID),
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200552 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
553 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
554 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300555 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
556 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530557 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
558 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200559 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100560 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100561 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
562 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
563 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800564 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
565 .len = IEEE80211_QOS_MAP_LEN_MAX },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200566 [NL80211_ATTR_MAC_HINT] = {
567 .type = NLA_EXACT_LEN_WARN,
568 .len = ETH_ALEN
569 },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200570 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530571 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200572 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300573 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300574 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200575 [NL80211_ATTR_TSID] = NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_TIDS - 1),
576 [NL80211_ATTR_USER_PRIO] =
577 NLA_POLICY_MAX(NLA_U8, IEEE80211_NUM_UPS - 1),
Johannes Berg960d01a2014-09-09 22:55:35 +0300578 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300579 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200580 [NL80211_ATTR_MAC_MASK] = {
581 .type = NLA_EXACT_LEN_WARN,
582 .len = ETH_ALEN
583 },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200584 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200585 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200586 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500587 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200588 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Arend van Spriel38de03d2016-03-02 20:37:18 +0100589 [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200590 [NL80211_ATTR_STA_SUPPORT_P2P_PS] =
591 NLA_POLICY_MAX(NLA_U8, NUM_NL80211_P2P_PS_STATUS - 1),
Aviya Erenfeldc6e6a0c2016-07-05 15:23:08 +0300592 [NL80211_ATTR_MU_MIMO_GROUP_DATA] = {
593 .len = VHT_MUMIMO_GROUPS_DATA_LEN
594 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200595 [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = {
596 .type = NLA_EXACT_LEN_WARN,
597 .len = ETH_ALEN
598 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200599 [NL80211_ATTR_NAN_MASTER_PREF] = NLA_POLICY_MIN(NLA_U8, 1),
Luca Coelho85859892017-02-08 15:00:34 +0200600 [NL80211_ATTR_BANDS] = { .type = NLA_U32 },
Ayala Bekera442b762016-09-20 17:31:15 +0300601 [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED },
Jouni Malinen348bd452016-10-27 00:42:03 +0300602 [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY,
603 .len = FILS_MAX_KEK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200604 [NL80211_ATTR_FILS_NONCES] = {
605 .type = NLA_EXACT_LEN_WARN,
606 .len = 2 * FILS_NONCE_LEN
607 },
Michael Braunce0ce132016-10-10 19:12:22 +0200608 [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200609 [NL80211_ATTR_BSSID] = { .type = NLA_EXACT_LEN_WARN, .len = ETH_ALEN },
vamsi krishnabf95ecd2017-01-13 01:12:20 +0200610 [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 },
611 [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = {
612 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
613 },
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +0200614 [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300615 [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY,
616 .len = FILS_ERP_MAX_USERNAME_LEN },
617 [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY,
618 .len = FILS_ERP_MAX_REALM_LEN },
619 [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 },
620 [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY,
621 .len = FILS_ERP_MAX_RRK_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200622 [NL80211_ATTR_FILS_CACHE_ID] = { .type = NLA_EXACT_LEN_WARN, .len = 2 },
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +0300623 [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN },
Arend Van Sprielca986ad2017-04-21 13:05:00 +0100624 [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +0200625 [NL80211_ATTR_EXTERNAL_AUTH_SUPPORT] = { .type = NLA_FLAG },
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +0200626
627 [NL80211_ATTR_TXQ_LIMIT] = { .type = NLA_U32 },
628 [NL80211_ATTR_TXQ_MEMORY_LIMIT] = { .type = NLA_U32 },
629 [NL80211_ATTR_TXQ_QUANTUM] = { .type = NLA_U32 },
Luca Coelhoc4cbaf72018-06-09 09:14:42 +0300630 [NL80211_ATTR_HE_CAPABILITY] = { .type = NLA_BINARY,
631 .len = NL80211_HE_MAX_CAPABILITY_LEN },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -0700632
633 [NL80211_ATTR_FTM_RESPONDER] = {
634 .type = NLA_NESTED,
635 .validation_data = nl80211_ftm_responder_policy,
636 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200637 [NL80211_ATTR_TIMEOUT] = NLA_POLICY_MIN(NLA_U32, 1),
638 [NL80211_ATTR_PEER_MEASUREMENTS] =
Johannes Berg23323282019-01-25 10:08:28 +0100639 NLA_POLICY_NESTED(nl80211_pmsr_attr_policy),
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -0800640 [NL80211_ATTR_AIRTIME_WEIGHT] = NLA_POLICY_MIN(NLA_U16, 1),
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +0000641 [NL80211_ATTR_SAE_PASSWORD] = { .type = NLA_BINARY,
642 .len = SAE_PASSWORD_MAX_LEN },
John Crispina0de1ca32019-05-28 13:49:48 +0200643 [NL80211_ATTR_TWT_RESPONDER] = { .type = NLA_FLAG },
John Crispin796e90f2019-07-30 18:37:00 +0200644 [NL80211_ATTR_HE_OBSS_PD] = NLA_POLICY_NESTED(he_obss_pd_policy),
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +0200645 [NL80211_ATTR_VLAN_ID] = NLA_POLICY_RANGE(NLA_U16, 1, VLAN_N_VID - 2),
John Crispin5c5e52d2019-12-17 15:19:18 +0100646 [NL80211_ATTR_HE_BSS_COLOR] = NLA_POLICY_NESTED(he_bss_color_policy),
Tamizh chelvam77f576d2020-01-20 13:21:22 +0530647 [NL80211_ATTR_TID_CONFIG] =
648 NLA_POLICY_NESTED_ARRAY(nl80211_tid_config_attr_policy),
Johannes Berg55682962007-09-20 13:09:35 -0400649};
650
Johannes Berge31b8212010-10-05 19:39:30 +0200651/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000652static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200653 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200654 [NL80211_KEY_IDX] = { .type = NLA_U8 },
655 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200656 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200657 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
658 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200659 [NL80211_KEY_TYPE] = NLA_POLICY_MAX(NLA_U32, NUM_NL80211_KEYTYPES - 1),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100660 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Alexander Wetzel6cdd3972019-03-19 21:34:07 +0100661 [NL80211_KEY_MODE] = NLA_POLICY_RANGE(NLA_U8, 0, NL80211_KEY_SET_TX),
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100662};
663
664/* policy for the key default flags */
665static const struct nla_policy
666nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
667 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
668 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200669};
670
Johannes Bergf83ace32016-10-17 08:04:07 +0200671#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +0200672/* policy for WoWLAN attributes */
673static const struct nla_policy
674nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
675 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
676 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
677 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
678 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200679 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
680 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
681 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
682 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100683 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300684 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100685};
686
687static const struct nla_policy
688nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
689 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
690 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200691 [NL80211_WOWLAN_TCP_DST_MAC] = {
692 .type = NLA_EXACT_LEN_WARN,
693 .len = ETH_ALEN
694 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100695 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
696 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200697 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100698 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
699 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
700 },
701 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
702 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
703 },
704 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200705 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .type = NLA_MIN_LEN, .len = 1 },
706 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .type = NLA_MIN_LEN, .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200707};
Johannes Bergf83ace32016-10-17 08:04:07 +0200708#endif /* CONFIG_PM */
Johannes Bergff1b6e62011-05-04 15:37:28 +0200709
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700710/* policy for coalesce rule attributes */
711static const struct nla_policy
712nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
713 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +0200714 [NL80211_ATTR_COALESCE_RULE_CONDITION] =
715 NLA_POLICY_RANGE(NLA_U32,
716 NL80211_COALESCE_CONDITION_MATCH,
717 NL80211_COALESCE_CONDITION_NO_MATCH),
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700718 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
719};
720
Johannes Berge5497d72011-07-05 16:35:40 +0200721/* policy for GTK rekey offload attributes */
722static const struct nla_policy
723nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
Johannes Berg180aa422019-05-28 14:19:07 +0200724 [NL80211_REKEY_DATA_KEK] = {
725 .type = NLA_EXACT_LEN_WARN,
726 .len = NL80211_KEK_LEN,
727 },
728 [NL80211_REKEY_DATA_KCK] = {
729 .type = NLA_EXACT_LEN_WARN,
730 .len = NL80211_KCK_LEN,
731 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200732 [NL80211_REKEY_DATA_REPLAY_CTR] = {
733 .type = NLA_EXACT_LEN_WARN,
734 .len = NL80211_REPLAY_CTR_LEN
735 },
Johannes Berge5497d72011-07-05 16:35:40 +0200736};
737
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300738static const struct nla_policy
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530739nl80211_match_band_rssi_policy[NUM_NL80211_BANDS] = {
740 [NL80211_BAND_2GHZ] = { .type = NLA_S32 },
741 [NL80211_BAND_5GHZ] = { .type = NLA_S32 },
Arend van Spriele548a1c2019-08-02 13:31:02 +0200742 [NL80211_BAND_6GHZ] = { .type = NLA_S32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530743 [NL80211_BAND_60GHZ] = { .type = NLA_S32 },
744};
745
746static const struct nla_policy
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300747nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200748 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300749 .len = IEEE80211_MAX_SSID_LEN },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200750 [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = {
751 .type = NLA_EXACT_LEN_WARN,
752 .len = ETH_ALEN
753 },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700754 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
vamsi krishna1e1b11b2019-02-01 18:34:51 +0530755 [NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI] =
756 NLA_POLICY_NESTED(nl80211_match_band_rssi_policy),
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300757};
758
Avraham Stern3b06d272015-10-12 09:51:34 +0300759static const struct nla_policy
760nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
761 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
762 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
763};
764
Arend van Spriel38de03d2016-03-02 20:37:18 +0100765static const struct nla_policy
766nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = {
767 [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG },
768 [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 },
769 [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = {
770 .len = sizeof(struct nl80211_bss_select_rssi_adjust)
771 },
772};
773
Ayala Bekera442b762016-09-20 17:31:15 +0300774/* policy for NAN function attributes */
775static const struct nla_policy
776nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = {
777 [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 },
Srinivas Dasari0a278442017-07-07 01:43:40 +0300778 [NL80211_NAN_FUNC_SERVICE_ID] = {
Ayala Bekera442b762016-09-20 17:31:15 +0300779 .len = NL80211_NAN_FUNC_SERVICE_ID_LEN },
780 [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 },
781 [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG },
782 [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG },
783 [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 },
784 [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 },
Johannes Berg1a28ed22019-05-28 14:18:07 +0200785 [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = {
786 .type = NLA_EXACT_LEN_WARN,
787 .len = ETH_ALEN
788 },
Ayala Bekera442b762016-09-20 17:31:15 +0300789 [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG },
790 [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 },
791 [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY,
792 .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN },
793 [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED },
794 [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED },
795 [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED },
796 [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 },
797 [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 },
798};
799
800/* policy for Service Response Filter attributes */
801static const struct nla_policy
802nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = {
803 [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG },
804 [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY,
805 .len = NL80211_NAN_FUNC_SRF_MAX_LEN },
806 [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 },
807 [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED },
808};
809
Peng Xuad670232017-10-03 23:21:51 +0300810/* policy for packet pattern attributes */
811static const struct nla_policy
812nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = {
813 [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, },
814 [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, },
815 [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 },
816};
817
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200818int nl80211_prepare_wdev_dump(struct netlink_callback *cb,
819 struct cfg80211_registered_device **rdev,
820 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100821{
Johannes Berg67748892010-10-04 21:14:06 +0200822 int err;
823
Johannes Berg97990a02013-04-19 01:02:55 +0200824 if (!cb->args[0]) {
Johannes Berg50508d92019-07-29 16:31:09 +0200825 struct nlattr **attrbuf;
826
827 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
828 GFP_KERNEL);
829 if (!attrbuf)
830 return -ENOMEM;
831
Johannes Berg8cb08172019-04-26 14:07:28 +0200832 err = nlmsg_parse_deprecated(cb->nlh,
833 GENL_HDRLEN + nl80211_fam.hdrsize,
Johannes Berg50508d92019-07-29 16:31:09 +0200834 attrbuf, nl80211_fam.maxattr,
Johannes Berg8cb08172019-04-26 14:07:28 +0200835 nl80211_policy, NULL);
Johannes Berg50508d92019-07-29 16:31:09 +0200836 if (err) {
837 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100838 return err;
Johannes Berg50508d92019-07-29 16:31:09 +0200839 }
Johannes Berg97990a02013-04-19 01:02:55 +0200840
Johannes Berg50508d92019-07-29 16:31:09 +0200841 *wdev = __cfg80211_wdev_from_attrs(sock_net(cb->skb->sk),
842 attrbuf);
843 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +0100844 if (IS_ERR(*wdev))
845 return PTR_ERR(*wdev);
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800846 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200847 /* 0 is the first index - add 1 to parse only once */
848 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200849 cb->args[1] = (*wdev)->identifier;
850 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200851 /* subtract the 1 again here */
852 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200853 struct wireless_dev *tmp;
854
Johannes Bergea90e0d2017-03-15 14:26:04 +0100855 if (!wiphy)
856 return -ENODEV;
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800857 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200858 *wdev = NULL;
859
Johannes Berg53873f12016-05-03 16:52:04 +0300860 list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) {
Johannes Berg97990a02013-04-19 01:02:55 +0200861 if (tmp->identifier == cb->args[1]) {
862 *wdev = tmp;
863 break;
864 }
865 }
Johannes Berg97990a02013-04-19 01:02:55 +0200866
Johannes Bergea90e0d2017-03-15 14:26:04 +0100867 if (!*wdev)
868 return -ENODEV;
Johannes Berg67748892010-10-04 21:14:06 +0200869 }
870
Johannes Berg67748892010-10-04 21:14:06 +0200871 return 0;
Johannes Berg67748892010-10-04 21:14:06 +0200872}
873
Johannes Berg55682962007-09-20 13:09:35 -0400874/* message building helper */
Johannes Berg9bb7e0f2018-09-10 13:29:12 +0200875void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
876 int flags, u8 cmd)
Johannes Berg55682962007-09-20 13:09:35 -0400877{
878 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000879 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400880}
881
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300882static int nl80211_msg_put_wmm_rules(struct sk_buff *msg,
883 const struct ieee80211_reg_rule *rule)
884{
885 int j;
886 struct nlattr *nl_wmm_rules =
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200887 nla_nest_start_noflag(msg, NL80211_FREQUENCY_ATTR_WMM);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300888
889 if (!nl_wmm_rules)
890 goto nla_put_failure;
891
892 for (j = 0; j < IEEE80211_NUM_ACS; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +0200893 struct nlattr *nl_wmm_rule = nla_nest_start_noflag(msg, j);
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300894
895 if (!nl_wmm_rule)
896 goto nla_put_failure;
897
898 if (nla_put_u16(msg, NL80211_WMMR_CW_MIN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200899 rule->wmm_rule.client[j].cw_min) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300900 nla_put_u16(msg, NL80211_WMMR_CW_MAX,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200901 rule->wmm_rule.client[j].cw_max) ||
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300902 nla_put_u8(msg, NL80211_WMMR_AIFSN,
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +0200903 rule->wmm_rule.client[j].aifsn) ||
Haim Dreyfussd3c89bb2018-08-21 09:22:19 +0300904 nla_put_u16(msg, NL80211_WMMR_TXOP,
905 rule->wmm_rule.client[j].cot))
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300906 goto nla_put_failure;
907
908 nla_nest_end(msg, nl_wmm_rule);
909 }
910 nla_nest_end(msg, nl_wmm_rules);
911
912 return 0;
913
914nla_put_failure:
915 return -ENOBUFS;
916}
917
918static int nl80211_msg_put_channel(struct sk_buff *msg, struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100919 struct ieee80211_channel *chan,
920 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400921{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200922 /* Some channels must be completely excluded from the
923 * list to protect old user-space tools from breaking
924 */
925 if (!large && chan->flags &
926 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
927 return 0;
928
David S. Miller9360ffd2012-03-29 04:41:26 -0400929 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
930 chan->center_freq))
931 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400932
David S. Miller9360ffd2012-03-29 04:41:26 -0400933 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
934 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
935 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200936 if (chan->flags & IEEE80211_CHAN_NO_IR) {
937 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
938 goto nla_put_failure;
939 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
940 goto nla_put_failure;
941 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100942 if (chan->flags & IEEE80211_CHAN_RADAR) {
943 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
944 goto nla_put_failure;
945 if (large) {
946 u32 time;
947
948 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
949
950 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
951 chan->dfs_state))
952 goto nla_put_failure;
953 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
954 time))
955 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100956 if (nla_put_u32(msg,
957 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
958 chan->dfs_cac_ms))
959 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100960 }
961 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400962
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100963 if (large) {
964 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
965 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
966 goto nla_put_failure;
967 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
968 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
969 goto nla_put_failure;
970 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
971 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
972 goto nla_put_failure;
973 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
974 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
975 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200976 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
977 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
978 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300979 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
980 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200981 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200982 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
983 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
984 goto nla_put_failure;
985 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
986 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
987 goto nla_put_failure;
Haim Dreyfuss1e61d822020-01-21 10:12:13 +0200988 if ((chan->flags & IEEE80211_CHAN_NO_HE) &&
989 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HE))
990 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100991 }
992
David S. Miller9360ffd2012-03-29 04:41:26 -0400993 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
994 DBM_TO_MBM(chan->max_power)))
995 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400996
Haim Dreyfuss50f32712018-04-20 13:49:26 +0300997 if (large) {
998 const struct ieee80211_reg_rule *rule =
Haim Dreyfussb88d26d2018-08-21 09:22:20 +0300999 freq_reg_info(wiphy, MHZ_TO_KHZ(chan->center_freq));
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001000
Stanislaw Gruszka38cb87e2018-08-22 13:52:21 +02001001 if (!IS_ERR_OR_NULL(rule) && rule->has_wmm) {
Haim Dreyfuss50f32712018-04-20 13:49:26 +03001002 if (nl80211_msg_put_wmm_rules(msg, rule))
1003 goto nla_put_failure;
1004 }
1005 }
1006
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -04001007 return 0;
1008
1009 nla_put_failure:
1010 return -ENOBUFS;
1011}
1012
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02001013static bool nl80211_put_txq_stats(struct sk_buff *msg,
1014 struct cfg80211_txq_stats *txqstats,
1015 int attrtype)
1016{
1017 struct nlattr *txqattr;
1018
1019#define PUT_TXQVAL_U32(attr, memb) do { \
1020 if (txqstats->filled & BIT(NL80211_TXQ_STATS_ ## attr) && \
1021 nla_put_u32(msg, NL80211_TXQ_STATS_ ## attr, txqstats->memb)) \
1022 return false; \
1023 } while (0)
1024
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001025 txqattr = nla_nest_start_noflag(msg, attrtype);
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02001026 if (!txqattr)
1027 return false;
1028
1029 PUT_TXQVAL_U32(BACKLOG_BYTES, backlog_bytes);
1030 PUT_TXQVAL_U32(BACKLOG_PACKETS, backlog_packets);
1031 PUT_TXQVAL_U32(FLOWS, flows);
1032 PUT_TXQVAL_U32(DROPS, drops);
1033 PUT_TXQVAL_U32(ECN_MARKS, ecn_marks);
1034 PUT_TXQVAL_U32(OVERLIMIT, overlimit);
1035 PUT_TXQVAL_U32(OVERMEMORY, overmemory);
1036 PUT_TXQVAL_U32(COLLISIONS, collisions);
1037 PUT_TXQVAL_U32(TX_BYTES, tx_bytes);
1038 PUT_TXQVAL_U32(TX_PACKETS, tx_packets);
1039 PUT_TXQVAL_U32(MAX_FLOWS, max_flows);
1040 nla_nest_end(msg, txqattr);
1041
1042#undef PUT_TXQVAL_U32
1043 return true;
1044}
1045
Johannes Berg55682962007-09-20 13:09:35 -04001046/* netlink command implementations */
1047
Johannes Bergb9454e82009-07-08 13:29:08 +02001048struct key_parse {
1049 struct key_params p;
1050 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +02001051 int type;
Jouni Malinen56be3932020-02-22 15:25:43 +02001052 bool def, defmgmt, defbeacon;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001053 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +02001054};
1055
Johannes Berg768075e2017-11-13 15:35:06 +01001056static int nl80211_parse_key_new(struct genl_info *info, struct nlattr *key,
1057 struct key_parse *k)
Johannes Bergb9454e82009-07-08 13:29:08 +02001058{
1059 struct nlattr *tb[NL80211_KEY_MAX + 1];
Johannes Berg8cb08172019-04-26 14:07:28 +02001060 int err = nla_parse_nested_deprecated(tb, NL80211_KEY_MAX, key,
1061 nl80211_key_policy,
1062 info->extack);
Johannes Bergb9454e82009-07-08 13:29:08 +02001063 if (err)
1064 return err;
1065
1066 k->def = !!tb[NL80211_KEY_DEFAULT];
1067 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
Jouni Malinen56be3932020-02-22 15:25:43 +02001068 k->defbeacon = !!tb[NL80211_KEY_DEFAULT_BEACON];
Johannes Bergb9454e82009-07-08 13:29:08 +02001069
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001070 if (k->def) {
1071 k->def_uni = true;
1072 k->def_multi = true;
1073 }
Jouni Malinen56be3932020-02-22 15:25:43 +02001074 if (k->defmgmt || k->defbeacon)
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001075 k->def_multi = true;
1076
Johannes Bergb9454e82009-07-08 13:29:08 +02001077 if (tb[NL80211_KEY_IDX])
1078 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
1079
1080 if (tb[NL80211_KEY_DATA]) {
1081 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
1082 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
1083 }
1084
1085 if (tb[NL80211_KEY_SEQ]) {
1086 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
1087 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
1088 }
1089
1090 if (tb[NL80211_KEY_CIPHER])
1091 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
1092
Johannes Bergab0d76f2018-10-02 10:00:07 +02001093 if (tb[NL80211_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001094 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001095
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001096 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
1097 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07001098
Johannes Berg8cb08172019-04-26 14:07:28 +02001099 err = nla_parse_nested_deprecated(kdt,
1100 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1101 tb[NL80211_KEY_DEFAULT_TYPES],
1102 nl80211_key_default_policy,
1103 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001104 if (err)
1105 return err;
1106
1107 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1108 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1109 }
1110
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01001111 if (tb[NL80211_KEY_MODE])
1112 k->p.mode = nla_get_u8(tb[NL80211_KEY_MODE]);
1113
Johannes Bergb9454e82009-07-08 13:29:08 +02001114 return 0;
1115}
1116
1117static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
1118{
1119 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1120 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1121 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1122 }
1123
1124 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
1125 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
1126 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
1127 }
1128
1129 if (info->attrs[NL80211_ATTR_KEY_IDX])
1130 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1131
1132 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
1133 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1134
1135 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
1136 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
1137
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001138 if (k->def) {
1139 k->def_uni = true;
1140 k->def_multi = true;
1141 }
1142 if (k->defmgmt)
1143 k->def_multi = true;
1144
Johannes Bergab0d76f2018-10-02 10:00:07 +02001145 if (info->attrs[NL80211_ATTR_KEY_TYPE])
Johannes Berge31b8212010-10-05 19:39:30 +02001146 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Johannes Berge31b8212010-10-05 19:39:30 +02001147
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001148 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
1149 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg8cb08172019-04-26 14:07:28 +02001150 int err = nla_parse_nested_deprecated(kdt,
1151 NUM_NL80211_KEY_DEFAULT_TYPES - 1,
1152 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
1153 nl80211_key_default_policy,
1154 info->extack);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001155 if (err)
1156 return err;
1157
1158 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
1159 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
1160 }
1161
Johannes Bergb9454e82009-07-08 13:29:08 +02001162 return 0;
1163}
1164
1165static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
1166{
1167 int err;
1168
1169 memset(k, 0, sizeof(*k));
1170 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +02001171 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02001172
1173 if (info->attrs[NL80211_ATTR_KEY])
Johannes Berg768075e2017-11-13 15:35:06 +01001174 err = nl80211_parse_key_new(info, info->attrs[NL80211_ATTR_KEY], k);
Johannes Bergb9454e82009-07-08 13:29:08 +02001175 else
1176 err = nl80211_parse_key_old(info, k);
1177
1178 if (err)
1179 return err;
1180
Jouni Malinen56be3932020-02-22 15:25:43 +02001181 if ((k->def ? 1 : 0) + (k->defmgmt ? 1 : 0) +
1182 (k->defbeacon ? 1 : 0) > 1) {
1183 GENL_SET_ERR_MSG(info,
1184 "key with multiple default flags is invalid");
Johannes Bergb9454e82009-07-08 13:29:08 +02001185 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001186 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001187
Jouni Malinen56be3932020-02-22 15:25:43 +02001188 if (k->defmgmt || k->defbeacon) {
Johannes Berg768075e2017-11-13 15:35:06 +01001189 if (k->def_uni || !k->def_multi) {
Jouni Malinen56be3932020-02-22 15:25:43 +02001190 GENL_SET_ERR_MSG(info,
1191 "defmgmt/defbeacon key must be mcast");
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001192 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001193 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001194 }
1195
Johannes Bergb9454e82009-07-08 13:29:08 +02001196 if (k->idx != -1) {
1197 if (k->defmgmt) {
Johannes Berg768075e2017-11-13 15:35:06 +01001198 if (k->idx < 4 || k->idx > 5) {
1199 GENL_SET_ERR_MSG(info,
1200 "defmgmt key idx not 4 or 5");
Johannes Bergb9454e82009-07-08 13:29:08 +02001201 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001202 }
Jouni Malinen56be3932020-02-22 15:25:43 +02001203 } else if (k->defbeacon) {
1204 if (k->idx < 6 || k->idx > 7) {
1205 GENL_SET_ERR_MSG(info,
1206 "defbeacon key idx not 6 or 7");
1207 return -EINVAL;
1208 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001209 } else if (k->def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001210 if (k->idx < 0 || k->idx > 3) {
1211 GENL_SET_ERR_MSG(info, "def key idx not 0-3");
Johannes Bergb9454e82009-07-08 13:29:08 +02001212 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001213 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001214 } else {
Jouni Malinen56be3932020-02-22 15:25:43 +02001215 if (k->idx < 0 || k->idx > 7) {
1216 GENL_SET_ERR_MSG(info, "key idx not 0-7");
Johannes Bergb9454e82009-07-08 13:29:08 +02001217 return -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001218 }
Johannes Bergb9454e82009-07-08 13:29:08 +02001219 }
1220 }
1221
1222 return 0;
1223}
1224
Johannes Bergfffd0932009-07-08 14:22:54 +02001225static struct cfg80211_cached_keys *
1226nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Johannes Berg768075e2017-11-13 15:35:06 +01001227 struct genl_info *info, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +02001228{
Johannes Berg768075e2017-11-13 15:35:06 +01001229 struct nlattr *keys = info->attrs[NL80211_ATTR_KEYS];
Johannes Bergfffd0932009-07-08 14:22:54 +02001230 struct key_parse parse;
1231 struct nlattr *key;
1232 struct cfg80211_cached_keys *result;
1233 int rem, err, def = 0;
Johannes Bergf1c1f172016-09-13 17:08:23 +02001234 bool have_key = false;
1235
1236 nla_for_each_nested(key, keys, rem) {
1237 have_key = true;
1238 break;
1239 }
1240
1241 if (!have_key)
1242 return NULL;
Johannes Bergfffd0932009-07-08 14:22:54 +02001243
1244 result = kzalloc(sizeof(*result), GFP_KERNEL);
1245 if (!result)
1246 return ERR_PTR(-ENOMEM);
1247
1248 result->def = -1;
Johannes Bergfffd0932009-07-08 14:22:54 +02001249
1250 nla_for_each_nested(key, keys, rem) {
1251 memset(&parse, 0, sizeof(parse));
1252 parse.idx = -1;
1253
Johannes Berg768075e2017-11-13 15:35:06 +01001254 err = nl80211_parse_key_new(info, key, &parse);
Johannes Bergfffd0932009-07-08 14:22:54 +02001255 if (err)
1256 goto error;
1257 err = -EINVAL;
1258 if (!parse.p.key)
1259 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001260 if (parse.idx < 0 || parse.idx > 3) {
1261 GENL_SET_ERR_MSG(info, "key index out of range [0-3]");
Johannes Bergfffd0932009-07-08 14:22:54 +02001262 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001263 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001264 if (parse.def) {
Johannes Berg768075e2017-11-13 15:35:06 +01001265 if (def) {
1266 GENL_SET_ERR_MSG(info,
1267 "only one key can be default");
Johannes Bergfffd0932009-07-08 14:22:54 +02001268 goto error;
Johannes Berg768075e2017-11-13 15:35:06 +01001269 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001270 def = 1;
1271 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01001272 if (!parse.def_uni || !parse.def_multi)
1273 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +02001274 } else if (parse.defmgmt)
1275 goto error;
1276 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +02001277 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +02001278 if (err)
1279 goto error;
Johannes Berg386b1f22016-09-13 16:10:02 +02001280 if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1281 parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) {
Johannes Berg768075e2017-11-13 15:35:06 +01001282 GENL_SET_ERR_MSG(info, "connect key must be WEP");
Johannes Berg386b1f22016-09-13 16:10:02 +02001283 err = -EINVAL;
1284 goto error;
1285 }
Johannes Bergfffd0932009-07-08 14:22:54 +02001286 result->params[parse.idx].cipher = parse.p.cipher;
1287 result->params[parse.idx].key_len = parse.p.key_len;
1288 result->params[parse.idx].key = result->data[parse.idx];
1289 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +05301290
Johannes Berg386b1f22016-09-13 16:10:02 +02001291 /* must be WEP key if we got here */
1292 if (no_ht)
1293 *no_ht = true;
Johannes Bergfffd0932009-07-08 14:22:54 +02001294 }
1295
Johannes Bergf1c1f172016-09-13 17:08:23 +02001296 if (result->def < 0) {
1297 err = -EINVAL;
Johannes Berg768075e2017-11-13 15:35:06 +01001298 GENL_SET_ERR_MSG(info, "need a default/TX key");
Johannes Bergf1c1f172016-09-13 17:08:23 +02001299 goto error;
1300 }
1301
Johannes Bergfffd0932009-07-08 14:22:54 +02001302 return result;
1303 error:
1304 kfree(result);
1305 return ERR_PTR(err);
1306}
1307
1308static int nl80211_key_allowed(struct wireless_dev *wdev)
1309{
1310 ASSERT_WDEV_LOCK(wdev);
1311
Johannes Bergfffd0932009-07-08 14:22:54 +02001312 switch (wdev->iftype) {
1313 case NL80211_IFTYPE_AP:
1314 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001315 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -07001316 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +02001317 break;
1318 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +02001319 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +02001320 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +02001321 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +02001322 return -ENOLINK;
1323 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +01001324 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01001325 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001326 case NL80211_IFTYPE_MONITOR:
Ayala Bekercb3b7d82016-09-20 17:31:13 +03001327 case NL80211_IFTYPE_NAN:
Johannes Bergde4fcba2014-10-31 14:16:12 +01001328 case NL80211_IFTYPE_P2P_DEVICE:
1329 case NL80211_IFTYPE_WDS:
1330 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +02001331 return -EINVAL;
1332 }
1333
1334 return 0;
1335}
1336
Jouni Malinen664834d2014-01-15 00:01:44 +02001337static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
1338 struct nlattr *tb)
1339{
1340 struct ieee80211_channel *chan;
1341
1342 if (tb == NULL)
1343 return NULL;
1344 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
1345 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
1346 return NULL;
1347 return chan;
1348}
1349
Johannes Berg7527a782011-05-13 10:58:57 +02001350static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
1351{
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001352 struct nlattr *nl_modes = nla_nest_start_noflag(msg, attr);
Johannes Berg7527a782011-05-13 10:58:57 +02001353 int i;
1354
1355 if (!nl_modes)
1356 goto nla_put_failure;
1357
1358 i = 0;
1359 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -04001360 if ((ifmodes & 1) && nla_put_flag(msg, i))
1361 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001362 ifmodes >>= 1;
1363 i++;
1364 }
1365
1366 nla_nest_end(msg, nl_modes);
1367 return 0;
1368
1369nla_put_failure:
1370 return -ENOBUFS;
1371}
1372
1373static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +01001374 struct sk_buff *msg,
1375 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +02001376{
1377 struct nlattr *nl_combis;
1378 int i, j;
1379
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001380 nl_combis = nla_nest_start_noflag(msg,
1381 NL80211_ATTR_INTERFACE_COMBINATIONS);
Johannes Berg7527a782011-05-13 10:58:57 +02001382 if (!nl_combis)
1383 goto nla_put_failure;
1384
1385 for (i = 0; i < wiphy->n_iface_combinations; i++) {
1386 const struct ieee80211_iface_combination *c;
1387 struct nlattr *nl_combi, *nl_limits;
1388
1389 c = &wiphy->iface_combinations[i];
1390
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001391 nl_combi = nla_nest_start_noflag(msg, i + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001392 if (!nl_combi)
1393 goto nla_put_failure;
1394
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001395 nl_limits = nla_nest_start_noflag(msg,
1396 NL80211_IFACE_COMB_LIMITS);
Johannes Berg7527a782011-05-13 10:58:57 +02001397 if (!nl_limits)
1398 goto nla_put_failure;
1399
1400 for (j = 0; j < c->n_limits; j++) {
1401 struct nlattr *nl_limit;
1402
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001403 nl_limit = nla_nest_start_noflag(msg, j + 1);
Johannes Berg7527a782011-05-13 10:58:57 +02001404 if (!nl_limit)
1405 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04001406 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
1407 c->limits[j].max))
1408 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001409 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
1410 c->limits[j].types))
1411 goto nla_put_failure;
1412 nla_nest_end(msg, nl_limit);
1413 }
1414
1415 nla_nest_end(msg, nl_limits);
1416
David S. Miller9360ffd2012-03-29 04:41:26 -04001417 if (c->beacon_int_infra_match &&
1418 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
1419 goto nla_put_failure;
1420 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
1421 c->num_different_channels) ||
1422 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
1423 c->max_interfaces))
1424 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001425 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001426 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1427 c->radar_detect_widths) ||
1428 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1429 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001430 goto nla_put_failure;
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05301431 if (c->beacon_int_min_gcd &&
1432 nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD,
1433 c->beacon_int_min_gcd))
1434 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001435
1436 nla_nest_end(msg, nl_combi);
1437 }
1438
1439 nla_nest_end(msg, nl_combis);
1440
1441 return 0;
1442nla_put_failure:
1443 return -ENOBUFS;
1444}
1445
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001447static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1448 struct sk_buff *msg)
1449{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001450 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001451 struct nlattr *nl_tcp;
1452
1453 if (!tcp)
1454 return 0;
1455
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001456 nl_tcp = nla_nest_start_noflag(msg,
1457 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Bergb56cf722013-02-20 01:02:38 +01001458 if (!nl_tcp)
1459 return -ENOBUFS;
1460
1461 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1462 tcp->data_payload_max))
1463 return -ENOBUFS;
1464
1465 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1466 tcp->data_payload_max))
1467 return -ENOBUFS;
1468
1469 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1470 return -ENOBUFS;
1471
1472 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1473 sizeof(*tcp->tok), tcp->tok))
1474 return -ENOBUFS;
1475
1476 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1477 tcp->data_interval_max))
1478 return -ENOBUFS;
1479
1480 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1481 tcp->wake_payload_max))
1482 return -ENOBUFS;
1483
1484 nla_nest_end(msg, nl_tcp);
1485 return 0;
1486}
1487
Johannes Berg3713b4e2013-02-14 16:19:38 +01001488static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001489 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001490 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491{
1492 struct nlattr *nl_wowlan;
1493
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 return 0;
1496
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001497 nl_wowlan = nla_nest_start_noflag(msg,
1498 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 if (!nl_wowlan)
1500 return -ENOBUFS;
1501
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001504 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001508 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001509 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001512 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001513 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001516 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1518 return -ENOBUFS;
1519
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001520 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001521 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1523 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1524 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1525 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001526 };
1527
1528 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1529 sizeof(pat), &pat))
1530 return -ENOBUFS;
1531 }
1532
Luciano Coelho75453cc2015-01-09 14:06:37 +02001533 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1534 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1535 rdev->wiphy.wowlan->max_nd_match_sets))
1536 return -ENOBUFS;
1537
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001538 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001539 return -ENOBUFS;
1540
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 nla_nest_end(msg, nl_wowlan);
1542
1543 return 0;
1544}
1545#endif
1546
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001547static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001548 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001549{
1550 struct nl80211_coalesce_rule_support rule;
1551
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001552 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001553 return 0;
1554
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001555 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1556 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1557 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1558 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1559 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1560 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001561
1562 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1563 return -ENOBUFS;
1564
1565 return 0;
1566}
1567
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001568static int
1569nl80211_send_iftype_data(struct sk_buff *msg,
1570 const struct ieee80211_sband_iftype_data *iftdata)
1571{
1572 const struct ieee80211_sta_he_cap *he_cap = &iftdata->he_cap;
1573
1574 if (nl80211_put_iftypes(msg, NL80211_BAND_IFTYPE_ATTR_IFTYPES,
1575 iftdata->types_mask))
1576 return -ENOBUFS;
1577
1578 if (he_cap->has_he) {
1579 if (nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC,
1580 sizeof(he_cap->he_cap_elem.mac_cap_info),
1581 he_cap->he_cap_elem.mac_cap_info) ||
1582 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY,
1583 sizeof(he_cap->he_cap_elem.phy_cap_info),
1584 he_cap->he_cap_elem.phy_cap_info) ||
1585 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET,
1586 sizeof(he_cap->he_mcs_nss_supp),
1587 &he_cap->he_mcs_nss_supp) ||
1588 nla_put(msg, NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE,
1589 sizeof(he_cap->ppe_thres), he_cap->ppe_thres))
1590 return -ENOBUFS;
1591 }
1592
1593 return 0;
1594}
1595
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1597 struct ieee80211_supported_band *sband)
1598{
1599 struct nlattr *nl_rates, *nl_rate;
1600 struct ieee80211_rate *rate;
1601 int i;
1602
1603 /* add HT info */
1604 if (sband->ht_cap.ht_supported &&
1605 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1606 sizeof(sband->ht_cap.mcs),
1607 &sband->ht_cap.mcs) ||
1608 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1609 sband->ht_cap.cap) ||
1610 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1611 sband->ht_cap.ampdu_factor) ||
1612 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1613 sband->ht_cap.ampdu_density)))
1614 return -ENOBUFS;
1615
1616 /* add VHT info */
1617 if (sband->vht_cap.vht_supported &&
1618 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1619 sizeof(sband->vht_cap.vht_mcs),
1620 &sband->vht_cap.vht_mcs) ||
1621 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1622 sband->vht_cap.cap)))
1623 return -ENOBUFS;
1624
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001625 if (sband->n_iftype_data) {
1626 struct nlattr *nl_iftype_data =
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001627 nla_nest_start_noflag(msg,
1628 NL80211_BAND_ATTR_IFTYPE_DATA);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001629 int err;
1630
1631 if (!nl_iftype_data)
1632 return -ENOBUFS;
1633
1634 for (i = 0; i < sband->n_iftype_data; i++) {
1635 struct nlattr *iftdata;
1636
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001637 iftdata = nla_nest_start_noflag(msg, i + 1);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03001638 if (!iftdata)
1639 return -ENOBUFS;
1640
1641 err = nl80211_send_iftype_data(msg,
1642 &sband->iftype_data[i]);
1643 if (err)
1644 return err;
1645
1646 nla_nest_end(msg, iftdata);
1647 }
1648
1649 nla_nest_end(msg, nl_iftype_data);
1650 }
1651
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03001652 /* add EDMG info */
1653 if (sband->edmg_cap.channels &&
1654 (nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_CHANNELS,
1655 sband->edmg_cap.channels) ||
1656 nla_put_u8(msg, NL80211_BAND_ATTR_EDMG_BW_CONFIG,
1657 sband->edmg_cap.bw_config)))
1658
1659 return -ENOBUFS;
1660
Johannes Berg3713b4e2013-02-14 16:19:38 +01001661 /* add bitrates */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001662 nl_rates = nla_nest_start_noflag(msg, NL80211_BAND_ATTR_RATES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001663 if (!nl_rates)
1664 return -ENOBUFS;
1665
1666 for (i = 0; i < sband->n_bitrates; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001667 nl_rate = nla_nest_start_noflag(msg, i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001668 if (!nl_rate)
1669 return -ENOBUFS;
1670
1671 rate = &sband->bitrates[i];
1672 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1673 rate->bitrate))
1674 return -ENOBUFS;
1675 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1676 nla_put_flag(msg,
1677 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1678 return -ENOBUFS;
1679
1680 nla_nest_end(msg, nl_rate);
1681 }
1682
1683 nla_nest_end(msg, nl_rates);
1684
1685 return 0;
1686}
1687
1688static int
1689nl80211_send_mgmt_stypes(struct sk_buff *msg,
1690 const struct ieee80211_txrx_stypes *mgmt_stypes)
1691{
1692 u16 stypes;
1693 struct nlattr *nl_ftypes, *nl_ifs;
1694 enum nl80211_iftype ift;
1695 int i;
1696
1697 if (!mgmt_stypes)
1698 return 0;
1699
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001700 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_TX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001701 if (!nl_ifs)
1702 return -ENOBUFS;
1703
1704 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001705 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001706 if (!nl_ftypes)
1707 return -ENOBUFS;
1708 i = 0;
1709 stypes = mgmt_stypes[ift].tx;
1710 while (stypes) {
1711 if ((stypes & 1) &&
1712 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1713 (i << 4) | IEEE80211_FTYPE_MGMT))
1714 return -ENOBUFS;
1715 stypes >>= 1;
1716 i++;
1717 }
1718 nla_nest_end(msg, nl_ftypes);
1719 }
1720
1721 nla_nest_end(msg, nl_ifs);
1722
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001723 nl_ifs = nla_nest_start_noflag(msg, NL80211_ATTR_RX_FRAME_TYPES);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001724 if (!nl_ifs)
1725 return -ENOBUFS;
1726
1727 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001728 nl_ftypes = nla_nest_start_noflag(msg, ift);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001729 if (!nl_ftypes)
1730 return -ENOBUFS;
1731 i = 0;
1732 stypes = mgmt_stypes[ift].rx;
1733 while (stypes) {
1734 if ((stypes & 1) &&
1735 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1736 (i << 4) | IEEE80211_FTYPE_MGMT))
1737 return -ENOBUFS;
1738 stypes >>= 1;
1739 i++;
1740 }
1741 nla_nest_end(msg, nl_ftypes);
1742 }
1743 nla_nest_end(msg, nl_ifs);
1744
1745 return 0;
1746}
1747
Johannes Berg17948992016-10-26 11:42:04 +02001748#define CMD(op, n) \
1749 do { \
1750 if (rdev->ops->op) { \
1751 i++; \
1752 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1753 goto nla_put_failure; \
1754 } \
1755 } while (0)
1756
1757static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev,
1758 struct sk_buff *msg)
1759{
1760 int i = 0;
1761
1762 /*
1763 * do *NOT* add anything into this function, new things need to be
1764 * advertised only to new versions of userspace that can deal with
1765 * the split (and they can't possibly care about new features...
1766 */
1767 CMD(add_virtual_intf, NEW_INTERFACE);
1768 CMD(change_virtual_intf, SET_INTERFACE);
1769 CMD(add_key, NEW_KEY);
1770 CMD(start_ap, START_AP);
1771 CMD(add_station, NEW_STATION);
1772 CMD(add_mpath, NEW_MPATH);
1773 CMD(update_mesh_config, SET_MESH_CONFIG);
1774 CMD(change_bss, SET_BSS);
1775 CMD(auth, AUTHENTICATE);
1776 CMD(assoc, ASSOCIATE);
1777 CMD(deauth, DEAUTHENTICATE);
1778 CMD(disassoc, DISASSOCIATE);
1779 CMD(join_ibss, JOIN_IBSS);
1780 CMD(join_mesh, JOIN_MESH);
1781 CMD(set_pmksa, SET_PMKSA);
1782 CMD(del_pmksa, DEL_PMKSA);
1783 CMD(flush_pmksa, FLUSH_PMKSA);
1784 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
1785 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1786 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1787 CMD(mgmt_tx, FRAME);
1788 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
1789 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
1790 i++;
1791 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1792 goto nla_put_failure;
1793 }
1794 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1795 rdev->ops->join_mesh) {
1796 i++;
1797 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1798 goto nla_put_failure;
1799 }
1800 CMD(set_wds_peer, SET_WDS_PEER);
1801 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
1802 CMD(tdls_mgmt, TDLS_MGMT);
1803 CMD(tdls_oper, TDLS_OPER);
1804 }
Arend Van Sprielca986ad2017-04-21 13:05:00 +01001805 if (rdev->wiphy.max_sched_scan_reqs)
Johannes Berg17948992016-10-26 11:42:04 +02001806 CMD(sched_scan_start, START_SCHED_SCAN);
1807 CMD(probe_client, PROBE_CLIENT);
1808 CMD(set_noack_map, SET_NOACK_MAP);
1809 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
1810 i++;
1811 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1812 goto nla_put_failure;
1813 }
1814 CMD(start_p2p_device, START_P2P_DEVICE);
1815 CMD(set_mcast_rate, SET_MCAST_RATE);
1816#ifdef CONFIG_NL80211_TESTMODE
1817 CMD(testmode_cmd, TESTMODE);
1818#endif
1819
1820 if (rdev->ops->connect || rdev->ops->auth) {
1821 i++;
1822 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
1823 goto nla_put_failure;
1824 }
1825
1826 if (rdev->ops->disconnect || rdev->ops->deauth) {
1827 i++;
1828 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1829 goto nla_put_failure;
1830 }
1831
1832 return i;
1833 nla_put_failure:
1834 return -ENOBUFS;
1835}
1836
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001837static int
1838nl80211_send_pmsr_ftm_capa(const struct cfg80211_pmsr_capabilities *cap,
1839 struct sk_buff *msg)
1840{
1841 struct nlattr *ftm;
1842
1843 if (!cap->ftm.supported)
1844 return 0;
1845
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001846 ftm = nla_nest_start_noflag(msg, NL80211_PMSR_TYPE_FTM);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001847 if (!ftm)
1848 return -ENOBUFS;
1849
1850 if (cap->ftm.asap && nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_ASAP))
1851 return -ENOBUFS;
1852 if (cap->ftm.non_asap &&
1853 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_NON_ASAP))
1854 return -ENOBUFS;
1855 if (cap->ftm.request_lci &&
1856 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_LCI))
1857 return -ENOBUFS;
1858 if (cap->ftm.request_civicloc &&
1859 nla_put_flag(msg, NL80211_PMSR_FTM_CAPA_ATTR_REQ_CIVICLOC))
1860 return -ENOBUFS;
1861 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_PREAMBLES,
1862 cap->ftm.preambles))
1863 return -ENOBUFS;
1864 if (nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_BANDWIDTHS,
1865 cap->ftm.bandwidths))
1866 return -ENOBUFS;
1867 if (cap->ftm.max_bursts_exponent >= 0 &&
1868 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_BURSTS_EXPONENT,
1869 cap->ftm.max_bursts_exponent))
1870 return -ENOBUFS;
1871 if (cap->ftm.max_ftms_per_burst &&
1872 nla_put_u32(msg, NL80211_PMSR_FTM_CAPA_ATTR_MAX_FTMS_PER_BURST,
1873 cap->ftm.max_ftms_per_burst))
1874 return -ENOBUFS;
1875
1876 nla_nest_end(msg, ftm);
1877 return 0;
1878}
1879
1880static int nl80211_send_pmsr_capa(struct cfg80211_registered_device *rdev,
1881 struct sk_buff *msg)
1882{
1883 const struct cfg80211_pmsr_capabilities *cap = rdev->wiphy.pmsr_capa;
1884 struct nlattr *pmsr, *caps;
1885
1886 if (!cap)
1887 return 0;
1888
1889 /*
1890 * we don't need to clean up anything here since the caller
1891 * will genlmsg_cancel() if we fail
1892 */
1893
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001894 pmsr = nla_nest_start_noflag(msg, NL80211_ATTR_PEER_MEASUREMENTS);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001895 if (!pmsr)
1896 return -ENOBUFS;
1897
1898 if (nla_put_u32(msg, NL80211_PMSR_ATTR_MAX_PEERS, cap->max_peers))
1899 return -ENOBUFS;
1900
1901 if (cap->report_ap_tsf &&
1902 nla_put_flag(msg, NL80211_PMSR_ATTR_REPORT_AP_TSF))
1903 return -ENOBUFS;
1904
1905 if (cap->randomize_mac_addr &&
1906 nla_put_flag(msg, NL80211_PMSR_ATTR_RANDOMIZE_MAC_ADDR))
1907 return -ENOBUFS;
1908
Michal Kubecekae0be8d2019-04-26 11:13:06 +02001909 caps = nla_nest_start_noflag(msg, NL80211_PMSR_ATTR_TYPE_CAPA);
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02001910 if (!caps)
1911 return -ENOBUFS;
1912
1913 if (nl80211_send_pmsr_ftm_capa(cap, msg))
1914 return -ENOBUFS;
1915
1916 nla_nest_end(msg, caps);
1917 nla_nest_end(msg, pmsr);
1918
1919 return 0;
1920}
1921
Veerendranath Jakkamd6039a32020-01-27 02:00:32 +05301922static int
1923nl80211_put_iftype_akm_suites(struct cfg80211_registered_device *rdev,
1924 struct sk_buff *msg)
1925{
1926 int i;
1927 struct nlattr *nested, *nested_akms;
1928 const struct wiphy_iftype_akm_suites *iftype_akms;
1929
1930 if (!rdev->wiphy.num_iftype_akm_suites ||
1931 !rdev->wiphy.iftype_akm_suites)
1932 return 0;
1933
1934 nested = nla_nest_start(msg, NL80211_ATTR_IFTYPE_AKM_SUITES);
1935 if (!nested)
1936 return -ENOBUFS;
1937
1938 for (i = 0; i < rdev->wiphy.num_iftype_akm_suites; i++) {
1939 nested_akms = nla_nest_start(msg, i + 1);
1940 if (!nested_akms)
1941 return -ENOBUFS;
1942
1943 iftype_akms = &rdev->wiphy.iftype_akm_suites[i];
1944
1945 if (nl80211_put_iftypes(msg, NL80211_IFTYPE_AKM_ATTR_IFTYPES,
1946 iftype_akms->iftypes_mask))
1947 return -ENOBUFS;
1948
1949 if (nla_put(msg, NL80211_IFTYPE_AKM_ATTR_SUITES,
1950 sizeof(u32) * iftype_akms->n_akm_suites,
1951 iftype_akms->akm_suites)) {
1952 return -ENOBUFS;
1953 }
1954 nla_nest_end(msg, nested_akms);
1955 }
1956
1957 nla_nest_end(msg, nested);
1958
1959 return 0;
1960}
1961
Johannes Berg3710a8a2020-02-24 11:34:25 +01001962static int
1963nl80211_put_tid_config_support(struct cfg80211_registered_device *rdev,
1964 struct sk_buff *msg)
1965{
1966 struct nlattr *supp;
1967
1968 if (!rdev->wiphy.tid_config_support.vif &&
1969 !rdev->wiphy.tid_config_support.peer)
1970 return 0;
1971
1972 supp = nla_nest_start(msg, NL80211_ATTR_TID_CONFIG);
1973 if (!supp)
1974 return -ENOSPC;
1975
1976 if (rdev->wiphy.tid_config_support.vif &&
1977 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_VIF_SUPP,
1978 rdev->wiphy.tid_config_support.vif,
1979 NL80211_TID_CONFIG_ATTR_PAD))
1980 goto fail;
1981
1982 if (rdev->wiphy.tid_config_support.peer &&
1983 nla_put_u64_64bit(msg, NL80211_TID_CONFIG_ATTR_PEER_SUPP,
1984 rdev->wiphy.tid_config_support.peer,
1985 NL80211_TID_CONFIG_ATTR_PAD))
1986 goto fail;
1987
1988 nla_nest_end(msg, supp);
1989
1990 return 0;
1991fail:
1992 nla_nest_cancel(msg, supp);
1993 return -ENOBUFS;
1994}
1995
Johannes Berg86e8cf92013-06-19 10:57:22 +02001996struct nl80211_dump_wiphy_state {
1997 s64 filter_wiphy;
1998 long start;
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05301999 long split_start, band_start, chan_start, capa_start;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002000 bool split;
2001};
2002
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002003static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02002004 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002005 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002006 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04002007{
2008 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01002009 struct nlattr *nl_bands, *nl_band;
2010 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01002011 struct nlattr *nl_cmds;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002012 enum nl80211_band band;
Johannes Bergee688b002008-01-24 19:38:39 +01002013 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01002014 int i;
Johannes Berg2e161f782010-08-12 15:38:38 +02002015 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002016 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002017 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04002018
Johannes Berg3bb20552014-05-26 13:52:25 +02002019 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002020 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002021 return -ENOBUFS;
2022
Johannes Berg86e8cf92013-06-19 10:57:22 +02002023 if (WARN_ON(!state))
2024 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04002025
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002026 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002027 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002028 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002029 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002030 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04002031 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002032
Johannes Berg3bb20552014-05-26 13:52:25 +02002033 if (cmd != NL80211_CMD_NEW_WIPHY)
2034 goto finish;
2035
Johannes Berg86e8cf92013-06-19 10:57:22 +02002036 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002037 case 0:
2038 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002039 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002040 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002041 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002042 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002043 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002044 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002045 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002046 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002047 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002048 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002049 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002050 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002051 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002052 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002053 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002054 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002055 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002056 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03002057 rdev->wiphy.max_match_sets) ||
2058 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
2059 rdev->wiphy.max_sched_scan_plans) ||
2060 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
2061 rdev->wiphy.max_sched_scan_plan_interval) ||
2062 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
2063 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01002064 goto nla_put_failure;
2065
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002066 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002067 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
2068 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002069 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002070 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
2071 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002072 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002073 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
2074 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002075 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002076 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
2077 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002078 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002079 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
2080 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002081 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002082 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04002083 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002084 state->split_start++;
2085 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002086 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002087 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002088 case 1:
2089 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002090 sizeof(u32) * rdev->wiphy.n_cipher_suites,
2091 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00002092 goto nla_put_failure;
2093
Johannes Berg3713b4e2013-02-14 16:19:38 +01002094 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002095 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01002096 goto nla_put_failure;
2097
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002098 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002099 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
2100 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002101
Johannes Berg3713b4e2013-02-14 16:19:38 +01002102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002103 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01002104 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002105 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002106 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002107
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002108 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002109 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002110 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002111 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02002112
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002113 if ((rdev->wiphy.available_antennas_tx ||
2114 rdev->wiphy.available_antennas_rx) &&
2115 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002116 u32 tx_ant = 0, rx_ant = 0;
2117 int res;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07002118
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002119 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002120 if (!res) {
2121 if (nla_put_u32(msg,
2122 NL80211_ATTR_WIPHY_ANTENNA_TX,
2123 tx_ant) ||
2124 nla_put_u32(msg,
2125 NL80211_ATTR_WIPHY_ANTENNA_RX,
2126 rx_ant))
2127 goto nla_put_failure;
2128 }
Johannes Bergee688b002008-01-24 19:38:39 +01002129 }
2130
Johannes Berg86e8cf92013-06-19 10:57:22 +02002131 state->split_start++;
2132 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002133 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002134 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002135 case 2:
2136 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002137 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002138 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002139 state->split_start++;
2140 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002141 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002142 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002143 case 3:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002144 nl_bands = nla_nest_start_noflag(msg,
2145 NL80211_ATTR_WIPHY_BANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002146 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01002147 goto nla_put_failure;
2148
Johannes Berg86e8cf92013-06-19 10:57:22 +02002149 for (band = state->band_start;
Johannes Berg57fbcce2016-04-12 15:56:15 +02002150 band < NUM_NL80211_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002151 struct ieee80211_supported_band *sband;
2152
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002153 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01002154
2155 if (!sband)
2156 continue;
2157
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002158 nl_band = nla_nest_start_noflag(msg, band);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002159 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01002160 goto nla_put_failure;
2161
Johannes Berg86e8cf92013-06-19 10:57:22 +02002162 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002163 case 0:
2164 if (nl80211_send_band_rateinfo(msg, sband))
2165 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002166 state->chan_start++;
2167 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002168 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002169 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002170 default:
2171 /* add frequencies */
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002172 nl_freqs = nla_nest_start_noflag(msg,
2173 NL80211_BAND_ATTR_FREQS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002174 if (!nl_freqs)
2175 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01002176
Johannes Berg86e8cf92013-06-19 10:57:22 +02002177 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002178 i < sband->n_channels;
2179 i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002180 nl_freq = nla_nest_start_noflag(msg,
2181 i);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002182 if (!nl_freq)
2183 goto nla_put_failure;
2184
2185 chan = &sband->channels[i];
2186
Johannes Berg86e8cf92013-06-19 10:57:22 +02002187 if (nl80211_msg_put_channel(
Haim Dreyfuss50f32712018-04-20 13:49:26 +03002188 msg, &rdev->wiphy, chan,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002189 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002190 goto nla_put_failure;
2191
2192 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002193 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002194 break;
2195 }
2196 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002197 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002198 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002199 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002200 nla_nest_end(msg, nl_freqs);
2201 }
2202
2203 nla_nest_end(msg, nl_band);
2204
Johannes Berg86e8cf92013-06-19 10:57:22 +02002205 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01002206 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002207 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002208 band--;
2209 break;
2210 }
Johannes Bergee688b002008-01-24 19:38:39 +01002211 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01002212 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01002213
Johannes Berg57fbcce2016-04-12 15:56:15 +02002214 if (band < NUM_NL80211_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02002215 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002216 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002217 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01002218
Johannes Berg3713b4e2013-02-14 16:19:38 +01002219 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002220 if (state->band_start == 0 && state->chan_start == 0)
2221 state->split_start++;
2222 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002223 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002224 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002225 case 4:
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002226 nl_cmds = nla_nest_start_noflag(msg,
2227 NL80211_ATTR_SUPPORTED_COMMANDS);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002228 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04002229 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002230
Johannes Berg17948992016-10-26 11:42:04 +02002231 i = nl80211_add_commands_unsplit(rdev, msg);
2232 if (i < 0)
2233 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002234 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02002235 CMD(crit_proto_start, CRIT_PROTOCOL_START);
2236 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002237 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02002238 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02002239 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02002240 if (rdev->wiphy.features &
2241 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03002242 CMD(add_tx_ts, ADD_TX_TS);
Michael Braunce0ce132016-10-10 19:12:22 +02002243 CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST);
vamsi krishna088e8df2016-10-27 16:51:11 +03002244 CMD(update_connect_params, UPDATE_CONNECT_PARAMS);
Matthew Wang70109982019-08-22 10:48:06 -07002245 CMD(update_ft_ies, UPDATE_FT_IES);
Arend van Spriel5de17982013-04-18 15:49:00 +02002246 }
Johannes Berg8fdc6212009-03-14 09:34:01 +01002247#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02002248
Johannes Berg3713b4e2013-02-14 16:19:38 +01002249 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002250 state->split_start++;
2251 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002252 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002253 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002254 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002255 if (rdev->ops->remain_on_channel &&
2256 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002257 nla_put_u32(msg,
2258 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002259 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f782010-08-12 15:38:38 +02002260 goto nla_put_failure;
2261
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002262 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002263 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
2264 goto nla_put_failure;
Johannes Berg2e161f782010-08-12 15:38:38 +02002265
Johannes Berg3713b4e2013-02-14 16:19:38 +01002266 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
2267 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002268 state->split_start++;
2269 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002270 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002271 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002272 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02002273#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002274 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002275 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002276 state->split_start++;
2277 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002278 break;
2279#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02002280 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002281#endif
Luca Coelho925b5972018-12-15 11:03:21 +02002282 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002283 case 7:
2284 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002285 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02002286 goto nla_put_failure;
2287
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002288 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002289 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002290 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002291
Johannes Berg86e8cf92013-06-19 10:57:22 +02002292 state->split_start++;
2293 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002294 break;
Luca Coelho925b5972018-12-15 11:03:21 +02002295 /* fall through */
Johannes Berg3713b4e2013-02-14 16:19:38 +01002296 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002297 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002298 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002299 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002300 goto nla_put_failure;
2301
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002302 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002303 /*
2304 * We can only add the per-channel limit information if the
2305 * dump is split, otherwise it makes it too big. Therefore
2306 * only advertise it in that case.
2307 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002308 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002309 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
2310 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002311 goto nla_put_failure;
2312
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002313 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002314 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002315 sizeof(*rdev->wiphy.ht_capa_mod_mask),
2316 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002317 goto nla_put_failure;
2318
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002319 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
2320 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002321 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002322 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01002323 goto nla_put_failure;
2324
2325 /*
2326 * Any information below this point is only available to
2327 * applications that can deal with it being split. This
2328 * helps ensure that newly added capabilities don't break
2329 * older tools by overrunning their buffers.
2330 *
2331 * We still increment split_start so that in the split
2332 * case we'll continue with more data in the next round,
2333 * but break unconditionally so unsplit data stops here.
2334 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002335 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002336 break;
2337 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002338 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002339 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002340 rdev->wiphy.extended_capabilities_len,
2341 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002342 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002343 rdev->wiphy.extended_capabilities_len,
2344 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01002345 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002346
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002347 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01002348 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002349 sizeof(*rdev->wiphy.vht_capa_mod_mask),
2350 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01002351 goto nla_put_failure;
2352
Denis Kenziorae6fa4d2019-07-22 06:33:12 -05002353 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN,
2354 rdev->wiphy.perm_addr))
2355 goto nla_put_failure;
2356
2357 if (!is_zero_ether_addr(rdev->wiphy.addr_mask) &&
2358 nla_put(msg, NL80211_ATTR_MAC_MASK, ETH_ALEN,
2359 rdev->wiphy.addr_mask))
2360 goto nla_put_failure;
2361
2362 if (rdev->wiphy.n_addresses > 1) {
2363 void *attr;
2364
2365 attr = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS);
2366 if (!attr)
2367 goto nla_put_failure;
2368
2369 for (i = 0; i < rdev->wiphy.n_addresses; i++)
2370 if (nla_put(msg, i + 1, ETH_ALEN,
2371 rdev->wiphy.addresses[i].addr))
2372 goto nla_put_failure;
2373
2374 nla_nest_end(msg, attr);
2375 }
2376
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002377 state->split_start++;
2378 break;
2379 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002380 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07002381 goto nla_put_failure;
2382
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002383 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002384 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
2385 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
2386 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02002387
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002388 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02002389 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002390 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02002391 goto nla_put_failure;
2392
Johannes Bergad7e7182013-11-13 13:37:47 +01002393 state->split_start++;
2394 break;
2395 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002396 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002397 const struct nl80211_vendor_cmd_info *info;
2398 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01002399
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002400 nested = nla_nest_start_noflag(msg,
2401 NL80211_ATTR_VENDOR_DATA);
Johannes Berg567ffc32013-12-18 14:43:31 +01002402 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01002403 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01002404
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002405 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
2406 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01002407 if (nla_put(msg, i + 1, sizeof(*info), info))
2408 goto nla_put_failure;
2409 }
2410 nla_nest_end(msg, nested);
2411 }
2412
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002413 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01002414 const struct nl80211_vendor_cmd_info *info;
2415 struct nlattr *nested;
2416
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002417 nested = nla_nest_start_noflag(msg,
2418 NL80211_ATTR_VENDOR_EVENTS);
Johannes Berg567ffc32013-12-18 14:43:31 +01002419 if (!nested)
2420 goto nla_put_failure;
2421
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002422 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
2423 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01002424 if (nla_put(msg, i + 1, sizeof(*info), info))
2425 goto nla_put_failure;
2426 }
2427 nla_nest_end(msg, nested);
2428 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002429 state->split_start++;
2430 break;
2431 case 12:
2432 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
2433 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
2434 rdev->wiphy.max_num_csa_counters))
2435 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01002436
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02002437 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
2438 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
2439 goto nla_put_failure;
2440
Arend Van Sprielca986ad2017-04-21 13:05:00 +01002441 if (rdev->wiphy.max_sched_scan_reqs &&
2442 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS,
2443 rdev->wiphy.max_sched_scan_reqs))
2444 goto nla_put_failure;
2445
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01002446 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
2447 sizeof(rdev->wiphy.ext_features),
2448 rdev->wiphy.ext_features))
2449 goto nla_put_failure;
2450
Arend van Spriel38de03d2016-03-02 20:37:18 +01002451 if (rdev->wiphy.bss_select_support) {
2452 struct nlattr *nested;
2453 u32 bss_select_support = rdev->wiphy.bss_select_support;
2454
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002455 nested = nla_nest_start_noflag(msg,
2456 NL80211_ATTR_BSS_SELECT);
Arend van Spriel38de03d2016-03-02 20:37:18 +01002457 if (!nested)
2458 goto nla_put_failure;
2459
2460 i = 0;
2461 while (bss_select_support) {
2462 if ((bss_select_support & 1) &&
2463 nla_put_flag(msg, i))
2464 goto nla_put_failure;
2465 i++;
2466 bss_select_support >>= 1;
2467 }
2468 nla_nest_end(msg, nested);
2469 }
2470
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302471 state->split_start++;
2472 break;
2473 case 13:
2474 if (rdev->wiphy.num_iftype_ext_capab &&
2475 rdev->wiphy.iftype_ext_capab) {
2476 struct nlattr *nested_ext_capab, *nested;
2477
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002478 nested = nla_nest_start_noflag(msg,
2479 NL80211_ATTR_IFTYPE_EXT_CAPA);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302480 if (!nested)
2481 goto nla_put_failure;
2482
2483 for (i = state->capa_start;
2484 i < rdev->wiphy.num_iftype_ext_capab; i++) {
2485 const struct wiphy_iftype_ext_capab *capab;
2486
2487 capab = &rdev->wiphy.iftype_ext_capab[i];
2488
Michal Kubecekae0be8d2019-04-26 11:13:06 +02002489 nested_ext_capab = nla_nest_start_noflag(msg,
2490 i);
Kanchanapally, Vidyullatha019ae3a2016-05-16 10:41:04 +05302491 if (!nested_ext_capab ||
2492 nla_put_u32(msg, NL80211_ATTR_IFTYPE,
2493 capab->iftype) ||
2494 nla_put(msg, NL80211_ATTR_EXT_CAPA,
2495 capab->extended_capabilities_len,
2496 capab->extended_capabilities) ||
2497 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
2498 capab->extended_capabilities_len,
2499 capab->extended_capabilities_mask))
2500 goto nla_put_failure;
2501
2502 nla_nest_end(msg, nested_ext_capab);
2503 if (state->split)
2504 break;
2505 }
2506 nla_nest_end(msg, nested);
2507 if (i < rdev->wiphy.num_iftype_ext_capab) {
2508 state->capa_start = i + 1;
2509 break;
2510 }
2511 }
2512
Luca Coelho85859892017-02-08 15:00:34 +02002513 if (nla_put_u32(msg, NL80211_ATTR_BANDS,
2514 rdev->wiphy.nan_supported_bands))
2515 goto nla_put_failure;
2516
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002517 if (wiphy_ext_feature_isset(&rdev->wiphy,
2518 NL80211_EXT_FEATURE_TXQS)) {
2519 struct cfg80211_txq_stats txqstats = {};
2520 int res;
2521
2522 res = rdev_get_txq_stats(rdev, NULL, &txqstats);
2523 if (!res &&
2524 !nl80211_put_txq_stats(msg, &txqstats,
2525 NL80211_ATTR_TXQ_STATS))
2526 goto nla_put_failure;
2527
2528 if (nla_put_u32(msg, NL80211_ATTR_TXQ_LIMIT,
2529 rdev->wiphy.txq_limit))
2530 goto nla_put_failure;
2531 if (nla_put_u32(msg, NL80211_ATTR_TXQ_MEMORY_LIMIT,
2532 rdev->wiphy.txq_memory_limit))
2533 goto nla_put_failure;
2534 if (nla_put_u32(msg, NL80211_ATTR_TXQ_QUANTUM,
2535 rdev->wiphy.txq_quantum))
2536 goto nla_put_failure;
2537 }
2538
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002539 state->split_start++;
2540 break;
2541 case 14:
2542 if (nl80211_send_pmsr_capa(rdev, msg))
2543 goto nla_put_failure;
2544
Veerendranath Jakkamab4dfa22018-12-19 22:52:25 +05302545 state->split_start++;
2546 break;
2547 case 15:
2548 if (rdev->wiphy.akm_suites &&
2549 nla_put(msg, NL80211_ATTR_AKM_SUITES,
2550 sizeof(u32) * rdev->wiphy.n_akm_suites,
2551 rdev->wiphy.akm_suites))
2552 goto nla_put_failure;
2553
Veerendranath Jakkamd6039a32020-01-27 02:00:32 +05302554 if (nl80211_put_iftype_akm_suites(rdev, msg))
2555 goto nla_put_failure;
2556
Johannes Berg3710a8a2020-02-24 11:34:25 +01002557 if (nl80211_put_tid_config_support(rdev, msg))
2558 goto nla_put_failure;
2559
Johannes Berg3713b4e2013-02-14 16:19:38 +01002560 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02002561 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002562 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02002563 }
Johannes Berg3bb20552014-05-26 13:52:25 +02002564 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01002565 genlmsg_end(msg, hdr);
2566 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002567
2568 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002569 genlmsg_cancel(msg, hdr);
2570 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002571}
2572
Johannes Berg86e8cf92013-06-19 10:57:22 +02002573static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
2574 struct netlink_callback *cb,
2575 struct nl80211_dump_wiphy_state *state)
2576{
Johannes Berg50508d92019-07-29 16:31:09 +02002577 struct nlattr **tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
2578 int ret;
2579
2580 if (!tb)
2581 return -ENOMEM;
2582
2583 ret = nlmsg_parse_deprecated(cb->nlh,
2584 GENL_HDRLEN + nl80211_fam.hdrsize,
2585 tb, nl80211_fam.maxattr,
2586 nl80211_policy, NULL);
Johannes Berg86e8cf92013-06-19 10:57:22 +02002587 /* ignore parse errors for backward compatibility */
Johannes Berg50508d92019-07-29 16:31:09 +02002588 if (ret) {
2589 ret = 0;
2590 goto out;
2591 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002592
2593 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
2594 if (tb[NL80211_ATTR_WIPHY])
2595 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
2596 if (tb[NL80211_ATTR_WDEV])
2597 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
2598 if (tb[NL80211_ATTR_IFINDEX]) {
2599 struct net_device *netdev;
2600 struct cfg80211_registered_device *rdev;
2601 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
2602
Ying Xue7f2b8562014-01-15 10:23:45 +08002603 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg50508d92019-07-29 16:31:09 +02002604 if (!netdev) {
2605 ret = -ENODEV;
2606 goto out;
2607 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002608 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002609 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02002610 netdev->ieee80211_ptr->wiphy);
2611 state->filter_wiphy = rdev->wiphy_idx;
2612 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002613 }
2614
Johannes Berg50508d92019-07-29 16:31:09 +02002615 ret = 0;
2616out:
2617 kfree(tb);
2618 return ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002619}
2620
Johannes Berg55682962007-09-20 13:09:35 -04002621static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
2622{
Johannes Berg645e77d2013-03-01 14:03:49 +01002623 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002624 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002625 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02002626
Johannes Berg5fe231e2013-05-08 21:45:15 +02002627 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002628 if (!state) {
2629 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04002630 if (!state) {
2631 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02002632 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002633 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002634 state->filter_wiphy = -1;
2635 ret = nl80211_dump_wiphy_parse(skb, cb, state);
2636 if (ret) {
2637 kfree(state);
2638 rtnl_unlock();
2639 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002640 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002641 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01002642 }
2643
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002644 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2645 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002646 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002647 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04002648 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02002649 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002650 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01002651 continue;
2652 /* attempt to fit multiple wiphy data chunks into the skb */
2653 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02002654 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
2655 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01002656 NETLINK_CB(cb->skb).portid,
2657 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002658 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002659 if (ret < 0) {
2660 /*
2661 * If sending the wiphy data didn't fit (ENOBUFS
2662 * or EMSGSIZE returned), this SKB is still
2663 * empty (so it's not too big because another
2664 * wiphy dataset is already in the skb) and
2665 * we've not tried to adjust the dump allocation
2666 * yet ... then adjust the alloc size to be
2667 * bigger, and return 1 but with the empty skb.
2668 * This results in an empty message being RX'ed
2669 * in userspace, but that is ignored.
2670 *
2671 * We can then retry with the larger buffer.
2672 */
2673 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002674 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01002675 cb->min_dump_alloc < 4096) {
2676 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01002677 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07002678 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01002679 return 1;
2680 }
2681 idx--;
2682 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01002683 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02002684 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01002685 break;
Johannes Berg55682962007-09-20 13:09:35 -04002686 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02002687 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002688
Johannes Berg86e8cf92013-06-19 10:57:22 +02002689 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04002690
2691 return skb->len;
2692}
2693
Johannes Berg86e8cf92013-06-19 10:57:22 +02002694static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
2695{
2696 kfree((void *)cb->args[0]);
2697 return 0;
2698}
2699
Johannes Berg55682962007-09-20 13:09:35 -04002700static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
2701{
2702 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02002704 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04002705
Johannes Berg645e77d2013-03-01 14:03:49 +01002706 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002707 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002708 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002709
Johannes Berg3bb20552014-05-26 13:52:25 +02002710 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
2711 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02002712 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002713 nlmsg_free(msg);
2714 return -ENOBUFS;
2715 }
Johannes Berg55682962007-09-20 13:09:35 -04002716
Johannes Berg134e6372009-07-10 09:51:34 +00002717 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002718}
2719
Jouni Malinen31888482008-10-30 16:59:24 +02002720static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
2721 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
2722 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
2723 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
2724 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
2725 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
2726};
2727
2728static int parse_txq_params(struct nlattr *tb[],
2729 struct ieee80211_txq_params *txq_params)
2730{
Dan Williams259d8c12018-01-29 17:03:15 -08002731 u8 ac;
2732
Johannes Berga3304b02012-03-28 11:04:24 +02002733 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02002734 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
2735 !tb[NL80211_TXQ_ATTR_AIFS])
2736 return -EINVAL;
2737
Dan Williams259d8c12018-01-29 17:03:15 -08002738 ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02002739 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
2740 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
2741 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
2742 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
2743
Dan Williams259d8c12018-01-29 17:03:15 -08002744 if (ac >= NL80211_NUM_ACS)
Johannes Berga3304b02012-03-28 11:04:24 +02002745 return -EINVAL;
Dan Williams259d8c12018-01-29 17:03:15 -08002746 txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS);
Jouni Malinen31888482008-10-30 16:59:24 +02002747 return 0;
2748}
2749
Johannes Bergf444de02010-05-05 15:25:02 +02002750static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
2751{
2752 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02002753 * You can only set the channel explicitly for WDS interfaces,
2754 * all others have their channel managed via their respective
2755 * "establish a connection" command (connect, join, ...)
2756 *
2757 * For AP/GO and mesh mode, the channel can be set with the
2758 * channel userspace API, but is only stored and passed to the
2759 * low-level driver when the AP starts or the mesh is joined.
2760 * This is for backward compatibility, userspace can also give
2761 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02002762 *
2763 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02002764 * whatever else is going on, so they have their own special
2765 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02002766 */
2767 return !wdev ||
2768 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02002769 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02002770 wdev->iftype == NL80211_IFTYPE_MONITOR ||
2771 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02002772}
2773
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02002774int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
2775 struct genl_info *info,
2776 struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002777{
Johannes Berg49f9cf02018-10-01 11:55:09 +02002778 struct netlink_ext_ack *extack = info->extack;
2779 struct nlattr **attrs = info->attrs;
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05302780 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01002781
Johannes Berg49f9cf02018-10-01 11:55:09 +02002782 if (!attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Berg683b6d32012-11-08 21:25:48 +01002783 return -EINVAL;
2784
Johannes Berg49f9cf02018-10-01 11:55:09 +02002785 control_freq = nla_get_u32(attrs[NL80211_ATTR_WIPHY_FREQ]);
Johannes Berg683b6d32012-11-08 21:25:48 +01002786
Johannes Bergf43e5212019-09-23 13:51:16 +02002787 memset(chandef, 0, sizeof(*chandef));
2788
Johannes Berg683b6d32012-11-08 21:25:48 +01002789 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002790 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
2791 chandef->center_freq1 = control_freq;
2792 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01002793
2794 /* Primary channel not allowed */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002795 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) {
2796 NL_SET_ERR_MSG_ATTR(extack, attrs[NL80211_ATTR_WIPHY_FREQ],
2797 "Channel is disabled");
Johannes Berg683b6d32012-11-08 21:25:48 +01002798 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002799 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002800
Johannes Berg49f9cf02018-10-01 11:55:09 +02002801 if (attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002802 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01002803
Johannes Berg49f9cf02018-10-01 11:55:09 +02002804 chantype = nla_get_u32(attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002805
2806 switch (chantype) {
2807 case NL80211_CHAN_NO_HT:
2808 case NL80211_CHAN_HT20:
2809 case NL80211_CHAN_HT40PLUS:
2810 case NL80211_CHAN_HT40MINUS:
2811 cfg80211_chandef_create(chandef, chandef->chan,
2812 chantype);
Tova Mussaiffa46292017-08-05 11:44:38 +03002813 /* user input for center_freq is incorrect */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002814 if (attrs[NL80211_ATTR_CENTER_FREQ1] &&
2815 chandef->center_freq1 != nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1])) {
2816 NL_SET_ERR_MSG_ATTR(extack,
2817 attrs[NL80211_ATTR_CENTER_FREQ1],
2818 "bad center frequency 1");
Tova Mussaiffa46292017-08-05 11:44:38 +03002819 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002820 }
Tova Mussaiffa46292017-08-05 11:44:38 +03002821 /* center_freq2 must be zero */
Johannes Berg49f9cf02018-10-01 11:55:09 +02002822 if (attrs[NL80211_ATTR_CENTER_FREQ2] &&
2823 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2])) {
2824 NL_SET_ERR_MSG_ATTR(extack,
2825 attrs[NL80211_ATTR_CENTER_FREQ2],
2826 "center frequency 2 can't be used");
Tova Mussaiffa46292017-08-05 11:44:38 +03002827 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002828 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002829 break;
2830 default:
Johannes Berg49f9cf02018-10-01 11:55:09 +02002831 NL_SET_ERR_MSG_ATTR(extack,
2832 attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
2833 "invalid channel type");
Johannes Berg683b6d32012-11-08 21:25:48 +01002834 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01002835 }
Johannes Berg49f9cf02018-10-01 11:55:09 +02002836 } else if (attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002837 chandef->width =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002838 nla_get_u32(attrs[NL80211_ATTR_CHANNEL_WIDTH]);
2839 if (attrs[NL80211_ATTR_CENTER_FREQ1])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002840 chandef->center_freq1 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002841 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ1]);
2842 if (attrs[NL80211_ATTR_CENTER_FREQ2])
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002843 chandef->center_freq2 =
Johannes Berg49f9cf02018-10-01 11:55:09 +02002844 nla_get_u32(attrs[NL80211_ATTR_CENTER_FREQ2]);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002845 }
2846
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +03002847 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
2848 chandef->edmg.channels =
2849 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
2850
2851 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
2852 chandef->edmg.bw_config =
2853 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
2854 } else {
2855 chandef->edmg.bw_config = 0;
2856 chandef->edmg.channels = 0;
2857 }
2858
Johannes Berg49f9cf02018-10-01 11:55:09 +02002859 if (!cfg80211_chandef_valid(chandef)) {
2860 NL_SET_ERR_MSG(extack, "invalid channel definition");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002861 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002862 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002863
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002864 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
Johannes Berg49f9cf02018-10-01 11:55:09 +02002865 IEEE80211_CHAN_DISABLED)) {
2866 NL_SET_ERR_MSG(extack, "(extension) channel is disabled");
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002867 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002868 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002869
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002870 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
2871 chandef->width == NL80211_CHAN_WIDTH_10) &&
Johannes Berg49f9cf02018-10-01 11:55:09 +02002872 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) {
2873 NL_SET_ERR_MSG(extack, "5/10 MHz not supported");
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002874 return -EINVAL;
Johannes Berg49f9cf02018-10-01 11:55:09 +02002875 }
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02002876
Johannes Berg683b6d32012-11-08 21:25:48 +01002877 return 0;
2878}
2879
Johannes Bergf444de02010-05-05 15:25:02 +02002880static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03002881 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02002882 struct genl_info *info)
2883{
Johannes Berg683b6d32012-11-08 21:25:48 +01002884 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002885 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002886 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002887 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002888
Jouni Malinene16821b2014-04-28 11:22:08 +03002889 if (dev)
2890 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002891 if (!nl80211_can_set_dev_channel(wdev))
2892 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002893 if (wdev)
2894 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002895
Johannes Berg683b6d32012-11-08 21:25:48 +01002896 result = nl80211_parse_chandef(rdev, info, &chandef);
2897 if (result)
2898 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002899
Johannes Berge8c9bd52012-06-06 08:18:22 +02002900 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002901 case NL80211_IFTYPE_AP:
2902 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002903 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2904 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002905 result = -EINVAL;
2906 break;
2907 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002908 if (wdev->beacon_interval) {
2909 if (!dev || !rdev->ops->set_ap_chanwidth ||
2910 !(rdev->wiphy.features &
2911 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2912 result = -EBUSY;
2913 break;
2914 }
2915
2916 /* Only allow dynamic channel width changes */
2917 if (chandef.chan != wdev->preset_chandef.chan) {
2918 result = -EBUSY;
2919 break;
2920 }
2921 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2922 if (result)
2923 break;
2924 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002925 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002926 result = 0;
2927 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002928 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002929 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002930 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002931 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002932 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002933 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002934 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002935 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002936 }
Johannes Bergf444de02010-05-05 15:25:02 +02002937
2938 return result;
2939}
2940
2941static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2942{
Johannes Berg4c476992010-10-04 21:36:35 +02002943 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2944 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002945
Jouni Malinene16821b2014-04-28 11:22:08 +03002946 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002947}
2948
Bill Jordane8347eb2010-10-01 13:54:28 -04002949static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2950{
Johannes Berg43b19952010-10-07 13:10:30 +02002951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2952 struct net_device *dev = info->user_ptr[1];
2953 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002954 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002955
2956 if (!info->attrs[NL80211_ATTR_MAC])
2957 return -EINVAL;
2958
Johannes Berg43b19952010-10-07 13:10:30 +02002959 if (netif_running(dev))
2960 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002961
Johannes Berg43b19952010-10-07 13:10:30 +02002962 if (!rdev->ops->set_wds_peer)
2963 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002964
Johannes Berg43b19952010-10-07 13:10:30 +02002965 if (wdev->iftype != NL80211_IFTYPE_WDS)
2966 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002967
2968 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002969 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002970}
2971
Johannes Berg55682962007-09-20 13:09:35 -04002972static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2973{
2974 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002975 struct net_device *netdev = NULL;
2976 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002977 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002978 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002979 u32 changed;
2980 u8 retry_short = 0, retry_long = 0;
2981 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002982 u8 coverage_class = 0;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02002983 u32 txq_limit = 0, txq_memory_limit = 0, txq_quantum = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002984
Johannes Berg5fe231e2013-05-08 21:45:15 +02002985 ASSERT_RTNL();
2986
Johannes Bergf444de02010-05-05 15:25:02 +02002987 /*
2988 * Try to find the wiphy and netdev. Normally this
2989 * function shouldn't need the netdev, but this is
2990 * done for backward compatibility -- previously
2991 * setting the channel was done per wiphy, but now
2992 * it is per netdev. Previous userland like hostapd
2993 * also passed a netdev to set_wiphy, so that it is
2994 * possible to let that go to the right netdev!
2995 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002996
Johannes Bergf444de02010-05-05 15:25:02 +02002997 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2998 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2999
Ying Xue7f2b8562014-01-15 10:23:45 +08003000 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003001 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08003002 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003003 else
Johannes Bergf444de02010-05-05 15:25:02 +02003004 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003005 }
3006
Johannes Bergf444de02010-05-05 15:25:02 +02003007 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02003008 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
3009 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02003010 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02003011 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02003012 wdev = NULL;
3013 netdev = NULL;
3014 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02003015 } else
Johannes Bergf444de02010-05-05 15:25:02 +02003016 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02003017
3018 /*
3019 * end workaround code, by now the rdev is available
3020 * and locked, and wdev may or may not be NULL.
3021 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003022
3023 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02003024 result = cfg80211_dev_rename(
3025 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003026
Johannes Berg4bbf4d52009-03-24 09:35:46 +01003027 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003028 return result;
Johannes Berg55682962007-09-20 13:09:35 -04003029
Jouni Malinen31888482008-10-30 16:59:24 +02003030 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
3031 struct ieee80211_txq_params txq_params;
3032 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
3033
Ying Xue7f2b8562014-01-15 10:23:45 +08003034 if (!rdev->ops->set_txq_params)
3035 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02003036
Ying Xue7f2b8562014-01-15 10:23:45 +08003037 if (!netdev)
3038 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03003039
Johannes Berg133a3ff2011-11-03 14:50:13 +01003040 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08003041 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3042 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01003043
Ying Xue7f2b8562014-01-15 10:23:45 +08003044 if (!netif_running(netdev))
3045 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02003046
Jouni Malinen31888482008-10-30 16:59:24 +02003047 nla_for_each_nested(nl_txq_params,
3048 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
3049 rem_txq_params) {
Johannes Berg8cb08172019-04-26 14:07:28 +02003050 result = nla_parse_nested_deprecated(tb,
3051 NL80211_TXQ_ATTR_MAX,
3052 nl_txq_params,
3053 txq_params_policy,
3054 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01003055 if (result)
3056 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003057 result = parse_txq_params(tb, &txq_params);
3058 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003059 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003060
Hila Gonene35e4d22012-06-27 17:19:42 +03003061 result = rdev_set_txq_params(rdev, netdev,
3062 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02003063 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003064 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02003065 }
3066 }
3067
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003068 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03003069 result = __nl80211_set_channel(
3070 rdev,
3071 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
3072 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003073 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003074 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02003075 }
3076
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003077 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02003078 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003079 enum nl80211_tx_power_setting type;
3080 int idx, mbm = 0;
3081
Johannes Bergc8442112012-10-24 10:17:18 +02003082 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
3083 txp_wdev = NULL;
3084
Ying Xue7f2b8562014-01-15 10:23:45 +08003085 if (!rdev->ops->set_tx_power)
3086 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003087
3088 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
3089 type = nla_get_u32(info->attrs[idx]);
3090
3091 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08003092 (type != NL80211_TX_POWER_AUTOMATIC))
3093 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003094
3095 if (type != NL80211_TX_POWER_AUTOMATIC) {
3096 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
3097 mbm = nla_get_u32(info->attrs[idx]);
3098 }
3099
Johannes Bergc8442112012-10-24 10:17:18 +02003100 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003101 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003102 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03003103 }
3104
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003105 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
3106 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
3107 u32 tx_ant, rx_ant;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003108
Bruno Randolf7f531e02010-12-16 11:30:22 +09003109 if ((!rdev->wiphy.available_antennas_tx &&
3110 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08003111 !rdev->ops->set_antenna)
3112 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003113
3114 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
3115 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
3116
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003117 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09003118 * available antenna masks, except for the "all" mask */
3119 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08003120 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
3121 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003122
Bruno Randolf7f531e02010-12-16 11:30:22 +09003123 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
3124 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09003125
Hila Gonene35e4d22012-06-27 17:19:42 +03003126 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003127 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08003128 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09003129 }
3130
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003131 changed = 0;
3132
3133 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
3134 retry_short = nla_get_u8(
3135 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003136
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003137 changed |= WIPHY_PARAM_RETRY_SHORT;
3138 }
3139
3140 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
3141 retry_long = nla_get_u8(
3142 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003143
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003144 changed |= WIPHY_PARAM_RETRY_LONG;
3145 }
3146
3147 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
3148 frag_threshold = nla_get_u32(
3149 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08003150 if (frag_threshold < 256)
3151 return -EINVAL;
3152
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003153 if (frag_threshold != (u32) -1) {
3154 /*
3155 * Fragments (apart from the last one) are required to
3156 * have even length. Make the fragmentation code
3157 * simpler by stripping LSB should someone try to use
3158 * odd threshold value.
3159 */
3160 frag_threshold &= ~0x1;
3161 }
3162 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
3163 }
3164
3165 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
3166 rts_threshold = nla_get_u32(
3167 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
3168 changed |= WIPHY_PARAM_RTS_THRESHOLD;
3169 }
3170
Lukáš Turek81077e82009-12-21 22:50:47 +01003171 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003172 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
3173 return -EINVAL;
3174
Lukáš Turek81077e82009-12-21 22:50:47 +01003175 coverage_class = nla_get_u8(
3176 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
3177 changed |= WIPHY_PARAM_COVERAGE_CLASS;
3178 }
3179
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02003180 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
3181 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
3182 return -EOPNOTSUPP;
3183
3184 changed |= WIPHY_PARAM_DYN_ACK;
3185 }
3186
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003187 if (info->attrs[NL80211_ATTR_TXQ_LIMIT]) {
3188 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3189 NL80211_EXT_FEATURE_TXQS))
3190 return -EOPNOTSUPP;
3191 txq_limit = nla_get_u32(
3192 info->attrs[NL80211_ATTR_TXQ_LIMIT]);
3193 changed |= WIPHY_PARAM_TXQ_LIMIT;
3194 }
3195
3196 if (info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]) {
3197 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3198 NL80211_EXT_FEATURE_TXQS))
3199 return -EOPNOTSUPP;
3200 txq_memory_limit = nla_get_u32(
3201 info->attrs[NL80211_ATTR_TXQ_MEMORY_LIMIT]);
3202 changed |= WIPHY_PARAM_TXQ_MEMORY_LIMIT;
3203 }
3204
3205 if (info->attrs[NL80211_ATTR_TXQ_QUANTUM]) {
3206 if (!wiphy_ext_feature_isset(&rdev->wiphy,
3207 NL80211_EXT_FEATURE_TXQS))
3208 return -EOPNOTSUPP;
3209 txq_quantum = nla_get_u32(
3210 info->attrs[NL80211_ATTR_TXQ_QUANTUM]);
3211 changed |= WIPHY_PARAM_TXQ_QUANTUM;
3212 }
3213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003214 if (changed) {
3215 u8 old_retry_short, old_retry_long;
3216 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003217 u8 old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003218 u32 old_txq_limit, old_txq_memory_limit, old_txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003219
Ying Xue7f2b8562014-01-15 10:23:45 +08003220 if (!rdev->ops->set_wiphy_params)
3221 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003222
3223 old_retry_short = rdev->wiphy.retry_short;
3224 old_retry_long = rdev->wiphy.retry_long;
3225 old_frag_threshold = rdev->wiphy.frag_threshold;
3226 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003227 old_coverage_class = rdev->wiphy.coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003228 old_txq_limit = rdev->wiphy.txq_limit;
3229 old_txq_memory_limit = rdev->wiphy.txq_memory_limit;
3230 old_txq_quantum = rdev->wiphy.txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003231
3232 if (changed & WIPHY_PARAM_RETRY_SHORT)
3233 rdev->wiphy.retry_short = retry_short;
3234 if (changed & WIPHY_PARAM_RETRY_LONG)
3235 rdev->wiphy.retry_long = retry_long;
3236 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
3237 rdev->wiphy.frag_threshold = frag_threshold;
3238 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
3239 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003240 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
3241 rdev->wiphy.coverage_class = coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003242 if (changed & WIPHY_PARAM_TXQ_LIMIT)
3243 rdev->wiphy.txq_limit = txq_limit;
3244 if (changed & WIPHY_PARAM_TXQ_MEMORY_LIMIT)
3245 rdev->wiphy.txq_memory_limit = txq_memory_limit;
3246 if (changed & WIPHY_PARAM_TXQ_QUANTUM)
3247 rdev->wiphy.txq_quantum = txq_quantum;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003248
Hila Gonene35e4d22012-06-27 17:19:42 +03003249 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003250 if (result) {
3251 rdev->wiphy.retry_short = old_retry_short;
3252 rdev->wiphy.retry_long = old_retry_long;
3253 rdev->wiphy.frag_threshold = old_frag_threshold;
3254 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01003255 rdev->wiphy.coverage_class = old_coverage_class;
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003256 rdev->wiphy.txq_limit = old_txq_limit;
3257 rdev->wiphy.txq_memory_limit = old_txq_memory_limit;
3258 rdev->wiphy.txq_quantum = old_txq_quantum;
Michal Kazior9189ee32015-08-03 10:55:24 +02003259 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003260 }
3261 }
Ying Xue7f2b8562014-01-15 10:23:45 +08003262 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003263}
3264
Johannes Berg683b6d32012-11-08 21:25:48 +01003265static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01003266 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01003267{
Johannes Berg601555c2014-11-27 17:26:56 +01003268 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
3269 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003270
Johannes Berg683b6d32012-11-08 21:25:48 +01003271 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
3272 chandef->chan->center_freq))
3273 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01003274 switch (chandef->width) {
3275 case NL80211_CHAN_WIDTH_20_NOHT:
3276 case NL80211_CHAN_WIDTH_20:
3277 case NL80211_CHAN_WIDTH_40:
3278 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
3279 cfg80211_get_chandef_type(chandef)))
3280 return -ENOBUFS;
3281 break;
3282 default:
3283 break;
3284 }
3285 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
3286 return -ENOBUFS;
3287 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
3288 return -ENOBUFS;
3289 if (chandef->center_freq2 &&
3290 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01003291 return -ENOBUFS;
3292 return 0;
3293}
3294
Eric W. Biederman15e47302012-09-07 20:12:54 +00003295static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02003296 struct cfg80211_registered_device *rdev,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003297 struct wireless_dev *wdev,
3298 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -04003299{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003300 struct net_device *dev = wdev->netdev;
Johannes Berg55682962007-09-20 13:09:35 -04003301 void *hdr;
3302
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003303 WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE &&
3304 cmd != NL80211_CMD_DEL_INTERFACE &&
3305 cmd != NL80211_CMD_SET_INTERFACE);
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02003306
3307 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04003308 if (!hdr)
3309 return -1;
3310
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003311 if (dev &&
3312 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003313 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003314 goto nla_put_failure;
3315
3316 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
3317 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02003318 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
3319 NL80211_ATTR_PAD) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02003320 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04003321 nla_put_u32(msg, NL80211_ATTR_GENERATION,
3322 rdev->devlist_generation ^
Antonio Quartulli446faa12018-06-14 09:43:06 +08003323 (cfg80211_rdev_list_generation << 2)) ||
3324 nla_put_u8(msg, NL80211_ATTR_4ADDR, wdev->use_4addr))
David S. Miller9360ffd2012-03-29 04:41:26 -04003325 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003326
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003327 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003328 int ret;
Johannes Bergf43e5212019-09-23 13:51:16 +02003329 struct cfg80211_chan_def chandef = {};
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003330
Johannes Berg683b6d32012-11-08 21:25:48 +01003331 ret = rdev_get_channel(rdev, wdev, &chandef);
3332 if (ret == 0) {
3333 if (nl80211_send_chandef(msg, &chandef))
3334 goto nla_put_failure;
3335 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02003336 }
3337
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02003338 if (rdev->ops->get_tx_power) {
3339 int dbm, ret;
3340
3341 ret = rdev_get_tx_power(rdev, wdev, &dbm);
3342 if (ret == 0 &&
3343 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
3344 DBM_TO_MBM(dbm)))
3345 goto nla_put_failure;
3346 }
3347
Johannes Berg44905262017-10-17 21:56:01 +02003348 wdev_lock(wdev);
3349 switch (wdev->iftype) {
3350 case NL80211_IFTYPE_AP:
3351 if (wdev->ssid_len &&
3352 nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
Johannes Berg4564b182017-12-11 12:33:47 +01003353 goto nla_put_failure_locked;
Johannes Berg44905262017-10-17 21:56:01 +02003354 break;
3355 case NL80211_IFTYPE_STATION:
3356 case NL80211_IFTYPE_P2P_CLIENT:
3357 case NL80211_IFTYPE_ADHOC: {
3358 const u8 *ssid_ie;
3359 if (!wdev->current_bss)
3360 break;
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003361 rcu_read_lock();
Johannes Berg44905262017-10-17 21:56:01 +02003362 ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub,
3363 WLAN_EID_SSID);
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003364 if (ssid_ie &&
3365 nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2))
3366 goto nla_put_failure_rcu_locked;
3367 rcu_read_unlock();
Johannes Berg44905262017-10-17 21:56:01 +02003368 break;
3369 }
3370 default:
3371 /* nothing */
3372 break;
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003373 }
Johannes Berg44905262017-10-17 21:56:01 +02003374 wdev_unlock(wdev);
Antonio Quartullib84e7a02012-11-07 12:52:20 +01003375
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02003376 if (rdev->ops->get_txq_stats) {
3377 struct cfg80211_txq_stats txqstats = {};
3378 int ret = rdev_get_txq_stats(rdev, wdev, &txqstats);
3379
3380 if (ret == 0 &&
3381 !nl80211_put_txq_stats(msg, &txqstats,
3382 NL80211_ATTR_TXQ_STATS))
3383 goto nla_put_failure;
3384 }
3385
Johannes Berg053c0952015-01-16 22:09:00 +01003386 genlmsg_end(msg, hdr);
3387 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04003388
Dominik Brodowski7a94b8c2018-01-15 08:12:15 +01003389 nla_put_failure_rcu_locked:
3390 rcu_read_unlock();
Johannes Berg4564b182017-12-11 12:33:47 +01003391 nla_put_failure_locked:
3392 wdev_unlock(wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003393 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003394 genlmsg_cancel(msg, hdr);
3395 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04003396}
3397
3398static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
3399{
3400 int wp_idx = 0;
3401 int if_idx = 0;
3402 int wp_start = cb->args[0];
3403 int if_start = cb->args[1];
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003404 int filter_wiphy = -1;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003405 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04003406 struct wireless_dev *wdev;
Johannes Bergea90e0d2017-03-15 14:26:04 +01003407 int ret;
Johannes Berg55682962007-09-20 13:09:35 -04003408
Johannes Berg5fe231e2013-05-08 21:45:15 +02003409 rtnl_lock();
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003410 if (!cb->args[2]) {
3411 struct nl80211_dump_wiphy_state state = {
3412 .filter_wiphy = -1,
3413 };
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003414
3415 ret = nl80211_dump_wiphy_parse(skb, cb, &state);
3416 if (ret)
Johannes Bergea90e0d2017-03-15 14:26:04 +01003417 goto out_unlock;
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003418
3419 filter_wiphy = state.filter_wiphy;
3420
3421 /*
3422 * if filtering, set cb->args[2] to +1 since 0 is the default
3423 * value needed to determine that parsing is necessary.
3424 */
3425 if (filter_wiphy >= 0)
3426 cb->args[2] = filter_wiphy + 1;
3427 else
3428 cb->args[2] = -1;
3429 } else if (cb->args[2] > 0) {
3430 filter_wiphy = cb->args[2] - 1;
3431 }
3432
Johannes Bergf5ea9122009-08-07 16:17:38 +02003433 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
3434 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02003435 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003436 if (wp_idx < wp_start) {
3437 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003438 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003439 }
Denis Kenziorb7fb44d2016-08-03 17:02:15 -05003440
3441 if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx)
3442 continue;
3443
Johannes Berg55682962007-09-20 13:09:35 -04003444 if_idx = 0;
3445
Johannes Berg53873f12016-05-03 16:52:04 +03003446 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003447 if (if_idx < if_start) {
3448 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003449 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003450 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00003451 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04003452 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003453 rdev, wdev,
3454 NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02003455 goto out;
3456 }
3457 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003458 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003459
3460 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04003461 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02003462 out:
Johannes Berg55682962007-09-20 13:09:35 -04003463 cb->args[0] = wp_idx;
3464 cb->args[1] = if_idx;
3465
Johannes Bergea90e0d2017-03-15 14:26:04 +01003466 ret = skb->len;
3467 out_unlock:
3468 rtnl_unlock();
3469
3470 return ret;
Johannes Berg55682962007-09-20 13:09:35 -04003471}
3472
3473static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
3474{
3475 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02003477 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003478
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04003480 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003481 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04003482
Eric W. Biederman15e47302012-09-07 20:12:54 +00003483 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003484 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003485 nlmsg_free(msg);
3486 return -ENOBUFS;
3487 }
Johannes Berg55682962007-09-20 13:09:35 -04003488
Johannes Berg134e6372009-07-10 09:51:34 +00003489 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003490}
3491
Michael Wu66f7ac52008-01-31 19:48:22 +01003492static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
3493 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
3494 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
3495 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
3496 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
3497 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003498 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01003499};
3500
3501static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
3502{
3503 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
3504 int flag;
3505
3506 *mntrflags = 0;
3507
3508 if (!nla)
3509 return -EINVAL;
3510
Johannes Berg8cb08172019-04-26 14:07:28 +02003511 if (nla_parse_nested_deprecated(flags, NL80211_MNTR_FLAG_MAX, nla, mntr_flags_policy, NULL))
Michael Wu66f7ac52008-01-31 19:48:22 +01003512 return -EINVAL;
3513
3514 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
3515 if (flags[flag])
3516 *mntrflags |= (1<<flag);
3517
Johannes Berg818a9862017-04-12 11:23:28 +02003518 *mntrflags |= MONITOR_FLAG_CHANGED;
3519
Michael Wu66f7ac52008-01-31 19:48:22 +01003520 return 0;
3521}
3522
Johannes Berg1db77592017-04-12 11:36:31 +02003523static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev,
3524 enum nl80211_iftype type,
3525 struct genl_info *info,
3526 struct vif_params *params)
3527{
3528 bool change = false;
3529 int err;
3530
3531 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
3532 if (type != NL80211_IFTYPE_MONITOR)
3533 return -EINVAL;
3534
3535 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
3536 &params->flags);
3537 if (err)
3538 return err;
3539
3540 change = true;
3541 }
3542
3543 if (params->flags & MONITOR_FLAG_ACTIVE &&
3544 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
3545 return -EOPNOTSUPP;
3546
3547 if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) {
3548 const u8 *mumimo_groups;
3549 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3550
3551 if (type != NL80211_IFTYPE_MONITOR)
3552 return -EINVAL;
3553
3554 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3555 return -EOPNOTSUPP;
3556
3557 mumimo_groups =
3558 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]);
3559
3560 /* bits 0 and 63 are reserved and must be zero */
Johannes Berg49546012017-04-27 09:13:38 +02003561 if ((mumimo_groups[0] & BIT(0)) ||
3562 (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7)))
Johannes Berg1db77592017-04-12 11:36:31 +02003563 return -EINVAL;
3564
3565 params->vht_mumimo_groups = mumimo_groups;
3566 change = true;
3567 }
3568
3569 if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) {
3570 u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER;
3571
3572 if (type != NL80211_IFTYPE_MONITOR)
3573 return -EINVAL;
3574
3575 if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag))
3576 return -EOPNOTSUPP;
3577
3578 params->vht_mumimo_follow_addr =
3579 nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]);
3580 change = true;
3581 }
3582
3583 return change ? 1 : 0;
3584}
3585
Johannes Berg9bc383d2009-11-19 11:55:19 +01003586static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003587 struct net_device *netdev, u8 use_4addr,
3588 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01003589{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003590 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00003591 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003592 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003593 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003594 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01003595
3596 switch (iftype) {
3597 case NL80211_IFTYPE_AP_VLAN:
3598 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
3599 return 0;
3600 break;
3601 case NL80211_IFTYPE_STATION:
3602 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
3603 return 0;
3604 break;
3605 default:
3606 break;
3607 }
3608
3609 return -EOPNOTSUPP;
3610}
3611
Johannes Berg55682962007-09-20 13:09:35 -04003612static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
3613{
Johannes Berg4c476992010-10-04 21:36:35 +02003614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003615 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02003616 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02003617 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02003618 struct net_device *dev = info->user_ptr[1];
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003619 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04003620
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003621 memset(&params, 0, sizeof(params));
3622
Johannes Berg04a773a2009-04-19 21:24:32 +02003623 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04003624
Johannes Berg723b0382008-09-16 20:22:09 +02003625 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003626 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02003627 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003628 change = true;
Johannes Berg723b0382008-09-16 20:22:09 +02003629 }
3630
Johannes Berg92ffe052008-09-16 20:39:36 +02003631 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01003632 struct wireless_dev *wdev = dev->ieee80211_ptr;
3633
Johannes Berg4c476992010-10-04 21:36:35 +02003634 if (ntype != NL80211_IFTYPE_MESH_POINT)
3635 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01003636 if (netif_running(dev))
3637 return -EBUSY;
3638
3639 wdev_lock(wdev);
3640 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3641 IEEE80211_MAX_MESH_ID_LEN);
3642 wdev->mesh_id_up_len =
3643 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3644 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3645 wdev->mesh_id_up_len);
3646 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003647 }
3648
Felix Fietkau8b787642009-11-10 18:53:10 +01003649 if (info->attrs[NL80211_ATTR_4ADDR]) {
3650 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
3651 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003652 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003653 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003654 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01003655 } else {
3656 params.use_4addr = -1;
3657 }
3658
Johannes Berg1db77592017-04-12 11:36:31 +02003659 err = nl80211_parse_mon_options(rdev, ntype, info, &params);
3660 if (err < 0)
3661 return err;
3662 if (err > 0)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003663 change = true;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003664
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003665 if (change)
Johannes Berg818a9862017-04-12 11:23:28 +02003666 err = cfg80211_change_iface(rdev, dev, ntype, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01003667 else
3668 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02003669
Johannes Berg9bc383d2009-11-19 11:55:19 +01003670 if (!err && params.use_4addr != -1)
3671 dev->ieee80211_ptr->use_4addr = params.use_4addr;
3672
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003673 if (change && !err) {
3674 struct wireless_dev *wdev = dev->ieee80211_ptr;
3675
3676 nl80211_notify_iface(rdev, wdev, NL80211_CMD_SET_INTERFACE);
3677 }
3678
Johannes Berg55682962007-09-20 13:09:35 -04003679 return err;
3680}
3681
3682static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
3683{
Johannes Berg4c476992010-10-04 21:36:35 +02003684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003685 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02003686 struct wireless_dev *wdev;
Denis Kenzior896ff062016-08-03 16:58:33 -05003687 struct sk_buff *msg;
Johannes Berg55682962007-09-20 13:09:35 -04003688 int err;
3689 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
3690
Johannes Berg78f22b62014-03-24 17:57:27 +01003691 /* to avoid failing a new interface creation due to pending removal */
3692 cfg80211_destroy_ifaces(rdev);
3693
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003694 memset(&params, 0, sizeof(params));
3695
Johannes Berg55682962007-09-20 13:09:35 -04003696 if (!info->attrs[NL80211_ATTR_IFNAME])
3697 return -EINVAL;
3698
Johannes Bergab0d76f2018-10-02 10:00:07 +02003699 if (info->attrs[NL80211_ATTR_IFTYPE])
Johannes Berg55682962007-09-20 13:09:35 -04003700 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg55682962007-09-20 13:09:35 -04003701
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303702 if (!rdev->ops->add_virtual_intf)
Johannes Berg4c476992010-10-04 21:36:35 +02003703 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04003704
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003705 if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN ||
Ben Greeare8f479b2014-10-22 12:23:05 -07003706 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
3707 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01003708 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
3709 ETH_ALEN);
3710 if (!is_valid_ether_addr(params.macaddr))
3711 return -EADDRNOTAVAIL;
3712 }
3713
Johannes Berg9bc383d2009-11-19 11:55:19 +01003714 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01003715 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01003716 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01003717 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003718 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01003719 }
Felix Fietkau8b787642009-11-10 18:53:10 +01003720
Manikanta Pubbisettye6f40512019-07-22 12:44:50 +05303721 if (!cfg80211_iftype_allowed(&rdev->wiphy, type, params.use_4addr, 0))
Manikanta Pubbisetty33d915d2019-05-08 14:55:33 +05303722 return -EOPNOTSUPP;
3723
Johannes Berg1db77592017-04-12 11:36:31 +02003724 err = nl80211_parse_mon_options(rdev, type, info, &params);
3725 if (err < 0)
3726 return err;
Felix Fietkaue057d3c2013-05-28 13:01:52 +02003727
Johannes Berga18c7192015-02-24 10:56:42 +01003728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
3729 if (!msg)
3730 return -ENOMEM;
3731
Hila Gonene35e4d22012-06-27 17:19:42 +03003732 wdev = rdev_add_virtual_intf(rdev,
3733 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Johannes Berg818a9862017-04-12 11:23:28 +02003734 NET_NAME_USER, type, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01003735 if (WARN_ON(!wdev)) {
3736 nlmsg_free(msg);
3737 return -EPROTO;
3738 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003739 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02003740 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003741 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003742
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02003743 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01003744 wdev->owner_nlportid = info->snd_portid;
3745
Johannes Berg98104fde2012-06-16 00:19:54 +02003746 switch (type) {
3747 case NL80211_IFTYPE_MESH_POINT:
3748 if (!info->attrs[NL80211_ATTR_MESH_ID])
3749 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003750 wdev_lock(wdev);
3751 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
3752 IEEE80211_MAX_MESH_ID_LEN);
3753 wdev->mesh_id_up_len =
3754 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
3755 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
3756 wdev->mesh_id_up_len);
3757 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003758 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003759 case NL80211_IFTYPE_NAN:
Johannes Berg98104fde2012-06-16 00:19:54 +02003760 case NL80211_IFTYPE_P2P_DEVICE:
3761 /*
Ayala Bekercb3b7d82016-09-20 17:31:13 +03003762 * P2P Device and NAN do not have a netdev, so don't go
Johannes Berg98104fde2012-06-16 00:19:54 +02003763 * through the netdev notifier and must be added here
3764 */
Johannes Berge4d42162018-09-13 14:12:03 +02003765 cfg80211_init_wdev(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02003766 break;
3767 default:
3768 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01003769 }
3770
Eric W. Biederman15e47302012-09-07 20:12:54 +00003771 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +02003772 rdev, wdev, NL80211_CMD_NEW_INTERFACE) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02003773 nlmsg_free(msg);
3774 return -ENOBUFS;
3775 }
3776
3777 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04003778}
3779
3780static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
3781{
Johannes Berg4c476992010-10-04 21:36:35 +02003782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02003783 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04003784
Johannes Berg4c476992010-10-04 21:36:35 +02003785 if (!rdev->ops->del_virtual_intf)
3786 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003787
Johannes Berg84efbb82012-06-16 00:00:26 +02003788 /*
3789 * If we remove a wireless device without a netdev then clear
3790 * user_ptr[1] so that nl80211_post_doit won't dereference it
3791 * to check if it needs to do dev_put(). Otherwise it crashes
3792 * since the wdev has been freed, unlike with a netdev where
3793 * we need the dev_put() for the netdev to really be freed.
3794 */
3795 if (!wdev->netdev)
3796 info->user_ptr[1] = NULL;
3797
Denis Kenzior7f8ed012016-08-03 16:58:35 -05003798 return rdev_del_virtual_intf(rdev, wdev);
Johannes Berg55682962007-09-20 13:09:35 -04003799}
3800
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003801static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
3802{
3803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3804 struct net_device *dev = info->user_ptr[1];
3805 u16 noack_map;
3806
3807 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
3808 return -EINVAL;
3809
3810 if (!rdev->ops->set_noack_map)
3811 return -EOPNOTSUPP;
3812
3813 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
3814
Hila Gonene35e4d22012-06-27 17:19:42 +03003815 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01003816}
3817
Johannes Berg41ade002007-12-19 02:03:29 +01003818struct get_key_cookie {
3819 struct sk_buff *msg;
3820 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02003821 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003822};
3823
3824static void get_key_callback(void *c, struct key_params *params)
3825{
Johannes Bergb9454e82009-07-08 13:29:08 +02003826 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01003827 struct get_key_cookie *cookie = c;
3828
David S. Miller9360ffd2012-03-29 04:41:26 -04003829 if ((params->key &&
3830 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
3831 params->key_len, params->key)) ||
3832 (params->seq &&
3833 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
3834 params->seq_len, params->seq)) ||
3835 (params->cipher &&
3836 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
3837 params->cipher)))
3838 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003839
Michal Kubecekae0be8d2019-04-26 11:13:06 +02003840 key = nla_nest_start_noflag(cookie->msg, NL80211_ATTR_KEY);
Johannes Bergb9454e82009-07-08 13:29:08 +02003841 if (!key)
3842 goto nla_put_failure;
3843
David S. Miller9360ffd2012-03-29 04:41:26 -04003844 if ((params->key &&
3845 nla_put(cookie->msg, NL80211_KEY_DATA,
3846 params->key_len, params->key)) ||
3847 (params->seq &&
3848 nla_put(cookie->msg, NL80211_KEY_SEQ,
3849 params->seq_len, params->seq)) ||
3850 (params->cipher &&
3851 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
3852 params->cipher)))
3853 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003854
Andrew Zaborowskiefdfce72018-09-24 18:10:22 +02003855 if (nla_put_u8(cookie->msg, NL80211_KEY_IDX, cookie->idx))
David S. Miller9360ffd2012-03-29 04:41:26 -04003856 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02003857
3858 nla_nest_end(cookie->msg, key);
3859
Johannes Berg41ade002007-12-19 02:03:29 +01003860 return;
3861 nla_put_failure:
3862 cookie->error = 1;
3863}
3864
3865static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
3866{
Johannes Berg4c476992010-10-04 21:36:35 +02003867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003868 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003869 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003870 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02003871 const u8 *mac_addr = NULL;
3872 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01003873 struct get_key_cookie cookie = {
3874 .error = 0,
3875 };
3876 void *hdr;
3877 struct sk_buff *msg;
3878
Jouni Malinen56be3932020-02-22 15:25:43 +02003879 if (info->attrs[NL80211_ATTR_KEY_IDX]) {
Johannes Berg41ade002007-12-19 02:03:29 +01003880 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
Jouni Malinen56be3932020-02-22 15:25:43 +02003881 if (key_idx > 5 &&
3882 !wiphy_ext_feature_isset(
3883 &rdev->wiphy,
3884 NL80211_EXT_FEATURE_BEACON_PROTECTION))
3885 return -EINVAL;
3886 }
Johannes Berg41ade002007-12-19 02:03:29 +01003887
Johannes Berg41ade002007-12-19 02:03:29 +01003888 if (info->attrs[NL80211_ATTR_MAC])
3889 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3890
Johannes Berge31b8212010-10-05 19:39:30 +02003891 pairwise = !!mac_addr;
3892 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
3893 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07003894
Johannes Berge31b8212010-10-05 19:39:30 +02003895 if (kt != NL80211_KEYTYPE_GROUP &&
3896 kt != NL80211_KEYTYPE_PAIRWISE)
3897 return -EINVAL;
3898 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
3899 }
3900
Johannes Berg4c476992010-10-04 21:36:35 +02003901 if (!rdev->ops->get_key)
3902 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003903
Johannes Berg0fa7b392015-01-23 11:10:12 +01003904 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3905 return -ENOENT;
3906
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02003908 if (!msg)
3909 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01003910
Eric W. Biederman15e47302012-09-07 20:12:54 +00003911 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01003912 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03003913 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02003914 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003915
3916 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02003917 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01003918
David S. Miller9360ffd2012-03-29 04:41:26 -04003919 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3920 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
3921 goto nla_put_failure;
3922 if (mac_addr &&
3923 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
3924 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01003925
Hila Gonene35e4d22012-06-27 17:19:42 +03003926 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
3927 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01003928
3929 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003930 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01003931
3932 if (cookie.error)
3933 goto nla_put_failure;
3934
3935 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02003936 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01003937
3938 nla_put_failure:
3939 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03003940 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01003941 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01003942 return err;
3943}
3944
3945static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
3946{
Johannes Berg4c476992010-10-04 21:36:35 +02003947 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02003948 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003949 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003950 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003951
Johannes Bergb9454e82009-07-08 13:29:08 +02003952 err = nl80211_parse_key(info, &key);
3953 if (err)
3954 return err;
3955
3956 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01003957 return -EINVAL;
3958
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003959 /* Only support setting default key and
3960 * Extended Key ID action NL80211_KEY_SET_TX.
3961 */
Jouni Malinen56be3932020-02-22 15:25:43 +02003962 if (!key.def && !key.defmgmt && !key.defbeacon &&
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003963 !(key.p.mode == NL80211_KEY_SET_TX))
Johannes Berg41ade002007-12-19 02:03:29 +01003964 return -EINVAL;
3965
Johannes Bergfffd0932009-07-08 14:22:54 +02003966 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003967
3968 if (key.def) {
3969 if (!rdev->ops->set_default_key) {
3970 err = -EOPNOTSUPP;
3971 goto out;
3972 }
3973
3974 err = nl80211_key_allowed(dev->ieee80211_ptr);
3975 if (err)
3976 goto out;
3977
Hila Gonene35e4d22012-06-27 17:19:42 +03003978 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003979 key.def_uni, key.def_multi);
3980
3981 if (err)
3982 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02003983
Johannes Berg3d23e342009-09-29 23:27:28 +02003984#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003985 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02003986#endif
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01003987 } else if (key.defmgmt) {
Johannes Bergdbd2fd62010-12-09 19:58:59 +01003988 if (key.def_uni || !key.def_multi) {
3989 err = -EINVAL;
3990 goto out;
3991 }
3992
3993 if (!rdev->ops->set_default_mgmt_key) {
3994 err = -EOPNOTSUPP;
3995 goto out;
3996 }
3997
3998 err = nl80211_key_allowed(dev->ieee80211_ptr);
3999 if (err)
4000 goto out;
4001
Hila Gonene35e4d22012-06-27 17:19:42 +03004002 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004003 if (err)
4004 goto out;
4005
4006#ifdef CONFIG_CFG80211_WEXT
4007 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
4008#endif
Jouni Malinen56be3932020-02-22 15:25:43 +02004009 } else if (key.defbeacon) {
4010 if (key.def_uni || !key.def_multi) {
4011 err = -EINVAL;
4012 goto out;
4013 }
4014
4015 if (!rdev->ops->set_default_beacon_key) {
4016 err = -EOPNOTSUPP;
4017 goto out;
4018 }
4019
4020 err = nl80211_key_allowed(dev->ieee80211_ptr);
4021 if (err)
4022 goto out;
4023
4024 err = rdev_set_default_beacon_key(rdev, dev, key.idx);
4025 if (err)
4026 goto out;
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004027 } else if (key.p.mode == NL80211_KEY_SET_TX &&
4028 wiphy_ext_feature_isset(&rdev->wiphy,
4029 NL80211_EXT_FEATURE_EXT_KEY_ID)) {
4030 u8 *mac_addr = NULL;
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004031
Alexander Wetzel6cdd3972019-03-19 21:34:07 +01004032 if (info->attrs[NL80211_ATTR_MAC])
4033 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4034
4035 if (!mac_addr || key.idx < 0 || key.idx > 1) {
4036 err = -EINVAL;
4037 goto out;
4038 }
4039
4040 err = rdev_add_key(rdev, dev, key.idx,
4041 NL80211_KEYTYPE_PAIRWISE,
4042 mac_addr, &key.p);
4043 } else {
4044 err = -EINVAL;
4045 }
Johannes Bergdbd2fd62010-12-09 19:58:59 +01004046 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02004047 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01004048
Johannes Berg41ade002007-12-19 02:03:29 +01004049 return err;
4050}
4051
4052static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
4053{
Johannes Berg4c476992010-10-04 21:36:35 +02004054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02004055 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004056 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02004057 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02004058 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01004059
Johannes Bergb9454e82009-07-08 13:29:08 +02004060 err = nl80211_parse_key(info, &key);
4061 if (err)
4062 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01004063
Jouni Malinenf8af7642020-02-22 15:25:42 +02004064 if (!key.p.key) {
4065 GENL_SET_ERR_MSG(info, "no key");
Johannes Berg41ade002007-12-19 02:03:29 +01004066 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004067 }
Johannes Berg41ade002007-12-19 02:03:29 +01004068
Johannes Berg41ade002007-12-19 02:03:29 +01004069 if (info->attrs[NL80211_ATTR_MAC])
4070 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4071
Johannes Berge31b8212010-10-05 19:39:30 +02004072 if (key.type == -1) {
4073 if (mac_addr)
4074 key.type = NL80211_KEYTYPE_PAIRWISE;
4075 else
4076 key.type = NL80211_KEYTYPE_GROUP;
4077 }
4078
4079 /* for now */
4080 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
Jouni Malinenf8af7642020-02-22 15:25:42 +02004081 key.type != NL80211_KEYTYPE_GROUP) {
4082 GENL_SET_ERR_MSG(info, "key type not pairwise or group");
Johannes Berge31b8212010-10-05 19:39:30 +02004083 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004084 }
Johannes Berge31b8212010-10-05 19:39:30 +02004085
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02004086 if (key.type == NL80211_KEYTYPE_GROUP &&
4087 info->attrs[NL80211_ATTR_VLAN_ID])
4088 key.p.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
4089
Johannes Berg4c476992010-10-04 21:36:35 +02004090 if (!rdev->ops->add_key)
4091 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004092
Johannes Berge31b8212010-10-05 19:39:30 +02004093 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
4094 key.type == NL80211_KEYTYPE_PAIRWISE,
Jouni Malinenf8af7642020-02-22 15:25:42 +02004095 mac_addr)) {
4096 GENL_SET_ERR_MSG(info, "key setting validation failed");
Johannes Berg4c476992010-10-04 21:36:35 +02004097 return -EINVAL;
Jouni Malinenf8af7642020-02-22 15:25:42 +02004098 }
Johannes Bergfffd0932009-07-08 14:22:54 +02004099
4100 wdev_lock(dev->ieee80211_ptr);
4101 err = nl80211_key_allowed(dev->ieee80211_ptr);
Jouni Malinenf8af7642020-02-22 15:25:42 +02004102 if (err)
4103 GENL_SET_ERR_MSG(info, "key not allowed");
4104 if (!err) {
Hila Gonene35e4d22012-06-27 17:19:42 +03004105 err = rdev_add_key(rdev, dev, key.idx,
4106 key.type == NL80211_KEYTYPE_PAIRWISE,
4107 mac_addr, &key.p);
Jouni Malinenf8af7642020-02-22 15:25:42 +02004108 if (err)
4109 GENL_SET_ERR_MSG(info, "key addition failed");
4110 }
Johannes Bergfffd0932009-07-08 14:22:54 +02004111 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01004112
Johannes Berg41ade002007-12-19 02:03:29 +01004113 return err;
4114}
4115
4116static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
4117{
Johannes Berg4c476992010-10-04 21:36:35 +02004118 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01004119 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004120 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01004121 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02004122 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01004123
Johannes Bergb9454e82009-07-08 13:29:08 +02004124 err = nl80211_parse_key(info, &key);
4125 if (err)
4126 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01004127
4128 if (info->attrs[NL80211_ATTR_MAC])
4129 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4130
Johannes Berge31b8212010-10-05 19:39:30 +02004131 if (key.type == -1) {
4132 if (mac_addr)
4133 key.type = NL80211_KEYTYPE_PAIRWISE;
4134 else
4135 key.type = NL80211_KEYTYPE_GROUP;
4136 }
4137
4138 /* for now */
4139 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
4140 key.type != NL80211_KEYTYPE_GROUP)
4141 return -EINVAL;
4142
Johannes Berg4c476992010-10-04 21:36:35 +02004143 if (!rdev->ops->del_key)
4144 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01004145
Johannes Bergfffd0932009-07-08 14:22:54 +02004146 wdev_lock(dev->ieee80211_ptr);
4147 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02004148
Johannes Berg0fa7b392015-01-23 11:10:12 +01004149 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02004150 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
4151 err = -ENOENT;
4152
Johannes Bergfffd0932009-07-08 14:22:54 +02004153 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03004154 err = rdev_del_key(rdev, dev, key.idx,
4155 key.type == NL80211_KEYTYPE_PAIRWISE,
4156 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01004157
Johannes Berg3d23e342009-09-29 23:27:28 +02004158#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02004159 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02004160 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02004161 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02004162 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02004163 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
4164 }
4165#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02004166 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02004167
Johannes Berg41ade002007-12-19 02:03:29 +01004168 return err;
4169}
4170
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304171/* This function returns an error or the number of nested attributes */
4172static int validate_acl_mac_addrs(struct nlattr *nl_attr)
4173{
4174 struct nlattr *attr;
4175 int n_entries = 0, tmp;
4176
4177 nla_for_each_nested(attr, nl_attr, tmp) {
4178 if (nla_len(attr) != ETH_ALEN)
4179 return -EINVAL;
4180
4181 n_entries++;
4182 }
4183
4184 return n_entries;
4185}
4186
4187/*
4188 * This function parses ACL information and allocates memory for ACL data.
4189 * On successful return, the calling function is responsible to free the
4190 * ACL buffer returned by this function.
4191 */
4192static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
4193 struct genl_info *info)
4194{
4195 enum nl80211_acl_policy acl_policy;
4196 struct nlattr *attr;
4197 struct cfg80211_acl_data *acl;
4198 int i = 0, n_entries, tmp;
4199
4200 if (!wiphy->max_acl_mac_addrs)
4201 return ERR_PTR(-EOPNOTSUPP);
4202
4203 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
4204 return ERR_PTR(-EINVAL);
4205
4206 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
4207 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
4208 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
4209 return ERR_PTR(-EINVAL);
4210
4211 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
4212 return ERR_PTR(-EINVAL);
4213
4214 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
4215 if (n_entries < 0)
4216 return ERR_PTR(n_entries);
4217
4218 if (n_entries > wiphy->max_acl_mac_addrs)
4219 return ERR_PTR(-ENOTSUPP);
4220
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05004221 acl = kzalloc(struct_size(acl, mac_addrs, n_entries), GFP_KERNEL);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05304222 if (!acl)
4223 return ERR_PTR(-ENOMEM);
4224
4225 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
4226 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
4227 i++;
4228 }
4229
4230 acl->n_acl_entries = n_entries;
4231 acl->acl_policy = acl_policy;
4232
4233 return acl;
4234}
4235
4236static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
4237{
4238 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4239 struct net_device *dev = info->user_ptr[1];
4240 struct cfg80211_acl_data *acl;
4241 int err;
4242
4243 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4244 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4245 return -EOPNOTSUPP;
4246
4247 if (!dev->ieee80211_ptr->beacon_interval)
4248 return -EINVAL;
4249
4250 acl = parse_acl_data(&rdev->wiphy, info);
4251 if (IS_ERR(acl))
4252 return PTR_ERR(acl);
4253
4254 err = rdev_set_mac_acl(rdev, dev, acl);
4255
4256 kfree(acl);
4257
4258 return err;
4259}
4260
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304261static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
4262 u8 *rates, u8 rates_len)
4263{
4264 u8 i;
4265 u32 mask = 0;
4266
4267 for (i = 0; i < rates_len; i++) {
4268 int rate = (rates[i] & 0x7f) * 5;
4269 int ridx;
4270
4271 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
4272 struct ieee80211_rate *srate =
4273 &sband->bitrates[ridx];
4274 if (rate == srate->bitrate) {
4275 mask |= 1 << ridx;
4276 break;
4277 }
4278 }
4279 if (ridx == sband->n_bitrates)
4280 return 0; /* rate not found */
4281 }
4282
4283 return mask;
4284}
4285
4286static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
4287 u8 *rates, u8 rates_len,
4288 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
4289{
4290 u8 i;
4291
4292 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
4293
4294 for (i = 0; i < rates_len; i++) {
4295 int ridx, rbit;
4296
4297 ridx = rates[i] / 8;
4298 rbit = BIT(rates[i] % 8);
4299
4300 /* check validity */
4301 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
4302 return false;
4303
4304 /* check availability */
Masashi Honma30fe6d52018-09-25 11:15:00 +09004305 ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304306 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
4307 mcs[ridx] |= rbit;
4308 else
4309 return false;
4310 }
4311
4312 return true;
4313}
4314
4315static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
4316{
4317 u16 mcs_mask = 0;
4318
4319 switch (vht_mcs_map) {
4320 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
4321 break;
4322 case IEEE80211_VHT_MCS_SUPPORT_0_7:
4323 mcs_mask = 0x00FF;
4324 break;
4325 case IEEE80211_VHT_MCS_SUPPORT_0_8:
4326 mcs_mask = 0x01FF;
4327 break;
4328 case IEEE80211_VHT_MCS_SUPPORT_0_9:
4329 mcs_mask = 0x03FF;
4330 break;
4331 default:
4332 break;
4333 }
4334
4335 return mcs_mask;
4336}
4337
4338static void vht_build_mcs_mask(u16 vht_mcs_map,
4339 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
4340{
4341 u8 nss;
4342
4343 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
4344 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
4345 vht_mcs_map >>= 2;
4346 }
4347}
4348
4349static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
4350 struct nl80211_txrate_vht *txrate,
4351 u16 mcs[NL80211_VHT_NSS_MAX])
4352{
4353 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4354 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
4355 u8 i;
4356
4357 if (!sband->vht_cap.vht_supported)
4358 return false;
4359
4360 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
4361
4362 /* Build vht_mcs_mask from VHT capabilities */
4363 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
4364
4365 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
4366 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
4367 mcs[i] = txrate->mcs[i];
4368 else
4369 return false;
4370 }
4371
4372 return true;
4373}
4374
4375static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
4376 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
4377 .len = NL80211_MAX_SUPP_RATES },
4378 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
4379 .len = NL80211_MAX_SUPP_HT_RATES },
Johannes Berg180aa422019-05-28 14:19:07 +02004380 [NL80211_TXRATE_VHT] = {
4381 .type = NLA_EXACT_LEN_WARN,
4382 .len = sizeof(struct nl80211_txrate_vht),
4383 },
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304384 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
4385};
4386
4387static int nl80211_parse_tx_bitrate_mask(struct genl_info *info,
4388 struct cfg80211_bitrate_mask *mask)
4389{
4390 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
4391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4392 int rem, i;
4393 struct nlattr *tx_rates;
4394 struct ieee80211_supported_band *sband;
4395 u16 vht_tx_mcs_map;
4396
4397 memset(mask, 0, sizeof(*mask));
4398 /* Default to all rates enabled */
4399 for (i = 0; i < NUM_NL80211_BANDS; i++) {
4400 sband = rdev->wiphy.bands[i];
4401
4402 if (!sband)
4403 continue;
4404
4405 mask->control[i].legacy = (1 << sband->n_bitrates) - 1;
4406 memcpy(mask->control[i].ht_mcs,
4407 sband->ht_cap.mcs.rx_mask,
4408 sizeof(mask->control[i].ht_mcs));
4409
4410 if (!sband->vht_cap.vht_supported)
4411 continue;
4412
4413 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
4414 vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs);
4415 }
4416
4417 /* if no rates are given set it back to the defaults */
4418 if (!info->attrs[NL80211_ATTR_TX_RATES])
4419 goto out;
4420
4421 /* The nested attribute uses enum nl80211_band as the index. This maps
4422 * directly to the enum nl80211_band values used in cfg80211.
4423 */
4424 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
4425 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
4426 enum nl80211_band band = nla_type(tx_rates);
4427 int err;
4428
4429 if (band < 0 || band >= NUM_NL80211_BANDS)
4430 return -EINVAL;
4431 sband = rdev->wiphy.bands[band];
4432 if (sband == NULL)
4433 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02004434 err = nla_parse_nested_deprecated(tb, NL80211_TXRATE_MAX,
4435 tx_rates,
4436 nl80211_txattr_policy,
4437 info->extack);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304438 if (err)
4439 return err;
4440 if (tb[NL80211_TXRATE_LEGACY]) {
4441 mask->control[band].legacy = rateset_to_mask(
4442 sband,
4443 nla_data(tb[NL80211_TXRATE_LEGACY]),
4444 nla_len(tb[NL80211_TXRATE_LEGACY]));
4445 if ((mask->control[band].legacy == 0) &&
4446 nla_len(tb[NL80211_TXRATE_LEGACY]))
4447 return -EINVAL;
4448 }
4449 if (tb[NL80211_TXRATE_HT]) {
4450 if (!ht_rateset_to_mask(
4451 sband,
4452 nla_data(tb[NL80211_TXRATE_HT]),
4453 nla_len(tb[NL80211_TXRATE_HT]),
4454 mask->control[band].ht_mcs))
4455 return -EINVAL;
4456 }
4457 if (tb[NL80211_TXRATE_VHT]) {
4458 if (!vht_set_mcs_mask(
4459 sband,
4460 nla_data(tb[NL80211_TXRATE_VHT]),
4461 mask->control[band].vht_mcs))
4462 return -EINVAL;
4463 }
4464 if (tb[NL80211_TXRATE_GI]) {
4465 mask->control[band].gi =
4466 nla_get_u8(tb[NL80211_TXRATE_GI]);
4467 if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI)
4468 return -EINVAL;
4469 }
4470
4471 if (mask->control[band].legacy == 0) {
4472 /* don't allow empty legacy rates if HT or VHT
4473 * are not even supported.
4474 */
4475 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
4476 rdev->wiphy.bands[band]->vht_cap.vht_supported))
4477 return -EINVAL;
4478
4479 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
4480 if (mask->control[band].ht_mcs[i])
4481 goto out;
4482
4483 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
4484 if (mask->control[band].vht_mcs[i])
4485 goto out;
4486
4487 /* legacy and mcs rates may not be both empty */
4488 return -EINVAL;
4489 }
4490 }
4491
4492out:
4493 return 0;
4494}
4495
Johannes Berg8564e382016-09-19 09:44:44 +02004496static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev,
4497 enum nl80211_band band,
4498 struct cfg80211_bitrate_mask *beacon_rate)
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304499{
Johannes Berg8564e382016-09-19 09:44:44 +02004500 u32 count_ht, count_vht, i;
4501 u32 rate = beacon_rate->control[band].legacy;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304502
4503 /* Allow only one rate */
4504 if (hweight32(rate) > 1)
4505 return -EINVAL;
4506
4507 count_ht = 0;
4508 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004509 if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304510 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004511 } else if (beacon_rate->control[band].ht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304512 count_ht++;
4513 if (count_ht > 1)
4514 return -EINVAL;
4515 }
4516 if (count_ht && rate)
4517 return -EINVAL;
4518 }
4519
4520 count_vht = 0;
4521 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
Johannes Berg8564e382016-09-19 09:44:44 +02004522 if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304523 return -EINVAL;
Johannes Berg8564e382016-09-19 09:44:44 +02004524 } else if (beacon_rate->control[band].vht_mcs[i]) {
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304525 count_vht++;
4526 if (count_vht > 1)
4527 return -EINVAL;
4528 }
4529 if (count_vht && rate)
4530 return -EINVAL;
4531 }
4532
4533 if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht))
4534 return -EINVAL;
4535
Johannes Berg8564e382016-09-19 09:44:44 +02004536 if (rate &&
4537 !wiphy_ext_feature_isset(&rdev->wiphy,
4538 NL80211_EXT_FEATURE_BEACON_RATE_LEGACY))
4539 return -EINVAL;
4540 if (count_ht &&
4541 !wiphy_ext_feature_isset(&rdev->wiphy,
4542 NL80211_EXT_FEATURE_BEACON_RATE_HT))
4543 return -EINVAL;
4544 if (count_vht &&
4545 !wiphy_ext_feature_isset(&rdev->wiphy,
4546 NL80211_EXT_FEATURE_BEACON_RATE_VHT))
4547 return -EINVAL;
4548
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304549 return 0;
4550}
4551
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004552static int nl80211_parse_beacon(struct cfg80211_registered_device *rdev,
4553 struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01004554 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01004555{
Johannes Berg88600202012-02-13 15:17:18 +01004556 bool haveinfo = false;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004557 int err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004558
Johannes Berg88600202012-02-13 15:17:18 +01004559 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01004560
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004561 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
4562 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
4563 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01004564 if (!bcn->head_len)
4565 return -EINVAL;
4566 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004567 }
4568
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004569 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
4570 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
4571 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01004572 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004573 }
4574
Johannes Berg4c476992010-10-04 21:36:35 +02004575 if (!haveinfo)
4576 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01004577
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004578 if (attrs[NL80211_ATTR_IE]) {
4579 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
4580 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004581 }
4582
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004583 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004584 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004585 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004586 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004587 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004588 }
4589
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004590 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01004591 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004592 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01004593 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004594 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03004595 }
4596
Simon Wunderlicha1193be2013-06-14 14:15:19 +02004597 if (attrs[NL80211_ATTR_PROBE_RESP]) {
4598 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
4599 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02004600 }
4601
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004602 if (attrs[NL80211_ATTR_FTM_RESPONDER]) {
4603 struct nlattr *tb[NL80211_FTM_RESP_ATTR_MAX + 1];
4604
Johannes Berg8cb08172019-04-26 14:07:28 +02004605 err = nla_parse_nested_deprecated(tb,
4606 NL80211_FTM_RESP_ATTR_MAX,
4607 attrs[NL80211_ATTR_FTM_RESPONDER],
4608 NULL, NULL);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004609 if (err)
4610 return err;
4611
4612 if (tb[NL80211_FTM_RESP_ATTR_ENABLED] &&
4613 wiphy_ext_feature_isset(&rdev->wiphy,
4614 NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER))
4615 bcn->ftm_responder = 1;
4616 else
4617 return -EOPNOTSUPP;
4618
4619 if (tb[NL80211_FTM_RESP_ATTR_LCI]) {
4620 bcn->lci = nla_data(tb[NL80211_FTM_RESP_ATTR_LCI]);
4621 bcn->lci_len = nla_len(tb[NL80211_FTM_RESP_ATTR_LCI]);
4622 }
4623
4624 if (tb[NL80211_FTM_RESP_ATTR_CIVICLOC]) {
4625 bcn->civicloc = nla_data(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4626 bcn->civicloc_len = nla_len(tb[NL80211_FTM_RESP_ATTR_CIVICLOC]);
4627 }
4628 } else {
4629 bcn->ftm_responder = -1;
4630 }
4631
Johannes Berg88600202012-02-13 15:17:18 +01004632 return 0;
4633}
4634
John Crispin796e90f2019-07-30 18:37:00 +02004635static int nl80211_parse_he_obss_pd(struct nlattr *attrs,
4636 struct ieee80211_he_obss_pd *he_obss_pd)
4637{
4638 struct nlattr *tb[NL80211_HE_OBSS_PD_ATTR_MAX + 1];
4639 int err;
4640
4641 err = nla_parse_nested(tb, NL80211_HE_OBSS_PD_ATTR_MAX, attrs,
4642 he_obss_pd_policy, NULL);
4643 if (err)
4644 return err;
4645
4646 if (!tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET] ||
4647 !tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET])
4648 return -EINVAL;
4649
4650 he_obss_pd->min_offset =
4651 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET]);
4652 he_obss_pd->max_offset =
4653 nla_get_u32(tb[NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET]);
4654
4655 if (he_obss_pd->min_offset >= he_obss_pd->max_offset)
4656 return -EINVAL;
4657
4658 he_obss_pd->enable = true;
4659
4660 return 0;
4661}
4662
John Crispin5c5e52d2019-12-17 15:19:18 +01004663static int nl80211_parse_he_bss_color(struct nlattr *attrs,
4664 struct cfg80211_he_bss_color *he_bss_color)
4665{
4666 struct nlattr *tb[NL80211_HE_BSS_COLOR_ATTR_MAX + 1];
4667 int err;
4668
4669 err = nla_parse_nested(tb, NL80211_HE_BSS_COLOR_ATTR_MAX, attrs,
4670 he_bss_color_policy, NULL);
4671 if (err)
4672 return err;
4673
4674 if (!tb[NL80211_HE_BSS_COLOR_ATTR_COLOR])
4675 return -EINVAL;
4676
4677 he_bss_color->color =
4678 nla_get_u8(tb[NL80211_HE_BSS_COLOR_ATTR_COLOR]);
4679 he_bss_color->disabled =
4680 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_DISABLED]);
4681 he_bss_color->partial =
4682 nla_get_flag(tb[NL80211_HE_BSS_COLOR_ATTR_PARTIAL]);
4683
4684 return 0;
4685}
4686
Johannes Berg66cd7942017-02-07 22:40:44 +02004687static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params,
4688 const u8 *rates)
4689{
4690 int i;
4691
4692 if (!rates)
4693 return;
4694
4695 for (i = 0; i < rates[1]; i++) {
4696 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
4697 params->ht_required = true;
4698 if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY)
4699 params->vht_required = true;
4700 }
4701}
4702
4703/*
4704 * Since the nl80211 API didn't include, from the beginning, attributes about
4705 * HT/VHT requirements/capabilities, we parse them out of the IEs for the
4706 * benefit of drivers that rebuild IEs in the firmware.
4707 */
4708static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params)
4709{
4710 const struct cfg80211_beacon_data *bcn = &params->beacon;
Igor Mitsyankoba83bfb2017-08-30 13:52:25 -07004711 size_t ies_len = bcn->tail_len;
4712 const u8 *ies = bcn->tail;
Johannes Berg66cd7942017-02-07 22:40:44 +02004713 const u8 *rates;
4714 const u8 *cap;
4715
4716 rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len);
4717 nl80211_check_ap_rate_selectors(params, rates);
4718
4719 rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len);
4720 nl80211_check_ap_rate_selectors(params, rates);
4721
4722 cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len);
4723 if (cap && cap[1] >= sizeof(*params->ht_cap))
4724 params->ht_cap = (void *)(cap + 2);
4725 cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len);
4726 if (cap && cap[1] >= sizeof(*params->vht_cap))
4727 params->vht_cap = (void *)(cap + 2);
Shaul Triebitz244eb9a2018-08-31 11:31:14 +03004728 cap = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, ies, ies_len);
4729 if (cap && cap[1] >= sizeof(*params->he_cap) + 1)
4730 params->he_cap = (void *)(cap + 3);
Johannes Berg66cd7942017-02-07 22:40:44 +02004731}
4732
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004733static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
4734 struct cfg80211_ap_settings *params)
4735{
4736 struct wireless_dev *wdev;
4737 bool ret = false;
4738
Johannes Berg53873f12016-05-03 16:52:04 +03004739 list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004740 if (wdev->iftype != NL80211_IFTYPE_AP &&
4741 wdev->iftype != NL80211_IFTYPE_P2P_GO)
4742 continue;
4743
Johannes Berg683b6d32012-11-08 21:25:48 +01004744 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004745 continue;
4746
Johannes Berg683b6d32012-11-08 21:25:48 +01004747 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004748 ret = true;
4749 break;
4750 }
4751
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004752 return ret;
4753}
4754
Jouni Malinene39e5b52012-09-30 19:29:39 +03004755static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
4756 enum nl80211_auth_type auth_type,
4757 enum nl80211_commands cmd)
4758{
4759 if (auth_type > NL80211_AUTHTYPE_MAX)
4760 return false;
4761
4762 switch (cmd) {
4763 case NL80211_CMD_AUTHENTICATE:
4764 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
4765 auth_type == NL80211_AUTHTYPE_SAE)
4766 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004767 if (!wiphy_ext_feature_isset(&rdev->wiphy,
4768 NL80211_EXT_FEATURE_FILS_STA) &&
4769 (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4770 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4771 auth_type == NL80211_AUTHTYPE_FILS_PK))
4772 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004773 return true;
4774 case NL80211_CMD_CONNECT:
Srinivas Dasari10773a72018-01-25 17:13:39 +02004775 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00004776 !wiphy_ext_feature_isset(&rdev->wiphy,
4777 NL80211_EXT_FEATURE_SAE_OFFLOAD) &&
Srinivas Dasari10773a72018-01-25 17:13:39 +02004778 auth_type == NL80211_AUTHTYPE_SAE)
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004779 return false;
Srinivas Dasari10773a72018-01-25 17:13:39 +02004780
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +03004781 /* FILS with SK PFS or PK not supported yet */
4782 if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4783 auth_type == NL80211_AUTHTYPE_FILS_PK)
4784 return false;
4785 if (!wiphy_ext_feature_isset(
4786 &rdev->wiphy,
4787 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
4788 auth_type == NL80211_AUTHTYPE_FILS_SK)
4789 return false;
4790 return true;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004791 case NL80211_CMD_START_AP:
4792 /* SAE not supported yet */
4793 if (auth_type == NL80211_AUTHTYPE_SAE)
4794 return false;
Jouni Malinen63181062016-10-27 00:42:02 +03004795 /* FILS not supported yet */
4796 if (auth_type == NL80211_AUTHTYPE_FILS_SK ||
4797 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
4798 auth_type == NL80211_AUTHTYPE_FILS_PK)
4799 return false;
Jouni Malinene39e5b52012-09-30 19:29:39 +03004800 return true;
4801 default:
4802 return false;
4803 }
4804}
4805
Johannes Berg88600202012-02-13 15:17:18 +01004806static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
4807{
4808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4809 struct net_device *dev = info->user_ptr[1];
4810 struct wireless_dev *wdev = dev->ieee80211_ptr;
4811 struct cfg80211_ap_settings params;
4812 int err;
4813
4814 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4815 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4816 return -EOPNOTSUPP;
4817
4818 if (!rdev->ops->start_ap)
4819 return -EOPNOTSUPP;
4820
4821 if (wdev->beacon_interval)
4822 return -EALREADY;
4823
4824 memset(&params, 0, sizeof(params));
4825
4826 /* these are required for START_AP */
4827 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
4828 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
4829 !info->attrs[NL80211_ATTR_BEACON_HEAD])
4830 return -EINVAL;
4831
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07004832 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01004833 if (err)
4834 return err;
4835
4836 params.beacon_interval =
4837 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
4838 params.dtim_period =
4839 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
4840
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05304841 err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype,
4842 params.beacon_interval);
Johannes Berg88600202012-02-13 15:17:18 +01004843 if (err)
4844 return err;
4845
4846 /*
4847 * In theory, some of these attributes should be required here
4848 * but since they were not used when the command was originally
4849 * added, keep them optional for old user space programs to let
4850 * them continue to work with drivers that do not need the
4851 * additional information -- drivers must check!
4852 */
4853 if (info->attrs[NL80211_ATTR_SSID]) {
4854 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
4855 params.ssid_len =
4856 nla_len(info->attrs[NL80211_ATTR_SSID]);
4857 if (params.ssid_len == 0 ||
4858 params.ssid_len > IEEE80211_MAX_SSID_LEN)
4859 return -EINVAL;
4860 }
4861
Johannes Bergab0d76f2018-10-02 10:00:07 +02004862 if (info->attrs[NL80211_ATTR_HIDDEN_SSID])
Johannes Berg88600202012-02-13 15:17:18 +01004863 params.hidden_ssid = nla_get_u32(
4864 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
Johannes Berg88600202012-02-13 15:17:18 +01004865
4866 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
4867
4868 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
4869 params.auth_type = nla_get_u32(
4870 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03004871 if (!nl80211_valid_auth_type(rdev, params.auth_type,
4872 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01004873 return -EINVAL;
4874 } else
4875 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
4876
4877 err = nl80211_crypto_settings(rdev, info, &params.crypto,
4878 NL80211_MAX_NR_CIPHER_SUITES);
4879 if (err)
4880 return err;
4881
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05304882 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
4883 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
4884 return -EOPNOTSUPP;
4885 params.inactivity_timeout = nla_get_u16(
4886 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
4887 }
4888
Johannes Berg53cabad2012-11-14 15:17:28 +01004889 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4890 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4891 return -EINVAL;
4892 params.p2p_ctwindow =
4893 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004894 if (params.p2p_ctwindow != 0 &&
4895 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4896 return -EINVAL;
4897 }
4898
4899 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4900 u8 tmp;
4901
4902 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4903 return -EINVAL;
4904 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01004905 params.p2p_opp_ps = tmp;
4906 if (params.p2p_opp_ps != 0 &&
4907 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4908 return -EINVAL;
4909 }
4910
Johannes Bergaa430da2012-05-16 23:50:18 +02004911 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004912 err = nl80211_parse_chandef(rdev, info, &params.chandef);
4913 if (err)
4914 return err;
4915 } else if (wdev->preset_chandef.chan) {
4916 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004917 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02004918 return -EINVAL;
4919
Arik Nemtsov923b3522015-07-08 15:41:44 +03004920 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
4921 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02004922 return -EINVAL;
4923
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304924 if (info->attrs[NL80211_ATTR_TX_RATES]) {
4925 err = nl80211_parse_tx_bitrate_mask(info, &params.beacon_rate);
4926 if (err)
4927 return err;
4928
Johannes Berg8564e382016-09-19 09:44:44 +02004929 err = validate_beacon_tx_rate(rdev, params.chandef.chan->band,
4930 &params.beacon_rate);
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +05304931 if (err)
4932 return err;
4933 }
4934
Eliad Peller18998c32014-09-10 14:07:34 +03004935 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
4936 params.smps_mode =
4937 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
4938 switch (params.smps_mode) {
4939 case NL80211_SMPS_OFF:
4940 break;
4941 case NL80211_SMPS_STATIC:
4942 if (!(rdev->wiphy.features &
4943 NL80211_FEATURE_STATIC_SMPS))
4944 return -EINVAL;
4945 break;
4946 case NL80211_SMPS_DYNAMIC:
4947 if (!(rdev->wiphy.features &
4948 NL80211_FEATURE_DYNAMIC_SMPS))
4949 return -EINVAL;
4950 break;
4951 default:
4952 return -EINVAL;
4953 }
4954 } else {
4955 params.smps_mode = NL80211_SMPS_OFF;
4956 }
4957
Purushottam Kushwaha6e8ef842016-07-05 13:44:51 +05304958 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
4959 if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ])
4960 return -EOPNOTSUPP;
4961
Ola Olsson4baf6be2015-10-29 07:04:58 +01004962 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
4963 params.acl = parse_acl_data(&rdev->wiphy, info);
4964 if (IS_ERR(params.acl))
4965 return PTR_ERR(params.acl);
4966 }
4967
John Crispina0de1ca32019-05-28 13:49:48 +02004968 params.twt_responder =
4969 nla_get_flag(info->attrs[NL80211_ATTR_TWT_RESPONDER]);
4970
John Crispin796e90f2019-07-30 18:37:00 +02004971 if (info->attrs[NL80211_ATTR_HE_OBSS_PD]) {
4972 err = nl80211_parse_he_obss_pd(
4973 info->attrs[NL80211_ATTR_HE_OBSS_PD],
4974 &params.he_obss_pd);
4975 if (err)
4976 return err;
4977 }
4978
John Crispin5c5e52d2019-12-17 15:19:18 +01004979 if (info->attrs[NL80211_ATTR_HE_BSS_COLOR]) {
4980 err = nl80211_parse_he_bss_color(
4981 info->attrs[NL80211_ATTR_HE_BSS_COLOR],
4982 &params.he_bss_color);
4983 if (err)
4984 return err;
4985 }
4986
Johannes Berg66cd7942017-02-07 22:40:44 +02004987 nl80211_calculate_ap_params(&params);
4988
Srinivas Dasarife494372019-01-23 18:06:56 +05304989 if (info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])
4990 params.flags |= AP_SETTINGS_EXTERNAL_AUTH_SUPPORT;
4991
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004992 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03004993 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02004994 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01004995 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01004996 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01004997 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01004998 wdev->ssid_len = params.ssid_len;
4999 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Denis Kenzior466a3062018-03-26 12:52:47 -05005000
5001 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
5002 wdev->conn_owner_nlportid = info->snd_portid;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02005003 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005004 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05305005
5006 kfree(params.acl);
5007
Johannes Berg56d18932011-05-09 18:41:15 +02005008 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01005009}
5010
Johannes Berg88600202012-02-13 15:17:18 +01005011static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
5012{
5013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5014 struct net_device *dev = info->user_ptr[1];
5015 struct wireless_dev *wdev = dev->ieee80211_ptr;
5016 struct cfg80211_beacon_data params;
5017 int err;
5018
5019 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5020 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
5021 return -EOPNOTSUPP;
5022
5023 if (!rdev->ops->change_beacon)
5024 return -EOPNOTSUPP;
5025
5026 if (!wdev->beacon_interval)
5027 return -EINVAL;
5028
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07005029 err = nl80211_parse_beacon(rdev, info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01005030 if (err)
5031 return err;
5032
Simon Wunderlichc56589e2013-11-21 18:19:49 +01005033 wdev_lock(wdev);
5034 err = rdev_change_beacon(rdev, dev, &params);
5035 wdev_unlock(wdev);
5036
5037 return err;
Johannes Berg88600202012-02-13 15:17:18 +01005038}
5039
5040static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01005041{
Johannes Berg4c476992010-10-04 21:36:35 +02005042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5043 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01005044
Ilan Peer7c8d5e02014-02-25 15:33:38 +02005045 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01005046}
5047
Johannes Berg5727ef12007-12-19 02:03:34 +01005048static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
5049 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
5050 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
5051 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03005052 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07005053 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01005054 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01005055};
5056
Johannes Bergeccb8e82009-05-11 21:57:56 +03005057static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005058 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03005059 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01005060{
5061 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03005062 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01005063 int flag;
5064
Johannes Bergeccb8e82009-05-11 21:57:56 +03005065 /*
5066 * Try parsing the new attribute first so userspace
5067 * can specify both for older kernels.
5068 */
5069 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
5070 if (nla) {
5071 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01005072
Johannes Bergeccb8e82009-05-11 21:57:56 +03005073 sta_flags = nla_data(nla);
5074 params->sta_flags_mask = sta_flags->mask;
5075 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005076 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03005077 if ((params->sta_flags_mask |
5078 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
5079 return -EINVAL;
5080 return 0;
5081 }
5082
5083 /* if present, parse the old attribute */
5084
5085 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01005086 if (!nla)
5087 return 0;
5088
Johannes Berg8cb08172019-04-26 14:07:28 +02005089 if (nla_parse_nested_deprecated(flags, NL80211_STA_FLAG_MAX, nla, sta_flags_policy, info->extack))
Johannes Berg5727ef12007-12-19 02:03:34 +01005090 return -EINVAL;
5091
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005092 /*
5093 * Only allow certain flags for interface types so that
5094 * other attributes are silently ignored. Remember that
5095 * this is backward compatibility code with old userspace
5096 * and shouldn't be hit in other cases anyway.
5097 */
5098 switch (iftype) {
5099 case NL80211_IFTYPE_AP:
5100 case NL80211_IFTYPE_AP_VLAN:
5101 case NL80211_IFTYPE_P2P_GO:
5102 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5103 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5104 BIT(NL80211_STA_FLAG_WME) |
5105 BIT(NL80211_STA_FLAG_MFP);
5106 break;
5107 case NL80211_IFTYPE_P2P_CLIENT:
5108 case NL80211_IFTYPE_STATION:
5109 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
5110 BIT(NL80211_STA_FLAG_TDLS_PEER);
5111 break;
5112 case NL80211_IFTYPE_MESH_POINT:
5113 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5114 BIT(NL80211_STA_FLAG_MFP) |
5115 BIT(NL80211_STA_FLAG_AUTHORIZED);
Bernd Edlinger5cf30062018-07-08 09:57:22 +00005116 break;
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005117 default:
5118 return -EINVAL;
5119 }
Johannes Berg5727ef12007-12-19 02:03:34 +01005120
Johannes Berg3383b5a2012-05-10 20:14:43 +02005121 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
5122 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03005123 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01005124
Johannes Berg3383b5a2012-05-10 20:14:43 +02005125 /* no longer support new API additions in old API */
5126 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
5127 return -EINVAL;
5128 }
5129 }
5130
Johannes Berg5727ef12007-12-19 02:03:34 +01005131 return 0;
5132}
5133
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02005134bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, int attr)
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005135{
5136 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03005137 u32 bitrate;
5138 u16 bitrate_compat;
Matthias Kaehlckebbf67e42017-04-17 15:59:52 -07005139 enum nl80211_rate_info rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005140
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005141 rate = nla_nest_start_noflag(msg, attr);
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005142 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005143 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005144
5145 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
5146 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03005147 /* report 16-bit bitrate only if we can */
5148 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005149 if (bitrate > 0 &&
5150 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
5151 return false;
5152 if (bitrate_compat > 0 &&
5153 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
5154 return false;
5155
Johannes Bergb51f3be2015-01-15 16:14:02 +01005156 switch (info->bw) {
5157 case RATE_INFO_BW_5:
5158 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
5159 break;
5160 case RATE_INFO_BW_10:
5161 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
5162 break;
5163 default:
5164 WARN_ON(1);
5165 /* fall through */
5166 case RATE_INFO_BW_20:
5167 rate_flg = 0;
5168 break;
5169 case RATE_INFO_BW_40:
5170 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
5171 break;
5172 case RATE_INFO_BW_80:
5173 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
5174 break;
5175 case RATE_INFO_BW_160:
5176 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
5177 break;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005178 case RATE_INFO_BW_HE_RU:
5179 rate_flg = 0;
5180 WARN_ON(!(info->flags & RATE_INFO_FLAGS_HE_MCS));
Johannes Bergb51f3be2015-01-15 16:14:02 +01005181 }
5182
5183 if (rate_flg && nla_put_flag(msg, rate_flg))
5184 return false;
5185
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005186 if (info->flags & RATE_INFO_FLAGS_MCS) {
5187 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
5188 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005189 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5190 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5191 return false;
5192 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
5193 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
5194 return false;
5195 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
5196 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005197 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
5198 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
5199 return false;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005200 } else if (info->flags & RATE_INFO_FLAGS_HE_MCS) {
5201 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_MCS, info->mcs))
5202 return false;
5203 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_NSS, info->nss))
5204 return false;
5205 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_GI, info->he_gi))
5206 return false;
5207 if (nla_put_u8(msg, NL80211_RATE_INFO_HE_DCM, info->he_dcm))
5208 return false;
5209 if (info->bw == RATE_INFO_BW_HE_RU &&
5210 nla_put_u8(msg, NL80211_RATE_INFO_HE_RU_ALLOC,
5211 info->he_ru_alloc))
5212 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01005213 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005214
5215 nla_nest_end(msg, rate);
5216 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005217}
5218
Felix Fietkau119363c2013-04-22 16:29:30 +02005219static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
5220 int id)
5221{
5222 void *attr;
5223 int i = 0;
5224
5225 if (!mask)
5226 return true;
5227
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005228 attr = nla_nest_start_noflag(msg, id);
Felix Fietkau119363c2013-04-22 16:29:30 +02005229 if (!attr)
5230 return false;
5231
5232 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
5233 if (!(mask & BIT(i)))
5234 continue;
5235
5236 if (nla_put_u8(msg, i, signal[i]))
5237 return false;
5238 }
5239
5240 nla_nest_end(msg, attr);
5241
5242 return true;
5243}
5244
Johannes Bergcf5ead82014-11-14 17:14:00 +01005245static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
5246 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04005247 struct cfg80211_registered_device *rdev,
5248 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01005249 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005250{
5251 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07005252 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005253
Johannes Bergcf5ead82014-11-14 17:14:00 +01005254 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Andy Strohmanf77bf482019-05-24 23:27:29 -07005255 if (!hdr) {
5256 cfg80211_sinfo_release_content(sinfo);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005257 return -1;
Andy Strohmanf77bf482019-05-24 23:27:29 -07005258 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005259
David S. Miller9360ffd2012-03-29 04:41:26 -04005260 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5261 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
5262 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
5263 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02005264
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005265 sinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_STA_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005266 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005267 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005268
5269#define PUT_SINFO(attr, memb, type) do { \
Johannes Bergd686b922016-04-26 09:54:11 +02005270 BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \
Omer Efrat397c6572018-06-17 13:06:14 +03005271 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Berg319090b2014-11-17 14:08:11 +01005272 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
5273 sinfo->memb)) \
5274 goto nla_put_failure; \
5275 } while (0)
Johannes Bergd686b922016-04-26 09:54:11 +02005276#define PUT_SINFO_U64(attr, memb) do { \
Omer Efrat397c6572018-06-17 13:06:14 +03005277 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005278 nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \
5279 sinfo->memb, NL80211_STA_INFO_PAD)) \
5280 goto nla_put_failure; \
5281 } while (0)
Johannes Berg319090b2014-11-17 14:08:11 +01005282
5283 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
5284 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
Ben Greear6c7a0032019-08-09 11:00:00 -07005285 PUT_SINFO_U64(ASSOC_AT_BOOTTIME, assoc_at);
Johannes Berg319090b2014-11-17 14:08:11 +01005286
Omer Efrat397c6572018-06-17 13:06:14 +03005287 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_RX_BYTES) |
5288 BIT_ULL(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005289 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005290 (u32)sinfo->rx_bytes))
5291 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005292
Omer Efrat397c6572018-06-17 13:06:14 +03005293 if (sinfo->filled & (BIT_ULL(NL80211_STA_INFO_TX_BYTES) |
5294 BIT_ULL(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02005295 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
5296 (u32)sinfo->tx_bytes))
5297 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005298
Johannes Bergd686b922016-04-26 09:54:11 +02005299 PUT_SINFO_U64(RX_BYTES64, rx_bytes);
5300 PUT_SINFO_U64(TX_BYTES64, tx_bytes);
Johannes Berg319090b2014-11-17 14:08:11 +01005301 PUT_SINFO(LLID, llid, u16);
5302 PUT_SINFO(PLID, plid, u16);
5303 PUT_SINFO(PLINK_STATE, plink_state, u8);
Johannes Bergd686b922016-04-26 09:54:11 +02005304 PUT_SINFO_U64(RX_DURATION, rx_duration);
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005305 PUT_SINFO_U64(TX_DURATION, tx_duration);
5306
5307 if (wiphy_ext_feature_isset(&rdev->wiphy,
5308 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5309 PUT_SINFO(AIRTIME_WEIGHT, airtime_weight, u16);
Johannes Berg319090b2014-11-17 14:08:11 +01005310
John W. Linville66266b32012-03-15 13:25:41 -04005311 switch (rdev->wiphy.signal_type) {
5312 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01005313 PUT_SINFO(SIGNAL, signal, u8);
5314 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04005315 break;
5316 default:
5317 break;
5318 }
Omer Efrat397c6572018-06-17 13:06:14 +03005319 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005320 if (!nl80211_put_signal(msg, sinfo->chains,
5321 sinfo->chain_signal,
5322 NL80211_STA_INFO_CHAIN_SIGNAL))
5323 goto nla_put_failure;
5324 }
Omer Efrat397c6572018-06-17 13:06:14 +03005325 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02005326 if (!nl80211_put_signal(msg, sinfo->chains,
5327 sinfo->chain_signal_avg,
5328 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
5329 goto nla_put_failure;
5330 }
Omer Efrat397c6572018-06-17 13:06:14 +03005331 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005332 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
5333 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01005334 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005335 }
Omer Efrat397c6572018-06-17 13:06:14 +03005336 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01005337 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
5338 NL80211_STA_INFO_RX_BITRATE))
5339 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01005340 }
Johannes Berg319090b2014-11-17 14:08:11 +01005341
5342 PUT_SINFO(RX_PACKETS, rx_packets, u32);
5343 PUT_SINFO(TX_PACKETS, tx_packets, u32);
5344 PUT_SINFO(TX_RETRIES, tx_retries, u32);
5345 PUT_SINFO(TX_FAILED, tx_failed, u32);
5346 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
Narayanraddi Mastiab606332019-02-07 12:16:05 -08005347 PUT_SINFO(AIRTIME_LINK_METRIC, airtime_link_metric, u32);
Johannes Berg319090b2014-11-17 14:08:11 +01005348 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
5349 PUT_SINFO(LOCAL_PM, local_pm, u32);
5350 PUT_SINFO(PEER_PM, peer_pm, u32);
5351 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
Bob Copelanddbdaee72018-10-25 15:48:53 -04005352 PUT_SINFO(CONNECTED_TO_GATE, connected_to_gate, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01005353
Omer Efrat397c6572018-06-17 13:06:14 +03005354 if (sinfo->filled & BIT_ULL(NL80211_STA_INFO_BSS_PARAM)) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005355 bss_param = nla_nest_start_noflag(msg,
5356 NL80211_STA_INFO_BSS_PARAM);
Paul Stewartf4263c92011-03-31 09:25:41 -07005357 if (!bss_param)
5358 goto nla_put_failure;
5359
David S. Miller9360ffd2012-03-29 04:41:26 -04005360 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
5361 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
5362 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
5363 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
5364 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
5365 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
5366 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
5367 sinfo->bss_param.dtim_period) ||
5368 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
5369 sinfo->bss_param.beacon_interval))
5370 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07005371
5372 nla_nest_end(msg, bss_param);
5373 }
Omer Efrat397c6572018-06-17 13:06:14 +03005374 if ((sinfo->filled & BIT_ULL(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005375 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
5376 sizeof(struct nl80211_sta_flag_update),
5377 &sinfo->sta_flags))
5378 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01005379
Johannes Bergd686b922016-04-26 09:54:11 +02005380 PUT_SINFO_U64(T_OFFSET, t_offset);
5381 PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc);
5382 PUT_SINFO_U64(BEACON_RX, rx_beacon);
Johannes Berga76b1942014-11-17 14:12:22 +01005383 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Ankita Bajaj0d4e14a2018-09-27 18:01:57 +03005384 PUT_SINFO(RX_MPDUS, rx_mpdu_count, u32);
5385 PUT_SINFO(FCS_ERROR_COUNT, fcs_err_count, u32);
Balaji Pothunoori81d54392018-04-16 20:18:40 +05305386 if (wiphy_ext_feature_isset(&rdev->wiphy,
Balaji Pothunoori9c066022018-07-19 18:56:27 +05305387 NL80211_EXT_FEATURE_ACK_SIGNAL_SUPPORT)) {
5388 PUT_SINFO(ACK_SIGNAL, ack_signal, u8);
5389 PUT_SINFO(ACK_SIGNAL_AVG, avg_ack_signal, s8);
5390 }
Johannes Berg319090b2014-11-17 14:08:11 +01005391
5392#undef PUT_SINFO
Johannes Bergd686b922016-04-26 09:54:11 +02005393#undef PUT_SINFO_U64
Johannes Berg6de39802014-12-19 12:34:00 +01005394
Arend van Spriel8689c052018-05-10 13:50:12 +02005395 if (sinfo->pertid) {
Johannes Berg6de39802014-12-19 12:34:00 +01005396 struct nlattr *tidsattr;
5397 int tid;
5398
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005399 tidsattr = nla_nest_start_noflag(msg,
5400 NL80211_STA_INFO_TID_STATS);
Johannes Berg6de39802014-12-19 12:34:00 +01005401 if (!tidsattr)
5402 goto nla_put_failure;
5403
5404 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
5405 struct cfg80211_tid_stats *tidstats;
5406 struct nlattr *tidattr;
5407
5408 tidstats = &sinfo->pertid[tid];
5409
5410 if (!tidstats->filled)
5411 continue;
5412
Michal Kubecekae0be8d2019-04-26 11:13:06 +02005413 tidattr = nla_nest_start_noflag(msg, tid + 1);
Johannes Berg6de39802014-12-19 12:34:00 +01005414 if (!tidattr)
5415 goto nla_put_failure;
5416
Johannes Bergd686b922016-04-26 09:54:11 +02005417#define PUT_TIDVAL_U64(attr, memb) do { \
Johannes Berg6de39802014-12-19 12:34:00 +01005418 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
Johannes Bergd686b922016-04-26 09:54:11 +02005419 nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \
5420 tidstats->memb, NL80211_TID_STATS_PAD)) \
Johannes Berg6de39802014-12-19 12:34:00 +01005421 goto nla_put_failure; \
5422 } while (0)
5423
Johannes Bergd686b922016-04-26 09:54:11 +02005424 PUT_TIDVAL_U64(RX_MSDU, rx_msdu);
5425 PUT_TIDVAL_U64(TX_MSDU, tx_msdu);
5426 PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries);
5427 PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed);
Johannes Berg6de39802014-12-19 12:34:00 +01005428
Johannes Bergd686b922016-04-26 09:54:11 +02005429#undef PUT_TIDVAL_U64
Toke Høiland-Jørgensen52539ca2018-05-08 13:03:50 +02005430 if ((tidstats->filled &
5431 BIT(NL80211_TID_STATS_TXQ_STATS)) &&
5432 !nl80211_put_txq_stats(msg, &tidstats->txq_stats,
5433 NL80211_TID_STATS_TXQ_STATS))
5434 goto nla_put_failure;
5435
Johannes Berg6de39802014-12-19 12:34:00 +01005436 nla_nest_end(msg, tidattr);
5437 }
5438
5439 nla_nest_end(msg, tidsattr);
5440 }
5441
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005442 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005443
Johannes Berg319090b2014-11-17 14:08:11 +01005444 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04005445 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
5446 sinfo->assoc_req_ies))
5447 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03005448
Johannes Berg7ea3e112018-05-18 11:40:44 +02005449 cfg80211_sinfo_release_content(sinfo);
Johannes Berg053c0952015-01-16 22:09:00 +01005450 genlmsg_end(msg, hdr);
5451 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005452
5453 nla_put_failure:
Johannes Berg7ea3e112018-05-18 11:40:44 +02005454 cfg80211_sinfo_release_content(sinfo);
Thomas Grafbc3ed282008-06-03 16:36:54 -07005455 genlmsg_cancel(msg, hdr);
5456 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005457}
5458
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005459static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005460 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005461{
Johannes Berg73887fd2018-05-18 09:57:55 +02005462 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005463 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02005464 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005465 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02005466 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005467 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005468
Johannes Bergea90e0d2017-03-15 14:26:04 +01005469 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02005470 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02005471 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01005472 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005473
Johannes Berg97990a02013-04-19 01:02:55 +02005474 if (!wdev->netdev) {
5475 err = -EINVAL;
5476 goto out_err;
5477 }
5478
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005479 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02005480 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005481 goto out_err;
5482 }
5483
Johannes Bergbba95fe2008-07-29 13:22:51 +02005484 while (1) {
Johannes Berg73887fd2018-05-18 09:57:55 +02005485 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005486 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Johannes Berg73887fd2018-05-18 09:57:55 +02005487 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02005488 if (err == -ENOENT)
5489 break;
5490 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01005491 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005492
Johannes Bergcf5ead82014-11-14 17:14:00 +01005493 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00005494 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02005495 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08005496 rdev, wdev->netdev, mac_addr,
Johannes Berg73887fd2018-05-18 09:57:55 +02005497 &sinfo) < 0)
Johannes Bergbba95fe2008-07-29 13:22:51 +02005498 goto out;
5499
5500 sta_idx++;
5501 }
5502
Johannes Bergbba95fe2008-07-29 13:22:51 +02005503 out:
Johannes Berg97990a02013-04-19 01:02:55 +02005504 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005505 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02005506 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01005507 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02005508
5509 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005510}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005511
Johannes Berg5727ef12007-12-19 02:03:34 +01005512static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
5513{
Johannes Berg4c476992010-10-04 21:36:35 +02005514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5515 struct net_device *dev = info->user_ptr[1];
Johannes Berg73887fd2018-05-18 09:57:55 +02005516 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005517 struct sk_buff *msg;
5518 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02005519 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005520
Johannes Berg73887fd2018-05-18 09:57:55 +02005521 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005522
Johannes Berg73887fd2018-05-18 09:57:55 +02005523 if (!info->attrs[NL80211_ATTR_MAC])
5524 return -EINVAL;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005525
5526 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5527
Johannes Berg73887fd2018-05-18 09:57:55 +02005528 if (!rdev->ops->get_station)
5529 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005530
Johannes Berg73887fd2018-05-18 09:57:55 +02005531 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005532 if (err)
Johannes Berg73887fd2018-05-18 09:57:55 +02005533 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005534
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005535 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg7ea3e112018-05-18 11:40:44 +02005536 if (!msg) {
Denis Kenziorba8f5662018-05-21 19:21:42 -05005537 cfg80211_sinfo_release_content(&sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +02005538 return -ENOMEM;
Johannes Berg7ea3e112018-05-18 11:40:44 +02005539 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005540
Johannes Bergcf5ead82014-11-14 17:14:00 +01005541 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
5542 info->snd_portid, info->snd_seq, 0,
Johannes Berg73887fd2018-05-18 09:57:55 +02005543 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02005544 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +02005545 return -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02005546 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01005547
Johannes Berg73887fd2018-05-18 09:57:55 +02005548 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01005549}
5550
Johannes Berg77ee7c82013-02-15 00:48:33 +01005551int cfg80211_check_station_change(struct wiphy *wiphy,
5552 struct station_parameters *params,
5553 enum cfg80211_station_type statype)
5554{
Ayala Bekere4208422015-10-23 11:20:06 +03005555 if (params->listen_interval != -1 &&
5556 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005557 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03005558
Ayala Beker17b94242016-03-17 15:41:38 +02005559 if (params->support_p2p_ps != -1 &&
5560 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
5561 return -EINVAL;
5562
Arik Nemtsovc72e1142014-07-17 17:14:29 +03005563 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03005564 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
5565 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005566 return -EINVAL;
5567
5568 /* When you run into this, adjust the code below for the new flag */
5569 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
5570
5571 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08005572 case CFG80211_STA_MESH_PEER_KERNEL:
5573 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005574 /*
5575 * No ignoring the TDLS flag here -- the userspace mesh
5576 * code doesn't have the bug of including TDLS in the
5577 * mask everywhere.
5578 */
5579 if (params->sta_flags_mask &
5580 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5581 BIT(NL80211_STA_FLAG_MFP) |
5582 BIT(NL80211_STA_FLAG_AUTHORIZED)))
5583 return -EINVAL;
5584 break;
5585 case CFG80211_STA_TDLS_PEER_SETUP:
5586 case CFG80211_STA_TDLS_PEER_ACTIVE:
5587 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
5588 return -EINVAL;
5589 /* ignore since it can't change */
5590 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5591 break;
5592 default:
5593 /* disallow mesh-specific things */
5594 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
5595 return -EINVAL;
5596 if (params->local_pm)
5597 return -EINVAL;
5598 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5599 return -EINVAL;
5600 }
5601
5602 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5603 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
5604 /* TDLS can't be set, ... */
5605 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
5606 return -EINVAL;
5607 /*
5608 * ... but don't bother the driver with it. This works around
5609 * a hostapd/wpa_supplicant issue -- it always includes the
5610 * TLDS_PEER flag in the mask even for AP mode.
5611 */
5612 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
5613 }
5614
Ayala Beker47edb112015-09-21 15:49:53 +03005615 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
5616 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005617 /* reject other things that can't change */
5618 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
5619 return -EINVAL;
5620 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
5621 return -EINVAL;
5622 if (params->supported_rates)
5623 return -EINVAL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005624 if (params->ext_capab || params->ht_capa || params->vht_capa ||
5625 params->he_capa)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005626 return -EINVAL;
5627 }
5628
Ayala Beker47edb112015-09-21 15:49:53 +03005629 if (statype != CFG80211_STA_AP_CLIENT &&
5630 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01005631 if (params->vlan)
5632 return -EINVAL;
5633 }
5634
5635 switch (statype) {
5636 case CFG80211_STA_AP_MLME_CLIENT:
5637 /* Use this only for authorizing/unauthorizing a station */
5638 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
5639 return -EOPNOTSUPP;
5640 break;
5641 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03005642 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005643 /* accept only the listed bits */
5644 if (params->sta_flags_mask &
5645 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5646 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5647 BIT(NL80211_STA_FLAG_ASSOCIATED) |
5648 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
5649 BIT(NL80211_STA_FLAG_WME) |
5650 BIT(NL80211_STA_FLAG_MFP)))
5651 return -EINVAL;
5652
5653 /* but authenticated/associated only if driver handles it */
5654 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
5655 params->sta_flags_mask &
5656 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
5657 BIT(NL80211_STA_FLAG_ASSOCIATED)))
5658 return -EINVAL;
5659 break;
5660 case CFG80211_STA_IBSS:
5661 case CFG80211_STA_AP_STA:
5662 /* reject any changes other than AUTHORIZED */
5663 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
5664 return -EINVAL;
5665 break;
5666 case CFG80211_STA_TDLS_PEER_SETUP:
5667 /* reject any changes other than AUTHORIZED or WME */
5668 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
5669 BIT(NL80211_STA_FLAG_WME)))
5670 return -EINVAL;
5671 /* force (at least) rates when authorizing */
5672 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
5673 !params->supported_rates)
5674 return -EINVAL;
5675 break;
5676 case CFG80211_STA_TDLS_PEER_ACTIVE:
5677 /* reject any changes */
5678 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005679 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005680 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
5681 return -EINVAL;
5682 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08005683 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08005684 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
5685 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01005686 return -EINVAL;
5687 break;
5688 }
5689
Beni Lev06f7c882016-07-19 19:28:56 +03005690 /*
5691 * Older kernel versions ignored this attribute entirely, so don't
5692 * reject attempts to update it but mark it as unused instead so the
5693 * driver won't look at the data.
5694 */
5695 if (statype != CFG80211_STA_AP_CLIENT_UNASSOC &&
5696 statype != CFG80211_STA_TDLS_PEER_SETUP)
5697 params->opmode_notif_used = false;
5698
Johannes Berg77ee7c82013-02-15 00:48:33 +01005699 return 0;
5700}
5701EXPORT_SYMBOL(cfg80211_check_station_change);
5702
Johannes Berg5727ef12007-12-19 02:03:34 +01005703/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01005704 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01005705 */
Johannes Berg80b99892011-11-18 16:23:01 +01005706static struct net_device *get_vlan(struct genl_info *info,
5707 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01005708{
Johannes Berg463d0182009-07-14 00:33:35 +02005709 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01005710 struct net_device *v;
5711 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01005712
Johannes Berg80b99892011-11-18 16:23:01 +01005713 if (!vlanattr)
5714 return NULL;
5715
5716 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
5717 if (!v)
5718 return ERR_PTR(-ENODEV);
5719
5720 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
5721 ret = -EINVAL;
5722 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01005723 }
Johannes Berg80b99892011-11-18 16:23:01 +01005724
Johannes Berg77ee7c82013-02-15 00:48:33 +01005725 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
5726 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
5727 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
5728 ret = -EINVAL;
5729 goto error;
5730 }
5731
Johannes Berg80b99892011-11-18 16:23:01 +01005732 if (!netif_running(v)) {
5733 ret = -ENETDOWN;
5734 goto error;
5735 }
5736
5737 return v;
5738 error:
5739 dev_put(v);
5740 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01005741}
5742
Johannes Berg94e860f2014-01-20 23:58:15 +01005743static const struct nla_policy
5744nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02005745 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
5746 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
5747};
5748
Johannes Bergff276692013-02-15 00:09:01 +01005749static int nl80211_parse_sta_wme(struct genl_info *info,
5750 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02005751{
Jouni Malinendf881292013-02-14 21:10:54 +02005752 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
5753 struct nlattr *nla;
5754 int err;
5755
Jouni Malinendf881292013-02-14 21:10:54 +02005756 /* parse WME attributes if present */
5757 if (!info->attrs[NL80211_ATTR_STA_WME])
5758 return 0;
5759
5760 nla = info->attrs[NL80211_ATTR_STA_WME];
Johannes Berg8cb08172019-04-26 14:07:28 +02005761 err = nla_parse_nested_deprecated(tb, NL80211_STA_WME_MAX, nla,
5762 nl80211_sta_wme_policy,
5763 info->extack);
Jouni Malinendf881292013-02-14 21:10:54 +02005764 if (err)
5765 return err;
5766
5767 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
5768 params->uapsd_queues = nla_get_u8(
5769 tb[NL80211_STA_WME_UAPSD_QUEUES]);
5770 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
5771 return -EINVAL;
5772
5773 if (tb[NL80211_STA_WME_MAX_SP])
5774 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
5775
5776 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
5777 return -EINVAL;
5778
5779 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
5780
5781 return 0;
5782}
5783
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305784static int nl80211_parse_sta_channel_info(struct genl_info *info,
5785 struct station_parameters *params)
5786{
5787 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
5788 params->supported_channels =
5789 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5790 params->supported_channels_len =
5791 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
5792 /*
5793 * Need to include at least one (first channel, number of
5794 * channels) tuple for each subband, and must have proper
5795 * tuples for the rest of the data as well.
5796 */
5797 if (params->supported_channels_len < 2)
5798 return -EINVAL;
5799 if (params->supported_channels_len % 2)
5800 return -EINVAL;
5801 }
5802
5803 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
5804 params->supported_oper_classes =
5805 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5806 params->supported_oper_classes_len =
5807 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
5808 /*
5809 * The value of the Length field of the Supported Operating
5810 * Classes element is between 2 and 253.
5811 */
5812 if (params->supported_oper_classes_len < 2 ||
5813 params->supported_oper_classes_len > 253)
5814 return -EINVAL;
5815 }
5816 return 0;
5817}
5818
Johannes Bergff276692013-02-15 00:09:01 +01005819static int nl80211_set_station_tdls(struct genl_info *info,
5820 struct station_parameters *params)
5821{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305822 int err;
Johannes Bergff276692013-02-15 00:09:01 +01005823 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03005824 if (info->attrs[NL80211_ATTR_PEER_AID])
5825 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01005826 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
5827 params->ht_capa =
5828 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
5829 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
5830 params->vht_capa =
5831 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03005832 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
5833 params->he_capa =
5834 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5835 params->he_capa_len =
5836 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
5837
5838 if (params->he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
5839 return -EINVAL;
5840 }
Johannes Bergff276692013-02-15 00:09:01 +01005841
Sunil Duttc01fc9a2013-10-09 20:45:21 +05305842 err = nl80211_parse_sta_channel_info(info, params);
5843 if (err)
5844 return err;
5845
Johannes Bergff276692013-02-15 00:09:01 +01005846 return nl80211_parse_sta_wme(info, params);
5847}
5848
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305849static int nl80211_parse_sta_txpower_setting(struct genl_info *info,
5850 struct station_parameters *params)
5851{
5852 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5853 int idx;
5854
5855 if (info->attrs[NL80211_ATTR_STA_TX_POWER_SETTING]) {
5856 if (!rdev->ops->set_tx_power ||
5857 !wiphy_ext_feature_isset(&rdev->wiphy,
5858 NL80211_EXT_FEATURE_STA_TX_PWR))
5859 return -EOPNOTSUPP;
5860
5861 idx = NL80211_ATTR_STA_TX_POWER_SETTING;
5862 params->txpwr.type = nla_get_u8(info->attrs[idx]);
5863
5864 if (params->txpwr.type == NL80211_TX_POWER_LIMITED) {
5865 idx = NL80211_ATTR_STA_TX_POWER;
5866
5867 if (info->attrs[idx])
5868 params->txpwr.power =
5869 nla_get_s16(info->attrs[idx]);
5870 else
5871 return -EINVAL;
5872 }
5873 params->sta_modify_mask |= STATION_PARAM_APPLY_STA_TXPOWER;
5874 }
5875
5876 return 0;
5877}
5878
Johannes Berg5727ef12007-12-19 02:03:34 +01005879static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
5880{
Johannes Berg4c476992010-10-04 21:36:35 +02005881 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005882 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01005883 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01005884 u8 *mac_addr;
5885 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01005886
5887 memset(&params, 0, sizeof(params));
5888
Johannes Berg77ee7c82013-02-15 00:48:33 +01005889 if (!rdev->ops->change_station)
5890 return -EOPNOTSUPP;
5891
Ayala Bekere4208422015-10-23 11:20:06 +03005892 /*
5893 * AID and listen_interval properties can be set only for unassociated
5894 * station. Include these parameters here and will check them in
5895 * cfg80211_check_station_change().
5896 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01005897 if (info->attrs[NL80211_ATTR_STA_AID])
5898 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03005899
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02005900 if (info->attrs[NL80211_ATTR_VLAN_ID])
5901 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
5902
Ayala Bekere4208422015-10-23 11:20:06 +03005903 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
5904 params.listen_interval =
5905 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
5906 else
5907 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01005908
Johannes Bergab0d76f2018-10-02 10:00:07 +02005909 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS])
5910 params.support_p2p_ps =
5911 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
5912 else
Ayala Beker17b94242016-03-17 15:41:38 +02005913 params.support_p2p_ps = -1;
Ayala Beker17b94242016-03-17 15:41:38 +02005914
Johannes Berg5727ef12007-12-19 02:03:34 +01005915 if (!info->attrs[NL80211_ATTR_MAC])
5916 return -EINVAL;
5917
5918 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
5919
5920 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
5921 params.supported_rates =
5922 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5923 params.supported_rates_len =
5924 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
5925 }
5926
Jouni Malinen9d62a982013-02-14 21:10:13 +02005927 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
5928 params.capability =
5929 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
5930 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
5931 }
5932
5933 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
5934 params.ext_capab =
5935 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5936 params.ext_capab_len =
5937 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
5938 }
5939
Johannes Bergbdd3ae32012-01-02 13:30:03 +01005940 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01005941 return -EINVAL;
5942
Johannes Bergab0d76f2018-10-02 10:00:07 +02005943 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005944 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005945 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01005946
Johannes Bergf8bacc22013-02-14 23:27:01 +01005947 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07005948 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01005949 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
Johannes Bergab0d76f2018-10-02 10:00:07 +02005950 if (info->attrs[NL80211_ATTR_MESH_PEER_AID])
Masashi Honma7d27a0b2016-07-01 10:19:34 +09005951 params.peer_aid = nla_get_u16(
5952 info->attrs[NL80211_ATTR_MESH_PEER_AID]);
Johannes Bergf8bacc22013-02-14 23:27:01 +01005953 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
5954 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07005955
Johannes Bergab0d76f2018-10-02 10:00:07 +02005956 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE])
5957 params.local_pm = nla_get_u32(
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005958 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
5959
Beni Lev06f7c882016-07-19 19:28:56 +03005960 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
5961 params.opmode_notif_used = true;
5962 params.opmode_notif =
5963 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
5964 }
5965
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08005966 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
5967 params.airtime_weight =
5968 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
5969
5970 if (params.airtime_weight &&
5971 !wiphy_ext_feature_isset(&rdev->wiphy,
5972 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
5973 return -EOPNOTSUPP;
5974
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05305975 err = nl80211_parse_sta_txpower_setting(info, &params);
5976 if (err)
5977 return err;
5978
Johannes Berg77ee7c82013-02-15 00:48:33 +01005979 /* Include parameters for TDLS peer (will check later) */
5980 err = nl80211_set_station_tdls(info, &params);
5981 if (err)
5982 return err;
5983
5984 params.vlan = get_vlan(info, rdev);
5985 if (IS_ERR(params.vlan))
5986 return PTR_ERR(params.vlan);
5987
Johannes Berga97f4422009-06-18 17:23:43 +02005988 switch (dev->ieee80211_ptr->iftype) {
5989 case NL80211_IFTYPE_AP:
5990 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005991 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02005992 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02005993 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01005994 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02005995 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02005996 break;
5997 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01005998 err = -EOPNOTSUPP;
5999 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02006000 }
6001
Johannes Berg77ee7c82013-02-15 00:48:33 +01006002 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03006003 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006004
Johannes Berg77ee7c82013-02-15 00:48:33 +01006005 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01006006 if (params.vlan)
6007 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01006008
Johannes Berg5727ef12007-12-19 02:03:34 +01006009 return err;
6010}
6011
6012static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
6013{
Johannes Berg4c476992010-10-04 21:36:35 +02006014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01006015 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006016 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01006017 struct station_parameters params;
6018 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01006019 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
6020 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01006021
6022 memset(&params, 0, sizeof(params));
6023
Johannes Berg984c3112013-02-14 23:43:25 +01006024 if (!rdev->ops->add_station)
6025 return -EOPNOTSUPP;
6026
Johannes Berg5727ef12007-12-19 02:03:34 +01006027 if (!info->attrs[NL80211_ATTR_MAC])
6028 return -EINVAL;
6029
Johannes Berg5727ef12007-12-19 02:03:34 +01006030 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
6031 return -EINVAL;
6032
6033 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
6034 return -EINVAL;
6035
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006036 if (!info->attrs[NL80211_ATTR_STA_AID] &&
6037 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02006038 return -EINVAL;
6039
Johannes Berg5727ef12007-12-19 02:03:34 +01006040 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
6041 params.supported_rates =
6042 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6043 params.supported_rates_len =
6044 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
6045 params.listen_interval =
6046 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02006047
Gurumoorthi Gnanasambandhan14f34e362019-10-31 23:46:40 +02006048 if (info->attrs[NL80211_ATTR_VLAN_ID])
6049 params.vlan_id = nla_get_u16(info->attrs[NL80211_ATTR_VLAN_ID]);
6050
Ayala Beker17b94242016-03-17 15:41:38 +02006051 if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) {
Johannes Bergab0d76f2018-10-02 10:00:07 +02006052 params.support_p2p_ps =
6053 nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]);
Ayala Beker17b94242016-03-17 15:41:38 +02006054 } else {
6055 /*
6056 * if not specified, assume it's supported for P2P GO interface,
6057 * and is NOT supported for AP interface
6058 */
6059 params.support_p2p_ps =
6060 dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO;
6061 }
6062
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006063 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03006064 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006065 else
6066 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02006067
Jouni Malinen9d62a982013-02-14 21:10:13 +02006068 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
6069 params.capability =
6070 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
6071 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
6072 }
6073
6074 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
6075 params.ext_capab =
6076 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6077 params.ext_capab_len =
6078 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
6079 }
6080
Jouni Malinen36aedc92008-08-25 11:58:58 +03006081 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
6082 params.ht_capa =
6083 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006084
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00006085 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
6086 params.vht_capa =
6087 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
6088
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006089 if (info->attrs[NL80211_ATTR_HE_CAPABILITY]) {
6090 params.he_capa =
6091 nla_data(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6092 params.he_capa_len =
6093 nla_len(info->attrs[NL80211_ATTR_HE_CAPABILITY]);
6094
6095 /* max len is validated in nla policy */
6096 if (params.he_capa_len < NL80211_HE_MIN_CAPABILITY_LEN)
6097 return -EINVAL;
6098 }
6099
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01006100 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
6101 params.opmode_notif_used = true;
6102 params.opmode_notif =
6103 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
6104 }
6105
Johannes Bergab0d76f2018-10-02 10:00:07 +02006106 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
Javier Cardona96b78df2011-04-07 15:08:33 -07006107 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01006108 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
Javier Cardona96b78df2011-04-07 15:08:33 -07006109
Toke Høiland-Jørgensen36647052018-12-18 17:02:07 -08006110 if (info->attrs[NL80211_ATTR_AIRTIME_WEIGHT])
6111 params.airtime_weight =
6112 nla_get_u16(info->attrs[NL80211_ATTR_AIRTIME_WEIGHT]);
6113
6114 if (params.airtime_weight &&
6115 !wiphy_ext_feature_isset(&rdev->wiphy,
6116 NL80211_EXT_FEATURE_AIRTIME_FAIRNESS))
6117 return -EOPNOTSUPP;
6118
Ashok Raj Nagarajane96d1cd2019-03-29 16:18:21 +05306119 err = nl80211_parse_sta_txpower_setting(info, &params);
6120 if (err)
6121 return err;
6122
Sunil Duttc01fc9a2013-10-09 20:45:21 +05306123 err = nl80211_parse_sta_channel_info(info, &params);
6124 if (err)
6125 return err;
6126
Johannes Bergff276692013-02-15 00:09:01 +01006127 err = nl80211_parse_sta_wme(info, &params);
6128 if (err)
6129 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006130
Johannes Bergbdd3ae32012-01-02 13:30:03 +01006131 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01006132 return -EINVAL;
6133
Johannes Berg496fcc22015-03-12 08:53:27 +02006134 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
6135 * as userspace might just pass through the capabilities from the IEs
6136 * directly, rather than enforcing this restriction and returning an
6137 * error in this case.
6138 */
6139 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
6140 params.ht_capa = NULL;
6141 params.vht_capa = NULL;
Luca Coelhoc4cbaf72018-06-09 09:14:42 +03006142
6143 /* HE requires WME */
6144 if (params.he_capa_len)
6145 return -EINVAL;
Johannes Berg496fcc22015-03-12 08:53:27 +02006146 }
6147
Johannes Berg77ee7c82013-02-15 00:48:33 +01006148 /* When you run into this, adjust the code below for the new flag */
6149 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
6150
Johannes Bergbdd90d52011-12-14 12:20:27 +01006151 switch (dev->ieee80211_ptr->iftype) {
6152 case NL80211_IFTYPE_AP:
6153 case NL80211_IFTYPE_AP_VLAN:
6154 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01006155 /* ignore WME attributes if iface/sta is not capable */
6156 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
6157 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
6158 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03006159
Johannes Bergbdd90d52011-12-14 12:20:27 +01006160 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006161 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6162 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02006163 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006164 /* but don't bother the driver with it */
6165 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03006166
Johannes Bergd582cff2012-10-26 17:53:44 +02006167 /* allow authenticated/associated only if driver handles it */
6168 if (!(rdev->wiphy.features &
6169 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01006170 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02006171 return -EINVAL;
6172
Johannes Bergbda95eb2015-11-26 16:26:13 +01006173 /* Older userspace, or userspace wanting to be compatible with
6174 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
6175 * and assoc flags in the mask, but assumes the station will be
6176 * added as associated anyway since this was the required driver
6177 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
6178 * introduced.
6179 * In order to not bother drivers with this quirk in the API
6180 * set the flags in both the mask and set for new stations in
6181 * this case.
6182 */
6183 if (!(params.sta_flags_mask & auth_assoc)) {
6184 params.sta_flags_mask |= auth_assoc;
6185 params.sta_flags_set |= auth_assoc;
6186 }
6187
Johannes Bergbdd90d52011-12-14 12:20:27 +01006188 /* must be last in here for error handling */
6189 params.vlan = get_vlan(info, rdev);
6190 if (IS_ERR(params.vlan))
6191 return PTR_ERR(params.vlan);
6192 break;
6193 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01006194 /* ignore uAPSD data */
6195 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6196
Johannes Bergd582cff2012-10-26 17:53:44 +02006197 /* associated is disallowed */
6198 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
6199 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006200 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03006201 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
6202 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02006203 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006204 break;
6205 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01006206 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01006207 /* ignore uAPSD data */
6208 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
6209
Johannes Berg77ee7c82013-02-15 00:48:33 +01006210 /* these are disallowed */
6211 if (params.sta_flags_mask &
6212 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
6213 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02006214 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01006215 /* Only TDLS peers can be added */
6216 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
6217 return -EINVAL;
6218 /* Can only add if TDLS ... */
6219 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
6220 return -EOPNOTSUPP;
6221 /* ... with external setup is supported */
6222 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
6223 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01006224 /*
6225 * Older wpa_supplicant versions always mark the TDLS peer
6226 * as authorized, but it shouldn't yet be.
6227 */
6228 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01006229 break;
6230 default:
6231 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03006232 }
6233
Johannes Bergbdd90d52011-12-14 12:20:27 +01006234 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01006235
Hila Gonene35e4d22012-06-27 17:19:42 +03006236 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006237
Johannes Berg5727ef12007-12-19 02:03:34 +01006238 if (params.vlan)
6239 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01006240 return err;
6241}
6242
6243static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
6244{
Johannes Berg4c476992010-10-04 21:36:35 +02006245 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6246 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03006247 struct station_del_parameters params;
6248
6249 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01006250
6251 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03006252 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01006253
Johannes Berge80cf852009-05-11 14:43:13 +02006254 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02006255 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02006256 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02006257 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6258 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02006259
Johannes Berg4c476992010-10-04 21:36:35 +02006260 if (!rdev->ops->del_station)
6261 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01006262
Jouni Malinen98856862014-10-20 13:20:45 +03006263 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
6264 params.subtype =
6265 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
6266 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
6267 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
6268 return -EINVAL;
6269 } else {
6270 /* Default to Deauthentication frame */
6271 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
6272 }
6273
6274 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
6275 params.reason_code =
6276 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6277 if (params.reason_code == 0)
6278 return -EINVAL; /* 0 is reserved */
6279 } else {
6280 /* Default to reason code 2 */
6281 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
6282 }
6283
Jouni Malinen89c771e2014-10-10 20:52:40 +03006284 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01006285}
6286
Eric W. Biederman15e47302012-09-07 20:12:54 +00006287static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006288 int flags, struct net_device *dev,
6289 u8 *dst, u8 *next_hop,
6290 struct mpath_info *pinfo)
6291{
6292 void *hdr;
6293 struct nlattr *pinfoattr;
6294
Henning Rogge1ef4c852014-11-04 16:14:58 +01006295 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006296 if (!hdr)
6297 return -1;
6298
David S. Miller9360ffd2012-03-29 04:41:26 -04006299 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6300 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
6301 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
6302 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
6303 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02006304
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006305 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MPATH_INFO);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006306 if (!pinfoattr)
6307 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006308 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
6309 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
6310 pinfo->frame_qlen))
6311 goto nla_put_failure;
6312 if (((pinfo->filled & MPATH_INFO_SN) &&
6313 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
6314 ((pinfo->filled & MPATH_INFO_METRIC) &&
6315 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
6316 pinfo->metric)) ||
6317 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
6318 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
6319 pinfo->exptime)) ||
6320 ((pinfo->filled & MPATH_INFO_FLAGS) &&
6321 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
6322 pinfo->flags)) ||
6323 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
6324 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
6325 pinfo->discovery_timeout)) ||
6326 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
6327 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
Julan Hsucc241632019-01-15 15:28:42 -08006328 pinfo->discovery_retries)) ||
6329 ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
6330 nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
Julan Hsu540bbcb2019-01-15 15:28:43 -08006331 pinfo->hop_count)) ||
6332 ((pinfo->filled & MPATH_INFO_PATH_CHANGE) &&
6333 nla_put_u32(msg, NL80211_MPATH_INFO_PATH_CHANGE,
6334 pinfo->path_change_count)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006335 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006336
6337 nla_nest_end(msg, pinfoattr);
6338
Johannes Berg053c0952015-01-16 22:09:00 +01006339 genlmsg_end(msg, hdr);
6340 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006341
6342 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07006343 genlmsg_cancel(msg, hdr);
6344 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006345}
6346
6347static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006348 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006349{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006350 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006351 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006352 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006353 u8 dst[ETH_ALEN];
6354 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02006355 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006356 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006357
Johannes Bergea90e0d2017-03-15 14:26:04 +01006358 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006359 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006360 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006361 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006362
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006363 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006364 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006365 goto out_err;
6366 }
6367
Johannes Berg97990a02013-04-19 01:02:55 +02006368 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02006369 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02006370 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02006371 }
6372
Johannes Bergbba95fe2008-07-29 13:22:51 +02006373 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006374 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02006375 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02006376 if (err == -ENOENT)
6377 break;
6378 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01006379 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006380
Eric W. Biederman15e47302012-09-07 20:12:54 +00006381 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006382 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006383 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02006384 &pinfo) < 0)
6385 goto out;
6386
6387 path_idx++;
6388 }
6389
Johannes Bergbba95fe2008-07-29 13:22:51 +02006390 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006391 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006392 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02006393 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006394 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02006395 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006396}
6397
6398static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
6399{
Johannes Berg4c476992010-10-04 21:36:35 +02006400 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006401 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02006402 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006403 struct mpath_info pinfo;
6404 struct sk_buff *msg;
6405 u8 *dst = NULL;
6406 u8 next_hop[ETH_ALEN];
6407
6408 memset(&pinfo, 0, sizeof(pinfo));
6409
6410 if (!info->attrs[NL80211_ATTR_MAC])
6411 return -EINVAL;
6412
6413 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6414
Johannes Berg4c476992010-10-04 21:36:35 +02006415 if (!rdev->ops->get_mpath)
6416 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006417
Johannes Berg4c476992010-10-04 21:36:35 +02006418 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6419 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006420
Hila Gonene35e4d22012-06-27 17:19:42 +03006421 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006422 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006423 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006424
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006425 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006426 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02006427 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006428
Eric W. Biederman15e47302012-09-07 20:12:54 +00006429 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02006430 dev, dst, next_hop, &pinfo) < 0) {
6431 nlmsg_free(msg);
6432 return -ENOBUFS;
6433 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006434
Johannes Berg4c476992010-10-04 21:36:35 +02006435 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006436}
6437
6438static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
6439{
Johannes Berg4c476992010-10-04 21:36:35 +02006440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6441 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006442 u8 *dst = NULL;
6443 u8 *next_hop = NULL;
6444
6445 if (!info->attrs[NL80211_ATTR_MAC])
6446 return -EINVAL;
6447
6448 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6449 return -EINVAL;
6450
6451 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6452 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6453
Johannes Berg4c476992010-10-04 21:36:35 +02006454 if (!rdev->ops->change_mpath)
6455 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006456
Johannes Berg4c476992010-10-04 21:36:35 +02006457 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6458 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006459
Hila Gonene35e4d22012-06-27 17:19:42 +03006460 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006461}
Johannes Berg4c476992010-10-04 21:36:35 +02006462
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006463static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
6464{
Johannes Berg4c476992010-10-04 21:36:35 +02006465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6466 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006467 u8 *dst = NULL;
6468 u8 *next_hop = NULL;
6469
6470 if (!info->attrs[NL80211_ATTR_MAC])
6471 return -EINVAL;
6472
6473 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
6474 return -EINVAL;
6475
6476 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6477 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
6478
Johannes Berg4c476992010-10-04 21:36:35 +02006479 if (!rdev->ops->add_mpath)
6480 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006481
Johannes Berg4c476992010-10-04 21:36:35 +02006482 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6483 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006484
Hila Gonene35e4d22012-06-27 17:19:42 +03006485 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006486}
6487
6488static int nl80211_del_mpath(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];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006492 u8 *dst = NULL;
6493
6494 if (info->attrs[NL80211_ATTR_MAC])
6495 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6496
Johannes Berg4c476992010-10-04 21:36:35 +02006497 if (!rdev->ops->del_mpath)
6498 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01006499
Miaoqing Panb5014262019-09-26 16:16:50 +08006500 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6501 return -EOPNOTSUPP;
6502
Hila Gonene35e4d22012-06-27 17:19:42 +03006503 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01006504}
6505
Henning Rogge66be7d22014-09-12 08:58:49 +02006506static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
6507{
6508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6509 int err;
6510 struct net_device *dev = info->user_ptr[1];
6511 struct mpath_info pinfo;
6512 struct sk_buff *msg;
6513 u8 *dst = NULL;
6514 u8 mpp[ETH_ALEN];
6515
6516 memset(&pinfo, 0, sizeof(pinfo));
6517
6518 if (!info->attrs[NL80211_ATTR_MAC])
6519 return -EINVAL;
6520
6521 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
6522
6523 if (!rdev->ops->get_mpp)
6524 return -EOPNOTSUPP;
6525
6526 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
6527 return -EOPNOTSUPP;
6528
6529 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
6530 if (err)
6531 return err;
6532
6533 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
6534 if (!msg)
6535 return -ENOMEM;
6536
6537 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
6538 dev, dst, mpp, &pinfo) < 0) {
6539 nlmsg_free(msg);
6540 return -ENOBUFS;
6541 }
6542
6543 return genlmsg_reply(msg, info);
6544}
6545
6546static int nl80211_dump_mpp(struct sk_buff *skb,
6547 struct netlink_callback *cb)
6548{
6549 struct mpath_info pinfo;
6550 struct cfg80211_registered_device *rdev;
6551 struct wireless_dev *wdev;
6552 u8 dst[ETH_ALEN];
6553 u8 mpp[ETH_ALEN];
6554 int path_idx = cb->args[2];
6555 int err;
6556
Johannes Bergea90e0d2017-03-15 14:26:04 +01006557 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02006558 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Henning Rogge66be7d22014-09-12 08:58:49 +02006559 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +01006560 goto out_err;
Henning Rogge66be7d22014-09-12 08:58:49 +02006561
6562 if (!rdev->ops->dump_mpp) {
6563 err = -EOPNOTSUPP;
6564 goto out_err;
6565 }
6566
6567 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
6568 err = -EOPNOTSUPP;
6569 goto out_err;
6570 }
6571
6572 while (1) {
6573 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
6574 mpp, &pinfo);
6575 if (err == -ENOENT)
6576 break;
6577 if (err)
6578 goto out_err;
6579
6580 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
6581 cb->nlh->nlmsg_seq, NLM_F_MULTI,
6582 wdev->netdev, dst, mpp,
6583 &pinfo) < 0)
6584 goto out;
6585
6586 path_idx++;
6587 }
6588
6589 out:
6590 cb->args[2] = path_idx;
6591 err = skb->len;
6592 out_err:
Johannes Bergea90e0d2017-03-15 14:26:04 +01006593 rtnl_unlock();
Henning Rogge66be7d22014-09-12 08:58:49 +02006594 return err;
6595}
6596
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006597static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
6598{
Johannes Berg4c476992010-10-04 21:36:35 +02006599 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6600 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006601 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006602 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006603 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006604
6605 memset(&params, 0, sizeof(params));
6606 /* default to not changing parameters */
6607 params.use_cts_prot = -1;
6608 params.use_short_preamble = -1;
6609 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006610 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01006611 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01006612 params.p2p_ctwindow = -1;
6613 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006614
6615 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
6616 params.use_cts_prot =
6617 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
6618 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
6619 params.use_short_preamble =
6620 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
6621 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
6622 params.use_short_slot_time =
6623 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02006624 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
6625 params.basic_rates =
6626 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6627 params.basic_rates_len =
6628 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
6629 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02006630 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
6631 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01006632 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
6633 params.ht_opmode =
6634 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006635
Johannes Berg53cabad2012-11-14 15:17:28 +01006636 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
6637 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6638 return -EINVAL;
6639 params.p2p_ctwindow =
Johannes Bergab0d76f2018-10-02 10:00:07 +02006640 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006641 if (params.p2p_ctwindow != 0 &&
6642 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
6643 return -EINVAL;
6644 }
6645
6646 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
6647 u8 tmp;
6648
6649 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6650 return -EINVAL;
6651 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
Johannes Berg53cabad2012-11-14 15:17:28 +01006652 params.p2p_opp_ps = tmp;
6653 if (params.p2p_opp_ps &&
6654 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
6655 return -EINVAL;
6656 }
6657
Johannes Berg4c476992010-10-04 21:36:35 +02006658 if (!rdev->ops->change_bss)
6659 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006660
Johannes Berg074ac8d2010-09-16 14:58:22 +02006661 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02006662 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
6663 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006664
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006665 wdev_lock(wdev);
6666 err = rdev_change_bss(rdev, dev, &params);
6667 wdev_unlock(wdev);
6668
6669 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03006670}
6671
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006672static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
6673{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006674 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05006675 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006676 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05006677 u32 owner_nlportid;
6678
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006679 /*
6680 * You should only get this when cfg80211 hasn't yet initialized
6681 * completely when built-in to the kernel right between the time
6682 * window between nl80211_init() and regulatory_init(), if that is
6683 * even possible.
6684 */
Johannes Berg458f4f92012-12-06 15:47:38 +01006685 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05006686 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05006687
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006688 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
6689 user_reg_hint_type =
6690 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
6691 else
6692 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
6693
6694 switch (user_reg_hint_type) {
6695 case NL80211_USER_REG_HINT_USER:
6696 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02006697 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
6698 return -EINVAL;
6699
6700 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
6701 return regulatory_hint_user(data, user_reg_hint_type);
6702 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05006703 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
6704 owner_nlportid = info->snd_portid;
6705 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
6706 } else {
6707 owner_nlportid = 0;
6708 is_indoor = true;
6709 }
6710
6711 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07006712 default:
6713 return -EINVAL;
6714 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07006715}
6716
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +02006717static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info)
6718{
6719 return reg_reload_regdb();
6720}
6721
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006722static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01006723 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006724{
Johannes Berg4c476992010-10-04 21:36:35 +02006725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02006726 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01006727 struct wireless_dev *wdev = dev->ieee80211_ptr;
6728 struct mesh_config cur_params;
6729 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006730 void *hdr;
6731 struct nlattr *pinfoattr;
6732 struct sk_buff *msg;
6733
Johannes Berg29cbe682010-12-03 09:20:44 +01006734 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
6735 return -EOPNOTSUPP;
6736
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006737 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02006738 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02006739
Johannes Berg29cbe682010-12-03 09:20:44 +01006740 wdev_lock(wdev);
6741 /* If not connected, get default parameters */
6742 if (!wdev->mesh_id_len)
6743 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
6744 else
Hila Gonene35e4d22012-06-27 17:19:42 +03006745 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01006746 wdev_unlock(wdev);
6747
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006748 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02006749 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006750
6751 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07006752 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02006753 if (!msg)
6754 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00006755 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006756 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006757 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01006758 goto out;
Michal Kubecekae0be8d2019-04-26 11:13:06 +02006759 pinfoattr = nla_nest_start_noflag(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006760 if (!pinfoattr)
6761 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006762 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
6763 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
6764 cur_params.dot11MeshRetryTimeout) ||
6765 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
6766 cur_params.dot11MeshConfirmTimeout) ||
6767 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
6768 cur_params.dot11MeshHoldingTimeout) ||
6769 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
6770 cur_params.dot11MeshMaxPeerLinks) ||
6771 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
6772 cur_params.dot11MeshMaxRetries) ||
6773 nla_put_u8(msg, NL80211_MESHCONF_TTL,
6774 cur_params.dot11MeshTTL) ||
6775 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
6776 cur_params.element_ttl) ||
6777 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6778 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04006779 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
6780 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006781 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6782 cur_params.dot11MeshHWMPmaxPREQretries) ||
6783 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
6784 cur_params.path_refresh_time) ||
6785 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6786 cur_params.min_discovery_timeout) ||
6787 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
6788 cur_params.dot11MeshHWMPactivePathTimeout) ||
6789 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
6790 cur_params.dot11MeshHWMPpreqMinInterval) ||
6791 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
6792 cur_params.dot11MeshHWMPperrMinInterval) ||
6793 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
6794 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
6795 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
6796 cur_params.dot11MeshHWMPRootMode) ||
6797 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6798 cur_params.dot11MeshHWMPRannInterval) ||
6799 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
6800 cur_params.dot11MeshGateAnnouncementProtocol) ||
6801 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
6802 cur_params.dot11MeshForwarding) ||
Masashi Honma335d5342017-03-16 10:57:17 +09006803 nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07006804 cur_params.rssi_threshold) ||
6805 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006806 cur_params.ht_opmode) ||
6807 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
6808 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
6809 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08006810 cur_params.dot11MeshHWMProotInterval) ||
6811 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006812 cur_params.dot11MeshHWMPconfirmationInterval) ||
6813 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
6814 cur_params.power_mode) ||
6815 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006816 cur_params.dot11MeshAwakeWindowDuration) ||
6817 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
Bob Copeland01d66fb2018-10-25 17:36:34 -04006818 cur_params.plink_timeout) ||
6819 nla_put_u8(msg, NL80211_MESHCONF_CONNECTED_TO_GATE,
6820 cur_params.dot11MeshConnectedToMeshGate))
David S. Miller9360ffd2012-03-29 04:41:26 -04006821 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006822 nla_nest_end(msg, pinfoattr);
6823 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02006824 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006825
Johannes Berg3b858752009-03-12 09:55:09 +01006826 nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01006827 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04006828 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02006829 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006830}
6831
Johannes Bergab0d76f2018-10-02 10:00:07 +02006832static const struct nla_policy
6833nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
6834 [NL80211_MESHCONF_RETRY_TIMEOUT] =
6835 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6836 [NL80211_MESHCONF_CONFIRM_TIMEOUT] =
6837 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6838 [NL80211_MESHCONF_HOLDING_TIMEOUT] =
6839 NLA_POLICY_RANGE(NLA_U16, 1, 255),
6840 [NL80211_MESHCONF_MAX_PEER_LINKS] =
6841 NLA_POLICY_RANGE(NLA_U16, 0, 255),
6842 [NL80211_MESHCONF_MAX_RETRIES] = NLA_POLICY_MAX(NLA_U8, 16),
6843 [NL80211_MESHCONF_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6844 [NL80211_MESHCONF_ELEMENT_TTL] = NLA_POLICY_MIN(NLA_U8, 1),
6845 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = NLA_POLICY_MAX(NLA_U8, 1),
6846 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] =
6847 NLA_POLICY_RANGE(NLA_U32, 1, 255),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006848 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
6849 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006850 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = NLA_POLICY_MIN(NLA_U16, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006851 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006852 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] =
6853 NLA_POLICY_MIN(NLA_U16, 1),
6854 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] =
6855 NLA_POLICY_MIN(NLA_U16, 1),
6856 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] =
6857 NLA_POLICY_MIN(NLA_U16, 1),
6858 [NL80211_MESHCONF_HWMP_ROOTMODE] = NLA_POLICY_MAX(NLA_U8, 4),
6859 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] =
6860 NLA_POLICY_MIN(NLA_U16, 1),
6861 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = NLA_POLICY_MAX(NLA_U8, 1),
6862 [NL80211_MESHCONF_FORWARDING] = NLA_POLICY_MAX(NLA_U8, 1),
6863 [NL80211_MESHCONF_RSSI_THRESHOLD] =
6864 NLA_POLICY_RANGE(NLA_S32, -255, 0),
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006865 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08006866 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
Johannes Bergab0d76f2018-10-02 10:00:07 +02006867 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] =
6868 NLA_POLICY_MIN(NLA_U16, 1),
6869 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] =
6870 NLA_POLICY_MIN(NLA_U16, 1),
6871 [NL80211_MESHCONF_POWER_MODE] =
6872 NLA_POLICY_RANGE(NLA_U32,
6873 NL80211_MESH_POWER_ACTIVE,
6874 NL80211_MESH_POWER_MAX),
Marco Porsch3b1c5a52013-01-07 16:04:52 +01006875 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07006876 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
Bob Copeland01d66fb2018-10-25 17:36:34 -04006877 [NL80211_MESHCONF_CONNECTED_TO_GATE] = NLA_POLICY_RANGE(NLA_U8, 0, 1),
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006878};
6879
Javier Cardonac80d5452010-12-16 17:37:49 -08006880static const struct nla_policy
6881 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07006882 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08006883 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
6884 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07006885 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07006886 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08006887 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Johannes Berg3d7af872018-10-02 10:00:08 +02006888 [NL80211_MESH_SETUP_IE] =
6889 NLA_POLICY_VALIDATE_FN(NLA_BINARY, validate_ie_attr,
6890 IEEE80211_MAX_DATA_LEN),
Javier Cardonab130e5c2011-05-03 16:57:07 -07006891 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08006892};
6893
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006894static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006895 struct mesh_config *cfg,
6896 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006897{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006898 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006899 u32 mask = 0;
Masashi Honma97572352016-08-03 10:07:44 +09006900 u16 ht_opmode;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006901
Johannes Bergab0d76f2018-10-02 10:00:07 +02006902#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, mask, attr, fn) \
6903do { \
6904 if (tb[attr]) { \
6905 cfg->param = fn(tb[attr]); \
6906 mask |= BIT((attr) - 1); \
6907 } \
Marco Porschea54fba2013-01-07 16:04:48 +01006908} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01006909
Javier Cardona24bdd9f2010-12-16 17:37:48 -08006910 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006911 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02006912 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 -07006913 return -EINVAL;
6914
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006915 /* This makes sure that there aren't more than 32 mesh config
6916 * parameters (otherwise our bitfield scheme would not work.) */
6917 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
6918
6919 /* Fill in the params struct */
Johannes Bergab0d76f2018-10-02 10:00:07 +02006920 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, mask,
6921 NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
6922 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, mask,
6923 NL80211_MESHCONF_CONFIRM_TIMEOUT,
6924 nla_get_u16);
6925 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, mask,
6926 NL80211_MESHCONF_HOLDING_TIMEOUT,
6927 nla_get_u16);
6928 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, mask,
6929 NL80211_MESHCONF_MAX_PEER_LINKS,
6930 nla_get_u16);
6931 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, mask,
6932 NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
6933 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, mask,
6934 NL80211_MESHCONF_TTL, nla_get_u8);
6935 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, mask,
6936 NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8);
6937 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, mask,
6938 NL80211_MESHCONF_AUTO_OPEN_PLINKS,
6939 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01006940 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006941 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006942 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006943 nla_get_u32);
6944 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, mask,
6945 NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
6946 nla_get_u8);
6947 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, mask,
6948 NL80211_MESHCONF_PATH_REFRESH_TIME,
6949 nla_get_u32);
6950 if (mask & BIT(NL80211_MESHCONF_PATH_REFRESH_TIME) &&
6951 (cfg->path_refresh_time < 1 || cfg->path_refresh_time > 65535))
6952 return -EINVAL;
6953 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, mask,
6954 NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
6955 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01006956 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006957 mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006958 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006959 nla_get_u32);
6960 if (mask & BIT(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT) &&
6961 (cfg->dot11MeshHWMPactivePathTimeout < 1 ||
6962 cfg->dot11MeshHWMPactivePathTimeout > 65535))
6963 return -EINVAL;
6964 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006965 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006966 nla_get_u16);
6967 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, mask,
Marco Porschea54fba2013-01-07 16:04:48 +01006968 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006969 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07006970 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006971 dot11MeshHWMPnetDiameterTraversalTime, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08006972 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006973 nla_get_u16);
6974 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask,
6975 NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8);
6976 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask,
6977 NL80211_MESHCONF_HWMP_RANN_INTERVAL,
6978 nla_get_u16);
6979 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshGateAnnouncementProtocol,
Marco Porschea54fba2013-01-07 16:04:48 +01006980 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Johannes Bergab0d76f2018-10-02 10:00:07 +02006981 nla_get_u8);
6982 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, mask,
6983 NL80211_MESHCONF_FORWARDING, nla_get_u8);
6984 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, mask,
6985 NL80211_MESHCONF_RSSI_THRESHOLD,
6986 nla_get_s32);
Bob Copeland01d66fb2018-10-25 17:36:34 -04006987 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConnectedToMeshGate, mask,
6988 NL80211_MESHCONF_CONNECTED_TO_GATE,
6989 nla_get_u8);
Masashi Honma97572352016-08-03 10:07:44 +09006990 /*
6991 * Check HT operation mode based on
Bob Copeland188f60a2018-06-24 21:10:49 -04006992 * IEEE 802.11-2016 9.4.2.57 HT Operation element.
Masashi Honma97572352016-08-03 10:07:44 +09006993 */
6994 if (tb[NL80211_MESHCONF_HT_OPMODE]) {
6995 ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]);
6996
6997 if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION |
6998 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT |
6999 IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT))
7000 return -EINVAL;
7001
Bob Copeland188f60a2018-06-24 21:10:49 -04007002 /* NON_HT_STA bit is reserved, but some programs set it */
7003 ht_opmode &= ~IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT;
Masashi Honma97572352016-08-03 10:07:44 +09007004
Masashi Honma97572352016-08-03 10:07:44 +09007005 cfg->ht_opmode = ht_opmode;
Masashi Honmafd551ba2017-01-26 08:56:13 +09007006 mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1));
Masashi Honma97572352016-08-03 10:07:44 +09007007 }
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08007008 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007009 dot11MeshHWMPactivePathToRootTimeout, mask,
7010 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
7011 nla_get_u32);
7012 if (mask & BIT(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT) &&
7013 (cfg->dot11MeshHWMPactivePathToRootTimeout < 1 ||
7014 cfg->dot11MeshHWMPactivePathToRootTimeout > 65535))
7015 return -EINVAL;
7016 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, mask,
7017 NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
7018 nla_get_u16);
7019 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPconfirmationInterval,
7020 mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08007021 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Johannes Bergab0d76f2018-10-02 10:00:07 +02007022 nla_get_u16);
7023 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, mask,
7024 NL80211_MESHCONF_POWER_MODE, nla_get_u32);
7025 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, mask,
7026 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
7027 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, mask,
7028 NL80211_MESHCONF_PLINK_TIMEOUT, nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007029 if (mask_out)
7030 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08007031
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007032 return 0;
7033
7034#undef FILL_IN_MESH_PARAM_IF_SET
7035}
7036
Javier Cardonac80d5452010-12-16 17:37:49 -08007037static int nl80211_parse_mesh_setup(struct genl_info *info,
7038 struct mesh_setup *setup)
7039{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007040 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08007041 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
7042
7043 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
7044 return -EINVAL;
Johannes Berg8cb08172019-04-26 14:07:28 +02007045 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 -08007046 return -EINVAL;
7047
Javier Cardonad299a1f2012-03-31 11:31:33 -07007048 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
7049 setup->sync_method =
7050 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
7051 IEEE80211_SYNC_METHOD_VENDOR :
7052 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
7053
Javier Cardonac80d5452010-12-16 17:37:49 -08007054 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
7055 setup->path_sel_proto =
7056 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
7057 IEEE80211_PATH_PROTOCOL_VENDOR :
7058 IEEE80211_PATH_PROTOCOL_HWMP;
7059
7060 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
7061 setup->path_metric =
7062 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
7063 IEEE80211_PATH_METRIC_VENDOR :
7064 IEEE80211_PATH_METRIC_AIRTIME;
7065
Javier Cardona581a8b02011-04-07 15:08:27 -07007066 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08007067 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07007068 tb[NL80211_MESH_SETUP_IE];
Javier Cardona581a8b02011-04-07 15:08:27 -07007069 setup->ie = nla_data(ieattr);
7070 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08007071 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007072 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
7073 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
7074 return -EINVAL;
7075 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07007076 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
7077 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08007078 if (setup->is_secure)
7079 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08007080
Colleen Twitty6e16d902013-05-08 11:45:59 -07007081 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
7082 if (!setup->user_mpm)
7083 return -EINVAL;
7084 setup->auth_id =
7085 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
7086 }
7087
Javier Cardonac80d5452010-12-16 17:37:49 -08007088 return 0;
7089}
7090
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007091static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01007092 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007093{
7094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7095 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01007096 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007097 struct mesh_config cfg;
7098 u32 mask;
7099 int err;
7100
Johannes Berg29cbe682010-12-03 09:20:44 +01007101 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
7102 return -EOPNOTSUPP;
7103
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007104 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007105 return -EOPNOTSUPP;
7106
Javier Cardona24bdd9f2010-12-16 17:37:48 -08007107 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01007108 if (err)
7109 return err;
7110
Johannes Berg29cbe682010-12-03 09:20:44 +01007111 wdev_lock(wdev);
7112 if (!wdev->mesh_id_len)
7113 err = -ENOLINK;
7114
7115 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03007116 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01007117
7118 wdev_unlock(wdev);
7119
7120 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07007121}
7122
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007123static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
7124 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007125{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007126 struct nlattr *nl_reg_rules;
7127 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007128
Johannes Berg458f4f92012-12-06 15:47:38 +01007129 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
7130 (regdom->dfs_region &&
7131 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007132 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01007133
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007134 nl_reg_rules = nla_nest_start_noflag(msg, NL80211_ATTR_REG_RULES);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007135 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007136 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007137
Johannes Berg458f4f92012-12-06 15:47:38 +01007138 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007139 struct nlattr *nl_reg_rule;
7140 const struct ieee80211_reg_rule *reg_rule;
7141 const struct ieee80211_freq_range *freq_range;
7142 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01007143 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007144
Johannes Berg458f4f92012-12-06 15:47:38 +01007145 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007146 freq_range = &reg_rule->freq_range;
7147 power_rule = &reg_rule->power_rule;
7148
Michal Kubecekae0be8d2019-04-26 11:13:06 +02007149 nl_reg_rule = nla_nest_start_noflag(msg, i);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007150 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007151 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007152
Janusz Dziedzic97524822014-01-30 09:52:20 +01007153 max_bandwidth_khz = freq_range->max_bandwidth_khz;
7154 if (!max_bandwidth_khz)
7155 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
7156 reg_rule);
7157
David S. Miller9360ffd2012-03-29 04:41:26 -04007158 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
7159 reg_rule->flags) ||
7160 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
7161 freq_range->start_freq_khz) ||
7162 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
7163 freq_range->end_freq_khz) ||
7164 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01007165 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04007166 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
7167 power_rule->max_antenna_gain) ||
7168 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01007169 power_rule->max_eirp) ||
7170 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
7171 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007172 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007173
7174 nla_nest_end(msg, nl_reg_rule);
7175 }
7176
7177 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007178 return 0;
7179
7180nla_put_failure:
7181 return -EMSGSIZE;
7182}
7183
7184static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
7185{
7186 const struct ieee80211_regdomain *regdom = NULL;
7187 struct cfg80211_registered_device *rdev;
7188 struct wiphy *wiphy = NULL;
7189 struct sk_buff *msg;
7190 void *hdr;
7191
7192 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
7193 if (!msg)
7194 return -ENOBUFS;
7195
7196 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
7197 NL80211_CMD_GET_REG);
7198 if (!hdr)
7199 goto put_failure;
7200
7201 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007202 bool self_managed;
7203
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007204 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
7205 if (IS_ERR(rdev)) {
7206 nlmsg_free(msg);
7207 return PTR_ERR(rdev);
7208 }
7209
7210 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007211 self_managed = wiphy->regulatory_flags &
7212 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007213 regdom = get_wiphy_regdom(wiphy);
7214
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007215 /* a self-managed-reg device must have a private regdom */
7216 if (WARN_ON(!regdom && self_managed)) {
7217 nlmsg_free(msg);
7218 return -EINVAL;
7219 }
7220
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007221 if (regdom &&
7222 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7223 goto nla_put_failure;
7224 }
7225
7226 if (!wiphy && reg_last_request_cell_base() &&
7227 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7228 NL80211_USER_REG_HINT_CELL_BASE))
7229 goto nla_put_failure;
7230
7231 rcu_read_lock();
7232
7233 if (!regdom)
7234 regdom = rcu_dereference(cfg80211_regdomain);
7235
7236 if (nl80211_put_regdom(regdom, msg))
7237 goto nla_put_failure_rcu;
7238
7239 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007240
7241 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007242 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007243
Johannes Berg458f4f92012-12-06 15:47:38 +01007244nla_put_failure_rcu:
7245 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007246nla_put_failure:
Julia Lawallefe1cf02011-01-28 15:17:11 +01007247put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04007248 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02007249 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08007250}
7251
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007252static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
7253 u32 seq, int flags, struct wiphy *wiphy,
7254 const struct ieee80211_regdomain *regdom)
7255{
7256 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
7257 NL80211_CMD_GET_REG);
7258
7259 if (!hdr)
7260 return -1;
7261
Michal Kubecek0a833c22017-11-15 13:09:32 +01007262 genl_dump_check_consistent(cb, hdr);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007263
7264 if (nl80211_put_regdom(regdom, msg))
7265 goto nla_put_failure;
7266
7267 if (!wiphy && reg_last_request_cell_base() &&
7268 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
7269 NL80211_USER_REG_HINT_CELL_BASE))
7270 goto nla_put_failure;
7271
7272 if (wiphy &&
7273 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
7274 goto nla_put_failure;
7275
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02007276 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
7277 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
7278 goto nla_put_failure;
7279
Johannes Berg053c0952015-01-16 22:09:00 +01007280 genlmsg_end(msg, hdr);
7281 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02007282
7283nla_put_failure:
7284 genlmsg_cancel(msg, hdr);
7285 return -EMSGSIZE;
7286}
7287
7288static int nl80211_get_reg_dump(struct sk_buff *skb,
7289 struct netlink_callback *cb)
7290{
7291 const struct ieee80211_regdomain *regdom = NULL;
7292 struct cfg80211_registered_device *rdev;
7293 int err, reg_idx, start = cb->args[2];
7294
7295 rtnl_lock();
7296
7297 if (cfg80211_regdomain && start == 0) {
7298 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7299 NLM_F_MULTI, NULL,
7300 rtnl_dereference(cfg80211_regdomain));
7301 if (err < 0)
7302 goto out_err;
7303 }
7304
7305 /* the global regdom is idx 0 */
7306 reg_idx = 1;
7307 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
7308 regdom = get_wiphy_regdom(&rdev->wiphy);
7309 if (!regdom)
7310 continue;
7311
7312 if (++reg_idx <= start)
7313 continue;
7314
7315 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
7316 NLM_F_MULTI, &rdev->wiphy, regdom);
7317 if (err < 0) {
7318 reg_idx--;
7319 break;
7320 }
7321 }
7322
7323 cb->args[2] = reg_idx;
7324 err = skb->len;
7325out_err:
7326 rtnl_unlock();
7327 return err;
7328}
7329
Johannes Bergb6863032015-10-15 09:25:18 +02007330#ifdef CONFIG_CFG80211_CRDA_SUPPORT
7331static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
7332 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
7333 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
7334 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
7335 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
7336 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
7337 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
7338 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
7339};
7340
7341static int parse_reg_rule(struct nlattr *tb[],
7342 struct ieee80211_reg_rule *reg_rule)
7343{
7344 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
7345 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
7346
7347 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
7348 return -EINVAL;
7349 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
7350 return -EINVAL;
7351 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
7352 return -EINVAL;
7353 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
7354 return -EINVAL;
7355 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
7356 return -EINVAL;
7357
7358 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
7359
7360 freq_range->start_freq_khz =
7361 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
7362 freq_range->end_freq_khz =
7363 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
7364 freq_range->max_bandwidth_khz =
7365 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
7366
7367 power_rule->max_eirp =
7368 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
7369
7370 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
7371 power_rule->max_antenna_gain =
7372 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
7373
7374 if (tb[NL80211_ATTR_DFS_CAC_TIME])
7375 reg_rule->dfs_cac_ms =
7376 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
7377
7378 return 0;
7379}
7380
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007381static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
7382{
7383 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
7384 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01007385 char *alpha2;
7386 int rem_reg_rules, r;
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007387 u32 num_rules = 0, rule_idx = 0;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01007388 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01007389 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007390
7391 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
7392 return -EINVAL;
7393
7394 if (!info->attrs[NL80211_ATTR_REG_RULES])
7395 return -EINVAL;
7396
7397 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
7398
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007399 if (info->attrs[NL80211_ATTR_DFS_REGION])
7400 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
7401
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007402 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007403 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007404 num_rules++;
7405 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04007406 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007407 }
7408
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08007409 if (!reg_is_valid_request(alpha2))
7410 return -EINVAL;
7411
Gustavo A. R. Silva391d1322019-04-03 10:37:44 -05007412 rd = kzalloc(struct_size(rd, reg_rules, num_rules), GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01007413 if (!rd)
7414 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007415
7416 rd->n_reg_rules = num_rules;
7417 rd->alpha2[0] = alpha2[0];
7418 rd->alpha2[1] = alpha2[1];
7419
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07007420 /*
7421 * Disable DFS master mode if the DFS region was
7422 * not supported or known on this kernel.
7423 */
7424 if (reg_supported_dfs_region(dfs_region))
7425 rd->dfs_region = dfs_region;
7426
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007427 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01007428 rem_reg_rules) {
Johannes Berg8cb08172019-04-26 14:07:28 +02007429 r = nla_parse_nested_deprecated(tb, NL80211_REG_RULE_ATTR_MAX,
7430 nl_reg_rule, reg_rule_policy,
7431 info->extack);
Johannes Bergae811e22014-01-24 10:17:47 +01007432 if (r)
7433 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007434 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
7435 if (r)
7436 goto bad_reg;
7437
7438 rule_idx++;
7439
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007440 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
7441 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007442 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007443 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007444 }
7445
Johannes Berg06627992016-06-09 10:40:09 +02007446 /* set_regdom takes ownership of rd */
7447 return set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Bergd2372b32008-10-24 20:32:20 +02007448 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007449 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04007450 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007451}
Johannes Bergb6863032015-10-15 09:25:18 +02007452#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07007453
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007454static int validate_scan_freqs(struct nlattr *freqs)
7455{
7456 struct nlattr *attr1, *attr2;
7457 int n_channels = 0, tmp1, tmp2;
7458
Srinivas Dasarid7f13f72017-07-07 01:43:42 +03007459 nla_for_each_nested(attr1, freqs, tmp1)
7460 if (nla_len(attr1) != sizeof(u32))
7461 return 0;
7462
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007463 nla_for_each_nested(attr1, freqs, tmp1) {
7464 n_channels++;
7465 /*
7466 * Some hardware has a limited channel list for
7467 * scanning, and it is pretty much nonsensical
7468 * to scan for a channel twice, so disallow that
7469 * and don't require drivers to check that the
7470 * channel list they get isn't longer than what
7471 * they can scan, as long as they can scan all
7472 * the channels they registered at once.
7473 */
7474 nla_for_each_nested(attr2, freqs, tmp2)
7475 if (attr1 != attr2 &&
7476 nla_get_u32(attr1) == nla_get_u32(attr2))
7477 return 0;
7478 }
7479
7480 return n_channels;
7481}
7482
Johannes Berg57fbcce2016-04-12 15:56:15 +02007483static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b)
Arend van Spriel38de03d2016-03-02 20:37:18 +01007484{
Johannes Berg57fbcce2016-04-12 15:56:15 +02007485 return b < NUM_NL80211_BANDS && wiphy->bands[b];
Arend van Spriel38de03d2016-03-02 20:37:18 +01007486}
7487
7488static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy,
7489 struct cfg80211_bss_selection *bss_select)
7490{
7491 struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1];
7492 struct nlattr *nest;
7493 int err;
7494 bool found = false;
7495 int i;
7496
7497 /* only process one nested attribute */
7498 nest = nla_data(nla);
7499 if (!nla_ok(nest, nla_len(nest)))
7500 return -EINVAL;
7501
Johannes Berg8cb08172019-04-26 14:07:28 +02007502 err = nla_parse_nested_deprecated(attr, NL80211_BSS_SELECT_ATTR_MAX,
7503 nest, nl80211_bss_select_policy,
7504 NULL);
Arend van Spriel38de03d2016-03-02 20:37:18 +01007505 if (err)
7506 return err;
7507
7508 /* only one attribute may be given */
7509 for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) {
7510 if (attr[i]) {
7511 if (found)
7512 return -EINVAL;
7513 found = true;
7514 }
7515 }
7516
7517 bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID;
7518
7519 if (attr[NL80211_BSS_SELECT_ATTR_RSSI])
7520 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI;
7521
7522 if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) {
7523 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF;
7524 bss_select->param.band_pref =
7525 nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]);
7526 if (!is_band_valid(wiphy, bss_select->param.band_pref))
7527 return -EINVAL;
7528 }
7529
7530 if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) {
7531 struct nl80211_bss_select_rssi_adjust *adj_param;
7532
7533 adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]);
7534 bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST;
7535 bss_select->param.adjust.band = adj_param->band;
7536 bss_select->param.adjust.delta = adj_param->delta;
7537 if (!is_band_valid(wiphy, bss_select->param.adjust.band))
7538 return -EINVAL;
7539 }
7540
7541 /* user-space did not provide behaviour attribute */
7542 if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID)
7543 return -EINVAL;
7544
7545 if (!(wiphy->bss_select_support & BIT(bss_select->behaviour)))
7546 return -EINVAL;
7547
7548 return 0;
7549}
7550
Johannes Berg9bb7e0f2018-09-10 13:29:12 +02007551int nl80211_parse_random_mac(struct nlattr **attrs,
7552 u8 *mac_addr, u8 *mac_addr_mask)
Johannes Bergad2b26a2014-06-12 21:39:05 +02007553{
7554 int i;
7555
7556 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08007557 eth_zero_addr(mac_addr);
7558 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02007559 mac_addr[0] = 0x2;
7560 mac_addr_mask[0] = 0x3;
7561
7562 return 0;
7563 }
7564
7565 /* need both or none */
7566 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
7567 return -EINVAL;
7568
7569 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
7570 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
7571
7572 /* don't allow or configure an mcast address */
7573 if (!is_multicast_ether_addr(mac_addr_mask) ||
7574 is_multicast_ether_addr(mac_addr))
7575 return -EINVAL;
7576
7577 /*
7578 * allow users to pass a MAC address that has bits set outside
7579 * of the mask, but don't bother drivers with having to deal
7580 * with such bits
7581 */
7582 for (i = 0; i < ETH_ALEN; i++)
7583 mac_addr[i] &= mac_addr_mask[i];
7584
7585 return 0;
7586}
7587
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307588static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev)
7589{
7590 ASSERT_WDEV_LOCK(wdev);
7591
7592 if (!cfg80211_beaconing_iface_active(wdev))
7593 return true;
7594
7595 if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR))
7596 return true;
7597
7598 return regulatory_pre_cac_allowed(wdev->wiphy);
7599}
7600
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007601static bool nl80211_check_scan_feat(struct wiphy *wiphy, u32 flags, u32 flag,
7602 enum nl80211_ext_feature_index feat)
7603{
7604 if (!(flags & flag))
7605 return true;
7606 if (wiphy_ext_feature_isset(wiphy, feat))
7607 return true;
7608 return false;
7609}
7610
Roee Zamir2d23d072017-08-06 11:38:22 +03007611static int
7612nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev,
7613 void *request, struct nlattr **attrs,
7614 bool is_sched_scan)
7615{
7616 u8 *mac_addr, *mac_addr_mask;
7617 u32 *flags;
7618 enum nl80211_feature_flags randomness_flag;
7619
7620 if (!attrs[NL80211_ATTR_SCAN_FLAGS])
7621 return 0;
7622
7623 if (is_sched_scan) {
7624 struct cfg80211_sched_scan_request *req = request;
7625
7626 randomness_flag = wdev ?
7627 NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR :
7628 NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
7629 flags = &req->flags;
7630 mac_addr = req->mac_addr;
7631 mac_addr_mask = req->mac_addr_mask;
7632 } else {
7633 struct cfg80211_scan_request *req = request;
7634
7635 randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR;
7636 flags = &req->flags;
7637 mac_addr = req->mac_addr;
7638 mac_addr_mask = req->mac_addr_mask;
7639 }
7640
7641 *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]);
7642
Sunil Dutt5037a002018-01-25 17:13:37 +02007643 if (((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
7644 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) ||
Johannes Bergdb0a4ad2018-05-28 15:47:37 +02007645 !nl80211_check_scan_feat(wiphy, *flags,
7646 NL80211_SCAN_FLAG_LOW_SPAN,
7647 NL80211_EXT_FEATURE_LOW_SPAN_SCAN) ||
7648 !nl80211_check_scan_feat(wiphy, *flags,
7649 NL80211_SCAN_FLAG_LOW_POWER,
7650 NL80211_EXT_FEATURE_LOW_POWER_SCAN) ||
7651 !nl80211_check_scan_feat(wiphy, *flags,
7652 NL80211_SCAN_FLAG_HIGH_ACCURACY,
7653 NL80211_EXT_FEATURE_HIGH_ACCURACY_SCAN) ||
7654 !nl80211_check_scan_feat(wiphy, *flags,
7655 NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME,
7656 NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME) ||
7657 !nl80211_check_scan_feat(wiphy, *flags,
7658 NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP,
7659 NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP) ||
7660 !nl80211_check_scan_feat(wiphy, *flags,
7661 NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION,
7662 NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) ||
7663 !nl80211_check_scan_feat(wiphy, *flags,
7664 NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE,
Johannes Berg2e076f12018-05-28 15:47:40 +02007665 NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE) ||
7666 !nl80211_check_scan_feat(wiphy, *flags,
7667 NL80211_SCAN_FLAG_RANDOM_SN,
7668 NL80211_EXT_FEATURE_SCAN_RANDOM_SN) ||
7669 !nl80211_check_scan_feat(wiphy, *flags,
7670 NL80211_SCAN_FLAG_MIN_PREQ_CONTENT,
7671 NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT))
Roee Zamir2d23d072017-08-06 11:38:22 +03007672 return -EOPNOTSUPP;
7673
7674 if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
7675 int err;
7676
7677 if (!(wiphy->features & randomness_flag) ||
7678 (wdev && wdev->current_bss))
7679 return -EOPNOTSUPP;
7680
7681 err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask);
7682 if (err)
7683 return err;
7684 }
7685
Roee Zamir2d23d072017-08-06 11:38:22 +03007686 return 0;
7687}
7688
Johannes Berg2a519312009-02-10 21:25:55 +01007689static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
7690{
Johannes Berg4c476992010-10-04 21:36:35 +02007691 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02007692 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01007693 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01007694 struct nlattr *attr;
7695 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007696 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007697 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01007698
Johannes Berg79c97e92009-07-07 03:56:12 +02007699 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01007700
Ayala Bekercb3b7d82016-09-20 17:31:13 +03007701 if (wdev->iftype == NL80211_IFTYPE_NAN)
7702 return -EOPNOTSUPP;
7703
Johannes Berg4c476992010-10-04 21:36:35 +02007704 if (!rdev->ops->scan)
7705 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01007706
Johannes Bergf9d15d12014-01-22 11:14:19 +02007707 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01007708 err = -EBUSY;
7709 goto unlock;
7710 }
Johannes Berg2a519312009-02-10 21:25:55 +01007711
7712 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02007713 n_channels = validate_scan_freqs(
7714 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01007715 if (!n_channels) {
7716 err = -EINVAL;
7717 goto unlock;
7718 }
Johannes Berg2a519312009-02-10 21:25:55 +01007719 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02007720 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01007721 }
7722
7723 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
7724 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
7725 n_ssids++;
7726
Johannes Bergf9f47522013-03-19 15:04:07 +01007727 if (n_ssids > wiphy->max_scan_ssids) {
7728 err = -EINVAL;
7729 goto unlock;
7730 }
Johannes Berg2a519312009-02-10 21:25:55 +01007731
Jouni Malinen70692ad2009-02-16 19:39:13 +02007732 if (info->attrs[NL80211_ATTR_IE])
7733 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7734 else
7735 ie_len = 0;
7736
Johannes Bergf9f47522013-03-19 15:04:07 +01007737 if (ie_len > wiphy->max_scan_ie_len) {
7738 err = -EINVAL;
7739 goto unlock;
7740 }
Johannes Berg18a83652009-03-31 12:12:05 +02007741
Johannes Berg2a519312009-02-10 21:25:55 +01007742 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03007743 + sizeof(*request->ssids) * n_ssids
7744 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02007745 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01007746 if (!request) {
7747 err = -ENOMEM;
7748 goto unlock;
7749 }
Johannes Berg2a519312009-02-10 21:25:55 +01007750
Johannes Berg2a519312009-02-10 21:25:55 +01007751 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02007752 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01007753 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02007754 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01007755 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02007756 request->ie = (void *)(request->ssids + n_ssids);
7757 else
7758 request->ie = (void *)(request->channels + n_channels);
7759 }
Johannes Berg2a519312009-02-10 21:25:55 +01007760
Johannes Berg584991d2009-11-02 13:32:03 +01007761 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01007762 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
7763 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01007764 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01007765 struct ieee80211_channel *chan;
7766
7767 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
7768
7769 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01007770 err = -EINVAL;
7771 goto out_free;
7772 }
Johannes Berg584991d2009-11-02 13:32:03 +01007773
7774 /* ignore disabled channels */
7775 if (chan->flags & IEEE80211_CHAN_DISABLED)
7776 continue;
7777
7778 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007779 i++;
7780 }
7781 } else {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007782 enum nl80211_band band;
Johannes Berg34850ab2011-07-18 18:08:35 +02007783
Johannes Berg2a519312009-02-10 21:25:55 +01007784 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02007785 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Johannes Berg2a519312009-02-10 21:25:55 +01007786 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07007787
Johannes Berg2a519312009-02-10 21:25:55 +01007788 if (!wiphy->bands[band])
7789 continue;
7790 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01007791 struct ieee80211_channel *chan;
7792
7793 chan = &wiphy->bands[band]->channels[j];
7794
7795 if (chan->flags & IEEE80211_CHAN_DISABLED)
7796 continue;
7797
7798 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01007799 i++;
7800 }
7801 }
7802 }
7803
Johannes Berg584991d2009-11-02 13:32:03 +01007804 if (!i) {
7805 err = -EINVAL;
7806 goto out_free;
7807 }
7808
7809 request->n_channels = i;
7810
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +05307811 wdev_lock(wdev);
7812 if (!cfg80211_off_channel_oper_allowed(wdev)) {
7813 struct ieee80211_channel *chan;
7814
7815 if (request->n_channels != 1) {
7816 wdev_unlock(wdev);
7817 err = -EBUSY;
7818 goto out_free;
7819 }
7820
7821 chan = request->channels[0];
7822 if (chan->center_freq != wdev->chandef.chan->center_freq) {
7823 wdev_unlock(wdev);
7824 err = -EBUSY;
7825 goto out_free;
7826 }
7827 }
7828 wdev_unlock(wdev);
7829
Johannes Berg2a519312009-02-10 21:25:55 +01007830 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01007831 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01007832 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03007833 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01007834 err = -EINVAL;
7835 goto out_free;
7836 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03007837 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01007838 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01007839 i++;
7840 }
7841 }
7842
Jouni Malinen70692ad2009-02-16 19:39:13 +02007843 if (info->attrs[NL80211_ATTR_IE]) {
7844 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02007845 memcpy((void *)request->ie,
7846 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02007847 request->ie_len);
7848 }
7849
Johannes Berg57fbcce2016-04-12 15:56:15 +02007850 for (i = 0; i < NUM_NL80211_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02007851 if (wiphy->bands[i])
7852 request->rates[i] =
7853 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02007854
7855 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
7856 nla_for_each_nested(attr,
7857 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
7858 tmp) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02007859 enum nl80211_band band = nla_type(attr);
Johannes Berg34850ab2011-07-18 18:08:35 +02007860
Johannes Berg57fbcce2016-04-12 15:56:15 +02007861 if (band < 0 || band >= NUM_NL80211_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02007862 err = -EINVAL;
7863 goto out_free;
7864 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01007865
7866 if (!wiphy->bands[band])
7867 continue;
7868
Johannes Berg34850ab2011-07-18 18:08:35 +02007869 err = ieee80211_get_ratemask(wiphy->bands[band],
7870 nla_data(attr),
7871 nla_len(attr),
7872 &request->rates[band]);
7873 if (err)
7874 goto out_free;
7875 }
7876 }
7877
Avraham Stern1d762502016-07-05 17:10:13 +03007878 if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) {
7879 if (!wiphy_ext_feature_isset(wiphy,
7880 NL80211_EXT_FEATURE_SET_SCAN_DWELL)) {
7881 err = -EOPNOTSUPP;
7882 goto out_free;
7883 }
7884
7885 request->duration =
7886 nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]);
7887 request->duration_mandatory =
7888 nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]);
7889 }
7890
Roee Zamir2d23d072017-08-06 11:38:22 +03007891 err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs,
7892 false);
7893 if (err)
7894 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07007895
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05307896 request->no_cck =
7897 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
7898
Vamsi Krishna2fa436b2016-12-02 23:59:08 +02007899 /* Initial implementation used NL80211_ATTR_MAC to set the specific
7900 * BSSID to scan for. This was problematic because that same attribute
7901 * was already used for another purpose (local random MAC address). The
7902 * NL80211_ATTR_BSSID attribute was added to fix this. For backwards
7903 * compatibility with older userspace components, also use the
7904 * NL80211_ATTR_MAC value here if it can be determined to be used for
7905 * the specific BSSID use case instead of the random MAC address
7906 * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use).
7907 */
7908 if (info->attrs[NL80211_ATTR_BSSID])
7909 memcpy(request->bssid,
7910 nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN);
7911 else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) &&
7912 info->attrs[NL80211_ATTR_MAC])
Jouni Malinen818965d2016-02-26 22:12:47 +02007913 memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]),
7914 ETH_ALEN);
7915 else
7916 eth_broadcast_addr(request->bssid);
7917
Johannes Bergfd014282012-06-18 19:17:03 +02007918 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02007919 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07007920 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01007921
Johannes Berg79c97e92009-07-07 03:56:12 +02007922 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03007923 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01007924
Johannes Berg463d0182009-07-14 00:33:35 +02007925 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02007926 nl80211_send_scan_start(rdev, wdev);
7927 if (wdev->netdev)
7928 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02007929 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01007930 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02007931 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01007932 kfree(request);
7933 }
Johannes Berg3b858752009-03-12 09:55:09 +01007934
Johannes Bergf9f47522013-03-19 15:04:07 +01007935 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01007936 return err;
7937}
7938
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05307939static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
7940{
7941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7942 struct wireless_dev *wdev = info->user_ptr[1];
7943
7944 if (!rdev->ops->abort_scan)
7945 return -EOPNOTSUPP;
7946
7947 if (rdev->scan_msg)
7948 return 0;
7949
7950 if (!rdev->scan_req)
7951 return -ENOENT;
7952
7953 rdev_abort_scan(rdev, wdev);
7954 return 0;
7955}
7956
Avraham Stern3b06d272015-10-12 09:51:34 +03007957static int
7958nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
7959 struct cfg80211_sched_scan_request *request,
7960 struct nlattr **attrs)
7961{
7962 int tmp, err, i = 0;
7963 struct nlattr *attr;
7964
7965 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
7966 u32 interval;
7967
7968 /*
7969 * If scan plans are not specified,
Arend Van Spriel5a88de52016-11-17 09:02:40 +00007970 * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this
Avraham Stern3b06d272015-10-12 09:51:34 +03007971 * case one scan plan will be set with the specified scan
7972 * interval and infinite number of iterations.
7973 */
Avraham Stern3b06d272015-10-12 09:51:34 +03007974 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
7975 if (!interval)
7976 return -EINVAL;
7977
7978 request->scan_plans[0].interval =
7979 DIV_ROUND_UP(interval, MSEC_PER_SEC);
7980 if (!request->scan_plans[0].interval)
7981 return -EINVAL;
7982
7983 if (request->scan_plans[0].interval >
7984 wiphy->max_sched_scan_plan_interval)
7985 request->scan_plans[0].interval =
7986 wiphy->max_sched_scan_plan_interval;
7987
7988 return 0;
7989 }
7990
7991 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
7992 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
7993
7994 if (WARN_ON(i >= n_plans))
7995 return -EINVAL;
7996
Johannes Berg8cb08172019-04-26 14:07:28 +02007997 err = nla_parse_nested_deprecated(plan,
7998 NL80211_SCHED_SCAN_PLAN_MAX,
7999 attr, nl80211_plan_policy,
8000 NULL);
Avraham Stern3b06d272015-10-12 09:51:34 +03008001 if (err)
8002 return err;
8003
8004 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
8005 return -EINVAL;
8006
8007 request->scan_plans[i].interval =
8008 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
8009 if (!request->scan_plans[i].interval ||
8010 request->scan_plans[i].interval >
8011 wiphy->max_sched_scan_plan_interval)
8012 return -EINVAL;
8013
8014 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
8015 request->scan_plans[i].iterations =
8016 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
8017 if (!request->scan_plans[i].iterations ||
8018 (request->scan_plans[i].iterations >
8019 wiphy->max_sched_scan_plan_iterations))
8020 return -EINVAL;
8021 } else if (i < n_plans - 1) {
8022 /*
8023 * All scan plans but the last one must specify
8024 * a finite number of iterations
8025 */
8026 return -EINVAL;
8027 }
8028
8029 i++;
8030 }
8031
8032 /*
8033 * The last scan plan must not specify the number of
8034 * iterations, it is supposed to run infinitely
8035 */
8036 if (request->scan_plans[n_plans - 1].iterations)
8037 return -EINVAL;
8038
8039 return 0;
8040}
8041
vamsi krishna1e1b11b2019-02-01 18:34:51 +05308042static int
8043nl80211_parse_sched_scan_per_band_rssi(struct wiphy *wiphy,
8044 struct cfg80211_match_set *match_sets,
8045 struct nlattr *tb_band_rssi,
8046 s32 rssi_thold)
8047{
8048 struct nlattr *attr;
8049 int i, tmp, ret = 0;
8050
8051 if (!wiphy_ext_feature_isset(wiphy,
8052 NL80211_EXT_FEATURE_SCHED_SCAN_BAND_SPECIFIC_RSSI_THOLD)) {
8053 if (tb_band_rssi)
8054 ret = -EOPNOTSUPP;
8055 else
8056 for (i = 0; i < NUM_NL80211_BANDS; i++)
8057 match_sets->per_band_rssi_thold[i] =
8058 NL80211_SCAN_RSSI_THOLD_OFF;
8059 return ret;
8060 }
8061
8062 for (i = 0; i < NUM_NL80211_BANDS; i++)
8063 match_sets->per_band_rssi_thold[i] = rssi_thold;
8064
8065 nla_for_each_nested(attr, tb_band_rssi, tmp) {
8066 enum nl80211_band band = nla_type(attr);
8067
8068 if (band < 0 || band >= NUM_NL80211_BANDS)
8069 return -EINVAL;
8070
8071 match_sets->per_band_rssi_thold[band] = nla_get_s32(attr);
8072 }
8073
8074 return 0;
8075}
8076
Luciano Coelho256da022014-11-10 16:13:46 +02008077static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02008078nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008079 struct nlattr **attrs, int max_match_sets)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008080{
8081 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008082 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03008083 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Johannes Berg57fbcce2016-04-12 15:56:15 +02008084 enum nl80211_band band;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008085 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008086 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01008087 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008088
Luciano Coelho256da022014-11-10 16:13:46 +02008089 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008090 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02008091 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008092 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02008093 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008094 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02008095 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008096 }
8097
Luciano Coelho256da022014-11-10 16:13:46 +02008098 if (attrs[NL80211_ATTR_SCAN_SSIDS])
8099 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008100 tmp)
8101 n_ssids++;
8102
Luciano Coelho93b6aa62011-07-13 14:57:28 +03008103 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02008104 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008105
Johannes Bergea73cbc2014-01-24 10:53:53 +01008106 /*
8107 * First, count the number of 'real' matchsets. Due to an issue with
8108 * the old implementation, matchsets containing only the RSSI attribute
8109 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
8110 * RSSI for all matchsets, rather than their own matchset for reporting
8111 * all APs with a strong RSSI. This is needed to be compatible with
8112 * older userspace that treated a matchset with only the RSSI as the
8113 * global RSSI for all other matchsets - if there are other matchsets.
8114 */
Luciano Coelho256da022014-11-10 16:13:46 +02008115 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008116 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008117 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01008118 tmp) {
8119 struct nlattr *rssi;
8120
Johannes Berg8cb08172019-04-26 14:07:28 +02008121 err = nla_parse_nested_deprecated(tb,
8122 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8123 attr,
8124 nl80211_match_policy,
8125 NULL);
Johannes Bergea73cbc2014-01-24 10:53:53 +01008126 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02008127 return ERR_PTR(err);
Arend Van Spriel3007e352017-04-21 13:05:01 +01008128
8129 /* SSID and BSSID are mutually exclusive */
8130 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] &&
8131 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID])
8132 return ERR_PTR(-EINVAL);
8133
Johannes Bergea73cbc2014-01-24 10:53:53 +01008134 /* add other standalone attributes here */
Arend Van Spriel3007e352017-04-21 13:05:01 +01008135 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] ||
8136 tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01008137 n_match_sets++;
8138 continue;
8139 }
8140 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8141 if (rssi)
8142 default_match_rssi = nla_get_s32(rssi);
8143 }
8144 }
8145
8146 /* However, if there's no other matchset, add the RSSI one */
8147 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
8148 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008149
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008150 if (n_match_sets > max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02008151 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008152
Luciano Coelho256da022014-11-10 16:13:46 +02008153 if (attrs[NL80211_ATTR_IE])
8154 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008155 else
8156 ie_len = 0;
8157
Luciano Coelho5a865ba2011-07-13 14:57:29 +03008158 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02008159 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03008160
Avraham Stern3b06d272015-10-12 09:51:34 +03008161 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
8162 /*
8163 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
8164 * each scan plan already specifies its own interval
8165 */
8166 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8167 return ERR_PTR(-EINVAL);
8168
8169 nla_for_each_nested(attr,
8170 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
8171 n_plans++;
8172 } else {
8173 /*
8174 * The scan interval attribute is kept for backward
8175 * compatibility. If no scan plans are specified and sched scan
8176 * interval is specified, one scan plan will be set with this
8177 * scan interval and infinite number of iterations.
8178 */
8179 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
8180 return ERR_PTR(-EINVAL);
8181
8182 n_plans = 1;
8183 }
8184
8185 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
8186 return ERR_PTR(-EINVAL);
8187
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008188 if (!wiphy_ext_feature_isset(
8189 wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) &&
8190 (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] ||
8191 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]))
8192 return ERR_PTR(-EINVAL);
8193
Luciano Coelho807f8a82011-05-11 17:09:35 +03008194 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008195 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008196 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03008197 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03008198 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03008199 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02008200 if (!request)
8201 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008202
8203 if (n_ssids)
8204 request->ssids = (void *)&request->channels[n_channels];
8205 request->n_ssids = n_ssids;
8206 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01008207 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008208 request->ie = (void *)(request->ssids + n_ssids);
8209 else
8210 request->ie = (void *)(request->channels + n_channels);
8211 }
8212
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008213 if (n_match_sets) {
8214 if (request->ie)
8215 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01008216 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008217 request->match_sets =
8218 (void *)(request->ssids + n_ssids);
8219 else
8220 request->match_sets =
8221 (void *)(request->channels + n_channels);
8222 }
8223 request->n_match_sets = n_match_sets;
8224
Avraham Stern3b06d272015-10-12 09:51:34 +03008225 if (n_match_sets)
8226 request->scan_plans = (void *)(request->match_sets +
8227 n_match_sets);
8228 else if (request->ie)
8229 request->scan_plans = (void *)(request->ie + ie_len);
8230 else if (n_ssids)
8231 request->scan_plans = (void *)(request->ssids + n_ssids);
8232 else
8233 request->scan_plans = (void *)(request->channels + n_channels);
8234
8235 request->n_scan_plans = n_plans;
8236
Luciano Coelho807f8a82011-05-11 17:09:35 +03008237 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008238 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008239 /* user specified, bail out if channel not found */
8240 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008241 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008242 tmp) {
8243 struct ieee80211_channel *chan;
8244
8245 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
8246
8247 if (!chan) {
8248 err = -EINVAL;
8249 goto out_free;
8250 }
8251
8252 /* ignore disabled channels */
8253 if (chan->flags & IEEE80211_CHAN_DISABLED)
8254 continue;
8255
8256 request->channels[i] = chan;
8257 i++;
8258 }
8259 } else {
8260 /* all channels */
Johannes Berg57fbcce2016-04-12 15:56:15 +02008261 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008262 int j;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07008263
Luciano Coelho807f8a82011-05-11 17:09:35 +03008264 if (!wiphy->bands[band])
8265 continue;
8266 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
8267 struct ieee80211_channel *chan;
8268
8269 chan = &wiphy->bands[band]->channels[j];
8270
8271 if (chan->flags & IEEE80211_CHAN_DISABLED)
8272 continue;
8273
8274 request->channels[i] = chan;
8275 i++;
8276 }
8277 }
8278 }
8279
8280 if (!i) {
8281 err = -EINVAL;
8282 goto out_free;
8283 }
8284
8285 request->n_channels = i;
8286
8287 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01008288 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02008289 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03008290 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03008291 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03008292 err = -EINVAL;
8293 goto out_free;
8294 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03008295 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008296 memcpy(request->ssids[i].ssid, nla_data(attr),
8297 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03008298 i++;
8299 }
8300 }
8301
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008302 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02008303 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008304 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02008305 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008306 tmp) {
Arend Van Spriel3007e352017-04-21 13:05:01 +01008307 struct nlattr *ssid, *bssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008308
Johannes Berg8cb08172019-04-26 14:07:28 +02008309 err = nla_parse_nested_deprecated(tb,
8310 NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
8311 attr,
8312 nl80211_match_policy,
8313 NULL);
Johannes Bergae811e22014-01-24 10:17:47 +01008314 if (err)
8315 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02008316 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Arend Van Spriel3007e352017-04-21 13:05:01 +01008317 bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID];
Johannes Bergd39f3b42019-04-08 13:40:47 +02008318
8319 if (!ssid && !bssid) {
8320 i++;
8321 continue;
8322 }
8323
8324 if (WARN_ON(i >= n_match_sets)) {
8325 /* this indicates a programming error,
8326 * the loop above should have verified
8327 * things properly
8328 */
8329 err = -EINVAL;
8330 goto out_free;
8331 }
8332
8333 if (ssid) {
8334 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01008335 err = -EINVAL;
8336 goto out_free;
8337 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02008338 memcpy(request->match_sets[i].ssid.ssid,
8339 nla_data(ssid), nla_len(ssid));
8340 request->match_sets[i].ssid.ssid_len =
8341 nla_len(ssid);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008342 }
Johannes Bergd39f3b42019-04-08 13:40:47 +02008343 if (bssid) {
8344 if (nla_len(bssid) != ETH_ALEN) {
8345 err = -EINVAL;
8346 goto out_free;
8347 }
8348 memcpy(request->match_sets[i].bssid,
8349 nla_data(bssid), ETH_ALEN);
8350 }
8351
8352 /* special attribute - old implementation w/a */
8353 request->match_sets[i].rssi_thold = default_match_rssi;
8354 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
8355 if (rssi)
8356 request->match_sets[i].rssi_thold =
8357 nla_get_s32(rssi);
vamsi krishna1e1b11b2019-02-01 18:34:51 +05308358
8359 /* Parse per band RSSI attribute */
8360 err = nl80211_parse_sched_scan_per_band_rssi(wiphy,
8361 &request->match_sets[i],
8362 tb[NL80211_SCHED_SCAN_MATCH_PER_BAND_RSSI],
8363 request->match_sets[i].rssi_thold);
8364 if (err)
8365 goto out_free;
8366
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008367 i++;
8368 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01008369
8370 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02008371 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01008372 request->match_sets[0].rssi_thold = default_match_rssi;
8373
8374 request->min_rssi_thold = INT_MAX;
8375 for (i = 0; i < n_match_sets; i++)
8376 request->min_rssi_thold =
8377 min(request->match_sets[i].rssi_thold,
8378 request->min_rssi_thold);
8379 } else {
8380 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03008381 }
8382
Johannes Berg9900e482014-02-04 21:01:25 +01008383 if (ie_len) {
8384 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008385 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02008386 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03008387 request->ie_len);
8388 }
8389
Roee Zamir2d23d072017-08-06 11:38:22 +03008390 err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true);
8391 if (err)
8392 goto out_free;
Sam Lefflered4737712012-10-11 21:03:31 -07008393
Luciano Coelho9c748932015-01-16 16:04:09 +02008394 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
8395 request->delay =
8396 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
8397
vamsi krishnabf95ecd2017-01-13 01:12:20 +02008398 if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) {
8399 request->relative_rssi = nla_get_s8(
8400 attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]);
8401 request->relative_rssi_set = true;
8402 }
8403
8404 if (request->relative_rssi_set &&
8405 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) {
8406 struct nl80211_bss_select_rssi_adjust *rssi_adjust;
8407
8408 rssi_adjust = nla_data(
8409 attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]);
8410 request->rssi_adjust.band = rssi_adjust->band;
8411 request->rssi_adjust.delta = rssi_adjust->delta;
8412 if (!is_band_valid(wiphy, request->rssi_adjust.band)) {
8413 err = -EINVAL;
8414 goto out_free;
8415 }
8416 }
8417
Avraham Stern3b06d272015-10-12 09:51:34 +03008418 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
8419 if (err)
8420 goto out_free;
8421
Sam Leffler15d60302012-10-11 21:03:34 -07008422 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008423
Luciano Coelho256da022014-11-10 16:13:46 +02008424 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008425
8426out_free:
8427 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02008428 return ERR_PTR(err);
8429}
8430
8431static int nl80211_start_sched_scan(struct sk_buff *skb,
8432 struct genl_info *info)
8433{
8434 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8435 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02008436 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008437 struct cfg80211_sched_scan_request *sched_scan_req;
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008438 bool want_multi;
Luciano Coelho256da022014-11-10 16:13:46 +02008439 int err;
8440
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008441 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start)
Luciano Coelho256da022014-11-10 16:13:46 +02008442 return -EOPNOTSUPP;
8443
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008444 want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI];
8445 err = cfg80211_sched_scan_req_possible(rdev, want_multi);
8446 if (err)
8447 return err;
Luciano Coelho256da022014-11-10 16:13:46 +02008448
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008449 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Arend Van Sprielaad1e812017-01-27 12:27:44 +00008450 info->attrs,
8451 rdev->wiphy.max_match_sets);
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008452
8453 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008454 if (err)
8455 goto out_err;
8456
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008457 /* leave request id zero for legacy request
8458 * or if driver does not support multi-scheduled scan
8459 */
Denis Kenzior2fd351a2019-10-08 11:43:50 -05008460 if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1)
8461 sched_scan_req->reqid = cfg80211_assign_cookie(rdev);
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008462
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008463 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008464 if (err)
8465 goto out_free;
8466
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008467 sched_scan_req->dev = dev;
8468 sched_scan_req->wiphy = &rdev->wiphy;
8469
Jukka Rissanen93a1e862014-12-15 13:25:39 +02008470 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
8471 sched_scan_req->owner_nlportid = info->snd_portid;
8472
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008473 cfg80211_add_sched_scan_req(rdev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008474
Arend Van Spriel96b08fd2017-04-13 13:06:27 +01008475 nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN);
Luciano Coelho256da022014-11-10 16:13:46 +02008476 return 0;
8477
8478out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02008479 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02008480out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03008481 return err;
8482}
8483
8484static int nl80211_stop_sched_scan(struct sk_buff *skb,
8485 struct genl_info *info)
8486{
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008487 struct cfg80211_sched_scan_request *req;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008489 u64 cookie;
Luciano Coelho807f8a82011-05-11 17:09:35 +03008490
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008491 if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop)
Luciano Coelho807f8a82011-05-11 17:09:35 +03008492 return -EOPNOTSUPP;
8493
Arend Van Sprielca986ad2017-04-21 13:05:00 +01008494 if (info->attrs[NL80211_ATTR_COOKIE]) {
8495 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8496 return __cfg80211_stop_sched_scan(rdev, cookie, false);
8497 }
8498
8499 req = list_first_or_null_rcu(&rdev->sched_scan_req_list,
8500 struct cfg80211_sched_scan_request,
8501 list);
8502 if (!req || req->reqid ||
8503 (req->owner_nlportid &&
8504 req->owner_nlportid != info->snd_portid))
8505 return -ENOENT;
8506
8507 return cfg80211_stop_sched_scan_req(rdev, req, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03008508}
8509
Simon Wunderlich04f39042013-02-08 18:16:19 +01008510static int nl80211_start_radar_detection(struct sk_buff *skb,
8511 struct genl_info *info)
8512{
8513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8514 struct net_device *dev = info->user_ptr[1];
8515 struct wireless_dev *wdev = dev->ieee80211_ptr;
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008516 struct wiphy *wiphy = wdev->wiphy;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008517 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008518 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008519 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008520 int err;
8521
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008522 dfs_region = reg_get_dfs_region(wiphy);
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01008523 if (dfs_region == NL80211_DFS_UNSET)
8524 return -EINVAL;
8525
Simon Wunderlich04f39042013-02-08 18:16:19 +01008526 err = nl80211_parse_chandef(rdev, info, &chandef);
8527 if (err)
8528 return err;
8529
Simon Wunderlichff311bc2013-09-03 19:43:18 +02008530 if (netif_carrier_ok(dev))
8531 return -EBUSY;
8532
Simon Wunderlich04f39042013-02-08 18:16:19 +01008533 if (wdev->cac_started)
8534 return -EBUSY;
8535
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008536 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008537 if (err < 0)
8538 return err;
8539
8540 if (err == 0)
8541 return -EINVAL;
8542
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008543 if (!cfg80211_chandef_dfs_usable(wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01008544 return -EINVAL;
8545
Dmitry Lebed13cf6de2018-03-01 12:39:15 +03008546 /* CAC start is offloaded to HW and can't be started manually */
8547 if (wiphy_ext_feature_isset(wiphy, NL80211_EXT_FEATURE_DFS_OFFLOAD))
8548 return -EOPNOTSUPP;
8549
Simon Wunderlich04f39042013-02-08 18:16:19 +01008550 if (!rdev->ops->start_radar_detection)
8551 return -EOPNOTSUPP;
8552
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008553 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
8554 if (WARN_ON(!cac_time_ms))
8555 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
8556
Ilan Peera1056b1b2015-10-22 22:27:46 +03008557 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01008558 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01008559 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008560 wdev->cac_started = true;
8561 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01008562 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01008563 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01008564 return err;
8565}
8566
Sriram R30c63112018-12-04 17:46:52 +05308567static int nl80211_notify_radar_detection(struct sk_buff *skb,
8568 struct genl_info *info)
8569{
8570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8571 struct net_device *dev = info->user_ptr[1];
8572 struct wireless_dev *wdev = dev->ieee80211_ptr;
8573 struct wiphy *wiphy = wdev->wiphy;
8574 struct cfg80211_chan_def chandef;
8575 enum nl80211_dfs_regions dfs_region;
8576 int err;
8577
8578 dfs_region = reg_get_dfs_region(wiphy);
8579 if (dfs_region == NL80211_DFS_UNSET) {
8580 GENL_SET_ERR_MSG(info,
8581 "DFS Region is not set. Unexpected Radar indication");
8582 return -EINVAL;
8583 }
8584
8585 err = nl80211_parse_chandef(rdev, info, &chandef);
8586 if (err) {
8587 GENL_SET_ERR_MSG(info, "Unable to extract chandef info");
8588 return err;
8589 }
8590
8591 err = cfg80211_chandef_dfs_required(wiphy, &chandef, wdev->iftype);
8592 if (err < 0) {
8593 GENL_SET_ERR_MSG(info, "chandef is invalid");
8594 return err;
8595 }
8596
8597 if (err == 0) {
8598 GENL_SET_ERR_MSG(info,
8599 "Unexpected Radar indication for chandef/iftype");
8600 return -EINVAL;
8601 }
8602
8603 /* Do not process this notification if radar is already detected
8604 * by kernel on this channel, and return success.
8605 */
8606 if (chandef.chan->dfs_state == NL80211_DFS_UNAVAILABLE)
8607 return 0;
8608
8609 cfg80211_set_dfs_state(wiphy, &chandef, NL80211_DFS_UNAVAILABLE);
8610
8611 cfg80211_sched_dfs_chan_update(rdev);
8612
Luca Coelhoa680fe42019-04-17 09:34:40 +03008613 rdev->radar_chandef = chandef;
Sriram R30c63112018-12-04 17:46:52 +05308614
8615 /* Propagate this notification to other radios as well */
8616 queue_work(cfg80211_wq, &rdev->propagate_radar_detect_wk);
8617
8618 return 0;
8619}
8620
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008621static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
8622{
8623 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8624 struct net_device *dev = info->user_ptr[1];
8625 struct wireless_dev *wdev = dev->ieee80211_ptr;
8626 struct cfg80211_csa_settings params;
8627 /* csa_attrs is defined static to avoid waste of stack size - this
8628 * function is called under RTNL lock, so this should not be a problem.
8629 */
8630 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008631 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008632 bool need_new_beacon = false;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008633 bool need_handle_dfs_flag = true;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008634 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03008635 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008636
8637 if (!rdev->ops->channel_switch ||
8638 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
8639 return -EOPNOTSUPP;
8640
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008641 switch (dev->ieee80211_ptr->iftype) {
8642 case NL80211_IFTYPE_AP:
8643 case NL80211_IFTYPE_P2P_GO:
8644 need_new_beacon = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008645 /* For all modes except AP the handle_dfs flag needs to be
8646 * supplied to tell the kernel that userspace will handle radar
8647 * events when they happen. Otherwise a switch to a channel
8648 * requiring DFS will be rejected.
8649 */
8650 need_handle_dfs_flag = false;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008651
8652 /* useless if AP is not running */
8653 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01008654 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008655 break;
8656 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008657 if (!wdev->ssid_len)
8658 return -ENOTCONN;
8659 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07008660 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01008661 if (!wdev->mesh_id_len)
8662 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008663 break;
8664 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008665 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008666 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008667
8668 memset(&params, 0, sizeof(params));
Johannes Bergc177db22018-10-30 09:17:44 +01008669 params.beacon_csa.ftm_responder = -1;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008670
8671 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8672 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
8673 return -EINVAL;
8674
8675 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02008676 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008677 return -EINVAL;
8678
Luciano Coelho252e07c2014-10-08 09:48:34 +03008679 /* Even though the attribute is u32, the specification says
8680 * u8, so let's make sure we don't overflow.
8681 */
8682 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
8683 if (cs_count > 255)
8684 return -EINVAL;
8685
8686 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008687
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008688 if (!need_new_beacon)
8689 goto skip_beacons;
8690
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008691 err = nl80211_parse_beacon(rdev, info->attrs, &params.beacon_after);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008692 if (err)
8693 return err;
8694
Johannes Berg8cb08172019-04-26 14:07:28 +02008695 err = nla_parse_nested_deprecated(csa_attrs, NL80211_ATTR_MAX,
8696 info->attrs[NL80211_ATTR_CSA_IES],
8697 nl80211_policy, info->extack);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008698 if (err)
8699 return err;
8700
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -07008701 err = nl80211_parse_beacon(rdev, csa_attrs, &params.beacon_csa);
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008702 if (err)
8703 return err;
8704
8705 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
8706 return -EINVAL;
8707
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008708 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8709 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008710 return -EINVAL;
8711
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008712 params.n_counter_offsets_beacon = len / sizeof(u16);
8713 if (rdev->wiphy.max_num_csa_counters &&
8714 (params.n_counter_offsets_beacon >
8715 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008716 return -EINVAL;
8717
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008718 params.counter_offsets_beacon =
8719 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
8720
8721 /* sanity checks - counters should fit and be the same */
8722 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
8723 u16 offset = params.counter_offsets_beacon[i];
8724
8725 if (offset >= params.beacon_csa.tail_len)
8726 return -EINVAL;
8727
8728 if (params.beacon_csa.tail[offset] != params.count)
8729 return -EINVAL;
8730 }
8731
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008732 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008733 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8734 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008735 return -EINVAL;
8736
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008737 params.n_counter_offsets_presp = len / sizeof(u16);
8738 if (rdev->wiphy.max_num_csa_counters &&
Johannes Bergad5987b2016-09-13 15:53:55 +02008739 (params.n_counter_offsets_presp >
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008740 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008741 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03008742
8743 params.counter_offsets_presp =
8744 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
8745
8746 /* sanity checks - counters should fit and be the same */
8747 for (i = 0; i < params.n_counter_offsets_presp; i++) {
8748 u16 offset = params.counter_offsets_presp[i];
8749
8750 if (offset >= params.beacon_csa.probe_resp_len)
8751 return -EINVAL;
8752
8753 if (params.beacon_csa.probe_resp[offset] !=
8754 params.count)
8755 return -EINVAL;
8756 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008757 }
8758
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02008759skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008760 err = nl80211_parse_chandef(rdev, info, &params.chandef);
8761 if (err)
8762 return err;
8763
Arik Nemtsov923b3522015-07-08 15:41:44 +03008764 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
8765 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008766 return -EINVAL;
8767
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008768 err = cfg80211_chandef_dfs_required(wdev->wiphy,
8769 &params.chandef,
8770 wdev->iftype);
8771 if (err < 0)
8772 return err;
8773
Benjamin Berg8d9de162017-05-16 11:23:12 +02008774 if (err > 0) {
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02008775 params.radar_required = true;
Benjamin Berg8d9de162017-05-16 11:23:12 +02008776 if (need_handle_dfs_flag &&
8777 !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) {
8778 return -EINVAL;
8779 }
8780 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008781
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008782 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
8783 params.block_tx = true;
8784
Simon Wunderlichc56589e2013-11-21 18:19:49 +01008785 wdev_lock(wdev);
8786 err = rdev_channel_switch(rdev, dev, &params);
8787 wdev_unlock(wdev);
8788
8789 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02008790}
8791
Johannes Berg9720bb32011-06-21 09:45:33 +02008792static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
8793 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008794 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02008795 struct wireless_dev *wdev,
8796 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01008797{
Johannes Berg48ab9052009-07-10 18:42:31 +02008798 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01008799 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01008800 void *hdr;
8801 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02008802
8803 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008804
Eric W. Biederman15e47302012-09-07 20:12:54 +00008805 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01008806 NL80211_CMD_NEW_SCAN_RESULTS);
8807 if (!hdr)
8808 return -1;
8809
Michal Kubecek0a833c22017-11-15 13:09:32 +01008810 genl_dump_check_consistent(cb, hdr);
Johannes Berg9720bb32011-06-21 09:45:33 +02008811
Johannes Berg97990a02013-04-19 01:02:55 +02008812 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
8813 goto nla_put_failure;
8814 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008815 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
8816 goto nla_put_failure;
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008817 if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
8818 NL80211_ATTR_PAD))
Johannes Berg97990a02013-04-19 01:02:55 +02008819 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008820
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008821 bss = nla_nest_start_noflag(msg, NL80211_ATTR_BSS);
Johannes Berg2a519312009-02-10 21:25:55 +01008822 if (!bss)
8823 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04008824 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01008825 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04008826 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01008827
8828 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02008829 /* indicate whether we have probe response data or not */
8830 if (rcu_access_pointer(res->proberesp_ies) &&
8831 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
8832 goto fail_unlock_rcu;
8833
8834 /* this pointer prefers to be pointed to probe response data
8835 * but is always valid
8836 */
Johannes Berg9caf0362012-11-29 01:25:20 +01008837 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01008838 if (ies) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008839 if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf,
8840 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008841 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01008842 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
8843 ies->len, ies->data))
8844 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008845 }
Johannes Berg0e227082014-08-12 20:34:30 +02008846
8847 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01008848 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02008849 if (ies && ies->from_beacon) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008850 if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf,
8851 NL80211_BSS_PAD))
Johannes Berg8cef2c92013-02-05 16:54:31 +01008852 goto fail_unlock_rcu;
8853 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
8854 ies->len, ies->data))
8855 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01008856 }
8857 rcu_read_unlock();
8858
David S. Miller9360ffd2012-03-29 04:41:26 -04008859 if (res->beacon_interval &&
8860 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
8861 goto nla_put_failure;
8862 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
8863 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02008864 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04008865 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
8866 jiffies_to_msecs(jiffies - intbss->ts)))
8867 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008868
Avraham Stern1d762502016-07-05 17:10:13 +03008869 if (intbss->parent_tsf &&
8870 (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF,
8871 intbss->parent_tsf, NL80211_BSS_PAD) ||
8872 nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN,
8873 intbss->parent_bssid)))
8874 goto nla_put_failure;
8875
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008876 if (intbss->ts_boottime &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02008877 nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
8878 intbss->ts_boottime, NL80211_BSS_PAD))
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02008879 goto nla_put_failure;
8880
Sunil Dutt983dafa2017-12-13 19:51:36 +02008881 if (!nl80211_put_signal(msg, intbss->pub.chains,
8882 intbss->pub.chain_signal,
8883 NL80211_BSS_CHAIN_SIGNAL))
8884 goto nla_put_failure;
8885
Johannes Berg77965c972009-02-18 18:45:06 +01008886 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01008887 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04008888 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
8889 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008890 break;
8891 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008892 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
8893 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01008894 break;
8895 default:
8896 break;
8897 }
8898
Johannes Berg48ab9052009-07-10 18:42:31 +02008899 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02008900 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02008901 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04008902 if (intbss == wdev->current_bss &&
8903 nla_put_u32(msg, NL80211_BSS_STATUS,
8904 NL80211_BSS_STATUS_ASSOCIATED))
8905 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008906 break;
8907 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04008908 if (intbss == wdev->current_bss &&
8909 nla_put_u32(msg, NL80211_BSS_STATUS,
8910 NL80211_BSS_STATUS_IBSS_JOINED))
8911 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02008912 break;
8913 default:
8914 break;
8915 }
8916
Johannes Berg2a519312009-02-10 21:25:55 +01008917 nla_nest_end(msg, bss);
8918
Johannes Berg053c0952015-01-16 22:09:00 +01008919 genlmsg_end(msg, hdr);
8920 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008921
Johannes Berg8cef2c92013-02-05 16:54:31 +01008922 fail_unlock_rcu:
8923 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008924 nla_put_failure:
8925 genlmsg_cancel(msg, hdr);
8926 return -EMSGSIZE;
8927}
8928
Johannes Berg97990a02013-04-19 01:02:55 +02008929static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01008930{
Johannes Berg48ab9052009-07-10 18:42:31 +02008931 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01008932 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02008933 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02008934 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01008935 int err;
8936
Johannes Bergea90e0d2017-03-15 14:26:04 +01008937 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02008938 err = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Bergea90e0d2017-03-15 14:26:04 +01008939 if (err) {
8940 rtnl_unlock();
Johannes Berg67748892010-10-04 21:14:06 +02008941 return err;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008942 }
Johannes Berg2a519312009-02-10 21:25:55 +01008943
Johannes Berg48ab9052009-07-10 18:42:31 +02008944 wdev_lock(wdev);
8945 spin_lock_bh(&rdev->bss_lock);
Denis Kenziord1e23c92018-05-21 10:31:13 -05008946
8947 /*
8948 * dump_scan will be called multiple times to break up the scan results
8949 * into multiple messages. It is unlikely that any more bss-es will be
8950 * expired after the first call, so only call only call this on the
8951 * first dump_scan invocation.
8952 */
8953 if (start == 0)
8954 cfg80211_bss_expire(rdev);
Johannes Berg48ab9052009-07-10 18:42:31 +02008955
Johannes Berg9720bb32011-06-21 09:45:33 +02008956 cb->seq = rdev->bss_generation;
8957
Johannes Berg48ab9052009-07-10 18:42:31 +02008958 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01008959 if (++idx <= start)
8960 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02008961 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01008962 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02008963 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01008964 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02008965 break;
Johannes Berg2a519312009-02-10 21:25:55 +01008966 }
8967 }
8968
Johannes Berg48ab9052009-07-10 18:42:31 +02008969 spin_unlock_bh(&rdev->bss_lock);
8970 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01008971
Johannes Berg97990a02013-04-19 01:02:55 +02008972 cb->args[2] = idx;
Johannes Bergea90e0d2017-03-15 14:26:04 +01008973 rtnl_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01008974
Johannes Berg67748892010-10-04 21:14:06 +02008975 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01008976}
8977
Eric W. Biederman15e47302012-09-07 20:12:54 +00008978static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01008979 int flags, struct net_device *dev,
8980 bool allow_radio_stats,
8981 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01008982{
8983 void *hdr;
8984 struct nlattr *infoattr;
8985
Johannes Berg11f78ac2014-11-14 16:43:50 +01008986 /* skip radio stats if userspace didn't request them */
8987 if (!survey->channel && !allow_radio_stats)
8988 return 0;
8989
Eric W. Biederman15e47302012-09-07 20:12:54 +00008990 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01008991 NL80211_CMD_NEW_SURVEY_RESULTS);
8992 if (!hdr)
8993 return -ENOMEM;
8994
David S. Miller9360ffd2012-03-29 04:41:26 -04008995 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
8996 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01008997
Michal Kubecekae0be8d2019-04-26 11:13:06 +02008998 infoattr = nla_nest_start_noflag(msg, NL80211_ATTR_SURVEY_INFO);
Holger Schurig61fa7132009-11-11 12:25:40 +01008999 if (!infoattr)
9000 goto nla_put_failure;
9001
Johannes Berg11f78ac2014-11-14 16:43:50 +01009002 if (survey->channel &&
9003 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04009004 survey->channel->center_freq))
9005 goto nla_put_failure;
9006
9007 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
9008 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
9009 goto nla_put_failure;
9010 if ((survey->filled & SURVEY_INFO_IN_USE) &&
9011 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
9012 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009013 if ((survey->filled & SURVEY_INFO_TIME) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009014 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME,
9015 survey->time, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009016 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009017 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009018 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY,
9019 survey->time_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009020 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009021 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009022 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
9023 survey->time_ext_busy, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009024 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009025 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009026 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX,
9027 survey->time_rx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009028 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01009029 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009030 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX,
9031 survey->time_tx, NL80211_SURVEY_INFO_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -04009032 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01009033 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009034 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN,
9035 survey->time_scan, NL80211_SURVEY_INFO_PAD))
Johannes Berg052536a2014-11-14 16:44:11 +01009036 goto nla_put_failure;
Felix Fietkauc8cd6e72019-08-28 12:20:42 +02009037 if ((survey->filled & SURVEY_INFO_TIME_BSS_RX) &&
9038 nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BSS_RX,
9039 survey->time_bss_rx, NL80211_SURVEY_INFO_PAD))
9040 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01009041
9042 nla_nest_end(msg, infoattr);
9043
Johannes Berg053c0952015-01-16 22:09:00 +01009044 genlmsg_end(msg, hdr);
9045 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01009046
9047 nla_put_failure:
9048 genlmsg_cancel(msg, hdr);
9049 return -EMSGSIZE;
9050}
9051
Johannes Berg11f78ac2014-11-14 16:43:50 +01009052static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01009053{
Johannes Berg50508d92019-07-29 16:31:09 +02009054 struct nlattr **attrbuf;
Holger Schurig61fa7132009-11-11 12:25:40 +01009055 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009056 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02009057 struct wireless_dev *wdev;
9058 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01009059 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01009060 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01009061
Johannes Berg50508d92019-07-29 16:31:09 +02009062 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
9063 if (!attrbuf)
9064 return -ENOMEM;
9065
Johannes Bergea90e0d2017-03-15 14:26:04 +01009066 rtnl_lock();
Johannes Berg5297c652018-09-27 14:36:44 +02009067 res = nl80211_prepare_wdev_dump(cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02009068 if (res)
Johannes Bergea90e0d2017-03-15 14:26:04 +01009069 goto out_err;
Holger Schurig61fa7132009-11-11 12:25:40 +01009070
Johannes Berg11f78ac2014-11-14 16:43:50 +01009071 /* prepare_wdev_dump parsed the attributes */
Johannes Bergc90c39d2016-10-24 14:40:01 +02009072 radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
Johannes Berg11f78ac2014-11-14 16:43:50 +01009073
Johannes Berg97990a02013-04-19 01:02:55 +02009074 if (!wdev->netdev) {
9075 res = -EINVAL;
9076 goto out_err;
9077 }
9078
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009079 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01009080 res = -EOPNOTSUPP;
9081 goto out_err;
9082 }
9083
9084 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08009085 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01009086 if (res == -ENOENT)
9087 break;
9088 if (res)
9089 goto out_err;
9090
Johannes Berg11f78ac2014-11-14 16:43:50 +01009091 /* don't send disabled channels, but do send non-channel data */
9092 if (survey.channel &&
9093 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07009094 survey_idx++;
9095 continue;
9096 }
9097
Holger Schurig61fa7132009-11-11 12:25:40 +01009098 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00009099 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01009100 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01009101 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01009102 goto out;
9103 survey_idx++;
9104 }
9105
9106 out:
Johannes Berg97990a02013-04-19 01:02:55 +02009107 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01009108 res = skb->len;
9109 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +02009110 kfree(attrbuf);
Johannes Bergea90e0d2017-03-15 14:26:04 +01009111 rtnl_unlock();
Holger Schurig61fa7132009-11-11 12:25:40 +01009112 return res;
9113}
9114
Samuel Ortizb23aa672009-07-01 21:26:54 +02009115static bool nl80211_valid_wpa_versions(u32 wpa_versions)
9116{
9117 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
Chung-Hsien Hsucc3e14c2019-05-09 09:49:05 +00009118 NL80211_WPA_VERSION_2 |
9119 NL80211_WPA_VERSION_3));
Samuel Ortizb23aa672009-07-01 21:26:54 +02009120}
9121
Jouni Malinen636a5d32009-03-19 13:39:22 +02009122static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
9123{
Johannes Berg4c476992010-10-04 21:36:35 +02009124 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9125 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009126 struct ieee80211_channel *chan;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009127 const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL;
9128 int err, ssid_len, ie_len = 0, auth_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02009129 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02009130 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009131 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009132
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009133 if (!info->attrs[NL80211_ATTR_MAC])
9134 return -EINVAL;
9135
Jouni Malinen17780922009-03-27 20:52:47 +02009136 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
9137 return -EINVAL;
9138
Johannes Berg19957bb2009-07-02 17:20:43 +02009139 if (!info->attrs[NL80211_ATTR_SSID])
9140 return -EINVAL;
9141
9142 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
9143 return -EINVAL;
9144
Johannes Bergfffd0932009-07-08 14:22:54 +02009145 err = nl80211_parse_key(info, &key);
9146 if (err)
9147 return err;
9148
9149 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02009150 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
9151 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02009152 if (!key.p.key || !key.p.key_len)
9153 return -EINVAL;
9154 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
9155 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
9156 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
9157 key.p.key_len != WLAN_KEY_LEN_WEP104))
9158 return -EINVAL;
Johannes Bergb6b55552016-09-13 16:25:58 +02009159 if (key.idx > 3)
Johannes Bergfffd0932009-07-08 14:22:54 +02009160 return -EINVAL;
9161 } else {
9162 key.p.key_len = 0;
9163 key.p.key = NULL;
9164 }
9165
Johannes Bergafea0b72010-08-10 09:46:42 +02009166 if (key.idx >= 0) {
9167 int i;
9168 bool ok = false;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009169
Johannes Bergafea0b72010-08-10 09:46:42 +02009170 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
9171 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
9172 ok = true;
9173 break;
9174 }
9175 }
Johannes Berg4c476992010-10-04 21:36:35 +02009176 if (!ok)
9177 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02009178 }
9179
Johannes Berg4c476992010-10-04 21:36:35 +02009180 if (!rdev->ops->auth)
9181 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009182
Johannes Berg074ac8d2010-09-16 14:58:22 +02009183 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009184 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9185 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009186
Johannes Berg19957bb2009-07-02 17:20:43 +02009187 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02009188 chan = nl80211_get_valid_chan(&rdev->wiphy,
9189 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9190 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009191 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009192
Johannes Berg19957bb2009-07-02 17:20:43 +02009193 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9194 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9195
9196 if (info->attrs[NL80211_ATTR_IE]) {
9197 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9198 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9199 }
9200
9201 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009202 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02009203 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02009204
Jouni Malinen63181062016-10-27 00:42:02 +03009205 if ((auth_type == NL80211_AUTHTYPE_SAE ||
9206 auth_type == NL80211_AUTHTYPE_FILS_SK ||
9207 auth_type == NL80211_AUTHTYPE_FILS_SK_PFS ||
9208 auth_type == NL80211_AUTHTYPE_FILS_PK) &&
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009209 !info->attrs[NL80211_ATTR_AUTH_DATA])
Jouni Malinene39e5b52012-09-30 19:29:39 +03009210 return -EINVAL;
9211
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009212 if (info->attrs[NL80211_ATTR_AUTH_DATA]) {
Jouni Malinen63181062016-10-27 00:42:02 +03009213 if (auth_type != NL80211_AUTHTYPE_SAE &&
9214 auth_type != NL80211_AUTHTYPE_FILS_SK &&
9215 auth_type != NL80211_AUTHTYPE_FILS_SK_PFS &&
9216 auth_type != NL80211_AUTHTYPE_FILS_PK)
Jouni Malinene39e5b52012-09-30 19:29:39 +03009217 return -EINVAL;
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009218 auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]);
9219 auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03009220 /* need to include at least Auth Transaction and Status Code */
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009221 if (auth_data_len < 4)
Jouni Malinene39e5b52012-09-30 19:29:39 +03009222 return -EINVAL;
9223 }
9224
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009225 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9226
Johannes Berg95de8172012-01-20 13:55:25 +01009227 /*
9228 * Since we no longer track auth state, ignore
9229 * requests to only change local state.
9230 */
9231 if (local_state_change)
9232 return 0;
9233
Johannes Berg91bf9b22013-05-15 17:44:01 +02009234 wdev_lock(dev->ieee80211_ptr);
9235 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
9236 ssid, ssid_len, ie, ie_len,
9237 key.p.key, key.p.key_len, key.idx,
Jouni Malinen11b6b5a2016-10-27 00:41:58 +03009238 auth_data, auth_data_len);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009239 wdev_unlock(dev->ieee80211_ptr);
9240 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009241}
9242
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009243static int validate_pae_over_nl80211(struct cfg80211_registered_device *rdev,
9244 struct genl_info *info)
9245{
9246 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9247 GENL_SET_ERR_MSG(info, "SOCKET_OWNER not set");
9248 return -EINVAL;
9249 }
9250
9251 if (!rdev->ops->tx_control_port ||
9252 !wiphy_ext_feature_isset(&rdev->wiphy,
9253 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
9254 return -EOPNOTSUPP;
9255
9256 return 0;
9257}
9258
Johannes Bergc0692b82010-08-27 14:26:53 +03009259static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
9260 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02009261 struct cfg80211_crypto_settings *settings,
9262 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009263{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02009264 memset(settings, 0, sizeof(*settings));
9265
Samuel Ortizb23aa672009-07-01 21:26:54 +02009266 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
9267
Johannes Bergc0692b82010-08-27 14:26:53 +03009268 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
9269 u16 proto;
Kirtika Ruchandani7a087e72016-05-29 19:51:23 -07009270
Johannes Bergc0692b82010-08-27 14:26:53 +03009271 proto = nla_get_u16(
9272 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
9273 settings->control_port_ethertype = cpu_to_be16(proto);
9274 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
9275 proto != ETH_P_PAE)
9276 return -EINVAL;
9277 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
9278 settings->control_port_no_encrypt = true;
9279 } else
9280 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
9281
Denis Kenzior64bf3d42018-03-26 12:52:43 -05009282 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9283 int r = validate_pae_over_nl80211(rdev, info);
9284
9285 if (r < 0)
9286 return r;
9287
9288 settings->control_port_over_nl80211 = true;
9289 }
9290
Samuel Ortizb23aa672009-07-01 21:26:54 +02009291 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
9292 void *data;
9293 int len, i;
9294
9295 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9296 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
9297 settings->n_ciphers_pairwise = len / sizeof(u32);
9298
9299 if (len % sizeof(u32))
9300 return -EINVAL;
9301
Johannes Berg3dc27d22009-07-02 21:36:37 +02009302 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02009303 return -EINVAL;
9304
9305 memcpy(settings->ciphers_pairwise, data, len);
9306
9307 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009308 if (!cfg80211_supported_cipher_suite(
9309 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02009310 settings->ciphers_pairwise[i]))
9311 return -EINVAL;
9312 }
9313
9314 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
9315 settings->cipher_group =
9316 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03009317 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
9318 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02009319 return -EINVAL;
9320 }
9321
9322 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
9323 settings->wpa_versions =
9324 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
9325 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
9326 return -EINVAL;
9327 }
9328
9329 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
9330 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03009331 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02009332
9333 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
9334 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
9335 settings->n_akm_suites = len / sizeof(u32);
9336
9337 if (len % sizeof(u32))
9338 return -EINVAL;
9339
Jouni Malinen1b9ca022011-09-21 16:13:07 +03009340 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
9341 return -EINVAL;
9342
Samuel Ortizb23aa672009-07-01 21:26:54 +02009343 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02009344 }
9345
Eliad Peller91b5ab62017-06-09 13:08:42 +01009346 if (info->attrs[NL80211_ATTR_PMK]) {
9347 if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN)
9348 return -EINVAL;
9349 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9350 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK))
9351 return -EINVAL;
9352 settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]);
9353 }
9354
Chung-Hsien Hsu26f70442019-05-09 09:49:06 +00009355 if (info->attrs[NL80211_ATTR_SAE_PASSWORD]) {
9356 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9357 NL80211_EXT_FEATURE_SAE_OFFLOAD))
9358 return -EINVAL;
9359 settings->sae_pwd =
9360 nla_data(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9361 settings->sae_pwd_len =
9362 nla_len(info->attrs[NL80211_ATTR_SAE_PASSWORD]);
9363 }
9364
Samuel Ortizb23aa672009-07-01 21:26:54 +02009365 return 0;
9366}
9367
Jouni Malinen636a5d32009-03-19 13:39:22 +02009368static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
9369{
Johannes Berg4c476992010-10-04 21:36:35 +02009370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9371 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02009372 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01009373 struct cfg80211_assoc_request req = {};
9374 const u8 *bssid, *ssid;
9375 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009376
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009377 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9378 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9379 return -EPERM;
9380
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009381 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02009382 !info->attrs[NL80211_ATTR_SSID] ||
9383 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009384 return -EINVAL;
9385
Johannes Berg4c476992010-10-04 21:36:35 +02009386 if (!rdev->ops->assoc)
9387 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009388
Johannes Berg074ac8d2010-09-16 14:58:22 +02009389 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009390 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9391 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009392
Johannes Berg19957bb2009-07-02 17:20:43 +02009393 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009394
Jouni Malinen664834d2014-01-15 00:01:44 +02009395 chan = nl80211_get_valid_chan(&rdev->wiphy,
9396 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
9397 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02009398 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009399
Johannes Berg19957bb2009-07-02 17:20:43 +02009400 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9401 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009402
9403 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009404 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9405 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009406 }
9407
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009408 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009409 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009410 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02009411 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01009412 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02009413 else if (mfp != NL80211_MFP_NO)
9414 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03009415 }
9416
Johannes Berg3e5d7642009-07-07 14:37:26 +02009417 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01009418 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02009419
Ben Greear7e7c8922011-11-18 11:31:59 -08009420 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009421 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08009422
9423 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009424 memcpy(&req.ht_capa_mask,
9425 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9426 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08009427
9428 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009429 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08009430 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009431 memcpy(&req.ht_capa,
9432 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9433 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08009434 }
9435
Johannes Bergee2aca32013-02-21 17:36:01 +01009436 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01009437 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01009438
9439 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01009440 memcpy(&req.vht_capa_mask,
9441 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
9442 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01009443
9444 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01009445 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01009446 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01009447 memcpy(&req.vht_capa,
9448 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
9449 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01009450 }
9451
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009452 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02009453 if (!((rdev->wiphy.features &
9454 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
9455 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
9456 !wiphy_ext_feature_isset(&rdev->wiphy,
9457 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03009458 return -EINVAL;
9459 req.flags |= ASSOC_REQ_USE_RRM;
9460 }
9461
Jouni Malinen348bd452016-10-27 00:42:03 +03009462 if (info->attrs[NL80211_ATTR_FILS_KEK]) {
9463 req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]);
9464 req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]);
9465 if (!info->attrs[NL80211_ATTR_FILS_NONCES])
9466 return -EINVAL;
9467 req.fils_nonces =
9468 nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]);
9469 }
9470
Johannes Bergf62fab72013-02-21 20:09:09 +01009471 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02009472 if (!err) {
9473 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009474
Johannes Bergf62fab72013-02-21 20:09:09 +01009475 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
9476 ssid, ssid_len, &req);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -05009477
9478 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
9479 dev->ieee80211_ptr->conn_owner_nlportid =
9480 info->snd_portid;
9481 memcpy(dev->ieee80211_ptr->disconnect_bssid,
9482 bssid, ETH_ALEN);
9483 }
9484
Johannes Berg91bf9b22013-05-15 17:44:01 +02009485 wdev_unlock(dev->ieee80211_ptr);
9486 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009487
Jouni Malinen636a5d32009-03-19 13:39:22 +02009488 return err;
9489}
9490
9491static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
9492{
Johannes Berg4c476992010-10-04 21:36:35 +02009493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9494 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009495 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009496 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009497 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009498 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009499
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009500 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9501 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9502 return -EPERM;
9503
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009504 if (!info->attrs[NL80211_ATTR_MAC])
9505 return -EINVAL;
9506
9507 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9508 return -EINVAL;
9509
Johannes Berg4c476992010-10-04 21:36:35 +02009510 if (!rdev->ops->deauth)
9511 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009512
Johannes Berg074ac8d2010-09-16 14:58:22 +02009513 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009514 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9515 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009516
Johannes Berg19957bb2009-07-02 17:20:43 +02009517 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009518
Johannes Berg19957bb2009-07-02 17:20:43 +02009519 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9520 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009521 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009522 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009523 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009524
9525 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009526 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9527 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009528 }
9529
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009530 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9531
Johannes Berg91bf9b22013-05-15 17:44:01 +02009532 wdev_lock(dev->ieee80211_ptr);
9533 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
9534 local_state_change);
9535 wdev_unlock(dev->ieee80211_ptr);
9536 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009537}
9538
9539static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
9540{
Johannes Berg4c476992010-10-04 21:36:35 +02009541 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9542 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02009543 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02009544 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02009545 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009546 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009547
Andrew Zaborowskibad29292018-05-22 02:46:02 +02009548 if (dev->ieee80211_ptr->conn_owner_nlportid &&
9549 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
9550 return -EPERM;
9551
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009552 if (!info->attrs[NL80211_ATTR_MAC])
9553 return -EINVAL;
9554
9555 if (!info->attrs[NL80211_ATTR_REASON_CODE])
9556 return -EINVAL;
9557
Johannes Berg4c476992010-10-04 21:36:35 +02009558 if (!rdev->ops->disassoc)
9559 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009560
Johannes Berg074ac8d2010-09-16 14:58:22 +02009561 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02009562 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
9563 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02009564
Johannes Berg19957bb2009-07-02 17:20:43 +02009565 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009566
Johannes Berg19957bb2009-07-02 17:20:43 +02009567 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
9568 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01009569 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02009570 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02009571 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02009572
9573 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02009574 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9575 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02009576 }
9577
Jouni Malinend5cdfac2010-04-04 09:37:19 +03009578 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
9579
Johannes Berg91bf9b22013-05-15 17:44:01 +02009580 wdev_lock(dev->ieee80211_ptr);
9581 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
9582 local_state_change);
9583 wdev_unlock(dev->ieee80211_ptr);
9584 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02009585}
9586
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009587static bool
9588nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
Johannes Berg57fbcce2016-04-12 15:56:15 +02009589 int mcast_rate[NUM_NL80211_BANDS],
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009590 int rateval)
9591{
9592 struct wiphy *wiphy = &rdev->wiphy;
9593 bool found = false;
9594 int band, i;
9595
Johannes Berg57fbcce2016-04-12 15:56:15 +02009596 for (band = 0; band < NUM_NL80211_BANDS; band++) {
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009597 struct ieee80211_supported_band *sband;
9598
9599 sband = wiphy->bands[band];
9600 if (!sband)
9601 continue;
9602
9603 for (i = 0; i < sband->n_bitrates; i++) {
9604 if (sband->bitrates[i].bitrate == rateval) {
9605 mcast_rate[band] = i + 1;
9606 found = true;
9607 break;
9608 }
9609 }
9610 }
9611
9612 return found;
9613}
9614
Johannes Berg04a773a2009-04-19 21:24:32 +02009615static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
9616{
Johannes Berg4c476992010-10-04 21:36:35 +02009617 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9618 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009619 struct cfg80211_ibss_params ibss;
9620 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02009621 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02009622 int err;
9623
Johannes Berg8e30bc52009-04-22 17:45:38 +02009624 memset(&ibss, 0, sizeof(ibss));
9625
Johannes Berg683b6d32012-11-08 21:25:48 +01009626 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02009627 !nla_len(info->attrs[NL80211_ATTR_SSID]))
9628 return -EINVAL;
9629
Johannes Berg8e30bc52009-04-22 17:45:38 +02009630 ibss.beacon_interval = 100;
9631
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309632 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL])
Johannes Berg8e30bc52009-04-22 17:45:38 +02009633 ibss.beacon_interval =
9634 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309635
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +05309636 err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC,
9637 ibss.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +05309638 if (err)
9639 return err;
Johannes Berg8e30bc52009-04-22 17:45:38 +02009640
Johannes Berg4c476992010-10-04 21:36:35 +02009641 if (!rdev->ops->join_ibss)
9642 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009643
Johannes Berg4c476992010-10-04 21:36:35 +02009644 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9645 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009646
Johannes Berg79c97e92009-07-07 03:56:12 +02009647 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02009648
Johannes Berg39193492011-09-16 13:45:25 +02009649 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02009650 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02009651
9652 if (!is_valid_ether_addr(ibss.bssid))
9653 return -EINVAL;
9654 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009655 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
9656 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
9657
9658 if (info->attrs[NL80211_ATTR_IE]) {
9659 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9660 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9661 }
9662
Johannes Berg683b6d32012-11-08 21:25:48 +01009663 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
9664 if (err)
9665 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009666
Ilan Peer174e0cd2014-02-23 09:13:01 +02009667 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
9668 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01009669 return -EINVAL;
9670
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009671 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02009672 case NL80211_CHAN_WIDTH_5:
9673 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009674 case NL80211_CHAN_WIDTH_20_NOHT:
9675 break;
9676 case NL80211_CHAN_WIDTH_20:
9677 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01009678 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9679 return -EINVAL;
9680 break;
9681 case NL80211_CHAN_WIDTH_80:
9682 case NL80211_CHAN_WIDTH_80P80:
9683 case NL80211_CHAN_WIDTH_160:
9684 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
9685 return -EINVAL;
9686 if (!wiphy_ext_feature_isset(&rdev->wiphy,
9687 NL80211_EXT_FEATURE_VHT_IBSS))
9688 return -EINVAL;
9689 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009690 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009691 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02009692 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01009693
Johannes Berg04a773a2009-04-19 21:24:32 +02009694 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02009695 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02009696
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009697 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
9698 u8 *rates =
9699 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9700 int n_rates =
9701 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
9702 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01009703 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009704
Johannes Berg34850ab2011-07-18 18:08:35 +02009705 err = ieee80211_get_ratemask(sband, rates, n_rates,
9706 &ibss.basic_rates);
9707 if (err)
9708 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009709 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009710
Simon Wunderlich803768f2013-06-28 10:39:58 +02009711 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9712 memcpy(&ibss.ht_capa_mask,
9713 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
9714 sizeof(ibss.ht_capa_mask));
9715
9716 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
9717 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
9718 return -EINVAL;
9719 memcpy(&ibss.ht_capa,
9720 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
9721 sizeof(ibss.ht_capa));
9722 }
9723
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01009724 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
9725 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
9726 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
9727 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03009728
Johannes Berg4c476992010-10-04 21:36:35 +02009729 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05309730 bool no_ht = false;
9731
Johannes Berg768075e2017-11-13 15:35:06 +01009732 connkeys = nl80211_parse_connkeys(rdev, info, &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02009733 if (IS_ERR(connkeys))
9734 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309735
Johannes Berg3d9d1d62012-11-08 23:14:50 +01009736 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
9737 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01009738 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05309739 return -EINVAL;
9740 }
Johannes Berg4c476992010-10-04 21:36:35 +02009741 }
Johannes Berg04a773a2009-04-19 21:24:32 +02009742
Antonio Quartulli267335d2012-01-31 20:25:47 +01009743 ibss.control_port =
9744 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
9745
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009746 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
9747 int r = validate_pae_over_nl80211(rdev, info);
9748
Johannes Bergd350a0f2018-12-15 11:03:22 +02009749 if (r < 0) {
9750 kzfree(connkeys);
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009751 return r;
Johannes Bergd350a0f2018-12-15 11:03:22 +02009752 }
Denis Kenziorc3bfe1f2018-03-26 12:52:48 -05009753
9754 ibss.control_port_over_nl80211 = true;
9755 }
9756
Simon Wunderlich5336fa82013-10-07 18:41:05 +02009757 ibss.userspace_handles_dfs =
9758 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
9759
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009760 wdev_lock(dev->ieee80211_ptr);
9761 err = __cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02009762 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03009763 kzfree(connkeys);
Denis Kenziorf8d16d32018-03-26 12:52:45 -05009764 else if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
9765 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
9766 wdev_unlock(dev->ieee80211_ptr);
9767
Johannes Berg04a773a2009-04-19 21:24:32 +02009768 return err;
9769}
9770
9771static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
9772{
Johannes Berg4c476992010-10-04 21:36:35 +02009773 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9774 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02009775
Johannes Berg4c476992010-10-04 21:36:35 +02009776 if (!rdev->ops->leave_ibss)
9777 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009778
Johannes Berg4c476992010-10-04 21:36:35 +02009779 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
9780 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02009781
Johannes Berg4c476992010-10-04 21:36:35 +02009782 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02009783}
9784
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009785static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
9786{
9787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9788 struct net_device *dev = info->user_ptr[1];
Johannes Berg57fbcce2016-04-12 15:56:15 +02009789 int mcast_rate[NUM_NL80211_BANDS];
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009790 u32 nla_rate;
9791 int err;
9792
9793 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02009794 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
9795 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009796 return -EOPNOTSUPP;
9797
9798 if (!rdev->ops->set_mcast_rate)
9799 return -EOPNOTSUPP;
9800
9801 memset(mcast_rate, 0, sizeof(mcast_rate));
9802
9803 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
9804 return -EINVAL;
9805
9806 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
9807 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
9808 return -EINVAL;
9809
Ilan Peera1056b1b2015-10-22 22:27:46 +03009810 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009811
9812 return err;
9813}
9814
Johannes Bergad7e7182013-11-13 13:37:47 +01009815static struct sk_buff *
9816__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009817 struct wireless_dev *wdev, int approxlen,
9818 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01009819 enum nl80211_attrs attr,
9820 const struct nl80211_vendor_cmd_info *info,
9821 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01009822{
9823 struct sk_buff *skb;
9824 void *hdr;
9825 struct nlattr *data;
9826
9827 skb = nlmsg_new(approxlen + 100, gfp);
9828 if (!skb)
9829 return NULL;
9830
9831 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
9832 if (!hdr) {
9833 kfree_skb(skb);
9834 return NULL;
9835 }
9836
9837 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
9838 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01009839
9840 if (info) {
9841 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
9842 info->vendor_id))
9843 goto nla_put_failure;
9844 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
9845 info->subcmd))
9846 goto nla_put_failure;
9847 }
9848
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009849 if (wdev) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +02009850 if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
9851 wdev_id(wdev), NL80211_ATTR_PAD))
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009852 goto nla_put_failure;
9853 if (wdev->netdev &&
9854 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
9855 wdev->netdev->ifindex))
9856 goto nla_put_failure;
9857 }
9858
Michal Kubecekae0be8d2019-04-26 11:13:06 +02009859 data = nla_nest_start_noflag(skb, attr);
Johannes Berg76e1fb42016-09-14 09:55:57 +02009860 if (!data)
9861 goto nla_put_failure;
Johannes Bergad7e7182013-11-13 13:37:47 +01009862
9863 ((void **)skb->cb)[0] = rdev;
9864 ((void **)skb->cb)[1] = hdr;
9865 ((void **)skb->cb)[2] = data;
9866
9867 return skb;
9868
9869 nla_put_failure:
9870 kfree_skb(skb);
9871 return NULL;
9872}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01009873
Johannes Berge03ad6e2014-01-01 17:22:30 +01009874struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009875 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009876 enum nl80211_commands cmd,
9877 enum nl80211_attrs attr,
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009878 unsigned int portid,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009879 int vendor_event_idx,
9880 int approxlen, gfp_t gfp)
9881{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009882 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009883 const struct nl80211_vendor_cmd_info *info;
9884
9885 switch (cmd) {
9886 case NL80211_CMD_TESTMODE:
9887 if (WARN_ON(vendor_event_idx != -1))
9888 return NULL;
9889 info = NULL;
9890 break;
9891 case NL80211_CMD_VENDOR:
9892 if (WARN_ON(vendor_event_idx < 0 ||
9893 vendor_event_idx >= wiphy->n_vendor_events))
9894 return NULL;
9895 info = &wiphy->vendor_events[vendor_event_idx];
9896 break;
9897 default:
9898 WARN_ON(1);
9899 return NULL;
9900 }
9901
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009902 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, portid, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01009903 cmd, attr, info, gfp);
9904}
9905EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
9906
9907void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
9908{
9909 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9910 void *hdr = ((void **)skb->cb)[1];
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009911 struct nlmsghdr *nlhdr = nlmsg_hdr(skb);
Johannes Berge03ad6e2014-01-01 17:22:30 +01009912 struct nlattr *data = ((void **)skb->cb)[2];
9913 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
9914
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009915 /* clear CB data for netlink core to own from now on */
9916 memset(skb->cb, 0, sizeof(skb->cb));
9917
Johannes Berge03ad6e2014-01-01 17:22:30 +01009918 nla_nest_end(skb, data);
9919 genlmsg_end(skb, hdr);
9920
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009921 if (nlhdr->nlmsg_pid) {
9922 genlmsg_unicast(wiphy_net(&rdev->wiphy), skb,
9923 nlhdr->nlmsg_pid);
9924 } else {
9925 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
9926 mcgrp = NL80211_MCGRP_VENDOR;
Johannes Berge03ad6e2014-01-01 17:22:30 +01009927
Johannes Berg55c1fdf2019-02-06 13:17:19 +02009928 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
9929 skb, 0, mcgrp, gfp);
9930 }
Johannes Berge03ad6e2014-01-01 17:22:30 +01009931}
9932EXPORT_SYMBOL(__cfg80211_send_event_skb);
9933
Johannes Bergaff89a92009-07-01 21:26:51 +02009934#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02009935static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
9936{
Johannes Berg4c476992010-10-04 21:36:35 +02009937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03009938 struct wireless_dev *wdev =
9939 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02009940 int err;
9941
David Spinadelfc73f112013-07-31 18:04:15 +03009942 if (!rdev->ops->testmode_cmd)
9943 return -EOPNOTSUPP;
9944
9945 if (IS_ERR(wdev)) {
9946 err = PTR_ERR(wdev);
9947 if (err != -EINVAL)
9948 return err;
9949 wdev = NULL;
9950 } else if (wdev->wiphy != &rdev->wiphy) {
9951 return -EINVAL;
9952 }
9953
Johannes Bergaff89a92009-07-01 21:26:51 +02009954 if (!info->attrs[NL80211_ATTR_TESTDATA])
9955 return -EINVAL;
9956
Johannes Bergad7e7182013-11-13 13:37:47 +01009957 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03009958 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02009959 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
9960 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01009961 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02009962
Johannes Bergaff89a92009-07-01 21:26:51 +02009963 return err;
9964}
9965
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009966static int nl80211_testmode_dump(struct sk_buff *skb,
9967 struct netlink_callback *cb)
9968{
Johannes Berg00918d32011-12-13 17:22:05 +01009969 struct cfg80211_registered_device *rdev;
Johannes Berg50508d92019-07-29 16:31:09 +02009970 struct nlattr **attrbuf = NULL;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009971 int err;
9972 long phy_idx;
9973 void *data = NULL;
9974 int data_len = 0;
9975
Johannes Berg5fe231e2013-05-08 21:45:15 +02009976 rtnl_lock();
9977
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009978 if (cb->args[0]) {
9979 /*
9980 * 0 is a valid index, but not valid for args[0],
9981 * so we need to offset by 1.
9982 */
9983 phy_idx = cb->args[0] - 1;
Luca Coelhoa4956dc2017-02-07 22:13:56 +02009984
9985 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
9986 if (!rdev) {
9987 err = -ENOENT;
9988 goto out_err;
9989 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07009990 } else {
Johannes Berg50508d92019-07-29 16:31:09 +02009991 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf),
9992 GFP_KERNEL);
9993 if (!attrbuf) {
9994 err = -ENOMEM;
9995 goto out_err;
9996 }
Johannes Bergc90c39d2016-10-24 14:40:01 +02009997
Johannes Berg8cb08172019-04-26 14:07:28 +02009998 err = nlmsg_parse_deprecated(cb->nlh,
9999 GENL_HDRLEN + nl80211_fam.hdrsize,
10000 attrbuf, nl80211_fam.maxattr,
10001 nl80211_policy, NULL);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010002 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +020010003 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +010010004
Johannes Bergc90c39d2016-10-24 14:40:01 +020010005 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg2bd7e352012-06-15 14:23:16 +020010006 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010007 err = PTR_ERR(rdev);
10008 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +010010009 }
Johannes Berg2bd7e352012-06-15 14:23:16 +020010010 phy_idx = rdev->wiphy_idx;
Johannes Berg2bd7e352012-06-15 14:23:16 +020010011
Johannes Bergc90c39d2016-10-24 14:40:01 +020010012 if (attrbuf[NL80211_ATTR_TESTDATA])
10013 cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA];
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010014 }
10015
10016 if (cb->args[1]) {
10017 data = nla_data((void *)cb->args[1]);
10018 data_len = nla_len((void *)cb->args[1]);
10019 }
10020
Johannes Berg00918d32011-12-13 17:22:05 +010010021 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010022 err = -EOPNOTSUPP;
10023 goto out_err;
10024 }
10025
10026 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000010027 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010028 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10029 NL80211_CMD_TESTMODE);
10030 struct nlattr *tmdata;
10031
Dan Carpentercb35fba2013-08-14 14:50:01 +030010032 if (!hdr)
10033 break;
10034
David S. Miller9360ffd2012-03-29 04:41:26 -040010035 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010036 genlmsg_cancel(skb, hdr);
10037 break;
10038 }
10039
Michal Kubecekae0be8d2019-04-26 11:13:06 +020010040 tmdata = nla_nest_start_noflag(skb, NL80211_ATTR_TESTDATA);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010041 if (!tmdata) {
10042 genlmsg_cancel(skb, hdr);
10043 break;
10044 }
Hila Gonene35e4d22012-06-27 17:19:42 +030010045 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010046 nla_nest_end(skb, tmdata);
10047
10048 if (err == -ENOBUFS || err == -ENOENT) {
10049 genlmsg_cancel(skb, hdr);
10050 break;
10051 } else if (err) {
10052 genlmsg_cancel(skb, hdr);
10053 goto out_err;
10054 }
10055
10056 genlmsg_end(skb, hdr);
10057 }
10058
10059 err = skb->len;
10060 /* see above */
10061 cb->args[0] = phy_idx + 1;
10062 out_err:
Johannes Berg50508d92019-07-29 16:31:09 +020010063 kfree(attrbuf);
Johannes Berg5fe231e2013-05-08 21:45:15 +020010064 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010065 return err;
10066}
Johannes Bergaff89a92009-07-01 21:26:51 +020010067#endif
10068
Samuel Ortizb23aa672009-07-01 21:26:54 +020010069static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
10070{
Johannes Berg4c476992010-10-04 21:36:35 +020010071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10072 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010073 struct cfg80211_connect_params connect;
10074 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +020010075 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010076 int err;
10077
10078 memset(&connect, 0, sizeof(connect));
10079
Samuel Ortizb23aa672009-07-01 21:26:54 +020010080 if (!info->attrs[NL80211_ATTR_SSID] ||
10081 !nla_len(info->attrs[NL80211_ATTR_SSID]))
10082 return -EINVAL;
10083
10084 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10085 connect.auth_type =
10086 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +030010087 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
10088 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +020010089 return -EINVAL;
10090 } else
10091 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
10092
10093 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
10094
Avraham Stern3a00df52017-06-09 13:08:43 +010010095 if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] &&
10096 !wiphy_ext_feature_isset(&rdev->wiphy,
10097 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
10098 return -EINVAL;
10099 connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS];
10100
Johannes Bergc0692b82010-08-27 14:26:53 +030010101 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +020010102 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010103 if (err)
10104 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010105
Johannes Berg074ac8d2010-09-16 14:58:22 +020010106 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010107 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10108 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010109
Johannes Berg79c97e92009-07-07 03:56:12 +020010110 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010111
Bala Shanmugam4486ea92012-03-07 17:27:12 +053010112 connect.bg_scan_period = -1;
10113 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
10114 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
10115 connect.bg_scan_period =
10116 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
10117 }
10118
Samuel Ortizb23aa672009-07-01 21:26:54 +020010119 if (info->attrs[NL80211_ATTR_MAC])
10120 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +020010121 else if (info->attrs[NL80211_ATTR_MAC_HINT])
10122 connect.bssid_hint =
10123 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +020010124 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10125 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10126
10127 if (info->attrs[NL80211_ATTR_IE]) {
10128 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10129 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10130 }
10131
Jouni Malinencee00a92013-01-15 17:15:57 +020010132 if (info->attrs[NL80211_ATTR_USE_MFP]) {
10133 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Emmanuel Grumbach65026002017-08-18 15:31:41 +030010134 if (connect.mfp == NL80211_MFP_OPTIONAL &&
10135 !wiphy_ext_feature_isset(&rdev->wiphy,
10136 NL80211_EXT_FEATURE_MFP_OPTIONAL))
10137 return -EOPNOTSUPP;
Jouni Malinencee00a92013-01-15 17:15:57 +020010138 } else {
10139 connect.mfp = NL80211_MFP_NO;
10140 }
10141
Jouni Malinenba6fbac2016-03-29 13:53:27 +030010142 if (info->attrs[NL80211_ATTR_PREV_BSSID])
10143 connect.prev_bssid =
10144 nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
10145
Samuel Ortizb23aa672009-07-01 21:26:54 +020010146 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +020010147 connect.channel = nl80211_get_valid_chan(
10148 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
10149 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +020010150 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +020010151 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +020010152 connect.channel_hint = nl80211_get_valid_chan(
10153 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
10154 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +020010155 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010156 }
10157
Alexei Avshalom Lazar2a380752019-08-18 17:35:17 +030010158 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]) {
10159 connect.edmg.channels =
10160 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_CHANNELS]);
10161
10162 if (info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG])
10163 connect.edmg.bw_config =
10164 nla_get_u8(info->attrs[NL80211_ATTR_WIPHY_EDMG_BW_CONFIG]);
10165 }
10166
Johannes Bergfffd0932009-07-08 14:22:54 +020010167 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Johannes Berg768075e2017-11-13 15:35:06 +010010168 connkeys = nl80211_parse_connkeys(rdev, info, NULL);
Johannes Berg4c476992010-10-04 21:36:35 +020010169 if (IS_ERR(connkeys))
10170 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +020010171 }
10172
Ben Greear7e7c8922011-11-18 11:31:59 -080010173 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
10174 connect.flags |= ASSOC_REQ_DISABLE_HT;
10175
10176 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
10177 memcpy(&connect.ht_capa_mask,
10178 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
10179 sizeof(connect.ht_capa_mask));
10180
10181 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +080010182 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +030010183 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -080010184 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +080010185 }
Ben Greear7e7c8922011-11-18 11:31:59 -080010186 memcpy(&connect.ht_capa,
10187 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
10188 sizeof(connect.ht_capa));
10189 }
10190
Johannes Bergee2aca32013-02-21 17:36:01 +010010191 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
10192 connect.flags |= ASSOC_REQ_DISABLE_VHT;
10193
10194 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
10195 memcpy(&connect.vht_capa_mask,
10196 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
10197 sizeof(connect.vht_capa_mask));
10198
10199 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
10200 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +030010201 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +010010202 return -EINVAL;
10203 }
10204 memcpy(&connect.vht_capa,
10205 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
10206 sizeof(connect.vht_capa));
10207 }
10208
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010209 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +020010210 if (!((rdev->wiphy.features &
10211 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
10212 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
10213 !wiphy_ext_feature_isset(&rdev->wiphy,
10214 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +010010215 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010216 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +010010217 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +030010218 connect.flags |= ASSOC_REQ_USE_RRM;
10219 }
10220
Lior David34d50512016-01-28 10:58:25 +020010221 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
Johannes Berg57fbcce2016-04-12 15:56:15 +020010222 if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) {
Lior David34d50512016-01-28 10:58:25 +020010223 kzfree(connkeys);
10224 return -EOPNOTSUPP;
10225 }
10226
Arend van Spriel38de03d2016-03-02 20:37:18 +010010227 if (info->attrs[NL80211_ATTR_BSS_SELECT]) {
10228 /* bss selection makes no sense if bssid is set */
10229 if (connect.bssid) {
10230 kzfree(connkeys);
10231 return -EINVAL;
10232 }
10233
10234 err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT],
10235 wiphy, &connect.bss_select);
10236 if (err) {
10237 kzfree(connkeys);
10238 return err;
10239 }
10240 }
10241
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010242 if (wiphy_ext_feature_isset(&rdev->wiphy,
10243 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) &&
10244 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10245 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10246 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10247 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10248 connect.fils_erp_username =
10249 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10250 connect.fils_erp_username_len =
10251 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10252 connect.fils_erp_realm =
10253 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10254 connect.fils_erp_realm_len =
10255 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10256 connect.fils_erp_next_seq_num =
10257 nla_get_u16(
10258 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10259 connect.fils_erp_rrk =
10260 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10261 connect.fils_erp_rrk_len =
10262 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10263 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10264 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10265 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10266 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10267 kzfree(connkeys);
10268 return -EINVAL;
10269 }
10270
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010271 if (nla_get_flag(info->attrs[NL80211_ATTR_EXTERNAL_AUTH_SUPPORT])) {
10272 if (!info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
Srinivas Dasari2f0605a2018-04-20 11:41:14 +053010273 kzfree(connkeys);
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020010274 GENL_SET_ERR_MSG(info,
10275 "external auth requires connection ownership");
10276 return -EINVAL;
10277 }
10278 connect.flags |= CONNECT_REQ_EXTERNAL_AUTH_SUPPORT;
10279 }
10280
Johannes Berg83739b02013-05-15 17:44:01 +020010281 wdev_lock(dev->ieee80211_ptr);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010282
Jouni Malinen4ce2bd92016-03-29 13:53:28 +030010283 err = cfg80211_connect(rdev, dev, &connect, connkeys,
10284 connect.prev_bssid);
Johannes Bergfffd0932009-07-08 14:22:54 +020010285 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +030010286 kzfree(connkeys);
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050010287
10288 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
10289 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
10290 if (connect.bssid)
10291 memcpy(dev->ieee80211_ptr->disconnect_bssid,
10292 connect.bssid, ETH_ALEN);
10293 else
10294 memset(dev->ieee80211_ptr->disconnect_bssid,
10295 0, ETH_ALEN);
10296 }
10297
10298 wdev_unlock(dev->ieee80211_ptr);
10299
Samuel Ortizb23aa672009-07-01 21:26:54 +020010300 return err;
10301}
10302
vamsi krishna088e8df2016-10-27 16:51:11 +030010303static int nl80211_update_connect_params(struct sk_buff *skb,
10304 struct genl_info *info)
10305{
10306 struct cfg80211_connect_params connect = {};
10307 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10308 struct net_device *dev = info->user_ptr[1];
10309 struct wireless_dev *wdev = dev->ieee80211_ptr;
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010310 bool fils_sk_offload;
10311 u32 auth_type;
vamsi krishna088e8df2016-10-27 16:51:11 +030010312 u32 changed = 0;
10313 int ret;
10314
10315 if (!rdev->ops->update_connect_params)
10316 return -EOPNOTSUPP;
10317
10318 if (info->attrs[NL80211_ATTR_IE]) {
vamsi krishna088e8df2016-10-27 16:51:11 +030010319 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10320 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10321 changed |= UPDATE_ASSOC_IES;
10322 }
10323
Vidyullatha Kanchanapally7f9a3e12018-05-22 10:19:08 +020010324 fils_sk_offload = wiphy_ext_feature_isset(&rdev->wiphy,
10325 NL80211_EXT_FEATURE_FILS_SK_OFFLOAD);
10326
10327 /*
10328 * when driver supports fils-sk offload all attributes must be
10329 * provided. So the else covers "fils-sk-not-all" and
10330 * "no-fils-sk-any".
10331 */
10332 if (fils_sk_offload &&
10333 info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] &&
10334 info->attrs[NL80211_ATTR_FILS_ERP_REALM] &&
10335 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] &&
10336 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10337 connect.fils_erp_username =
10338 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10339 connect.fils_erp_username_len =
10340 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]);
10341 connect.fils_erp_realm =
10342 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10343 connect.fils_erp_realm_len =
10344 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]);
10345 connect.fils_erp_next_seq_num =
10346 nla_get_u16(
10347 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]);
10348 connect.fils_erp_rrk =
10349 nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10350 connect.fils_erp_rrk_len =
10351 nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]);
10352 changed |= UPDATE_FILS_ERP_INFO;
10353 } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] ||
10354 info->attrs[NL80211_ATTR_FILS_ERP_REALM] ||
10355 info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] ||
10356 info->attrs[NL80211_ATTR_FILS_ERP_RRK]) {
10357 return -EINVAL;
10358 }
10359
10360 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
10361 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
10362 if (!nl80211_valid_auth_type(rdev, auth_type,
10363 NL80211_CMD_CONNECT))
10364 return -EINVAL;
10365
10366 if (auth_type == NL80211_AUTHTYPE_FILS_SK &&
10367 fils_sk_offload && !(changed & UPDATE_FILS_ERP_INFO))
10368 return -EINVAL;
10369
10370 connect.auth_type = auth_type;
10371 changed |= UPDATE_AUTH_TYPE;
10372 }
10373
vamsi krishna088e8df2016-10-27 16:51:11 +030010374 wdev_lock(dev->ieee80211_ptr);
10375 if (!wdev->current_bss)
10376 ret = -ENOLINK;
10377 else
10378 ret = rdev_update_connect_params(rdev, dev, &connect, changed);
10379 wdev_unlock(dev->ieee80211_ptr);
10380
10381 return ret;
10382}
10383
Samuel Ortizb23aa672009-07-01 21:26:54 +020010384static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
10385{
Johannes Berg4c476992010-10-04 21:36:35 +020010386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10387 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +020010388 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +020010389 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010390
Andrew Zaborowskibad29292018-05-22 02:46:02 +020010391 if (dev->ieee80211_ptr->conn_owner_nlportid &&
10392 dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid)
10393 return -EPERM;
10394
Samuel Ortizb23aa672009-07-01 21:26:54 +020010395 if (!info->attrs[NL80211_ATTR_REASON_CODE])
10396 reason = WLAN_REASON_DEAUTH_LEAVING;
10397 else
10398 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
10399
10400 if (reason == 0)
10401 return -EINVAL;
10402
Johannes Berg074ac8d2010-09-16 14:58:22 +020010403 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010404 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10405 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010406
Johannes Berg83739b02013-05-15 17:44:01 +020010407 wdev_lock(dev->ieee80211_ptr);
10408 ret = cfg80211_disconnect(rdev, dev, reason, true);
10409 wdev_unlock(dev->ieee80211_ptr);
10410 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +020010411}
10412
Johannes Berg463d0182009-07-14 00:33:35 +020010413static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
10414{
Johannes Berg4c476992010-10-04 21:36:35 +020010415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +020010416 struct net *net;
10417 int err;
Johannes Berg463d0182009-07-14 00:33:35 +020010418
Vadim Kochan4b681c82015-01-12 16:34:05 +020010419 if (info->attrs[NL80211_ATTR_PID]) {
10420 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
10421
10422 net = get_net_ns_by_pid(pid);
10423 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
10424 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
10425
10426 net = get_net_ns_by_fd(fd);
10427 } else {
Johannes Berg463d0182009-07-14 00:33:35 +020010428 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +020010429 }
Johannes Berg463d0182009-07-14 00:33:35 +020010430
Johannes Berg4c476992010-10-04 21:36:35 +020010431 if (IS_ERR(net))
10432 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010433
10434 err = 0;
10435
10436 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +020010437 if (!net_eq(wiphy_net(&rdev->wiphy), net))
10438 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +020010439
Johannes Berg463d0182009-07-14 00:33:35 +020010440 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +020010441 return err;
10442}
10443
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010444static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
10445{
Johannes Berg4c476992010-10-04 21:36:35 +020010446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010447 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
10448 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +020010449 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010450 struct cfg80211_pmksa pmksa;
10451
10452 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
10453
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010454 if (!info->attrs[NL80211_ATTR_PMKID])
10455 return -EINVAL;
10456
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010457 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030010458
10459 if (info->attrs[NL80211_ATTR_MAC]) {
10460 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
10461 } else if (info->attrs[NL80211_ATTR_SSID] &&
10462 info->attrs[NL80211_ATTR_FILS_CACHE_ID] &&
10463 (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA ||
10464 info->attrs[NL80211_ATTR_PMK])) {
10465 pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
10466 pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
10467 pmksa.cache_id =
10468 nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]);
10469 } else {
10470 return -EINVAL;
10471 }
10472 if (info->attrs[NL80211_ATTR_PMK]) {
10473 pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
10474 pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
10475 }
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010476
Johannes Berg074ac8d2010-09-16 14:58:22 +020010477 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Liangwei Dong6c900362019-01-18 16:54:38 +053010478 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT &&
10479 !(dev->ieee80211_ptr->iftype == NL80211_IFTYPE_AP &&
10480 wiphy_ext_feature_isset(&rdev->wiphy,
10481 NL80211_EXT_FEATURE_AP_PMKSA_CACHING)))
Johannes Berg4c476992010-10-04 21:36:35 +020010482 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010483
10484 switch (info->genlhdr->cmd) {
10485 case NL80211_CMD_SET_PMKSA:
10486 rdev_ops = rdev->ops->set_pmksa;
10487 break;
10488 case NL80211_CMD_DEL_PMKSA:
10489 rdev_ops = rdev->ops->del_pmksa;
10490 break;
10491 default:
10492 WARN_ON(1);
10493 break;
10494 }
10495
Johannes Berg4c476992010-10-04 21:36:35 +020010496 if (!rdev_ops)
10497 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010498
Johannes Berg4c476992010-10-04 21:36:35 +020010499 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010500}
10501
10502static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
10503{
Johannes Berg4c476992010-10-04 21:36:35 +020010504 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10505 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010506
Johannes Berg074ac8d2010-09-16 14:58:22 +020010507 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020010508 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
10509 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010510
Johannes Berg4c476992010-10-04 21:36:35 +020010511 if (!rdev->ops->flush_pmksa)
10512 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010513
Hila Gonene35e4d22012-06-27 17:19:42 +030010514 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010515}
10516
Arik Nemtsov109086c2011-09-28 14:12:50 +030010517static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
10518{
10519 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10520 struct net_device *dev = info->user_ptr[1];
10521 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010522 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010523 u16 status_code;
10524 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010525 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +030010526
10527 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10528 !rdev->ops->tdls_mgmt)
10529 return -EOPNOTSUPP;
10530
10531 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
10532 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
10533 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
10534 !info->attrs[NL80211_ATTR_IE] ||
10535 !info->attrs[NL80211_ATTR_MAC])
10536 return -EINVAL;
10537
10538 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10539 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
10540 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
10541 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010542 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010543 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
10544 peer_capability =
10545 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010546
Hila Gonene35e4d22012-06-27 17:19:42 +030010547 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +053010548 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +030010549 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +030010550 nla_data(info->attrs[NL80211_ATTR_IE]),
10551 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +030010552}
10553
10554static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
10555{
10556 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10557 struct net_device *dev = info->user_ptr[1];
10558 enum nl80211_tdls_operation operation;
10559 u8 *peer;
10560
10561 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
10562 !rdev->ops->tdls_oper)
10563 return -EOPNOTSUPP;
10564
10565 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
10566 !info->attrs[NL80211_ATTR_MAC])
10567 return -EINVAL;
10568
10569 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
10570 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10571
Hila Gonene35e4d22012-06-27 17:19:42 +030010572 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +030010573}
10574
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010575static int nl80211_remain_on_channel(struct sk_buff *skb,
10576 struct genl_info *info)
10577{
Johannes Berg4c476992010-10-04 21:36:35 +020010578 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010579 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010580 struct cfg80211_chan_def chandef;
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010581 const struct cfg80211_chan_def *compat_chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010582 struct sk_buff *msg;
10583 void *hdr;
10584 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +010010585 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010586 int err;
10587
10588 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
10589 !info->attrs[NL80211_ATTR_DURATION])
10590 return -EINVAL;
10591
10592 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
10593
Johannes Berg7c4ef712011-11-18 15:33:48 +010010594 if (!rdev->ops->remain_on_channel ||
10595 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +020010596 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010597
Johannes Bergebf348f2012-06-01 12:50:54 +020010598 /*
10599 * We should be on that channel for at least a minimum amount of
10600 * time (10ms) but no longer than the driver supports.
10601 */
10602 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10603 duration > rdev->wiphy.max_remain_on_channel_duration)
10604 return -EINVAL;
10605
Johannes Berg683b6d32012-11-08 21:25:48 +010010606 err = nl80211_parse_chandef(rdev, info, &chandef);
10607 if (err)
10608 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010609
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010610 wdev_lock(wdev);
10611 if (!cfg80211_off_channel_oper_allowed(wdev) &&
10612 !cfg80211_chandef_identical(&wdev->chandef, &chandef)) {
10613 compat_chandef = cfg80211_chandef_compatible(&wdev->chandef,
10614 &chandef);
10615 if (compat_chandef != &chandef) {
10616 wdev_unlock(wdev);
10617 return -EBUSY;
10618 }
10619 }
10620 wdev_unlock(wdev);
10621
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010622 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010623 if (!msg)
10624 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010625
Eric W. Biederman15e47302012-09-07 20:12:54 +000010626 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010627 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010628 if (!hdr) {
10629 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010630 goto free_msg;
10631 }
10632
Johannes Berg683b6d32012-11-08 21:25:48 +010010633 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
10634 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010635
10636 if (err)
10637 goto free_msg;
10638
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010639 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10640 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010641 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010642
10643 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010644
10645 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010646
10647 nla_put_failure:
10648 err = -ENOBUFS;
10649 free_msg:
10650 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010651 return err;
10652}
10653
10654static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
10655 struct genl_info *info)
10656{
Johannes Berg4c476992010-10-04 21:36:35 +020010657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010658 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010659 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010660
10661 if (!info->attrs[NL80211_ATTR_COOKIE])
10662 return -EINVAL;
10663
Johannes Berg4c476992010-10-04 21:36:35 +020010664 if (!rdev->ops->cancel_remain_on_channel)
10665 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010666
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010667 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10668
Hila Gonene35e4d22012-06-27 17:19:42 +030010669 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010670}
10671
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010672static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
10673 struct genl_info *info)
10674{
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010675 struct cfg80211_bitrate_mask mask;
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010676 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020010677 struct net_device *dev = info->user_ptr[1];
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010678 int err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010679
Johannes Berg4c476992010-10-04 21:36:35 +020010680 if (!rdev->ops->set_bitrate_mask)
10681 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010682
Purushottam Kushwahaa7c7fbf2016-09-14 17:38:44 +053010683 err = nl80211_parse_tx_bitrate_mask(info, &mask);
10684 if (err)
10685 return err;
Janusz Dziedzic78693032013-12-03 09:50:44 +010010686
Hila Gonene35e4d22012-06-27 17:19:42 +030010687 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010688}
10689
Johannes Berg2e161f782010-08-12 15:38:38 +020010690static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010691{
Johannes Berg4c476992010-10-04 21:36:35 +020010692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010693 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +020010694 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +020010695
10696 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
10697 return -EINVAL;
10698
Johannes Berg2e161f782010-08-12 15:38:38 +020010699 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
10700 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +020010701
Johannes Berg71bbc992012-06-15 15:30:18 +020010702 switch (wdev->iftype) {
10703 case NL80211_IFTYPE_STATION:
10704 case NL80211_IFTYPE_ADHOC:
10705 case NL80211_IFTYPE_P2P_CLIENT:
10706 case NL80211_IFTYPE_AP:
10707 case NL80211_IFTYPE_AP_VLAN:
10708 case NL80211_IFTYPE_MESH_POINT:
10709 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010710 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010711 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010712 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010713 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010714 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010715 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010716
10717 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +020010718 if (!rdev->ops->mgmt_tx)
10719 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010720
Eric W. Biederman15e47302012-09-07 20:12:54 +000010721 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Ilan Peerff74c512020-01-31 13:45:29 +020010722 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10723 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]),
10724 info->extack);
Jouni Malinen026331c2010-02-15 12:53:10 +020010725}
10726
Johannes Berg2e161f782010-08-12 15:38:38 +020010727static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +020010728{
Johannes Berg4c476992010-10-04 21:36:35 +020010729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010730 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +010010731 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +020010732 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +010010733 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010734 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +010010735 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010736 struct cfg80211_mgmt_tx_params params = {
10737 .dont_wait_for_ack =
10738 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
10739 };
Jouni Malinen026331c2010-02-15 12:53:10 +020010740
Johannes Berg683b6d32012-11-08 21:25:48 +010010741 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +020010742 return -EINVAL;
10743
Johannes Berg4c476992010-10-04 21:36:35 +020010744 if (!rdev->ops->mgmt_tx)
10745 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +020010746
Johannes Berg71bbc992012-06-15 15:30:18 +020010747 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +020010748 case NL80211_IFTYPE_P2P_DEVICE:
10749 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
10750 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +020010751 case NL80211_IFTYPE_STATION:
10752 case NL80211_IFTYPE_ADHOC:
10753 case NL80211_IFTYPE_P2P_CLIENT:
10754 case NL80211_IFTYPE_AP:
10755 case NL80211_IFTYPE_AP_VLAN:
10756 case NL80211_IFTYPE_MESH_POINT:
10757 case NL80211_IFTYPE_P2P_GO:
10758 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010759 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010760 default:
Johannes Berg4c476992010-10-04 21:36:35 +020010761 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010762 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010763
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010764 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +010010765 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010766 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010767 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +020010768
10769 /*
10770 * We should wait on the channel for at least a minimum amount
10771 * of time (10ms) but no longer than the driver supports.
10772 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010773 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
10774 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +020010775 return -EINVAL;
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010776 }
10777
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010778 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010779
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010780 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +010010781 return -EINVAL;
10782
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010783 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +053010784
Antonio Quartulliea141b752013-06-11 14:20:03 +020010785 /* get the channel if any has been specified, otherwise pass NULL to
10786 * the driver. The latter will use the current one
10787 */
10788 chandef.chan = NULL;
10789 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
10790 err = nl80211_parse_chandef(rdev, info, &chandef);
10791 if (err)
10792 return err;
10793 }
10794
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010795 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +020010796 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +020010797
Vasanthakumar Thiagarajan34373d12017-02-27 17:04:34 +053010798 wdev_lock(wdev);
10799 if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) {
10800 wdev_unlock(wdev);
10801 return -EBUSY;
10802 }
10803 wdev_unlock(wdev);
10804
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +030010805 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
10806 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
10807
10808 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
10809 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10810 int i;
10811
10812 if (len % sizeof(u16))
10813 return -EINVAL;
10814
10815 params.n_csa_offsets = len / sizeof(u16);
10816 params.csa_offsets =
10817 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
10818
10819 /* check that all the offsets fit the frame */
10820 for (i = 0; i < params.n_csa_offsets; i++) {
10821 if (params.csa_offsets[i] >= params.len)
10822 return -EINVAL;
10823 }
10824 }
10825
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010826 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +010010827 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10828 if (!msg)
10829 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +020010830
Eric W. Biederman15e47302012-09-07 20:12:54 +000010831 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +010010832 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +030010833 if (!hdr) {
10834 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +010010835 goto free_msg;
10836 }
Jouni Malinen026331c2010-02-15 12:53:10 +020010837 }
Johannes Berge247bd902011-11-04 11:18:21 +010010838
Andrei Otcheretianskib176e622013-11-18 19:06:49 +020010839 params.chan = chandef.chan;
10840 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +020010841 if (err)
10842 goto free_msg;
10843
Johannes Berge247bd902011-11-04 11:18:21 +010010844 if (msg) {
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020010845 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
10846 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040010847 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020010848
Johannes Berge247bd902011-11-04 11:18:21 +010010849 genlmsg_end(msg, hdr);
10850 return genlmsg_reply(msg, info);
10851 }
10852
10853 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +020010854
10855 nla_put_failure:
10856 err = -ENOBUFS;
10857 free_msg:
10858 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +020010859 return err;
10860}
10861
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010862static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
10863{
10864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +020010865 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010866 u64 cookie;
10867
10868 if (!info->attrs[NL80211_ATTR_COOKIE])
10869 return -EINVAL;
10870
10871 if (!rdev->ops->mgmt_tx_cancel_wait)
10872 return -EOPNOTSUPP;
10873
Johannes Berg71bbc992012-06-15 15:30:18 +020010874 switch (wdev->iftype) {
10875 case NL80211_IFTYPE_STATION:
10876 case NL80211_IFTYPE_ADHOC:
10877 case NL80211_IFTYPE_P2P_CLIENT:
10878 case NL80211_IFTYPE_AP:
10879 case NL80211_IFTYPE_AP_VLAN:
10880 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +020010881 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +020010882 break;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030010883 case NL80211_IFTYPE_NAN:
Johannes Berg71bbc992012-06-15 15:30:18 +020010884 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010885 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +020010886 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010887
10888 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
10889
Hila Gonene35e4d22012-06-27 17:19:42 +030010890 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010891}
10892
Kalle Valoffb9eb32010-02-17 17:58:10 +020010893static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
10894{
Johannes Berg4c476992010-10-04 21:36:35 +020010895 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010896 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010897 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010898 u8 ps_state;
10899 bool state;
10900 int err;
10901
Johannes Berg4c476992010-10-04 21:36:35 +020010902 if (!info->attrs[NL80211_ATTR_PS_STATE])
10903 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010904
10905 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
10906
Kalle Valoffb9eb32010-02-17 17:58:10 +020010907 wdev = dev->ieee80211_ptr;
10908
Johannes Berg4c476992010-10-04 21:36:35 +020010909 if (!rdev->ops->set_power_mgmt)
10910 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010911
10912 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
10913
10914 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +020010915 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010916
Hila Gonene35e4d22012-06-27 17:19:42 +030010917 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +020010918 if (!err)
10919 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010920 return err;
10921}
10922
10923static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
10924{
Johannes Berg4c476992010-10-04 21:36:35 +020010925 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010926 enum nl80211_ps_state ps_state;
10927 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010928 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +020010929 struct sk_buff *msg;
10930 void *hdr;
10931 int err;
10932
Kalle Valoffb9eb32010-02-17 17:58:10 +020010933 wdev = dev->ieee80211_ptr;
10934
Johannes Berg4c476992010-10-04 21:36:35 +020010935 if (!rdev->ops->set_power_mgmt)
10936 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010937
10938 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +020010939 if (!msg)
10940 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010941
Eric W. Biederman15e47302012-09-07 20:12:54 +000010942 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010943 NL80211_CMD_GET_POWER_SAVE);
10944 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +020010945 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010946 goto free_msg;
10947 }
10948
10949 if (wdev->ps)
10950 ps_state = NL80211_PS_ENABLED;
10951 else
10952 ps_state = NL80211_PS_DISABLED;
10953
David S. Miller9360ffd2012-03-29 04:41:26 -040010954 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
10955 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +020010956
10957 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +020010958 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010959
Johannes Berg4c476992010-10-04 21:36:35 +020010960 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010961 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +020010962 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +020010963 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +020010964 return err;
10965}
10966
Johannes Berg94e860f2014-01-20 23:58:15 +010010967static const struct nla_policy
10968nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010969 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010970 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
10971 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -070010972 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
10973 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
10974 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010010975 [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010976};
10977
Thomas Pedersen84f10702012-07-12 16:17:33 -070010978static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +010010979 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010980{
10981 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -070010982 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020010983 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -070010984
Johannes Bergd9d8b012012-11-26 12:51:52 +010010985 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -070010986 return -EINVAL;
10987
Thomas Pedersen84f10702012-07-12 16:17:33 -070010988 if (!rdev->ops->set_cqm_txe_config)
10989 return -EOPNOTSUPP;
10990
10991 if (wdev->iftype != NL80211_IFTYPE_STATION &&
10992 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
10993 return -EOPNOTSUPP;
10994
Hila Gonene35e4d22012-06-27 17:19:42 +030010995 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -070010996}
10997
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010010998static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev,
10999 struct net_device *dev)
11000{
11001 struct wireless_dev *wdev = dev->ieee80211_ptr;
11002 s32 last, low, high;
11003 u32 hyst;
Masashi Honma1222a162018-09-25 11:15:01 +090011004 int i, n, low_index;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011005 int err;
11006
11007 /* RSSI reporting disabled? */
11008 if (!wdev->cqm_config)
11009 return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0);
11010
11011 /*
11012 * Obtain current RSSI value if possible, if not and no RSSI threshold
11013 * event has been received yet, we should receive an event after a
11014 * connection is established and enough beacons received to calculate
11015 * the average.
11016 */
11017 if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss &&
11018 rdev->ops->get_station) {
Johannes Berg73887fd2018-05-18 09:57:55 +020011019 struct station_info sinfo = {};
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011020 u8 *mac_addr;
11021
11022 mac_addr = wdev->current_bss->pub.bssid;
11023
Johannes Berg73887fd2018-05-18 09:57:55 +020011024 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
11025 if (err)
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011026 return err;
11027
Felix Fietkaudf167372020-01-08 18:06:30 +010011028 cfg80211_sinfo_release_content(&sinfo);
Omer Efrat397c6572018-06-17 13:06:14 +030011029 if (sinfo.filled & BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG))
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011030 wdev->cqm_config->last_rssi_event_value =
Johannes Berg73887fd2018-05-18 09:57:55 +020011031 (s8) sinfo.rx_beacon_signal_avg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011032 }
11033
11034 last = wdev->cqm_config->last_rssi_event_value;
11035 hyst = wdev->cqm_config->rssi_hyst;
11036 n = wdev->cqm_config->n_rssi_thresholds;
11037
Masashi Honma4b2c5a12019-09-08 09:56:53 +090011038 for (i = 0; i < n; i++) {
11039 i = array_index_nospec(i, n);
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011040 if (last < wdev->cqm_config->rssi_thresholds[i])
11041 break;
Masashi Honma4b2c5a12019-09-08 09:56:53 +090011042 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011043
Masashi Honma1222a162018-09-25 11:15:01 +090011044 low_index = i - 1;
11045 if (low_index >= 0) {
11046 low_index = array_index_nospec(low_index, n);
11047 low = wdev->cqm_config->rssi_thresholds[low_index] - hyst;
11048 } else {
11049 low = S32_MIN;
11050 }
11051 if (i < n) {
11052 i = array_index_nospec(i, n);
11053 high = wdev->cqm_config->rssi_thresholds[i] + hyst - 1;
11054 } else {
11055 high = S32_MAX;
11056 }
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011057
11058 return rdev_set_cqm_rssi_range_config(rdev, dev, low, high);
11059}
11060
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011061static int nl80211_set_cqm_rssi(struct genl_info *info,
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011062 const s32 *thresholds, int n_thresholds,
11063 u32 hysteresis)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011064{
Johannes Berg4c476992010-10-04 21:36:35 +020011065 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +020011066 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011067 struct wireless_dev *wdev = dev->ieee80211_ptr;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011068 int i, err;
11069 s32 prev = S32_MIN;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011070
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011071 /* Check all values negative and sorted */
11072 for (i = 0; i < n_thresholds; i++) {
11073 if (thresholds[i] > 0 || thresholds[i] <= prev)
11074 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011075
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011076 prev = thresholds[i];
11077 }
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011078
Johannes Berg074ac8d2010-09-16 14:58:22 +020011079 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +020011080 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
11081 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011082
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011083 wdev_lock(wdev);
11084 cfg80211_cqm_config_free(wdev);
11085 wdev_unlock(wdev);
11086
11087 if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) {
11088 if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */
11089 return rdev_set_cqm_rssi_config(rdev, dev, 0, 0);
11090
11091 return rdev_set_cqm_rssi_config(rdev, dev,
11092 thresholds[0], hysteresis);
11093 }
11094
11095 if (!wiphy_ext_feature_isset(&rdev->wiphy,
11096 NL80211_EXT_FEATURE_CQM_RSSI_LIST))
11097 return -EOPNOTSUPP;
11098
11099 if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */
11100 n_thresholds = 0;
11101
11102 wdev_lock(wdev);
11103 if (n_thresholds) {
11104 struct cfg80211_cqm_config *cqm_config;
11105
11106 cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) +
11107 n_thresholds * sizeof(s32), GFP_KERNEL);
11108 if (!cqm_config) {
11109 err = -ENOMEM;
11110 goto unlock;
11111 }
11112
11113 cqm_config->rssi_hyst = hysteresis;
11114 cqm_config->n_rssi_thresholds = n_thresholds;
11115 memcpy(cqm_config->rssi_thresholds, thresholds,
11116 n_thresholds * sizeof(s32));
11117
11118 wdev->cqm_config = cqm_config;
11119 }
11120
11121 err = cfg80211_cqm_rssi_update(rdev, dev);
11122
11123unlock:
11124 wdev_unlock(wdev);
11125
11126 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011127}
11128
11129static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
11130{
11131 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
11132 struct nlattr *cqm;
11133 int err;
11134
11135 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011136 if (!cqm)
11137 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011138
Johannes Berg8cb08172019-04-26 14:07:28 +020011139 err = nla_parse_nested_deprecated(attrs, NL80211_ATTR_CQM_MAX, cqm,
11140 nl80211_attr_cqm_policy,
11141 info->extack);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011142 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011143 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011144
11145 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
11146 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011147 const s32 *thresholds =
11148 nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
11149 int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011150 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011151
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010011152 if (len % 4)
11153 return -EINVAL;
11154
11155 return nl80211_set_cqm_rssi(info, thresholds, len / 4,
11156 hysteresis);
Johannes Berg1da5fcc2013-08-06 14:10:48 +020011157 }
11158
11159 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
11160 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
11161 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
11162 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
11163 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
11164 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
11165
11166 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
11167 }
11168
11169 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011170}
11171
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011172static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
11173{
11174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11175 struct net_device *dev = info->user_ptr[1];
11176 struct ocb_setup setup = {};
11177 int err;
11178
11179 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11180 if (err)
11181 return err;
11182
11183 return cfg80211_join_ocb(rdev, dev, &setup);
11184}
11185
11186static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
11187{
11188 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11189 struct net_device *dev = info->user_ptr[1];
11190
11191 return cfg80211_leave_ocb(rdev, dev);
11192}
11193
Johannes Berg29cbe682010-12-03 09:20:44 +010011194static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
11195{
11196 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11197 struct net_device *dev = info->user_ptr[1];
11198 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -080011199 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +010011200 int err;
11201
11202 /* start with default */
11203 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -080011204 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +010011205
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011206 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +010011207 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -080011208 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +010011209 if (err)
11210 return err;
11211 }
11212
11213 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
11214 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
11215 return -EINVAL;
11216
Javier Cardonac80d5452010-12-16 17:37:49 -080011217 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
11218 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
11219
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -080011220 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
11221 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
11222 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
11223 return -EINVAL;
11224
Marco Porsch9bdbf042013-01-07 16:04:51 +010011225 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
11226 setup.beacon_interval =
11227 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011228
Purushottam Kushwaha0c317a02016-10-12 18:26:51 +053011229 err = cfg80211_validate_beacon_int(rdev,
11230 NL80211_IFTYPE_MESH_POINT,
11231 setup.beacon_interval);
Purushottam Kushwaha12d20fc92016-08-11 15:14:02 +053011232 if (err)
11233 return err;
Marco Porsch9bdbf042013-01-07 16:04:51 +010011234 }
11235
11236 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
11237 setup.dtim_period =
11238 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
11239 if (setup.dtim_period < 1 || setup.dtim_period > 100)
11240 return -EINVAL;
11241 }
11242
Javier Cardonac80d5452010-12-16 17:37:49 -080011243 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
11244 /* parse additional setup parameters if given */
11245 err = nl80211_parse_mesh_setup(info, &setup);
11246 if (err)
11247 return err;
11248 }
11249
Thomas Pedersend37bb182013-03-04 13:06:13 -080011250 if (setup.user_mpm)
11251 cfg.auto_open_plinks = false;
11252
Johannes Bergcc1d2802012-05-16 23:50:20 +020011253 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +010011254 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
11255 if (err)
11256 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011257 } else {
Denis Kenzior188c1b32018-03-26 12:52:46 -050011258 /* __cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +010011259 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +020011260 }
11261
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -070011262 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
11263 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11264 int n_rates =
11265 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
11266 struct ieee80211_supported_band *sband;
11267
11268 if (!setup.chandef.chan)
11269 return -EINVAL;
11270
11271 sband = rdev->wiphy.bands[setup.chandef.chan->band];
11272
11273 err = ieee80211_get_ratemask(sband, rates, n_rates,
11274 &setup.basic_rates);
11275 if (err)
11276 return err;
11277 }
11278
Johannes Berg8564e382016-09-19 09:44:44 +020011279 if (info->attrs[NL80211_ATTR_TX_RATES]) {
11280 err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate);
11281 if (err)
11282 return err;
11283
Johannes Berg265698d2017-09-18 22:46:36 +020011284 if (!setup.chandef.chan)
11285 return -EINVAL;
11286
Johannes Berg8564e382016-09-19 09:44:44 +020011287 err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band,
11288 &setup.beacon_rate);
11289 if (err)
11290 return err;
11291 }
11292
Benjamin Bergd37d49c2017-05-16 11:23:11 +020011293 setup.userspace_handles_dfs =
11294 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
11295
Denis Kenzior1224f582018-03-26 12:52:49 -050011296 if (info->attrs[NL80211_ATTR_CONTROL_PORT_OVER_NL80211]) {
11297 int r = validate_pae_over_nl80211(rdev, info);
11298
11299 if (r < 0)
11300 return r;
11301
11302 setup.control_port_over_nl80211 = true;
11303 }
11304
Denis Kenzior188c1b32018-03-26 12:52:46 -050011305 wdev_lock(dev->ieee80211_ptr);
11306 err = __cfg80211_join_mesh(rdev, dev, &setup, &cfg);
11307 if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER])
11308 dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid;
11309 wdev_unlock(dev->ieee80211_ptr);
11310
11311 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +010011312}
11313
11314static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
11315{
11316 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11317 struct net_device *dev = info->user_ptr[1];
11318
11319 return cfg80211_leave_mesh(rdev, dev);
11320}
11321
Johannes Bergdfb89c52012-06-27 09:23:48 +020011322#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011323static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
11324 struct cfg80211_registered_device *rdev)
11325{
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011326 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011327 struct nlattr *nl_pats, *nl_pat;
11328 int i, pat_len;
11329
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011330 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011331 return 0;
11332
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011333 nl_pats = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011334 if (!nl_pats)
11335 return -ENOBUFS;
11336
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011337 for (i = 0; i < wowlan->n_patterns; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011338 nl_pat = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011339 if (!nl_pat)
11340 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011341 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011342 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011343 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011344 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11345 wowlan->patterns[i].pattern) ||
11346 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011347 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011348 return -ENOBUFS;
11349 nla_nest_end(msg, nl_pat);
11350 }
11351 nla_nest_end(msg, nl_pats);
11352
11353 return 0;
11354}
11355
Johannes Berg2a0e0472013-01-23 22:57:40 +010011356static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
11357 struct cfg80211_wowlan_tcp *tcp)
11358{
11359 struct nlattr *nl_tcp;
11360
11361 if (!tcp)
11362 return 0;
11363
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011364 nl_tcp = nla_nest_start_noflag(msg,
11365 NL80211_WOWLAN_TRIG_TCP_CONNECTION);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011366 if (!nl_tcp)
11367 return -ENOBUFS;
11368
Jiri Benc930345e2015-03-29 16:59:25 +020011369 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
11370 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +010011371 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
11372 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
11373 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
11374 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
11375 tcp->payload_len, tcp->payload) ||
11376 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
11377 tcp->data_interval) ||
11378 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
11379 tcp->wake_len, tcp->wake_data) ||
11380 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
11381 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
11382 return -ENOBUFS;
11383
11384 if (tcp->payload_seq.len &&
11385 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
11386 sizeof(tcp->payload_seq), &tcp->payload_seq))
11387 return -ENOBUFS;
11388
11389 if (tcp->payload_tok.len &&
11390 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
11391 sizeof(tcp->payload_tok) + tcp->tokens_size,
11392 &tcp->payload_tok))
11393 return -ENOBUFS;
11394
Johannes Berge248ad32013-05-16 10:24:28 +020011395 nla_nest_end(msg, nl_tcp);
11396
Johannes Berg2a0e0472013-01-23 22:57:40 +010011397 return 0;
11398}
11399
Luciano Coelho75453cc2015-01-09 14:06:37 +020011400static int nl80211_send_wowlan_nd(struct sk_buff *msg,
11401 struct cfg80211_sched_scan_request *req)
11402{
Avraham Stern3b06d272015-10-12 09:51:34 +030011403 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011404 int i;
11405
11406 if (!req)
11407 return 0;
11408
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011409 nd = nla_nest_start_noflag(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011410 if (!nd)
11411 return -ENOBUFS;
11412
Avraham Stern3b06d272015-10-12 09:51:34 +030011413 if (req->n_scan_plans == 1 &&
11414 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
11415 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +020011416 return -ENOBUFS;
11417
Luciano Coelho21fea562015-03-17 16:36:01 +020011418 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
11419 return -ENOBUFS;
11420
vamsi krishnabf95ecd2017-01-13 01:12:20 +020011421 if (req->relative_rssi_set) {
11422 struct nl80211_bss_select_rssi_adjust rssi_adjust;
11423
11424 if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI,
11425 req->relative_rssi))
11426 return -ENOBUFS;
11427
11428 rssi_adjust.band = req->rssi_adjust.band;
11429 rssi_adjust.delta = req->rssi_adjust.delta;
11430 if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST,
11431 sizeof(rssi_adjust), &rssi_adjust))
11432 return -ENOBUFS;
11433 }
11434
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011435 freqs = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho75453cc2015-01-09 14:06:37 +020011436 if (!freqs)
11437 return -ENOBUFS;
11438
Johannes Berg53b18982016-09-14 09:59:21 +020011439 for (i = 0; i < req->n_channels; i++) {
11440 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11441 return -ENOBUFS;
11442 }
Luciano Coelho75453cc2015-01-09 14:06:37 +020011443
11444 nla_nest_end(msg, freqs);
11445
11446 if (req->n_match_sets) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011447 matches = nla_nest_start_noflag(msg,
11448 NL80211_ATTR_SCHED_SCAN_MATCH);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011449 if (!matches)
11450 return -ENOBUFS;
11451
Luciano Coelho75453cc2015-01-09 14:06:37 +020011452 for (i = 0; i < req->n_match_sets; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011453 match = nla_nest_start_noflag(msg, i);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011454 if (!match)
11455 return -ENOBUFS;
11456
Johannes Berg53b18982016-09-14 09:59:21 +020011457 if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
11458 req->match_sets[i].ssid.ssid_len,
11459 req->match_sets[i].ssid.ssid))
11460 return -ENOBUFS;
Luciano Coelho75453cc2015-01-09 14:06:37 +020011461 nla_nest_end(msg, match);
11462 }
11463 nla_nest_end(msg, matches);
11464 }
11465
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011466 scan_plans = nla_nest_start_noflag(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
Avraham Stern3b06d272015-10-12 09:51:34 +030011467 if (!scan_plans)
11468 return -ENOBUFS;
11469
11470 for (i = 0; i < req->n_scan_plans; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011471 scan_plan = nla_nest_start_noflag(msg, i + 1);
Johannes Berg76e1fb42016-09-14 09:55:57 +020011472 if (!scan_plan)
11473 return -ENOBUFS;
11474
Colin Ian King67626962018-09-06 10:58:44 +010011475 if (nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
Avraham Stern3b06d272015-10-12 09:51:34 +030011476 req->scan_plans[i].interval) ||
11477 (req->scan_plans[i].iterations &&
11478 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
11479 req->scan_plans[i].iterations)))
11480 return -ENOBUFS;
11481 nla_nest_end(msg, scan_plan);
11482 }
11483 nla_nest_end(msg, scan_plans);
11484
Luciano Coelho75453cc2015-01-09 14:06:37 +020011485 nla_nest_end(msg, nd);
11486
11487 return 0;
11488}
11489
Johannes Bergff1b6e62011-05-04 15:37:28 +020011490static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
11491{
11492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11493 struct sk_buff *msg;
11494 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011495 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011496
Johannes Berg964dc9e2013-06-03 17:25:34 +020011497 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011498 return -EOPNOTSUPP;
11499
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011500 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +010011501 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011502 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
11503 rdev->wiphy.wowlan_config->tcp->payload_len +
11504 rdev->wiphy.wowlan_config->tcp->wake_len +
11505 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011506 }
11507
11508 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011509 if (!msg)
11510 return -ENOMEM;
11511
Eric W. Biederman15e47302012-09-07 20:12:54 +000011512 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +020011513 NL80211_CMD_GET_WOWLAN);
11514 if (!hdr)
11515 goto nla_put_failure;
11516
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011517 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011518 struct nlattr *nl_wowlan;
11519
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011520 nl_wowlan = nla_nest_start_noflag(msg,
11521 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011522 if (!nl_wowlan)
11523 goto nla_put_failure;
11524
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011525 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011526 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011527 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011528 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011529 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011530 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011531 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011532 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011533 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011534 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011535 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011536 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011537 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -040011538 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
11539 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011540
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011541 if (nl80211_send_wowlan_patterns(msg, rdev))
11542 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011543
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011544 if (nl80211_send_wowlan_tcp(msg,
11545 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +010011546 goto nla_put_failure;
11547
Luciano Coelho75453cc2015-01-09 14:06:37 +020011548 if (nl80211_send_wowlan_nd(
11549 msg,
11550 rdev->wiphy.wowlan_config->nd_config))
11551 goto nla_put_failure;
11552
Johannes Bergff1b6e62011-05-04 15:37:28 +020011553 nla_nest_end(msg, nl_wowlan);
11554 }
11555
11556 genlmsg_end(msg, hdr);
11557 return genlmsg_reply(msg, info);
11558
11559nla_put_failure:
11560 nlmsg_free(msg);
11561 return -ENOBUFS;
11562}
11563
Johannes Berg2a0e0472013-01-23 22:57:40 +010011564static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
11565 struct nlattr *attr,
11566 struct cfg80211_wowlan *trig)
11567{
11568 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
11569 struct cfg80211_wowlan_tcp *cfg;
11570 struct nl80211_wowlan_tcp_data_token *tok = NULL;
11571 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
11572 u32 size;
11573 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
11574 int err, port;
11575
Johannes Berg964dc9e2013-06-03 17:25:34 +020011576 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011577 return -EINVAL;
11578
Johannes Berg8cb08172019-04-26 14:07:28 +020011579 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TCP, attr,
11580 nl80211_wowlan_tcp_policy, NULL);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011581 if (err)
11582 return err;
11583
11584 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
11585 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
11586 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
11587 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
11588 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
11589 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
11590 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
11591 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
11592 return -EINVAL;
11593
11594 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011595 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011596 return -EINVAL;
11597
11598 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +020011599 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +010011600 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011601 return -EINVAL;
11602
11603 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011604 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011605 return -EINVAL;
11606
11607 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
11608 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
11609 return -EINVAL;
11610
11611 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
11612 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11613
11614 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
11615 tokens_size = tokln - sizeof(*tok);
11616
11617 if (!tok->len || tokens_size % tok->len)
11618 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011619 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011620 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011621 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011622 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011623 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011624 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011625 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011626 return -EINVAL;
11627 if (tok->offset + tok->len > data_size)
11628 return -EINVAL;
11629 }
11630
11631 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
11632 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +020011633 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +010011634 return -EINVAL;
11635 if (seq->len == 0 || seq->len > 4)
11636 return -EINVAL;
11637 if (seq->len + seq->offset > data_size)
11638 return -EINVAL;
11639 }
11640
11641 size = sizeof(*cfg);
11642 size += data_size;
11643 size += wake_size + wake_mask_size;
11644 size += tokens_size;
11645
11646 cfg = kzalloc(size, GFP_KERNEL);
11647 if (!cfg)
11648 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +020011649 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
11650 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011651 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
11652 ETH_ALEN);
11653 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
11654 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
11655 else
11656 port = 0;
11657#ifdef CONFIG_INET
11658 /* allocate a socket and port for it and use it */
11659 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
11660 IPPROTO_TCP, &cfg->sock, 1);
11661 if (err) {
11662 kfree(cfg);
11663 return err;
11664 }
11665 if (inet_csk_get_port(cfg->sock->sk, port)) {
11666 sock_release(cfg->sock);
11667 kfree(cfg);
11668 return -EADDRINUSE;
11669 }
11670 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
11671#else
11672 if (!port) {
11673 kfree(cfg);
11674 return -EINVAL;
11675 }
11676 cfg->src_port = port;
11677#endif
11678
11679 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
11680 cfg->payload_len = data_size;
11681 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
11682 memcpy((void *)cfg->payload,
11683 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
11684 data_size);
11685 if (seq)
11686 cfg->payload_seq = *seq;
11687 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
11688 cfg->wake_len = wake_size;
11689 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
11690 memcpy((void *)cfg->wake_data,
11691 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
11692 wake_size);
11693 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
11694 data_size + wake_size;
11695 memcpy((void *)cfg->wake_mask,
11696 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
11697 wake_mask_size);
11698 if (tok) {
11699 cfg->tokens_size = tokens_size;
11700 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
11701 }
11702
11703 trig->tcp = cfg;
11704
11705 return 0;
11706}
11707
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011708static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
11709 const struct wiphy_wowlan_support *wowlan,
11710 struct nlattr *attr,
11711 struct cfg80211_wowlan *trig)
11712{
11713 struct nlattr **tb;
11714 int err;
11715
Kees Cook6396bb22018-06-12 14:03:40 -070011716 tb = kcalloc(NUM_NL80211_ATTR, sizeof(*tb), GFP_KERNEL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011717 if (!tb)
11718 return -ENOMEM;
11719
11720 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
11721 err = -EOPNOTSUPP;
11722 goto out;
11723 }
11724
Johannes Berg8cb08172019-04-26 14:07:28 +020011725 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_MAX, attr,
11726 nl80211_policy, NULL);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011727 if (err)
11728 goto out;
11729
Arend Van Sprielaad1e812017-01-27 12:27:44 +000011730 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb,
11731 wowlan->max_nd_match_sets);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011732 err = PTR_ERR_OR_ZERO(trig->nd_config);
11733 if (err)
11734 trig->nd_config = NULL;
11735
11736out:
11737 kfree(tb);
11738 return err;
11739}
11740
Johannes Bergff1b6e62011-05-04 15:37:28 +020011741static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
11742{
11743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
11744 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011745 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +020011746 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +020011747 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011748 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011749 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +020011750 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011751
Johannes Berg964dc9e2013-06-03 17:25:34 +020011752 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011753 return -EOPNOTSUPP;
11754
Johannes Bergae33bd82012-07-12 16:25:02 +020011755 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
11756 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011757 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +020011758 goto set_wakeup;
11759 }
Johannes Bergff1b6e62011-05-04 15:37:28 +020011760
Johannes Berg8cb08172019-04-26 14:07:28 +020011761 err = nla_parse_nested_deprecated(tb, MAX_NL80211_WOWLAN_TRIG,
11762 info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS],
11763 nl80211_wowlan_policy, info->extack);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011764 if (err)
11765 return err;
11766
11767 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
11768 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
11769 return -EINVAL;
11770 new_triggers.any = true;
11771 }
11772
11773 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
11774 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
11775 return -EINVAL;
11776 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011777 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011778 }
11779
11780 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
11781 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
11782 return -EINVAL;
11783 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011784 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011785 }
11786
Johannes Berg77dbbb12011-07-13 10:48:55 +020011787 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
11788 return -EINVAL;
11789
11790 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
11791 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
11792 return -EINVAL;
11793 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011794 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011795 }
11796
11797 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
11798 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
11799 return -EINVAL;
11800 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011801 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011802 }
11803
11804 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
11805 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
11806 return -EINVAL;
11807 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011808 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011809 }
11810
11811 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
11812 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
11813 return -EINVAL;
11814 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +020011815 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +020011816 }
11817
Johannes Bergff1b6e62011-05-04 15:37:28 +020011818 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
11819 struct nlattr *pat;
11820 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011821 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011822 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +020011823
Johannes Berg98fc4382015-03-01 09:10:13 +020011824 regular = true;
11825
Johannes Bergff1b6e62011-05-04 15:37:28 +020011826 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11827 rem)
11828 n_patterns++;
11829 if (n_patterns > wowlan->n_patterns)
11830 return -EINVAL;
11831
11832 new_triggers.patterns = kcalloc(n_patterns,
11833 sizeof(new_triggers.patterns[0]),
11834 GFP_KERNEL);
11835 if (!new_triggers.patterns)
11836 return -ENOMEM;
11837
11838 new_triggers.n_patterns = n_patterns;
11839 i = 0;
11840
11841 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
11842 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020011843 u8 *mask_pat;
11844
Johannes Berg8cb08172019-04-26 14:07:28 +020011845 err = nla_parse_nested_deprecated(pat_tb,
11846 MAX_NL80211_PKTPAT,
11847 pat,
11848 nl80211_packet_pattern_policy,
11849 info->extack);
Johannes Berg95bca622018-06-29 09:33:39 +020011850 if (err)
11851 goto error;
11852
Johannes Bergff1b6e62011-05-04 15:37:28 +020011853 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011854 if (!pat_tb[NL80211_PKTPAT_MASK] ||
11855 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +020011856 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011857 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011858 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011859 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +020011860 goto error;
11861 if (pat_len > wowlan->pattern_max_len ||
11862 pat_len < wowlan->pattern_min_len)
11863 goto error;
11864
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011865 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011866 pkt_offset = 0;
11867 else
11868 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011869 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -080011870 if (pkt_offset > wowlan->max_pkt_offset)
11871 goto error;
11872 new_triggers.patterns[i].pkt_offset = pkt_offset;
11873
Johannes Berg922bd802014-05-19 17:59:50 +020011874 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
11875 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +020011876 err = -ENOMEM;
11877 goto error;
11878 }
Johannes Berg922bd802014-05-19 17:59:50 +020011879 new_triggers.patterns[i].mask = mask_pat;
11880 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011881 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +020011882 mask_pat += mask_len;
11883 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011884 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020011885 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -070011886 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +020011887 pat_len);
11888 i++;
11889 }
11890 }
11891
Johannes Berg2a0e0472013-01-23 22:57:40 +010011892 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011893 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +010011894 err = nl80211_parse_wowlan_tcp(
11895 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
11896 &new_triggers);
11897 if (err)
11898 goto error;
11899 }
11900
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011901 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +020011902 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +030011903 err = nl80211_parse_wowlan_nd(
11904 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
11905 &new_triggers);
11906 if (err)
11907 goto error;
11908 }
11909
Johannes Berg98fc4382015-03-01 09:10:13 +020011910 /* The 'any' trigger means the device continues operating more or less
11911 * as in its normal operation mode and wakes up the host on most of the
11912 * normal interrupts (like packet RX, ...)
11913 * It therefore makes little sense to combine with the more constrained
11914 * wakeup trigger modes.
11915 */
11916 if (new_triggers.any && regular) {
11917 err = -EINVAL;
11918 goto error;
11919 }
11920
Johannes Bergae33bd82012-07-12 16:25:02 +020011921 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
11922 if (!ntrig) {
11923 err = -ENOMEM;
11924 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011925 }
Johannes Bergae33bd82012-07-12 16:25:02 +020011926 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011927 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +020011928
Johannes Bergae33bd82012-07-12 16:25:02 +020011929 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +020011930 if (rdev->ops->set_wakeup &&
11931 prev_enabled != !!rdev->wiphy.wowlan_config)
11932 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +020011933
Johannes Bergff1b6e62011-05-04 15:37:28 +020011934 return 0;
11935 error:
11936 for (i = 0; i < new_triggers.n_patterns; i++)
11937 kfree(new_triggers.patterns[i].mask);
11938 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +010011939 if (new_triggers.tcp && new_triggers.tcp->sock)
11940 sock_release(new_triggers.tcp->sock);
11941 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +010011942 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +020011943 return err;
11944}
Johannes Bergdfb89c52012-06-27 09:23:48 +020011945#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +020011946
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011947static int nl80211_send_coalesce_rules(struct sk_buff *msg,
11948 struct cfg80211_registered_device *rdev)
11949{
11950 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
11951 int i, j, pat_len;
11952 struct cfg80211_coalesce_rules *rule;
11953
11954 if (!rdev->coalesce->n_rules)
11955 return 0;
11956
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011957 nl_rules = nla_nest_start_noflag(msg, NL80211_ATTR_COALESCE_RULE);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011958 if (!nl_rules)
11959 return -ENOBUFS;
11960
11961 for (i = 0; i < rdev->coalesce->n_rules; i++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011962 nl_rule = nla_nest_start_noflag(msg, i + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011963 if (!nl_rule)
11964 return -ENOBUFS;
11965
11966 rule = &rdev->coalesce->rules[i];
11967 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
11968 rule->delay))
11969 return -ENOBUFS;
11970
11971 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
11972 rule->condition))
11973 return -ENOBUFS;
11974
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011975 nl_pats = nla_nest_start_noflag(msg,
11976 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011977 if (!nl_pats)
11978 return -ENOBUFS;
11979
11980 for (j = 0; j < rule->n_patterns; j++) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020011981 nl_pat = nla_nest_start_noflag(msg, j + 1);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070011982 if (!nl_pat)
11983 return -ENOBUFS;
11984 pat_len = rule->patterns[j].pattern_len;
11985 if (nla_put(msg, NL80211_PKTPAT_MASK,
11986 DIV_ROUND_UP(pat_len, 8),
11987 rule->patterns[j].mask) ||
11988 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
11989 rule->patterns[j].pattern) ||
11990 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
11991 rule->patterns[j].pkt_offset))
11992 return -ENOBUFS;
11993 nla_nest_end(msg, nl_pat);
11994 }
11995 nla_nest_end(msg, nl_pats);
11996 nla_nest_end(msg, nl_rule);
11997 }
11998 nla_nest_end(msg, nl_rules);
11999
12000 return 0;
12001}
12002
12003static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
12004{
12005 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12006 struct sk_buff *msg;
12007 void *hdr;
12008
12009 if (!rdev->wiphy.coalesce)
12010 return -EOPNOTSUPP;
12011
12012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12013 if (!msg)
12014 return -ENOMEM;
12015
12016 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12017 NL80211_CMD_GET_COALESCE);
12018 if (!hdr)
12019 goto nla_put_failure;
12020
12021 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
12022 goto nla_put_failure;
12023
12024 genlmsg_end(msg, hdr);
12025 return genlmsg_reply(msg, info);
12026
12027nla_put_failure:
12028 nlmsg_free(msg);
12029 return -ENOBUFS;
12030}
12031
12032void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
12033{
12034 struct cfg80211_coalesce *coalesce = rdev->coalesce;
12035 int i, j;
12036 struct cfg80211_coalesce_rules *rule;
12037
12038 if (!coalesce)
12039 return;
12040
12041 for (i = 0; i < coalesce->n_rules; i++) {
12042 rule = &coalesce->rules[i];
12043 for (j = 0; j < rule->n_patterns; j++)
12044 kfree(rule->patterns[j].mask);
12045 kfree(rule->patterns);
12046 }
12047 kfree(coalesce->rules);
12048 kfree(coalesce);
12049 rdev->coalesce = NULL;
12050}
12051
12052static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
12053 struct nlattr *rule,
12054 struct cfg80211_coalesce_rules *new_rule)
12055{
12056 int err, i;
12057 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12058 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
12059 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
12060 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
12061
Johannes Berg8cb08172019-04-26 14:07:28 +020012062 err = nla_parse_nested_deprecated(tb, NL80211_ATTR_COALESCE_RULE_MAX,
12063 rule, nl80211_coalesce_policy, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012064 if (err)
12065 return err;
12066
12067 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
12068 new_rule->delay =
12069 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
12070 if (new_rule->delay > coalesce->max_delay)
12071 return -EINVAL;
12072
12073 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
12074 new_rule->condition =
12075 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012076
12077 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
12078 return -EINVAL;
12079
12080 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12081 rem)
12082 n_patterns++;
12083 if (n_patterns > coalesce->n_patterns)
12084 return -EINVAL;
12085
12086 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
12087 GFP_KERNEL);
12088 if (!new_rule->patterns)
12089 return -ENOMEM;
12090
12091 new_rule->n_patterns = n_patterns;
12092 i = 0;
12093
12094 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
12095 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +020012096 u8 *mask_pat;
12097
Johannes Berg8cb08172019-04-26 14:07:28 +020012098 err = nla_parse_nested_deprecated(pat_tb, MAX_NL80211_PKTPAT,
12099 pat,
12100 nl80211_packet_pattern_policy,
12101 NULL);
Johannes Berg95bca622018-06-29 09:33:39 +020012102 if (err)
12103 return err;
12104
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012105 if (!pat_tb[NL80211_PKTPAT_MASK] ||
12106 !pat_tb[NL80211_PKTPAT_PATTERN])
12107 return -EINVAL;
12108 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
12109 mask_len = DIV_ROUND_UP(pat_len, 8);
12110 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
12111 return -EINVAL;
12112 if (pat_len > coalesce->pattern_max_len ||
12113 pat_len < coalesce->pattern_min_len)
12114 return -EINVAL;
12115
12116 if (!pat_tb[NL80211_PKTPAT_OFFSET])
12117 pkt_offset = 0;
12118 else
12119 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
12120 if (pkt_offset > coalesce->max_pkt_offset)
12121 return -EINVAL;
12122 new_rule->patterns[i].pkt_offset = pkt_offset;
12123
Johannes Berg922bd802014-05-19 17:59:50 +020012124 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
12125 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012126 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +020012127
12128 new_rule->patterns[i].mask = mask_pat;
12129 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
12130 mask_len);
12131
12132 mask_pat += mask_len;
12133 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012134 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +020012135 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
12136 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012137 i++;
12138 }
12139
12140 return 0;
12141}
12142
12143static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
12144{
12145 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12146 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
12147 struct cfg80211_coalesce new_coalesce = {};
12148 struct cfg80211_coalesce *n_coalesce;
12149 int err, rem_rule, n_rules = 0, i, j;
12150 struct nlattr *rule;
12151 struct cfg80211_coalesce_rules *tmp_rule;
12152
12153 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
12154 return -EOPNOTSUPP;
12155
12156 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
12157 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b1b2015-10-22 22:27:46 +030012158 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012159 return 0;
12160 }
12161
12162 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12163 rem_rule)
12164 n_rules++;
12165 if (n_rules > coalesce->n_rules)
12166 return -EINVAL;
12167
12168 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
12169 GFP_KERNEL);
12170 if (!new_coalesce.rules)
12171 return -ENOMEM;
12172
12173 new_coalesce.n_rules = n_rules;
12174 i = 0;
12175
12176 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
12177 rem_rule) {
12178 err = nl80211_parse_coalesce_rule(rdev, rule,
12179 &new_coalesce.rules[i]);
12180 if (err)
12181 goto error;
12182
12183 i++;
12184 }
12185
Ilan Peera1056b1b2015-10-22 22:27:46 +030012186 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070012187 if (err)
12188 goto error;
12189
12190 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
12191 if (!n_coalesce) {
12192 err = -ENOMEM;
12193 goto error;
12194 }
12195 cfg80211_rdev_free_coalesce(rdev);
12196 rdev->coalesce = n_coalesce;
12197
12198 return 0;
12199error:
12200 for (i = 0; i < new_coalesce.n_rules; i++) {
12201 tmp_rule = &new_coalesce.rules[i];
12202 for (j = 0; j < tmp_rule->n_patterns; j++)
12203 kfree(tmp_rule->patterns[j].mask);
12204 kfree(tmp_rule->patterns);
12205 }
12206 kfree(new_coalesce.rules);
12207
12208 return err;
12209}
12210
Johannes Berge5497d72011-07-05 16:35:40 +020012211static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
12212{
12213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12214 struct net_device *dev = info->user_ptr[1];
12215 struct wireless_dev *wdev = dev->ieee80211_ptr;
12216 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
12217 struct cfg80211_gtk_rekey_data rekey_data;
12218 int err;
12219
12220 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
12221 return -EINVAL;
12222
Johannes Berg8cb08172019-04-26 14:07:28 +020012223 err = nla_parse_nested_deprecated(tb, MAX_NL80211_REKEY_DATA,
12224 info->attrs[NL80211_ATTR_REKEY_DATA],
12225 nl80211_rekey_policy, info->extack);
Johannes Berge5497d72011-07-05 16:35:40 +020012226 if (err)
12227 return err;
12228
Vladis Dronove785fa02017-09-13 00:21:21 +020012229 if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] ||
12230 !tb[NL80211_REKEY_DATA_KCK])
12231 return -EINVAL;
Johannes Berge5497d72011-07-05 16:35:40 +020012232 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
12233 return -ERANGE;
12234 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
12235 return -ERANGE;
12236 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
12237 return -ERANGE;
12238
Johannes Berg78f686c2014-09-10 22:28:06 +030012239 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
12240 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
12241 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +020012242
12243 wdev_lock(wdev);
12244 if (!wdev->current_bss) {
12245 err = -ENOTCONN;
12246 goto out;
12247 }
12248
12249 if (!rdev->ops->set_rekey_data) {
12250 err = -EOPNOTSUPP;
12251 goto out;
12252 }
12253
Hila Gonene35e4d22012-06-27 17:19:42 +030012254 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +020012255 out:
12256 wdev_unlock(wdev);
12257 return err;
12258}
12259
Johannes Berg28946da2011-11-04 11:18:12 +010012260static int nl80211_register_unexpected_frame(struct sk_buff *skb,
12261 struct genl_info *info)
12262{
12263 struct net_device *dev = info->user_ptr[1];
12264 struct wireless_dev *wdev = dev->ieee80211_ptr;
12265
12266 if (wdev->iftype != NL80211_IFTYPE_AP &&
12267 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12268 return -EINVAL;
12269
Eric W. Biederman15e47302012-09-07 20:12:54 +000012270 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012271 return -EBUSY;
12272
Eric W. Biederman15e47302012-09-07 20:12:54 +000012273 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +010012274 return 0;
12275}
12276
Johannes Berg7f6cf312011-11-04 11:18:15 +010012277static int nl80211_probe_client(struct sk_buff *skb,
12278 struct genl_info *info)
12279{
12280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12281 struct net_device *dev = info->user_ptr[1];
12282 struct wireless_dev *wdev = dev->ieee80211_ptr;
12283 struct sk_buff *msg;
12284 void *hdr;
12285 const u8 *addr;
12286 u64 cookie;
12287 int err;
12288
12289 if (wdev->iftype != NL80211_IFTYPE_AP &&
12290 wdev->iftype != NL80211_IFTYPE_P2P_GO)
12291 return -EOPNOTSUPP;
12292
12293 if (!info->attrs[NL80211_ATTR_MAC])
12294 return -EINVAL;
12295
12296 if (!rdev->ops->probe_client)
12297 return -EOPNOTSUPP;
12298
12299 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12300 if (!msg)
12301 return -ENOMEM;
12302
Eric W. Biederman15e47302012-09-07 20:12:54 +000012303 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +010012304 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +030012305 if (!hdr) {
12306 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012307 goto free_msg;
12308 }
12309
12310 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
12311
Hila Gonene35e4d22012-06-27 17:19:42 +030012312 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012313 if (err)
12314 goto free_msg;
12315
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020012316 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12317 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040012318 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012319
12320 genlmsg_end(msg, hdr);
12321
12322 return genlmsg_reply(msg, info);
12323
12324 nla_put_failure:
12325 err = -ENOBUFS;
12326 free_msg:
12327 nlmsg_free(msg);
12328 return err;
12329}
12330
Johannes Berg5e760232011-11-04 11:18:17 +010012331static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
12332{
12333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -070012334 struct cfg80211_beacon_registration *reg, *nreg;
12335 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012336
12337 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
12338 return -EOPNOTSUPP;
12339
Ben Greear37c73b52012-10-26 14:49:25 -070012340 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
12341 if (!nreg)
12342 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +010012343
Ben Greear37c73b52012-10-26 14:49:25 -070012344 /* First, check if already registered. */
12345 spin_lock_bh(&rdev->beacon_registrations_lock);
12346 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12347 if (reg->nlportid == info->snd_portid) {
12348 rv = -EALREADY;
12349 goto out_err;
12350 }
12351 }
12352 /* Add it to the list */
12353 nreg->nlportid = info->snd_portid;
12354 list_add(&nreg->list, &rdev->beacon_registrations);
12355
12356 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012357
12358 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -070012359out_err:
12360 spin_unlock_bh(&rdev->beacon_registrations_lock);
12361 kfree(nreg);
12362 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +010012363}
12364
Johannes Berg98104fde2012-06-16 00:19:54 +020012365static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
12366{
12367 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12368 struct wireless_dev *wdev = info->user_ptr[1];
12369 int err;
12370
12371 if (!rdev->ops->start_p2p_device)
12372 return -EOPNOTSUPP;
12373
12374 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12375 return -EOPNOTSUPP;
12376
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012377 if (wdev_running(wdev))
Johannes Berg98104fde2012-06-16 00:19:54 +020012378 return 0;
12379
Luciano Coelhob6a55012014-02-27 11:07:21 +020012380 if (rfkill_blocked(rdev->rfkill))
12381 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +020012382
Johannes Bergeeb126e2012-10-23 15:16:50 +020012383 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012384 if (err)
12385 return err;
12386
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012387 wdev->is_running = true;
Johannes Berg98104fde2012-06-16 00:19:54 +020012388 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +020012389
12390 return 0;
12391}
12392
12393static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
12394{
12395 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12396 struct wireless_dev *wdev = info->user_ptr[1];
12397
12398 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
12399 return -EOPNOTSUPP;
12400
12401 if (!rdev->ops->stop_p2p_device)
12402 return -EOPNOTSUPP;
12403
Johannes Bergf9f47522013-03-19 15:04:07 +010012404 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020012405
12406 return 0;
12407}
12408
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012409static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info)
12410{
12411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12412 struct wireless_dev *wdev = info->user_ptr[1];
12413 struct cfg80211_nan_conf conf = {};
12414 int err;
12415
12416 if (wdev->iftype != NL80211_IFTYPE_NAN)
12417 return -EOPNOTSUPP;
12418
Johannes Bergeeb04a92016-11-21 13:55:48 +010012419 if (wdev_running(wdev))
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012420 return -EEXIST;
12421
12422 if (rfkill_blocked(rdev->rfkill))
12423 return -ERFKILL;
12424
12425 if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF])
12426 return -EINVAL;
12427
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012428 conf.master_pref =
12429 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012430
Luca Coelho85859892017-02-08 15:00:34 +020012431 if (info->attrs[NL80211_ATTR_BANDS]) {
12432 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12433
12434 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12435 return -EOPNOTSUPP;
12436
12437 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12438 return -EINVAL;
12439
12440 conf.bands = bands;
12441 }
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012442
12443 err = rdev_start_nan(rdev, wdev, &conf);
12444 if (err)
12445 return err;
12446
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012447 wdev->is_running = true;
Ayala Bekercb3b7d82016-09-20 17:31:13 +030012448 rdev->opencount++;
12449
12450 return 0;
12451}
12452
12453static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info)
12454{
12455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12456 struct wireless_dev *wdev = info->user_ptr[1];
12457
12458 if (wdev->iftype != NL80211_IFTYPE_NAN)
12459 return -EOPNOTSUPP;
12460
12461 cfg80211_stop_nan(rdev, wdev);
12462
12463 return 0;
12464}
12465
Ayala Bekera442b762016-09-20 17:31:15 +030012466static int validate_nan_filter(struct nlattr *filter_attr)
12467{
12468 struct nlattr *attr;
12469 int len = 0, n_entries = 0, rem;
12470
12471 nla_for_each_nested(attr, filter_attr, rem) {
12472 len += nla_len(attr);
12473 n_entries++;
12474 }
12475
12476 if (len >= U8_MAX)
12477 return -EINVAL;
12478
12479 return n_entries;
12480}
12481
12482static int handle_nan_filter(struct nlattr *attr_filter,
12483 struct cfg80211_nan_func *func,
12484 bool tx)
12485{
12486 struct nlattr *attr;
12487 int n_entries, rem, i;
12488 struct cfg80211_nan_func_filter *filter;
12489
12490 n_entries = validate_nan_filter(attr_filter);
12491 if (n_entries < 0)
12492 return n_entries;
12493
12494 BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters));
12495
12496 filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL);
12497 if (!filter)
12498 return -ENOMEM;
12499
12500 i = 0;
12501 nla_for_each_nested(attr, attr_filter, rem) {
Thomas Grafb15ca182016-10-26 10:53:16 +020012502 filter[i].filter = nla_memdup(attr, GFP_KERNEL);
Ayala Bekera442b762016-09-20 17:31:15 +030012503 filter[i].len = nla_len(attr);
12504 i++;
12505 }
12506 if (tx) {
12507 func->num_tx_filters = n_entries;
12508 func->tx_filters = filter;
12509 } else {
12510 func->num_rx_filters = n_entries;
12511 func->rx_filters = filter;
12512 }
12513
12514 return 0;
12515}
12516
12517static int nl80211_nan_add_func(struct sk_buff *skb,
12518 struct genl_info *info)
12519{
12520 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12521 struct wireless_dev *wdev = info->user_ptr[1];
12522 struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr;
12523 struct cfg80211_nan_func *func;
12524 struct sk_buff *msg = NULL;
12525 void *hdr = NULL;
12526 int err = 0;
12527
12528 if (wdev->iftype != NL80211_IFTYPE_NAN)
12529 return -EOPNOTSUPP;
12530
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012531 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012532 return -ENOTCONN;
12533
12534 if (!info->attrs[NL80211_ATTR_NAN_FUNC])
12535 return -EINVAL;
12536
Johannes Berg8cb08172019-04-26 14:07:28 +020012537 err = nla_parse_nested_deprecated(tb, NL80211_NAN_FUNC_ATTR_MAX,
12538 info->attrs[NL80211_ATTR_NAN_FUNC],
12539 nl80211_nan_func_policy,
12540 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012541 if (err)
12542 return err;
12543
12544 func = kzalloc(sizeof(*func), GFP_KERNEL);
12545 if (!func)
12546 return -ENOMEM;
12547
Johannes Bergb60ad342018-10-01 11:52:07 +020012548 func->cookie = cfg80211_assign_cookie(rdev);
Ayala Bekera442b762016-09-20 17:31:15 +030012549
12550 if (!tb[NL80211_NAN_FUNC_TYPE] ||
12551 nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) {
12552 err = -EINVAL;
12553 goto out;
12554 }
12555
12556
12557 func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]);
12558
12559 if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) {
12560 err = -EINVAL;
12561 goto out;
12562 }
12563
12564 memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]),
12565 sizeof(func->service_id));
12566
12567 func->close_range =
12568 nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]);
12569
12570 if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) {
12571 func->serv_spec_info_len =
12572 nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]);
12573 func->serv_spec_info =
12574 kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]),
12575 func->serv_spec_info_len,
12576 GFP_KERNEL);
12577 if (!func->serv_spec_info) {
12578 err = -ENOMEM;
12579 goto out;
12580 }
12581 }
12582
12583 if (tb[NL80211_NAN_FUNC_TTL])
12584 func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]);
12585
12586 switch (func->type) {
12587 case NL80211_NAN_FUNC_PUBLISH:
12588 if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) {
12589 err = -EINVAL;
12590 goto out;
12591 }
12592
12593 func->publish_type =
12594 nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]);
12595 func->publish_bcast =
12596 nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]);
12597
12598 if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) &&
12599 func->publish_bcast) {
12600 err = -EINVAL;
12601 goto out;
12602 }
12603 break;
12604 case NL80211_NAN_FUNC_SUBSCRIBE:
12605 func->subscribe_active =
12606 nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]);
12607 break;
12608 case NL80211_NAN_FUNC_FOLLOW_UP:
12609 if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] ||
Hao Chen3ea15452018-01-03 11:00:31 +080012610 !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] ||
12611 !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) {
Ayala Bekera442b762016-09-20 17:31:15 +030012612 err = -EINVAL;
12613 goto out;
12614 }
12615
12616 func->followup_id =
12617 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]);
12618 func->followup_reqid =
12619 nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]);
12620 memcpy(func->followup_dest.addr,
12621 nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]),
12622 sizeof(func->followup_dest.addr));
12623 if (func->ttl) {
12624 err = -EINVAL;
12625 goto out;
12626 }
12627 break;
12628 default:
12629 err = -EINVAL;
12630 goto out;
12631 }
12632
12633 if (tb[NL80211_NAN_FUNC_SRF]) {
12634 struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR];
12635
Johannes Berg8cb08172019-04-26 14:07:28 +020012636 err = nla_parse_nested_deprecated(srf_tb,
12637 NL80211_NAN_SRF_ATTR_MAX,
12638 tb[NL80211_NAN_FUNC_SRF],
12639 nl80211_nan_srf_policy,
12640 info->extack);
Ayala Bekera442b762016-09-20 17:31:15 +030012641 if (err)
12642 goto out;
12643
12644 func->srf_include =
12645 nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]);
12646
12647 if (srf_tb[NL80211_NAN_SRF_BF]) {
12648 if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] ||
12649 !srf_tb[NL80211_NAN_SRF_BF_IDX]) {
12650 err = -EINVAL;
12651 goto out;
12652 }
12653
12654 func->srf_bf_len =
12655 nla_len(srf_tb[NL80211_NAN_SRF_BF]);
12656 func->srf_bf =
12657 kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]),
12658 func->srf_bf_len, GFP_KERNEL);
12659 if (!func->srf_bf) {
12660 err = -ENOMEM;
12661 goto out;
12662 }
12663
12664 func->srf_bf_idx =
12665 nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]);
12666 } else {
12667 struct nlattr *attr, *mac_attr =
12668 srf_tb[NL80211_NAN_SRF_MAC_ADDRS];
12669 int n_entries, rem, i = 0;
12670
12671 if (!mac_attr) {
12672 err = -EINVAL;
12673 goto out;
12674 }
12675
12676 n_entries = validate_acl_mac_addrs(mac_attr);
12677 if (n_entries <= 0) {
12678 err = -EINVAL;
12679 goto out;
12680 }
12681
12682 func->srf_num_macs = n_entries;
12683 func->srf_macs =
Kees Cook6396bb22018-06-12 14:03:40 -070012684 kcalloc(n_entries, sizeof(*func->srf_macs),
Ayala Bekera442b762016-09-20 17:31:15 +030012685 GFP_KERNEL);
12686 if (!func->srf_macs) {
12687 err = -ENOMEM;
12688 goto out;
12689 }
12690
12691 nla_for_each_nested(attr, mac_attr, rem)
12692 memcpy(func->srf_macs[i++].addr, nla_data(attr),
12693 sizeof(*func->srf_macs));
12694 }
12695 }
12696
12697 if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) {
12698 err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER],
12699 func, true);
12700 if (err)
12701 goto out;
12702 }
12703
12704 if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) {
12705 err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER],
12706 func, false);
12707 if (err)
12708 goto out;
12709 }
12710
12711 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12712 if (!msg) {
12713 err = -ENOMEM;
12714 goto out;
12715 }
12716
12717 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12718 NL80211_CMD_ADD_NAN_FUNCTION);
12719 /* This can't really happen - we just allocated 4KB */
12720 if (WARN_ON(!hdr)) {
12721 err = -ENOMEM;
12722 goto out;
12723 }
12724
12725 err = rdev_add_nan_func(rdev, wdev, func);
12726out:
12727 if (err < 0) {
12728 cfg80211_free_nan_func(func);
12729 nlmsg_free(msg);
12730 return err;
12731 }
12732
12733 /* propagate the instance id and cookie to userspace */
12734 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie,
12735 NL80211_ATTR_PAD))
12736 goto nla_put_failure;
12737
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012738 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Bekera442b762016-09-20 17:31:15 +030012739 if (!func_attr)
12740 goto nla_put_failure;
12741
12742 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID,
12743 func->instance_id))
12744 goto nla_put_failure;
12745
12746 nla_nest_end(msg, func_attr);
12747
12748 genlmsg_end(msg, hdr);
12749 return genlmsg_reply(msg, info);
12750
12751nla_put_failure:
12752 nlmsg_free(msg);
12753 return -ENOBUFS;
12754}
12755
12756static int nl80211_nan_del_func(struct sk_buff *skb,
12757 struct genl_info *info)
12758{
12759 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12760 struct wireless_dev *wdev = info->user_ptr[1];
12761 u64 cookie;
12762
12763 if (wdev->iftype != NL80211_IFTYPE_NAN)
12764 return -EOPNOTSUPP;
12765
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012766 if (!wdev_running(wdev))
Ayala Bekera442b762016-09-20 17:31:15 +030012767 return -ENOTCONN;
12768
12769 if (!info->attrs[NL80211_ATTR_COOKIE])
12770 return -EINVAL;
12771
Ayala Bekera442b762016-09-20 17:31:15 +030012772 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
12773
12774 rdev_del_nan_func(rdev, wdev, cookie);
12775
12776 return 0;
12777}
12778
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012779static int nl80211_nan_change_config(struct sk_buff *skb,
12780 struct genl_info *info)
12781{
12782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12783 struct wireless_dev *wdev = info->user_ptr[1];
12784 struct cfg80211_nan_conf conf = {};
12785 u32 changed = 0;
12786
12787 if (wdev->iftype != NL80211_IFTYPE_NAN)
12788 return -EOPNOTSUPP;
12789
Arend Van Spriel73c7da32016-10-20 20:08:22 +010012790 if (!wdev_running(wdev))
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012791 return -ENOTCONN;
12792
12793 if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) {
12794 conf.master_pref =
12795 nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]);
12796 if (conf.master_pref <= 1 || conf.master_pref == 255)
12797 return -EINVAL;
12798
12799 changed |= CFG80211_NAN_CONF_CHANGED_PREF;
12800 }
12801
Luca Coelho85859892017-02-08 15:00:34 +020012802 if (info->attrs[NL80211_ATTR_BANDS]) {
12803 u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]);
12804
12805 if (bands & ~(u32)wdev->wiphy->nan_supported_bands)
12806 return -EOPNOTSUPP;
12807
12808 if (bands && !(bands & BIT(NL80211_BAND_2GHZ)))
12809 return -EINVAL;
12810
12811 conf.bands = bands;
12812 changed |= CFG80211_NAN_CONF_CHANGED_BANDS;
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030012813 }
12814
12815 if (!changed)
12816 return -EINVAL;
12817
12818 return rdev_nan_change_conf(rdev, wdev, &conf, changed);
12819}
12820
Ayala Beker50bcd312016-09-20 17:31:17 +030012821void cfg80211_nan_match(struct wireless_dev *wdev,
12822 struct cfg80211_nan_match_params *match, gfp_t gfp)
12823{
12824 struct wiphy *wiphy = wdev->wiphy;
12825 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12826 struct nlattr *match_attr, *local_func_attr, *peer_func_attr;
12827 struct sk_buff *msg;
12828 void *hdr;
12829
12830 if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr))
12831 return;
12832
12833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12834 if (!msg)
12835 return;
12836
12837 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH);
12838 if (!hdr) {
12839 nlmsg_free(msg);
12840 return;
12841 }
12842
12843 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12844 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12845 wdev->netdev->ifindex)) ||
12846 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12847 NL80211_ATTR_PAD))
12848 goto nla_put_failure;
12849
12850 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie,
12851 NL80211_ATTR_PAD) ||
12852 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr))
12853 goto nla_put_failure;
12854
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012855 match_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_MATCH);
Ayala Beker50bcd312016-09-20 17:31:17 +030012856 if (!match_attr)
12857 goto nla_put_failure;
12858
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012859 local_func_attr = nla_nest_start_noflag(msg,
12860 NL80211_NAN_MATCH_FUNC_LOCAL);
Ayala Beker50bcd312016-09-20 17:31:17 +030012861 if (!local_func_attr)
12862 goto nla_put_failure;
12863
12864 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id))
12865 goto nla_put_failure;
12866
12867 nla_nest_end(msg, local_func_attr);
12868
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012869 peer_func_attr = nla_nest_start_noflag(msg,
12870 NL80211_NAN_MATCH_FUNC_PEER);
Ayala Beker50bcd312016-09-20 17:31:17 +030012871 if (!peer_func_attr)
12872 goto nla_put_failure;
12873
12874 if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) ||
12875 nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id))
12876 goto nla_put_failure;
12877
12878 if (match->info && match->info_len &&
12879 nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len,
12880 match->info))
12881 goto nla_put_failure;
12882
12883 nla_nest_end(msg, peer_func_attr);
12884 nla_nest_end(msg, match_attr);
12885 genlmsg_end(msg, hdr);
12886
12887 if (!wdev->owner_nlportid)
12888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12889 msg, 0, NL80211_MCGRP_NAN, gfp);
12890 else
12891 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12892 wdev->owner_nlportid);
12893
12894 return;
12895
12896nla_put_failure:
12897 nlmsg_free(msg);
12898}
12899EXPORT_SYMBOL(cfg80211_nan_match);
12900
Ayala Beker368e5a72016-09-20 17:31:18 +030012901void cfg80211_nan_func_terminated(struct wireless_dev *wdev,
12902 u8 inst_id,
12903 enum nl80211_nan_func_term_reason reason,
12904 u64 cookie, gfp_t gfp)
12905{
12906 struct wiphy *wiphy = wdev->wiphy;
12907 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12908 struct sk_buff *msg;
12909 struct nlattr *func_attr;
12910 void *hdr;
12911
12912 if (WARN_ON(!inst_id))
12913 return;
12914
12915 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12916 if (!msg)
12917 return;
12918
12919 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION);
12920 if (!hdr) {
12921 nlmsg_free(msg);
12922 return;
12923 }
12924
12925 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12926 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12927 wdev->netdev->ifindex)) ||
12928 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
12929 NL80211_ATTR_PAD))
12930 goto nla_put_failure;
12931
12932 if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
12933 NL80211_ATTR_PAD))
12934 goto nla_put_failure;
12935
Michal Kubecekae0be8d2019-04-26 11:13:06 +020012936 func_attr = nla_nest_start_noflag(msg, NL80211_ATTR_NAN_FUNC);
Ayala Beker368e5a72016-09-20 17:31:18 +030012937 if (!func_attr)
12938 goto nla_put_failure;
12939
12940 if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) ||
12941 nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason))
12942 goto nla_put_failure;
12943
12944 nla_nest_end(msg, func_attr);
12945 genlmsg_end(msg, hdr);
12946
12947 if (!wdev->owner_nlportid)
12948 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
12949 msg, 0, NL80211_MCGRP_NAN, gfp);
12950 else
12951 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
12952 wdev->owner_nlportid);
12953
12954 return;
12955
12956nla_put_failure:
12957 nlmsg_free(msg);
12958}
12959EXPORT_SYMBOL(cfg80211_nan_func_terminated);
12960
Johannes Berg3713b4e2013-02-14 16:19:38 +010012961static int nl80211_get_protocol_features(struct sk_buff *skb,
12962 struct genl_info *info)
12963{
12964 void *hdr;
12965 struct sk_buff *msg;
12966
12967 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12968 if (!msg)
12969 return -ENOMEM;
12970
12971 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
12972 NL80211_CMD_GET_PROTOCOL_FEATURES);
12973 if (!hdr)
12974 goto nla_put_failure;
12975
12976 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
12977 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
12978 goto nla_put_failure;
12979
12980 genlmsg_end(msg, hdr);
12981 return genlmsg_reply(msg, info);
12982
12983 nla_put_failure:
12984 kfree_skb(msg);
12985 return -ENOBUFS;
12986}
12987
Jouni Malinen355199e2013-02-27 17:14:27 +020012988static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
12989{
12990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
12991 struct cfg80211_update_ft_ies_params ft_params;
12992 struct net_device *dev = info->user_ptr[1];
12993
12994 if (!rdev->ops->update_ft_ies)
12995 return -EOPNOTSUPP;
12996
12997 if (!info->attrs[NL80211_ATTR_MDID] ||
Johannes Berg3d7af872018-10-02 10:00:08 +020012998 !info->attrs[NL80211_ATTR_IE])
Jouni Malinen355199e2013-02-27 17:14:27 +020012999 return -EINVAL;
13000
13001 memset(&ft_params, 0, sizeof(ft_params));
13002 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
13003 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13004 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13005
13006 return rdev_update_ft_ies(rdev, dev, &ft_params);
13007}
13008
Arend van Spriel5de17982013-04-18 15:49:00 +020013009static int nl80211_crit_protocol_start(struct sk_buff *skb,
13010 struct genl_info *info)
13011{
13012 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13013 struct wireless_dev *wdev = info->user_ptr[1];
13014 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
13015 u16 duration;
13016 int ret;
13017
13018 if (!rdev->ops->crit_proto_start)
13019 return -EOPNOTSUPP;
13020
13021 if (WARN_ON(!rdev->ops->crit_proto_stop))
13022 return -EINVAL;
13023
13024 if (rdev->crit_proto_nlportid)
13025 return -EBUSY;
13026
13027 /* determine protocol if provided */
13028 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
13029 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
13030
13031 if (proto >= NUM_NL80211_CRIT_PROTO)
13032 return -EINVAL;
13033
13034 /* timeout must be provided */
13035 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
13036 return -EINVAL;
13037
13038 duration =
13039 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
13040
13041 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
13042 return -ERANGE;
13043
13044 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
13045 if (!ret)
13046 rdev->crit_proto_nlportid = info->snd_portid;
13047
13048 return ret;
13049}
13050
13051static int nl80211_crit_protocol_stop(struct sk_buff *skb,
13052 struct genl_info *info)
13053{
13054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13055 struct wireless_dev *wdev = info->user_ptr[1];
13056
13057 if (!rdev->ops->crit_proto_stop)
13058 return -EOPNOTSUPP;
13059
13060 if (rdev->crit_proto_nlportid) {
13061 rdev->crit_proto_nlportid = 0;
13062 rdev_crit_proto_stop(rdev, wdev);
13063 }
13064 return 0;
13065}
13066
Johannes Berg901bb982019-05-28 10:56:03 +020013067static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,
13068 struct nlattr *attr,
13069 struct netlink_ext_ack *extack)
13070{
13071 if (vcmd->policy == VENDOR_CMD_RAW_DATA) {
13072 if (attr->nla_type & NLA_F_NESTED) {
13073 NL_SET_ERR_MSG_ATTR(extack, attr,
13074 "unexpected nested data");
13075 return -EINVAL;
13076 }
13077
13078 return 0;
13079 }
13080
13081 if (!(attr->nla_type & NLA_F_NESTED)) {
13082 NL_SET_ERR_MSG_ATTR(extack, attr, "expected nested data");
13083 return -EINVAL;
13084 }
13085
Michal Kubecek32d51092019-12-11 10:58:19 +010013086 return nla_validate_nested(attr, vcmd->maxattr, vcmd->policy, extack);
Johannes Berg901bb982019-05-28 10:56:03 +020013087}
13088
Johannes Bergad7e7182013-11-13 13:37:47 +010013089static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
13090{
13091 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13092 struct wireless_dev *wdev =
13093 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
13094 int i, err;
13095 u32 vid, subcmd;
13096
13097 if (!rdev->wiphy.vendor_commands)
13098 return -EOPNOTSUPP;
13099
13100 if (IS_ERR(wdev)) {
13101 err = PTR_ERR(wdev);
13102 if (err != -EINVAL)
13103 return err;
13104 wdev = NULL;
13105 } else if (wdev->wiphy != &rdev->wiphy) {
13106 return -EINVAL;
13107 }
13108
13109 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
13110 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
13111 return -EINVAL;
13112
13113 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
13114 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
13115 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
13116 const struct wiphy_vendor_command *vcmd;
13117 void *data = NULL;
13118 int len = 0;
13119
13120 vcmd = &rdev->wiphy.vendor_commands[i];
13121
13122 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13123 continue;
13124
13125 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13126 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
13127 if (!wdev)
13128 return -EINVAL;
13129 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
13130 !wdev->netdev)
13131 return -EINVAL;
13132
13133 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Arend Van Spriel73c7da32016-10-20 20:08:22 +010013134 if (!wdev_running(wdev))
Johannes Bergad7e7182013-11-13 13:37:47 +010013135 return -ENETDOWN;
13136 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013137
13138 if (!vcmd->doit)
13139 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010013140 } else {
13141 wdev = NULL;
13142 }
13143
13144 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
13145 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
13146 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020013147
13148 err = nl80211_vendor_check_policy(vcmd,
13149 info->attrs[NL80211_ATTR_VENDOR_DATA],
13150 info->extack);
13151 if (err)
13152 return err;
Johannes Bergad7e7182013-11-13 13:37:47 +010013153 }
13154
13155 rdev->cur_cmd_info = info;
Johannes Berg901bb982019-05-28 10:56:03 +020013156 err = vcmd->doit(&rdev->wiphy, wdev, data, len);
Johannes Bergad7e7182013-11-13 13:37:47 +010013157 rdev->cur_cmd_info = NULL;
13158 return err;
13159 }
13160
13161 return -EOPNOTSUPP;
13162}
13163
Johannes Berg7bdbe402015-08-15 22:39:49 +030013164static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
13165 struct netlink_callback *cb,
13166 struct cfg80211_registered_device **rdev,
13167 struct wireless_dev **wdev)
13168{
Johannes Berg50508d92019-07-29 16:31:09 +020013169 struct nlattr **attrbuf;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013170 u32 vid, subcmd;
13171 unsigned int i;
13172 int vcmd_idx = -1;
13173 int err;
13174 void *data = NULL;
13175 unsigned int data_len = 0;
13176
Johannes Berg7bdbe402015-08-15 22:39:49 +030013177 if (cb->args[0]) {
13178 /* subtract the 1 again here */
13179 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
13180 struct wireless_dev *tmp;
13181
Johannes Bergea90e0d2017-03-15 14:26:04 +010013182 if (!wiphy)
13183 return -ENODEV;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013184 *rdev = wiphy_to_rdev(wiphy);
13185 *wdev = NULL;
13186
13187 if (cb->args[1]) {
Johannes Berg53873f12016-05-03 16:52:04 +030013188 list_for_each_entry(tmp, &wiphy->wdev_list, list) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013189 if (tmp->identifier == cb->args[1] - 1) {
13190 *wdev = tmp;
13191 break;
13192 }
13193 }
13194 }
13195
13196 /* keep rtnl locked in successful case */
13197 return 0;
13198 }
13199
Johannes Berg50508d92019-07-29 16:31:09 +020013200 attrbuf = kcalloc(NUM_NL80211_ATTR, sizeof(*attrbuf), GFP_KERNEL);
13201 if (!attrbuf)
13202 return -ENOMEM;
13203
Johannes Berg8cb08172019-04-26 14:07:28 +020013204 err = nlmsg_parse_deprecated(cb->nlh,
13205 GENL_HDRLEN + nl80211_fam.hdrsize,
13206 attrbuf, nl80211_fam.maxattr,
13207 nl80211_policy, NULL);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013208 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020013209 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013210
Johannes Bergc90c39d2016-10-24 14:40:01 +020013211 if (!attrbuf[NL80211_ATTR_VENDOR_ID] ||
Johannes Berg50508d92019-07-29 16:31:09 +020013212 !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
13213 err = -EINVAL;
13214 goto out;
13215 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013216
Johannes Bergc90c39d2016-10-24 14:40:01 +020013217 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013218 if (IS_ERR(*wdev))
13219 *wdev = NULL;
13220
Johannes Bergc90c39d2016-10-24 14:40:01 +020013221 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf);
Johannes Berg50508d92019-07-29 16:31:09 +020013222 if (IS_ERR(*rdev)) {
13223 err = PTR_ERR(*rdev);
13224 goto out;
13225 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013226
Johannes Bergc90c39d2016-10-24 14:40:01 +020013227 vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]);
13228 subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013229
13230 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
13231 const struct wiphy_vendor_command *vcmd;
13232
13233 vcmd = &(*rdev)->wiphy.vendor_commands[i];
13234
13235 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
13236 continue;
13237
Johannes Berg50508d92019-07-29 16:31:09 +020013238 if (!vcmd->dumpit) {
13239 err = -EOPNOTSUPP;
13240 goto out;
13241 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013242
13243 vcmd_idx = i;
13244 break;
13245 }
13246
Johannes Berg50508d92019-07-29 16:31:09 +020013247 if (vcmd_idx < 0) {
13248 err = -EOPNOTSUPP;
13249 goto out;
13250 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013251
Johannes Bergc90c39d2016-10-24 14:40:01 +020013252 if (attrbuf[NL80211_ATTR_VENDOR_DATA]) {
13253 data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]);
13254 data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]);
Johannes Berg901bb982019-05-28 10:56:03 +020013255
13256 err = nl80211_vendor_check_policy(
13257 &(*rdev)->wiphy.vendor_commands[vcmd_idx],
13258 attrbuf[NL80211_ATTR_VENDOR_DATA],
13259 cb->extack);
13260 if (err)
Johannes Berg50508d92019-07-29 16:31:09 +020013261 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013262 }
13263
13264 /* 0 is the first index - add 1 to parse only once */
13265 cb->args[0] = (*rdev)->wiphy_idx + 1;
13266 /* add 1 to know if it was NULL */
13267 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
13268 cb->args[2] = vcmd_idx;
13269 cb->args[3] = (unsigned long)data;
13270 cb->args[4] = data_len;
13271
13272 /* keep rtnl locked in successful case */
Johannes Berg50508d92019-07-29 16:31:09 +020013273 err = 0;
13274out:
13275 kfree(attrbuf);
13276 return err;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013277}
13278
13279static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
13280 struct netlink_callback *cb)
13281{
13282 struct cfg80211_registered_device *rdev;
13283 struct wireless_dev *wdev;
13284 unsigned int vcmd_idx;
13285 const struct wiphy_vendor_command *vcmd;
13286 void *data;
13287 int data_len;
13288 int err;
13289 struct nlattr *vendor_data;
13290
Johannes Bergea90e0d2017-03-15 14:26:04 +010013291 rtnl_lock();
Johannes Berg7bdbe402015-08-15 22:39:49 +030013292 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
13293 if (err)
Johannes Bergea90e0d2017-03-15 14:26:04 +010013294 goto out;
Johannes Berg7bdbe402015-08-15 22:39:49 +030013295
13296 vcmd_idx = cb->args[2];
13297 data = (void *)cb->args[3];
13298 data_len = cb->args[4];
13299 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
13300
13301 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
13302 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013303 if (!wdev) {
13304 err = -EINVAL;
13305 goto out;
13306 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013307 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
Johannes Bergea90e0d2017-03-15 14:26:04 +010013308 !wdev->netdev) {
13309 err = -EINVAL;
13310 goto out;
13311 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013312
13313 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
Johannes Bergea90e0d2017-03-15 14:26:04 +010013314 if (!wdev_running(wdev)) {
13315 err = -ENETDOWN;
13316 goto out;
13317 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030013318 }
13319 }
13320
13321 while (1) {
13322 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
13323 cb->nlh->nlmsg_seq, NLM_F_MULTI,
13324 NL80211_CMD_VENDOR);
13325 if (!hdr)
13326 break;
13327
13328 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020013329 (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV,
13330 wdev_id(wdev),
13331 NL80211_ATTR_PAD))) {
Johannes Berg7bdbe402015-08-15 22:39:49 +030013332 genlmsg_cancel(skb, hdr);
13333 break;
13334 }
13335
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013336 vendor_data = nla_nest_start_noflag(skb,
13337 NL80211_ATTR_VENDOR_DATA);
Johannes Berg7bdbe402015-08-15 22:39:49 +030013338 if (!vendor_data) {
13339 genlmsg_cancel(skb, hdr);
13340 break;
13341 }
13342
13343 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
13344 (unsigned long *)&cb->args[5]);
13345 nla_nest_end(skb, vendor_data);
13346
13347 if (err == -ENOBUFS || err == -ENOENT) {
13348 genlmsg_cancel(skb, hdr);
13349 break;
13350 } else if (err) {
13351 genlmsg_cancel(skb, hdr);
13352 goto out;
13353 }
13354
13355 genlmsg_end(skb, hdr);
13356 }
13357
13358 err = skb->len;
13359 out:
13360 rtnl_unlock();
13361 return err;
13362}
13363
Johannes Bergad7e7182013-11-13 13:37:47 +010013364struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
13365 enum nl80211_commands cmd,
13366 enum nl80211_attrs attr,
13367 int approxlen)
13368{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013369 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010013370
13371 if (WARN_ON(!rdev->cur_cmd_info))
13372 return NULL;
13373
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020013374 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010013375 rdev->cur_cmd_info->snd_portid,
13376 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010013377 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010013378}
13379EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
13380
13381int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
13382{
13383 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
13384 void *hdr = ((void **)skb->cb)[1];
13385 struct nlattr *data = ((void **)skb->cb)[2];
13386
Johannes Bergbd8c78e2014-07-30 14:55:26 +020013387 /* clear CB data for netlink core to own from now on */
13388 memset(skb->cb, 0, sizeof(skb->cb));
13389
Johannes Bergad7e7182013-11-13 13:37:47 +010013390 if (WARN_ON(!rdev->cur_cmd_info)) {
13391 kfree_skb(skb);
13392 return -EINVAL;
13393 }
13394
13395 nla_nest_end(skb, data);
13396 genlmsg_end(skb, hdr);
13397 return genlmsg_reply(skb, rdev->cur_cmd_info);
13398}
13399EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
13400
Johannes Berg55c1fdf2019-02-06 13:17:19 +020013401unsigned int cfg80211_vendor_cmd_get_sender(struct wiphy *wiphy)
13402{
13403 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
13404
13405 if (WARN_ON(!rdev->cur_cmd_info))
13406 return 0;
13407
13408 return rdev->cur_cmd_info->snd_portid;
13409}
13410EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_get_sender);
13411
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080013412static int nl80211_set_qos_map(struct sk_buff *skb,
13413 struct genl_info *info)
13414{
13415 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13416 struct cfg80211_qos_map *qos_map = NULL;
13417 struct net_device *dev = info->user_ptr[1];
13418 u8 *pos, len, num_des, des_len, des;
13419 int ret;
13420
13421 if (!rdev->ops->set_qos_map)
13422 return -EOPNOTSUPP;
13423
13424 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
13425 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
13426 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
13427
13428 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
13429 len > IEEE80211_QOS_MAP_LEN_MAX)
13430 return -EINVAL;
13431
13432 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
13433 if (!qos_map)
13434 return -ENOMEM;
13435
13436 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
13437 if (num_des) {
13438 des_len = num_des *
13439 sizeof(struct cfg80211_dscp_exception);
13440 memcpy(qos_map->dscp_exception, pos, des_len);
13441 qos_map->num_des = num_des;
13442 for (des = 0; des < num_des; des++) {
13443 if (qos_map->dscp_exception[des].up > 7) {
13444 kfree(qos_map);
13445 return -EINVAL;
13446 }
13447 }
13448 pos += des_len;
13449 }
13450 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
13451 }
13452
13453 wdev_lock(dev->ieee80211_ptr);
13454 ret = nl80211_key_allowed(dev->ieee80211_ptr);
13455 if (!ret)
13456 ret = rdev_set_qos_map(rdev, dev, qos_map);
13457 wdev_unlock(dev->ieee80211_ptr);
13458
13459 kfree(qos_map);
13460 return ret;
13461}
13462
Johannes Berg960d01a2014-09-09 22:55:35 +030013463static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
13464{
13465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13466 struct net_device *dev = info->user_ptr[1];
13467 struct wireless_dev *wdev = dev->ieee80211_ptr;
13468 const u8 *peer;
13469 u8 tsid, up;
13470 u16 admitted_time = 0;
13471 int err;
13472
Johannes Berg723e73a2014-10-22 09:25:06 +020013473 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030013474 return -EOPNOTSUPP;
13475
13476 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
13477 !info->attrs[NL80211_ATTR_USER_PRIO])
13478 return -EINVAL;
13479
13480 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013481 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
Johannes Berg960d01a2014-09-09 22:55:35 +030013482
13483 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020013484 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030013485 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020013486 * need more attributes for that (e.g. BA session requirement);
13487 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030013488 */
13489 return -EINVAL;
13490 }
13491
13492 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13493
13494 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
13495 admitted_time =
13496 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
13497 if (!admitted_time)
13498 return -EINVAL;
13499 }
13500
13501 wdev_lock(wdev);
13502 switch (wdev->iftype) {
13503 case NL80211_IFTYPE_STATION:
13504 case NL80211_IFTYPE_P2P_CLIENT:
13505 if (wdev->current_bss)
13506 break;
13507 err = -ENOTCONN;
13508 goto out;
13509 default:
13510 err = -EOPNOTSUPP;
13511 goto out;
13512 }
13513
13514 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
13515
13516 out:
13517 wdev_unlock(wdev);
13518 return err;
13519}
13520
13521static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
13522{
13523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13524 struct net_device *dev = info->user_ptr[1];
13525 struct wireless_dev *wdev = dev->ieee80211_ptr;
13526 const u8 *peer;
13527 u8 tsid;
13528 int err;
13529
13530 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
13531 return -EINVAL;
13532
13533 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
13534 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
13535
13536 wdev_lock(wdev);
13537 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
13538 wdev_unlock(wdev);
13539
13540 return err;
13541}
13542
Arik Nemtsov1057d352014-11-19 12:54:26 +020013543static int nl80211_tdls_channel_switch(struct sk_buff *skb,
13544 struct genl_info *info)
13545{
13546 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13547 struct net_device *dev = info->user_ptr[1];
13548 struct wireless_dev *wdev = dev->ieee80211_ptr;
13549 struct cfg80211_chan_def chandef = {};
13550 const u8 *addr;
13551 u8 oper_class;
13552 int err;
13553
13554 if (!rdev->ops->tdls_channel_switch ||
13555 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13556 return -EOPNOTSUPP;
13557
13558 switch (dev->ieee80211_ptr->iftype) {
13559 case NL80211_IFTYPE_STATION:
13560 case NL80211_IFTYPE_P2P_CLIENT:
13561 break;
13562 default:
13563 return -EOPNOTSUPP;
13564 }
13565
13566 if (!info->attrs[NL80211_ATTR_MAC] ||
13567 !info->attrs[NL80211_ATTR_OPER_CLASS])
13568 return -EINVAL;
13569
13570 err = nl80211_parse_chandef(rdev, info, &chandef);
13571 if (err)
13572 return err;
13573
13574 /*
13575 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
13576 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
13577 * specification is not defined for them.
13578 */
Johannes Berg57fbcce2016-04-12 15:56:15 +020013579 if (chandef.chan->band == NL80211_BAND_2GHZ &&
Arik Nemtsov1057d352014-11-19 12:54:26 +020013580 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
13581 chandef.width != NL80211_CHAN_WIDTH_20)
13582 return -EINVAL;
13583
13584 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030013585 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
13586 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020013587 return -EINVAL;
13588
13589 /* don't allow switching to DFS channels */
13590 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
13591 return -EINVAL;
13592
13593 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13594 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
13595
13596 wdev_lock(wdev);
13597 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
13598 wdev_unlock(wdev);
13599
13600 return err;
13601}
13602
13603static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
13604 struct genl_info *info)
13605{
13606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13607 struct net_device *dev = info->user_ptr[1];
13608 struct wireless_dev *wdev = dev->ieee80211_ptr;
13609 const u8 *addr;
13610
13611 if (!rdev->ops->tdls_channel_switch ||
13612 !rdev->ops->tdls_cancel_channel_switch ||
13613 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
13614 return -EOPNOTSUPP;
13615
13616 switch (dev->ieee80211_ptr->iftype) {
13617 case NL80211_IFTYPE_STATION:
13618 case NL80211_IFTYPE_P2P_CLIENT:
13619 break;
13620 default:
13621 return -EOPNOTSUPP;
13622 }
13623
13624 if (!info->attrs[NL80211_ATTR_MAC])
13625 return -EINVAL;
13626
13627 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
13628
13629 wdev_lock(wdev);
13630 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
13631 wdev_unlock(wdev);
13632
13633 return 0;
13634}
13635
Michael Braunce0ce132016-10-10 19:12:22 +020013636static int nl80211_set_multicast_to_unicast(struct sk_buff *skb,
13637 struct genl_info *info)
13638{
13639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13640 struct net_device *dev = info->user_ptr[1];
13641 struct wireless_dev *wdev = dev->ieee80211_ptr;
13642 const struct nlattr *nla;
13643 bool enabled;
13644
Michael Braunce0ce132016-10-10 19:12:22 +020013645 if (!rdev->ops->set_multicast_to_unicast)
13646 return -EOPNOTSUPP;
13647
13648 if (wdev->iftype != NL80211_IFTYPE_AP &&
13649 wdev->iftype != NL80211_IFTYPE_P2P_GO)
13650 return -EOPNOTSUPP;
13651
13652 nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED];
13653 enabled = nla_get_flag(nla);
13654
13655 return rdev_set_multicast_to_unicast(rdev, dev, enabled);
13656}
13657
Avraham Stern3a00df52017-06-09 13:08:43 +010013658static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info)
13659{
13660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13661 struct net_device *dev = info->user_ptr[1];
13662 struct wireless_dev *wdev = dev->ieee80211_ptr;
13663 struct cfg80211_pmk_conf pmk_conf = {};
13664 int ret;
13665
13666 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13667 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13668 return -EOPNOTSUPP;
13669
13670 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13671 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13672 return -EOPNOTSUPP;
13673
13674 if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK])
13675 return -EINVAL;
13676
13677 wdev_lock(wdev);
13678 if (!wdev->current_bss) {
13679 ret = -ENOTCONN;
13680 goto out;
13681 }
13682
13683 pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13684 if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) {
13685 ret = -EINVAL;
13686 goto out;
13687 }
13688
13689 pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]);
13690 pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]);
13691 if (pmk_conf.pmk_len != WLAN_PMK_LEN &&
13692 pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) {
13693 ret = -EINVAL;
13694 goto out;
13695 }
13696
13697 if (info->attrs[NL80211_ATTR_PMKR0_NAME]) {
13698 int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13699
13700 if (r0_name_len != WLAN_PMK_NAME_LEN) {
13701 ret = -EINVAL;
13702 goto out;
13703 }
13704
13705 pmk_conf.pmk_r0_name =
13706 nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]);
13707 }
13708
13709 ret = rdev_set_pmk(rdev, dev, &pmk_conf);
13710out:
13711 wdev_unlock(wdev);
13712 return ret;
13713}
13714
13715static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info)
13716{
13717 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13718 struct net_device *dev = info->user_ptr[1];
13719 struct wireless_dev *wdev = dev->ieee80211_ptr;
13720 const u8 *aa;
13721 int ret;
13722
13723 if (wdev->iftype != NL80211_IFTYPE_STATION &&
13724 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
13725 return -EOPNOTSUPP;
13726
13727 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13728 NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X))
13729 return -EOPNOTSUPP;
13730
13731 if (!info->attrs[NL80211_ATTR_MAC])
13732 return -EINVAL;
13733
13734 wdev_lock(wdev);
13735 aa = nla_data(info->attrs[NL80211_ATTR_MAC]);
13736 ret = rdev_del_pmk(rdev, dev, aa);
13737 wdev_unlock(wdev);
13738
13739 return ret;
13740}
13741
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013742static int nl80211_external_auth(struct sk_buff *skb, struct genl_info *info)
13743{
13744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13745 struct net_device *dev = info->user_ptr[1];
13746 struct cfg80211_external_auth_params params;
13747
Srinivas Dasaridb8d93a2018-02-02 11:15:27 +020013748 if (!rdev->ops->external_auth)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013749 return -EOPNOTSUPP;
13750
Srinivas Dasarife494372019-01-23 18:06:56 +053013751 if (!info->attrs[NL80211_ATTR_SSID] &&
13752 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
13753 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013754 return -EINVAL;
13755
13756 if (!info->attrs[NL80211_ATTR_BSSID])
13757 return -EINVAL;
13758
13759 if (!info->attrs[NL80211_ATTR_STATUS_CODE])
13760 return -EINVAL;
13761
13762 memset(&params, 0, sizeof(params));
13763
Srinivas Dasarife494372019-01-23 18:06:56 +053013764 if (info->attrs[NL80211_ATTR_SSID]) {
13765 params.ssid.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
13766 if (params.ssid.ssid_len == 0 ||
13767 params.ssid.ssid_len > IEEE80211_MAX_SSID_LEN)
13768 return -EINVAL;
13769 memcpy(params.ssid.ssid,
13770 nla_data(info->attrs[NL80211_ATTR_SSID]),
13771 params.ssid.ssid_len);
13772 }
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013773
13774 memcpy(params.bssid, nla_data(info->attrs[NL80211_ATTR_BSSID]),
13775 ETH_ALEN);
13776
13777 params.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13778
Srinivas Dasarife494372019-01-23 18:06:56 +053013779 if (info->attrs[NL80211_ATTR_PMKID])
13780 params.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
13781
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020013782 return rdev_external_auth(rdev, dev, &params);
13783}
13784
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013785static int nl80211_tx_control_port(struct sk_buff *skb, struct genl_info *info)
13786{
13787 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13788 struct net_device *dev = info->user_ptr[1];
13789 struct wireless_dev *wdev = dev->ieee80211_ptr;
13790 const u8 *buf;
13791 size_t len;
13792 u8 *dest;
13793 u16 proto;
13794 bool noencrypt;
13795 int err;
13796
13797 if (!wiphy_ext_feature_isset(&rdev->wiphy,
13798 NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211))
13799 return -EOPNOTSUPP;
13800
13801 if (!rdev->ops->tx_control_port)
13802 return -EOPNOTSUPP;
13803
13804 if (!info->attrs[NL80211_ATTR_FRAME] ||
13805 !info->attrs[NL80211_ATTR_MAC] ||
13806 !info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
13807 GENL_SET_ERR_MSG(info, "Frame, MAC or ethertype missing");
13808 return -EINVAL;
13809 }
13810
13811 wdev_lock(wdev);
13812
13813 switch (wdev->iftype) {
13814 case NL80211_IFTYPE_AP:
13815 case NL80211_IFTYPE_P2P_GO:
13816 case NL80211_IFTYPE_MESH_POINT:
13817 break;
13818 case NL80211_IFTYPE_ADHOC:
13819 case NL80211_IFTYPE_STATION:
13820 case NL80211_IFTYPE_P2P_CLIENT:
13821 if (wdev->current_bss)
13822 break;
13823 err = -ENOTCONN;
13824 goto out;
13825 default:
13826 err = -EOPNOTSUPP;
13827 goto out;
13828 }
13829
13830 wdev_unlock(wdev);
13831
13832 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13833 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13834 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13835 proto = nla_get_u16(info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
13836 noencrypt =
13837 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]);
13838
13839 return rdev_tx_control_port(rdev, dev, buf, len,
Johannes Berg8d74a622020-02-24 10:19:12 +010013840 dest, cpu_to_be16(proto), noencrypt);
Denis Kenzior2576a9a2018-03-26 12:52:42 -050013841
13842 out:
13843 wdev_unlock(wdev);
13844 return err;
13845}
13846
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013847static int nl80211_get_ftm_responder_stats(struct sk_buff *skb,
13848 struct genl_info *info)
13849{
13850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13851 struct net_device *dev = info->user_ptr[1];
13852 struct wireless_dev *wdev = dev->ieee80211_ptr;
13853 struct cfg80211_ftm_responder_stats ftm_stats = {};
13854 struct sk_buff *msg;
13855 void *hdr;
13856 struct nlattr *ftm_stats_attr;
13857 int err;
13858
13859 if (wdev->iftype != NL80211_IFTYPE_AP || !wdev->beacon_interval)
13860 return -EOPNOTSUPP;
13861
13862 err = rdev_get_ftm_responder_stats(rdev, dev, &ftm_stats);
13863 if (err)
13864 return err;
13865
13866 if (!ftm_stats.filled)
13867 return -ENODATA;
13868
13869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13870 if (!msg)
13871 return -ENOMEM;
13872
13873 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
13874 NL80211_CMD_GET_FTM_RESPONDER_STATS);
13875 if (!hdr)
Navid Emamdoost1399c592019-10-04 14:42:19 -050013876 goto nla_put_failure;
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013877
13878 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
13879 goto nla_put_failure;
13880
Michal Kubecekae0be8d2019-04-26 11:13:06 +020013881 ftm_stats_attr = nla_nest_start_noflag(msg,
13882 NL80211_ATTR_FTM_RESPONDER_STATS);
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070013883 if (!ftm_stats_attr)
13884 goto nla_put_failure;
13885
13886#define SET_FTM(field, name, type) \
13887 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13888 nla_put_ ## type(msg, NL80211_FTM_STATS_ ## name, \
13889 ftm_stats.field)) \
13890 goto nla_put_failure; } while (0)
13891#define SET_FTM_U64(field, name) \
13892 do { if ((ftm_stats.filled & BIT(NL80211_FTM_STATS_ ## name)) && \
13893 nla_put_u64_64bit(msg, NL80211_FTM_STATS_ ## name, \
13894 ftm_stats.field, NL80211_FTM_STATS_PAD)) \
13895 goto nla_put_failure; } while (0)
13896
13897 SET_FTM(success_num, SUCCESS_NUM, u32);
13898 SET_FTM(partial_num, PARTIAL_NUM, u32);
13899 SET_FTM(failed_num, FAILED_NUM, u32);
13900 SET_FTM(asap_num, ASAP_NUM, u32);
13901 SET_FTM(non_asap_num, NON_ASAP_NUM, u32);
13902 SET_FTM_U64(total_duration_ms, TOTAL_DURATION_MSEC);
13903 SET_FTM(unknown_triggers_num, UNKNOWN_TRIGGERS_NUM, u32);
13904 SET_FTM(reschedule_requests_num, RESCHEDULE_REQUESTS_NUM, u32);
13905 SET_FTM(out_of_window_triggers_num, OUT_OF_WINDOW_TRIGGERS_NUM, u32);
13906#undef SET_FTM
13907
13908 nla_nest_end(msg, ftm_stats_attr);
13909
13910 genlmsg_end(msg, hdr);
13911 return genlmsg_reply(msg, info);
13912
13913nla_put_failure:
13914 nlmsg_free(msg);
13915 return -ENOBUFS;
13916}
13917
Sunil Duttcb74e972019-02-20 16:18:07 +053013918static int nl80211_update_owe_info(struct sk_buff *skb, struct genl_info *info)
13919{
13920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13921 struct cfg80211_update_owe_info owe_info;
13922 struct net_device *dev = info->user_ptr[1];
13923
13924 if (!rdev->ops->update_owe_info)
13925 return -EOPNOTSUPP;
13926
13927 if (!info->attrs[NL80211_ATTR_STATUS_CODE] ||
13928 !info->attrs[NL80211_ATTR_MAC])
13929 return -EINVAL;
13930
13931 memset(&owe_info, 0, sizeof(owe_info));
13932 owe_info.status = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
13933 nla_memcpy(owe_info.peer, info->attrs[NL80211_ATTR_MAC], ETH_ALEN);
13934
13935 if (info->attrs[NL80211_ATTR_IE]) {
13936 owe_info.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
13937 owe_info.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
13938 }
13939
13940 return rdev_update_owe_info(rdev, dev, &owe_info);
13941}
13942
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070013943static int nl80211_probe_mesh_link(struct sk_buff *skb, struct genl_info *info)
13944{
13945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
13946 struct net_device *dev = info->user_ptr[1];
13947 struct wireless_dev *wdev = dev->ieee80211_ptr;
13948 struct station_info sinfo = {};
13949 const u8 *buf;
13950 size_t len;
13951 u8 *dest;
13952 int err;
13953
13954 if (!rdev->ops->probe_mesh_link || !rdev->ops->get_station)
13955 return -EOPNOTSUPP;
13956
13957 if (!info->attrs[NL80211_ATTR_MAC] ||
13958 !info->attrs[NL80211_ATTR_FRAME]) {
13959 GENL_SET_ERR_MSG(info, "Frame or MAC missing");
13960 return -EINVAL;
13961 }
13962
13963 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
13964 return -EOPNOTSUPP;
13965
13966 dest = nla_data(info->attrs[NL80211_ATTR_MAC]);
13967 buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
13968 len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
13969
13970 if (len < sizeof(struct ethhdr))
13971 return -EINVAL;
13972
13973 if (!ether_addr_equal(buf, dest) || is_multicast_ether_addr(buf) ||
13974 !ether_addr_equal(buf + ETH_ALEN, dev->dev_addr))
13975 return -EINVAL;
13976
13977 err = rdev_get_station(rdev, dev, dest, &sinfo);
13978 if (err)
13979 return err;
13980
Felix Fietkau2a279b342020-01-08 18:06:29 +010013981 cfg80211_sinfo_release_content(&sinfo);
13982
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070013983 return rdev_probe_mesh_link(rdev, dev, dest, buf, len);
13984}
13985
Tamizh chelvam77f576d2020-01-20 13:21:22 +053013986static int parse_tid_conf(struct cfg80211_registered_device *rdev,
13987 struct nlattr *attrs[], struct net_device *dev,
Johannes Berg3710a8a2020-02-24 11:34:25 +010013988 struct cfg80211_tid_cfg *tid_conf,
Tamizh chelvam77f576d2020-01-20 13:21:22 +053013989 struct genl_info *info, const u8 *peer)
13990{
13991 struct netlink_ext_ack *extack = info->extack;
Johannes Berg3710a8a2020-02-24 11:34:25 +010013992 u64 mask;
Tamizh chelvam77f576d2020-01-20 13:21:22 +053013993 int err;
13994
13995 if (!attrs[NL80211_TID_CONFIG_ATTR_TIDS])
13996 return -EINVAL;
13997
13998 tid_conf->config_override =
13999 nla_get_flag(attrs[NL80211_TID_CONFIG_ATTR_OVERRIDE]);
Johannes Berg3710a8a2020-02-24 11:34:25 +010014000 tid_conf->tids = nla_get_u16(attrs[NL80211_TID_CONFIG_ATTR_TIDS]);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014001
14002 if (tid_conf->config_override) {
14003 if (rdev->ops->reset_tid_config) {
14004 err = rdev_reset_tid_config(rdev, dev, peer,
Johannes Berg3710a8a2020-02-24 11:34:25 +010014005 tid_conf->tids);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014006 /* If peer is there no other configuration will be
14007 * allowed
14008 */
14009 if (err || peer)
14010 return err;
14011 } else {
14012 return -EINVAL;
14013 }
14014 }
14015
14016 if (attrs[NL80211_TID_CONFIG_ATTR_NOACK]) {
Johannes Berg3710a8a2020-02-24 11:34:25 +010014017 tid_conf->mask |= BIT(NL80211_TID_CONFIG_ATTR_NOACK);
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014018 tid_conf->noack =
14019 nla_get_u8(attrs[NL80211_TID_CONFIG_ATTR_NOACK]);
14020 }
14021
Johannes Berg3710a8a2020-02-24 11:34:25 +010014022 if (peer)
14023 mask = rdev->wiphy.tid_config_support.peer;
14024 else
14025 mask = rdev->wiphy.tid_config_support.vif;
14026
14027 if (tid_conf->mask & ~mask) {
14028 NL_SET_ERR_MSG(extack, "unsupported TID configuration");
14029 return -ENOTSUPP;
14030 }
14031
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014032 return 0;
14033}
14034
14035static int nl80211_set_tid_config(struct sk_buff *skb,
14036 struct genl_info *info)
14037{
14038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
14039 struct nlattr *attrs[NL80211_TID_CONFIG_ATTR_MAX + 1];
14040 struct net_device *dev = info->user_ptr[1];
Johannes Berg3710a8a2020-02-24 11:34:25 +010014041 struct cfg80211_tid_config *tid_config;
Tamizh chelvam77f576d2020-01-20 13:21:22 +053014042 struct nlattr *tid;
14043 int conf_idx = 0, rem_conf;
14044 int ret = -EINVAL;
14045 u32 num_conf = 0;
14046
14047 if (!info->attrs[NL80211_ATTR_TID_CONFIG])
14048 return -EINVAL;
14049
14050 if (!rdev->ops->set_tid_config)
14051 return -EOPNOTSUPP;
14052
14053 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14054 rem_conf)
14055 num_conf++;
14056
14057 tid_config = kzalloc(struct_size(tid_config, tid_conf, num_conf),
14058 GFP_KERNEL);
14059 if (!tid_config)
14060 return -ENOMEM;
14061
14062 tid_config->n_tid_conf = num_conf;
14063
14064 if (info->attrs[NL80211_ATTR_MAC])
14065 tid_config->peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
14066
14067 nla_for_each_nested(tid, info->attrs[NL80211_ATTR_TID_CONFIG],
14068 rem_conf) {
14069 ret = nla_parse_nested(attrs, NL80211_TID_CONFIG_ATTR_MAX,
14070 tid, NULL, NULL);
14071
14072 if (ret)
14073 goto bad_tid_conf;
14074
14075 ret = parse_tid_conf(rdev, attrs, dev,
14076 &tid_config->tid_conf[conf_idx],
14077 info, tid_config->peer);
14078 if (ret)
14079 goto bad_tid_conf;
14080
14081 conf_idx++;
14082 }
14083
14084 ret = rdev_set_tid_config(rdev, dev, tid_config);
14085
14086bad_tid_conf:
14087 kfree(tid_config);
14088 return ret;
14089}
14090
Johannes Berg4c476992010-10-04 21:36:35 +020014091#define NL80211_FLAG_NEED_WIPHY 0x01
14092#define NL80211_FLAG_NEED_NETDEV 0x02
14093#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020014094#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
14095#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
14096 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020014097#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020014098/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020014099#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
14100 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030014101#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020014102
Johannes Bergf84f7712013-11-14 17:14:45 +010014103static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020014104 struct genl_info *info)
14105{
14106 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020014107 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020014108 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020014109 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
14110
14111 if (rtnl)
14112 rtnl_lock();
14113
14114 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020014115 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020014116 if (IS_ERR(rdev)) {
14117 if (rtnl)
14118 rtnl_unlock();
14119 return PTR_ERR(rdev);
14120 }
14121 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020014122 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
14123 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020014124 ASSERT_RTNL();
14125
Johannes Berg89a54e42012-06-15 14:33:17 +020014126 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
14127 info->attrs);
14128 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020014129 if (rtnl)
14130 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020014131 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020014132 }
Johannes Berg89a54e42012-06-15 14:33:17 +020014133
Johannes Berg89a54e42012-06-15 14:33:17 +020014134 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080014135 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020014136
Johannes Berg1bf614e2012-06-15 15:23:36 +020014137 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
14138 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020014139 if (rtnl)
14140 rtnl_unlock();
14141 return -EINVAL;
14142 }
14143
14144 info->user_ptr[1] = dev;
14145 } else {
14146 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020014147 }
Johannes Berg89a54e42012-06-15 14:33:17 +020014148
Arend Van Spriel73c7da32016-10-20 20:08:22 +010014149 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
14150 !wdev_running(wdev)) {
14151 if (rtnl)
14152 rtnl_unlock();
14153 return -ENETDOWN;
Johannes Berg1bf614e2012-06-15 15:23:36 +020014154 }
14155
Arend Van Spriel73c7da32016-10-20 20:08:22 +010014156 if (dev)
14157 dev_hold(dev);
14158
Johannes Berg4c476992010-10-04 21:36:35 +020014159 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020014160 }
14161
14162 return 0;
14163}
14164
Johannes Bergf84f7712013-11-14 17:14:45 +010014165static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020014166 struct genl_info *info)
14167{
Johannes Berg1bf614e2012-06-15 15:23:36 +020014168 if (info->user_ptr[1]) {
14169 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
14170 struct wireless_dev *wdev = info->user_ptr[1];
14171
14172 if (wdev->netdev)
14173 dev_put(wdev->netdev);
14174 } else {
14175 dev_put(info->user_ptr[1]);
14176 }
14177 }
Johannes Berg5393b912014-09-10 15:00:16 +030014178
Johannes Berg4c476992010-10-04 21:36:35 +020014179 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
14180 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030014181
14182 /* If needed, clear the netlink message payload from the SKB
14183 * as it might contain key data that shouldn't stick around on
14184 * the heap after the SKB is freed. The netlink message header
14185 * is still needed for further processing, so leave it intact.
14186 */
14187 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
14188 struct nlmsghdr *nlh = nlmsg_hdr(skb);
14189
14190 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
14191 }
Johannes Berg4c476992010-10-04 21:36:35 +020014192}
14193
Johannes Berg4534de82013-11-14 17:14:46 +010014194static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040014195 {
14196 .cmd = NL80211_CMD_GET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014197 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014198 .doit = nl80211_get_wiphy,
14199 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020014200 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040014201 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020014202 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14203 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014204 },
14205 {
14206 .cmd = NL80211_CMD_SET_WIPHY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014207 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014208 .doit = nl80211_set_wiphy,
Martin Willi5617c6c2016-05-09 18:33:58 +020014209 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014210 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014211 },
14212 {
14213 .cmd = NL80211_CMD_GET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014214 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014215 .doit = nl80211_get_interface,
14216 .dumpit = nl80211_dump_interface,
Johannes Berg55682962007-09-20 13:09:35 -040014217 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020014218 .internal_flags = NL80211_FLAG_NEED_WDEV |
14219 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014220 },
14221 {
14222 .cmd = NL80211_CMD_SET_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014223 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014224 .doit = nl80211_set_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014225 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014226 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14227 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014228 },
14229 {
14230 .cmd = NL80211_CMD_NEW_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014231 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014232 .doit = nl80211_new_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014233 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014234 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14235 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014236 },
14237 {
14238 .cmd = NL80211_CMD_DEL_INTERFACE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014239 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg55682962007-09-20 13:09:35 -040014240 .doit = nl80211_del_interface,
Martin Willi5617c6c2016-05-09 18:33:58 +020014241 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020014242 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014243 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040014244 },
Johannes Berg41ade002007-12-19 02:03:29 +010014245 {
14246 .cmd = NL80211_CMD_GET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014247 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014248 .doit = nl80211_get_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014249 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014250 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014251 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010014252 },
14253 {
14254 .cmd = NL80211_CMD_SET_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014255 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014256 .doit = nl80211_set_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014257 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014258 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014259 NL80211_FLAG_NEED_RTNL |
14260 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010014261 },
14262 {
14263 .cmd = NL80211_CMD_NEW_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014264 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014265 .doit = nl80211_new_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014266 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014267 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014268 NL80211_FLAG_NEED_RTNL |
14269 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010014270 },
14271 {
14272 .cmd = NL80211_CMD_DEL_KEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014273 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg41ade002007-12-19 02:03:29 +010014274 .doit = nl80211_del_key,
Martin Willi5617c6c2016-05-09 18:33:58 +020014275 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014276 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014277 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010014278 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010014279 {
14280 .cmd = NL80211_CMD_SET_BEACON,
Johannes Bergef6243a2019-04-26 14:07:31 +020014281 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014282 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014283 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014284 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014285 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014286 },
14287 {
Johannes Berg88600202012-02-13 15:17:18 +010014288 .cmd = NL80211_CMD_START_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014289 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014290 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014291 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014292 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014293 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014294 },
14295 {
Johannes Berg88600202012-02-13 15:17:18 +010014296 .cmd = NL80211_CMD_STOP_AP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014297 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Martin Willi5617c6c2016-05-09 18:33:58 +020014298 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010014299 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014300 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014301 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010014302 },
Johannes Berg5727ef12007-12-19 02:03:34 +010014303 {
14304 .cmd = NL80211_CMD_GET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014305 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014306 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014307 .dumpit = nl80211_dump_station,
Johannes Berg4c476992010-10-04 21:36:35 +020014308 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14309 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014310 },
14311 {
14312 .cmd = NL80211_CMD_SET_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014313 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014314 .doit = nl80211_set_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014315 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014317 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014318 },
14319 {
14320 .cmd = NL80211_CMD_NEW_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014321 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014322 .doit = nl80211_new_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014323 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014324 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014325 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014326 },
14327 {
14328 .cmd = NL80211_CMD_DEL_STATION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014329 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5727ef12007-12-19 02:03:34 +010014330 .doit = nl80211_del_station,
Martin Willi5617c6c2016-05-09 18:33:58 +020014331 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014332 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014333 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010014334 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014335 {
14336 .cmd = NL80211_CMD_GET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014337 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014338 .doit = nl80211_get_mpath,
14339 .dumpit = nl80211_dump_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014340 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014341 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014342 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014343 },
14344 {
Henning Rogge66be7d22014-09-12 08:58:49 +020014345 .cmd = NL80211_CMD_GET_MPP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014346 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Henning Rogge66be7d22014-09-12 08:58:49 +020014347 .doit = nl80211_get_mpp,
14348 .dumpit = nl80211_dump_mpp,
Martin Willi5617c6c2016-05-09 18:33:58 +020014349 .flags = GENL_UNS_ADMIN_PERM,
Henning Rogge66be7d22014-09-12 08:58:49 +020014350 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14351 NL80211_FLAG_NEED_RTNL,
14352 },
14353 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014354 .cmd = NL80211_CMD_SET_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014355 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014356 .doit = nl80211_set_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014357 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014358 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014359 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014360 },
14361 {
14362 .cmd = NL80211_CMD_NEW_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014363 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014364 .doit = nl80211_new_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014365 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014366 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014367 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014368 },
14369 {
14370 .cmd = NL80211_CMD_DEL_MPATH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014371 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014372 .doit = nl80211_del_mpath,
Martin Willi5617c6c2016-05-09 18:33:58 +020014373 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014374 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014375 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010014376 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014377 {
14378 .cmd = NL80211_CMD_SET_BSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014379 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014380 .doit = nl80211_set_bss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014381 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014382 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014383 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030014384 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014385 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014386 .cmd = NL80211_CMD_GET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014387 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020014388 .doit = nl80211_get_reg_do,
14389 .dumpit = nl80211_get_reg_dump,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014390 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014391 /* can be retrieved by unprivileged users */
14392 },
Johannes Bergb6863032015-10-15 09:25:18 +020014393#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080014394 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014395 .cmd = NL80211_CMD_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014396 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014397 .doit = nl80211_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014398 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020014399 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014400 },
Johannes Bergb6863032015-10-15 09:25:18 +020014401#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014402 {
14403 .cmd = NL80211_CMD_REQ_SET_REG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014404 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014405 .doit = nl80211_req_set_reg,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070014406 .flags = GENL_ADMIN_PERM,
14407 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014408 {
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014409 .cmd = NL80211_CMD_RELOAD_REGDB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014410 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014411 .doit = nl80211_reload_regdb,
Johannes Berg1ea4ff3e92017-09-13 16:07:22 +020014412 .flags = GENL_ADMIN_PERM,
14413 },
14414 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014415 .cmd = NL80211_CMD_GET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014416 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014417 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014418 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014420 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014421 },
14422 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014423 .cmd = NL80211_CMD_SET_MESH_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014424 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Javier Cardona24bdd9f2010-12-16 17:37:48 -080014425 .doit = nl80211_update_mesh_config,
Martin Willi5617c6c2016-05-09 18:33:58 +020014426 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014428 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070014429 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020014430 {
Johannes Berg2a519312009-02-10 21:25:55 +010014431 .cmd = NL80211_CMD_TRIGGER_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014432 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014433 .doit = nl80211_trigger_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014434 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020014435 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014436 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010014437 },
14438 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014439 .cmd = NL80211_CMD_ABORT_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014440 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014441 .doit = nl80211_abort_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014442 .flags = GENL_UNS_ADMIN_PERM,
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053014443 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14444 NL80211_FLAG_NEED_RTNL,
14445 },
14446 {
Johannes Berg2a519312009-02-10 21:25:55 +010014447 .cmd = NL80211_CMD_GET_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014448 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2a519312009-02-10 21:25:55 +010014449 .dumpit = nl80211_dump_scan,
14450 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020014451 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030014452 .cmd = NL80211_CMD_START_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014453 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014454 .doit = nl80211_start_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014455 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014456 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14457 NL80211_FLAG_NEED_RTNL,
14458 },
14459 {
14460 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014461 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014462 .doit = nl80211_stop_sched_scan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014463 .flags = GENL_UNS_ADMIN_PERM,
Luciano Coelho807f8a82011-05-11 17:09:35 +030014464 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14465 NL80211_FLAG_NEED_RTNL,
14466 },
14467 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020014468 .cmd = NL80211_CMD_AUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014469 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014470 .doit = nl80211_authenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014471 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014472 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014473 NL80211_FLAG_NEED_RTNL |
14474 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014475 },
14476 {
14477 .cmd = NL80211_CMD_ASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014478 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014479 .doit = nl80211_associate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014480 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014481 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014482 NL80211_FLAG_NEED_RTNL |
14483 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014484 },
14485 {
14486 .cmd = NL80211_CMD_DEAUTHENTICATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014487 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014488 .doit = nl80211_deauthenticate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014489 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014490 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014491 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014492 },
14493 {
14494 .cmd = NL80211_CMD_DISASSOCIATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014495 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014496 .doit = nl80211_disassociate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014497 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014498 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014499 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020014500 },
Johannes Berg04a773a2009-04-19 21:24:32 +020014501 {
14502 .cmd = NL80211_CMD_JOIN_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014503 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014504 .doit = nl80211_join_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014505 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014506 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014507 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014508 },
14509 {
14510 .cmd = NL80211_CMD_LEAVE_IBSS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014511 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg04a773a2009-04-19 21:24:32 +020014512 .doit = nl80211_leave_ibss,
Martin Willi5617c6c2016-05-09 18:33:58 +020014513 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014514 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014515 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020014516 },
Johannes Bergaff89a92009-07-01 21:26:51 +020014517#ifdef CONFIG_NL80211_TESTMODE
14518 {
14519 .cmd = NL80211_CMD_TESTMODE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014520 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergaff89a92009-07-01 21:26:51 +020014521 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070014522 .dumpit = nl80211_testmode_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014523 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014524 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14525 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020014526 },
14527#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020014528 {
14529 .cmd = NL80211_CMD_CONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014530 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014531 .doit = nl80211_connect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014532 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014533 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014534 NL80211_FLAG_NEED_RTNL |
14535 NL80211_FLAG_CLEAR_SKB,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014536 },
14537 {
vamsi krishna088e8df2016-10-27 16:51:11 +030014538 .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014539 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
vamsi krishna088e8df2016-10-27 16:51:11 +030014540 .doit = nl80211_update_connect_params,
vamsi krishna088e8df2016-10-27 16:51:11 +030014541 .flags = GENL_ADMIN_PERM,
14542 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014543 NL80211_FLAG_NEED_RTNL |
14544 NL80211_FLAG_CLEAR_SKB,
vamsi krishna088e8df2016-10-27 16:51:11 +030014545 },
14546 {
Samuel Ortizb23aa672009-07-01 21:26:54 +020014547 .cmd = NL80211_CMD_DISCONNECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014548 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014549 .doit = nl80211_disconnect,
Martin Willi5617c6c2016-05-09 18:33:58 +020014550 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020014551 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014552 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020014553 },
Johannes Berg463d0182009-07-14 00:33:35 +020014554 {
14555 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014556 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg463d0182009-07-14 00:33:35 +020014557 .doit = nl80211_wiphy_netns,
Martin Willi5617c6c2016-05-09 18:33:58 +020014558 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014559 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14560 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020014561 },
Holger Schurig61fa7132009-11-11 12:25:40 +010014562 {
14563 .cmd = NL80211_CMD_GET_SURVEY,
Johannes Bergef6243a2019-04-26 14:07:31 +020014564 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Holger Schurig61fa7132009-11-11 12:25:40 +010014565 .dumpit = nl80211_dump_survey,
14566 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014567 {
14568 .cmd = NL80211_CMD_SET_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014569 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014570 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014571 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014572 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014573 NL80211_FLAG_NEED_RTNL |
14574 NL80211_FLAG_CLEAR_SKB,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014575 },
14576 {
14577 .cmd = NL80211_CMD_DEL_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014578 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014579 .doit = nl80211_setdel_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014580 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014582 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014583 },
14584 {
14585 .cmd = NL80211_CMD_FLUSH_PMKSA,
Johannes Bergef6243a2019-04-26 14:07:31 +020014586 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014587 .doit = nl80211_flush_pmksa,
Martin Willi5617c6c2016-05-09 18:33:58 +020014588 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014590 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010014591 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014592 {
14593 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014594 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014595 .doit = nl80211_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014596 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014597 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014598 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014599 },
14600 {
14601 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014602 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014603 .doit = nl80211_cancel_remain_on_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014604 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014605 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014606 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010014607 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014608 {
14609 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014610 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014611 .doit = nl80211_set_tx_bitrate_mask,
Martin Willi5617c6c2016-05-09 18:33:58 +020014612 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014613 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14614 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020014615 },
Jouni Malinen026331c2010-02-15 12:53:10 +020014616 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014617 .cmd = NL80211_CMD_REGISTER_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014618 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014619 .doit = nl80211_register_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014620 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014621 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020014622 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014623 },
14624 {
Johannes Berg2e161f782010-08-12 15:38:38 +020014625 .cmd = NL80211_CMD_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014626 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg2e161f782010-08-12 15:38:38 +020014627 .doit = nl80211_tx_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014628 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014629 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020014630 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020014631 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020014632 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014633 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014634 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014635 .doit = nl80211_tx_mgmt_cancel_wait,
Martin Willi5617c6c2016-05-09 18:33:58 +020014636 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020014637 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010014638 NL80211_FLAG_NEED_RTNL,
14639 },
14640 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020014641 .cmd = NL80211_CMD_SET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014642 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014643 .doit = nl80211_set_power_save,
Martin Willi5617c6c2016-05-09 18:33:58 +020014644 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014645 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14646 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014647 },
14648 {
14649 .cmd = NL80211_CMD_GET_POWER_SAVE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014650 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014651 .doit = nl80211_get_power_save,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014652 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020014653 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14654 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020014655 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014656 {
14657 .cmd = NL80211_CMD_SET_CQM,
Johannes Bergef6243a2019-04-26 14:07:31 +020014658 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014659 .doit = nl80211_set_cqm,
Martin Willi5617c6c2016-05-09 18:33:58 +020014660 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014661 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14662 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020014663 },
Johannes Bergf444de02010-05-05 15:25:02 +020014664 {
14665 .cmd = NL80211_CMD_SET_CHANNEL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014666 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergf444de02010-05-05 15:25:02 +020014667 .doit = nl80211_set_channel,
Martin Willi5617c6c2016-05-09 18:33:58 +020014668 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020014669 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14670 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020014671 },
Bill Jordane8347eb2010-10-01 13:54:28 -040014672 {
14673 .cmd = NL80211_CMD_SET_WDS_PEER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014674 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Bill Jordane8347eb2010-10-01 13:54:28 -040014675 .doit = nl80211_set_wds_peer,
Martin Willi5617c6c2016-05-09 18:33:58 +020014676 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020014677 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14678 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040014679 },
Johannes Berg29cbe682010-12-03 09:20:44 +010014680 {
14681 .cmd = NL80211_CMD_JOIN_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014682 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014683 .doit = nl80211_join_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014684 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014685 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14686 NL80211_FLAG_NEED_RTNL,
14687 },
14688 {
14689 .cmd = NL80211_CMD_LEAVE_MESH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014690 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg29cbe682010-12-03 09:20:44 +010014691 .doit = nl80211_leave_mesh,
Martin Willi5617c6c2016-05-09 18:33:58 +020014692 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010014693 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14694 NL80211_FLAG_NEED_RTNL,
14695 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014696 {
14697 .cmd = NL80211_CMD_JOIN_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014698 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014699 .doit = nl80211_join_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014700 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014701 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14702 NL80211_FLAG_NEED_RTNL,
14703 },
14704 {
14705 .cmd = NL80211_CMD_LEAVE_OCB,
Johannes Bergef6243a2019-04-26 14:07:31 +020014706 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014707 .doit = nl80211_leave_ocb,
Martin Willi5617c6c2016-05-09 18:33:58 +020014708 .flags = GENL_UNS_ADMIN_PERM,
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010014709 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14710 NL80211_FLAG_NEED_RTNL,
14711 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014712#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020014713 {
14714 .cmd = NL80211_CMD_GET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014715 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014716 .doit = nl80211_get_wowlan,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014717 /* can be retrieved by unprivileged users */
14718 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14719 NL80211_FLAG_NEED_RTNL,
14720 },
14721 {
14722 .cmd = NL80211_CMD_SET_WOWLAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014723 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014724 .doit = nl80211_set_wowlan,
Martin Willi5617c6c2016-05-09 18:33:58 +020014725 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergff1b6e62011-05-04 15:37:28 +020014726 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14727 NL80211_FLAG_NEED_RTNL,
14728 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020014729#endif
Johannes Berge5497d72011-07-05 16:35:40 +020014730 {
14731 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
Johannes Bergef6243a2019-04-26 14:07:31 +020014732 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berge5497d72011-07-05 16:35:40 +020014733 .doit = nl80211_set_rekey_data,
Martin Willi5617c6c2016-05-09 18:33:58 +020014734 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berge5497d72011-07-05 16:35:40 +020014735 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030014736 NL80211_FLAG_NEED_RTNL |
14737 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020014738 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030014739 {
14740 .cmd = NL80211_CMD_TDLS_MGMT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014741 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014742 .doit = nl80211_tdls_mgmt,
Martin Willi5617c6c2016-05-09 18:33:58 +020014743 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014744 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14745 NL80211_FLAG_NEED_RTNL,
14746 },
14747 {
14748 .cmd = NL80211_CMD_TDLS_OPER,
Johannes Bergef6243a2019-04-26 14:07:31 +020014749 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014750 .doit = nl80211_tdls_oper,
Martin Willi5617c6c2016-05-09 18:33:58 +020014751 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov109086c2011-09-28 14:12:50 +030014752 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14753 NL80211_FLAG_NEED_RTNL,
14754 },
Johannes Berg28946da2011-11-04 11:18:12 +010014755 {
14756 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020014757 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg28946da2011-11-04 11:18:12 +010014758 .doit = nl80211_register_unexpected_frame,
Martin Willi5617c6c2016-05-09 18:33:58 +020014759 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg28946da2011-11-04 11:18:12 +010014760 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14761 NL80211_FLAG_NEED_RTNL,
14762 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010014763 {
14764 .cmd = NL80211_CMD_PROBE_CLIENT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014765 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg7f6cf312011-11-04 11:18:15 +010014766 .doit = nl80211_probe_client,
Martin Willi5617c6c2016-05-09 18:33:58 +020014767 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020014768 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010014769 NL80211_FLAG_NEED_RTNL,
14770 },
Johannes Berg5e760232011-11-04 11:18:17 +010014771 {
14772 .cmd = NL80211_CMD_REGISTER_BEACONS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014773 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg5e760232011-11-04 11:18:17 +010014774 .doit = nl80211_register_beacons,
Martin Willi5617c6c2016-05-09 18:33:58 +020014775 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg5e760232011-11-04 11:18:17 +010014776 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14777 NL80211_FLAG_NEED_RTNL,
14778 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014779 {
14780 .cmd = NL80211_CMD_SET_NOACK_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014781 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014782 .doit = nl80211_set_noack_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014783 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010014784 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14785 NL80211_FLAG_NEED_RTNL,
14786 },
Johannes Berg98104fde2012-06-16 00:19:54 +020014787 {
14788 .cmd = NL80211_CMD_START_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014789 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014790 .doit = nl80211_start_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014791 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014792 .internal_flags = NL80211_FLAG_NEED_WDEV |
14793 NL80211_FLAG_NEED_RTNL,
14794 },
14795 {
14796 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014797 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg98104fde2012-06-16 00:19:54 +020014798 .doit = nl80211_stop_p2p_device,
Martin Willi5617c6c2016-05-09 18:33:58 +020014799 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg98104fde2012-06-16 00:19:54 +020014800 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14801 NL80211_FLAG_NEED_RTNL,
14802 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014803 {
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014804 .cmd = NL80211_CMD_START_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014805 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014806 .doit = nl80211_start_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014807 .flags = GENL_ADMIN_PERM,
14808 .internal_flags = NL80211_FLAG_NEED_WDEV |
14809 NL80211_FLAG_NEED_RTNL,
14810 },
14811 {
14812 .cmd = NL80211_CMD_STOP_NAN,
Johannes Bergef6243a2019-04-26 14:07:31 +020014813 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014814 .doit = nl80211_stop_nan,
Ayala Bekercb3b7d82016-09-20 17:31:13 +030014815 .flags = GENL_ADMIN_PERM,
14816 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14817 NL80211_FLAG_NEED_RTNL,
14818 },
14819 {
Ayala Bekera442b762016-09-20 17:31:15 +030014820 .cmd = NL80211_CMD_ADD_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014821 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014822 .doit = nl80211_nan_add_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014823 .flags = GENL_ADMIN_PERM,
14824 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14825 NL80211_FLAG_NEED_RTNL,
14826 },
14827 {
14828 .cmd = NL80211_CMD_DEL_NAN_FUNCTION,
Johannes Bergef6243a2019-04-26 14:07:31 +020014829 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera442b762016-09-20 17:31:15 +030014830 .doit = nl80211_nan_del_func,
Ayala Bekera442b762016-09-20 17:31:15 +030014831 .flags = GENL_ADMIN_PERM,
14832 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14833 NL80211_FLAG_NEED_RTNL,
14834 },
14835 {
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014836 .cmd = NL80211_CMD_CHANGE_NAN_CONFIG,
Johannes Bergef6243a2019-04-26 14:07:31 +020014837 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014838 .doit = nl80211_nan_change_config,
Ayala Bekera5a9dcf2016-09-20 17:31:16 +030014839 .flags = GENL_ADMIN_PERM,
14840 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14841 NL80211_FLAG_NEED_RTNL,
14842 },
14843 {
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014844 .cmd = NL80211_CMD_SET_MCAST_RATE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014845 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014846 .doit = nl80211_set_mcast_rate,
Martin Willi5617c6c2016-05-09 18:33:58 +020014847 .flags = GENL_UNS_ADMIN_PERM,
Antonio Quartullif4e583c2012-11-02 13:27:48 +010014848 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14849 NL80211_FLAG_NEED_RTNL,
14850 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014851 {
14852 .cmd = NL80211_CMD_SET_MAC_ACL,
Johannes Bergef6243a2019-04-26 14:07:31 +020014853 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014854 .doit = nl80211_set_mac_acl,
Martin Willi5617c6c2016-05-09 18:33:58 +020014855 .flags = GENL_UNS_ADMIN_PERM,
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053014856 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14857 NL80211_FLAG_NEED_RTNL,
14858 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010014859 {
14860 .cmd = NL80211_CMD_RADAR_DETECT,
Johannes Bergef6243a2019-04-26 14:07:31 +020014861 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014862 .doit = nl80211_start_radar_detection,
Martin Willi5617c6c2016-05-09 18:33:58 +020014863 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich04f39042013-02-08 18:16:19 +010014864 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14865 NL80211_FLAG_NEED_RTNL,
14866 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010014867 {
14868 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014869 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014870 .doit = nl80211_get_protocol_features,
Johannes Berg3713b4e2013-02-14 16:19:38 +010014871 },
Jouni Malinen355199e2013-02-27 17:14:27 +020014872 {
14873 .cmd = NL80211_CMD_UPDATE_FT_IES,
Johannes Bergef6243a2019-04-26 14:07:31 +020014874 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Jouni Malinen355199e2013-02-27 17:14:27 +020014875 .doit = nl80211_update_ft_ies,
Martin Willi5617c6c2016-05-09 18:33:58 +020014876 .flags = GENL_UNS_ADMIN_PERM,
Jouni Malinen355199e2013-02-27 17:14:27 +020014877 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14878 NL80211_FLAG_NEED_RTNL,
14879 },
Arend van Spriel5de17982013-04-18 15:49:00 +020014880 {
14881 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020014882 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014883 .doit = nl80211_crit_protocol_start,
Martin Willi5617c6c2016-05-09 18:33:58 +020014884 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014885 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14886 NL80211_FLAG_NEED_RTNL,
14887 },
14888 {
14889 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014890 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arend van Spriel5de17982013-04-18 15:49:00 +020014891 .doit = nl80211_crit_protocol_stop,
Martin Willi5617c6c2016-05-09 18:33:58 +020014892 .flags = GENL_UNS_ADMIN_PERM,
Arend van Spriel5de17982013-04-18 15:49:00 +020014893 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
14894 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014895 },
14896 {
14897 .cmd = NL80211_CMD_GET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014898 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014899 .doit = nl80211_get_coalesce,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014900 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14901 NL80211_FLAG_NEED_RTNL,
14902 },
14903 {
14904 .cmd = NL80211_CMD_SET_COALESCE,
Johannes Bergef6243a2019-04-26 14:07:31 +020014905 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014906 .doit = nl80211_set_coalesce,
Martin Willi5617c6c2016-05-09 18:33:58 +020014907 .flags = GENL_UNS_ADMIN_PERM,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070014908 .internal_flags = NL80211_FLAG_NEED_WIPHY |
14909 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014910 },
14911 {
14912 .cmd = NL80211_CMD_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014913 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014914 .doit = nl80211_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014915 .flags = GENL_UNS_ADMIN_PERM,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020014916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14917 NL80211_FLAG_NEED_RTNL,
14918 },
Johannes Bergad7e7182013-11-13 13:37:47 +010014919 {
14920 .cmd = NL80211_CMD_VENDOR,
Johannes Bergef6243a2019-04-26 14:07:31 +020014921 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Bergad7e7182013-11-13 13:37:47 +010014922 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030014923 .dumpit = nl80211_vendor_cmd_dump,
Martin Willi5617c6c2016-05-09 18:33:58 +020014924 .flags = GENL_UNS_ADMIN_PERM,
Johannes Bergad7e7182013-11-13 13:37:47 +010014925 .internal_flags = NL80211_FLAG_NEED_WIPHY |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014926 NL80211_FLAG_NEED_RTNL |
14927 NL80211_FLAG_CLEAR_SKB,
Johannes Bergad7e7182013-11-13 13:37:47 +010014928 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014929 {
14930 .cmd = NL80211_CMD_SET_QOS_MAP,
Johannes Bergef6243a2019-04-26 14:07:31 +020014931 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014932 .doit = nl80211_set_qos_map,
Martin Willi5617c6c2016-05-09 18:33:58 +020014933 .flags = GENL_UNS_ADMIN_PERM,
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080014934 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14935 NL80211_FLAG_NEED_RTNL,
14936 },
Johannes Berg960d01a2014-09-09 22:55:35 +030014937 {
14938 .cmd = NL80211_CMD_ADD_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014939 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014940 .doit = nl80211_add_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014941 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014942 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14943 NL80211_FLAG_NEED_RTNL,
14944 },
14945 {
14946 .cmd = NL80211_CMD_DEL_TX_TS,
Johannes Bergef6243a2019-04-26 14:07:31 +020014947 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg960d01a2014-09-09 22:55:35 +030014948 .doit = nl80211_del_tx_ts,
Martin Willi5617c6c2016-05-09 18:33:58 +020014949 .flags = GENL_UNS_ADMIN_PERM,
Johannes Berg960d01a2014-09-09 22:55:35 +030014950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14951 NL80211_FLAG_NEED_RTNL,
14952 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020014953 {
14954 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014955 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014956 .doit = nl80211_tdls_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014957 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014958 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14959 NL80211_FLAG_NEED_RTNL,
14960 },
14961 {
14962 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014963 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014964 .doit = nl80211_tdls_cancel_channel_switch,
Martin Willi5617c6c2016-05-09 18:33:58 +020014965 .flags = GENL_UNS_ADMIN_PERM,
Arik Nemtsov1057d352014-11-19 12:54:26 +020014966 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14967 NL80211_FLAG_NEED_RTNL,
14968 },
Michael Braunce0ce132016-10-10 19:12:22 +020014969 {
14970 .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST,
Johannes Bergef6243a2019-04-26 14:07:31 +020014971 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Michael Braunce0ce132016-10-10 19:12:22 +020014972 .doit = nl80211_set_multicast_to_unicast,
Michael Braunce0ce132016-10-10 19:12:22 +020014973 .flags = GENL_UNS_ADMIN_PERM,
14974 .internal_flags = NL80211_FLAG_NEED_NETDEV |
14975 NL80211_FLAG_NEED_RTNL,
14976 },
Avraham Stern3a00df52017-06-09 13:08:43 +010014977 {
14978 .cmd = NL80211_CMD_SET_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014979 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014980 .doit = nl80211_set_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014981 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Sunil Duttd6db02a2019-02-25 15:37:20 +053014982 NL80211_FLAG_NEED_RTNL |
14983 NL80211_FLAG_CLEAR_SKB,
Avraham Stern3a00df52017-06-09 13:08:43 +010014984 },
14985 {
14986 .cmd = NL80211_CMD_DEL_PMK,
Johannes Bergef6243a2019-04-26 14:07:31 +020014987 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Avraham Stern3a00df52017-06-09 13:08:43 +010014988 .doit = nl80211_del_pmk,
Avraham Stern3a00df52017-06-09 13:08:43 +010014989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14990 NL80211_FLAG_NEED_RTNL,
14991 },
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014992 {
14993 .cmd = NL80211_CMD_EXTERNAL_AUTH,
Johannes Bergef6243a2019-04-26 14:07:31 +020014994 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014995 .doit = nl80211_external_auth,
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020014996 .flags = GENL_ADMIN_PERM,
14997 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
14998 NL80211_FLAG_NEED_RTNL,
14999 },
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015000 {
15001 .cmd = NL80211_CMD_CONTROL_PORT_FRAME,
Johannes Bergef6243a2019-04-26 14:07:31 +020015002 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015003 .doit = nl80211_tx_control_port,
Denis Kenzior2576a9a2018-03-26 12:52:42 -050015004 .flags = GENL_UNS_ADMIN_PERM,
15005 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15006 NL80211_FLAG_NEED_RTNL,
15007 },
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015008 {
15009 .cmd = NL80211_CMD_GET_FTM_RESPONDER_STATS,
Johannes Bergef6243a2019-04-26 14:07:31 +020015010 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015011 .doit = nl80211_get_ftm_responder_stats,
Pradeep Kumar Chitrapu81e54d02018-09-20 17:30:09 -070015012 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15013 NL80211_FLAG_NEED_RTNL,
15014 },
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015015 {
15016 .cmd = NL80211_CMD_PEER_MEASUREMENT_START,
Johannes Bergef6243a2019-04-26 14:07:31 +020015017 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015018 .doit = nl80211_pmsr_start,
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020015019 .flags = GENL_UNS_ADMIN_PERM,
15020 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
15021 NL80211_FLAG_NEED_RTNL,
15022 },
Sriram R30c63112018-12-04 17:46:52 +053015023 {
15024 .cmd = NL80211_CMD_NOTIFY_RADAR,
Johannes Bergef6243a2019-04-26 14:07:31 +020015025 .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
Sriram R30c63112018-12-04 17:46:52 +053015026 .doit = nl80211_notify_radar_detection,
Sriram R30c63112018-12-04 17:46:52 +053015027 .flags = GENL_UNS_ADMIN_PERM,
15028 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15029 NL80211_FLAG_NEED_RTNL,
15030 },
Sunil Duttcb74e972019-02-20 16:18:07 +053015031 {
15032 .cmd = NL80211_CMD_UPDATE_OWE_INFO,
15033 .doit = nl80211_update_owe_info,
15034 .flags = GENL_ADMIN_PERM,
15035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15036 NL80211_FLAG_NEED_RTNL,
15037 },
Rajkumar Manoharan5ab92e72019-04-11 13:47:24 -070015038 {
15039 .cmd = NL80211_CMD_PROBE_MESH_LINK,
15040 .doit = nl80211_probe_mesh_link,
15041 .flags = GENL_UNS_ADMIN_PERM,
15042 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
15043 NL80211_FLAG_NEED_RTNL,
15044 },
Tamizh chelvam77f576d2020-01-20 13:21:22 +053015045 {
15046 .cmd = NL80211_CMD_SET_TID_CONFIG,
15047 .doit = nl80211_set_tid_config,
15048 .flags = GENL_UNS_ADMIN_PERM,
15049 .internal_flags = NL80211_FLAG_NEED_NETDEV |
15050 NL80211_FLAG_NEED_RTNL,
15051 },
Johannes Berg55682962007-09-20 13:09:35 -040015052};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015053
Johannes Berg56989f62016-10-24 14:40:05 +020015054static struct genl_family nl80211_fam __ro_after_init = {
Johannes Berg489111e2016-10-24 14:40:03 +020015055 .name = NL80211_GENL_NAME, /* have users key off the name instead */
15056 .hdrsize = 0, /* no private header */
15057 .version = 1, /* no particular meaning now */
15058 .maxattr = NL80211_ATTR_MAX,
Johannes Berg3b0f31f2019-03-21 22:51:02 +010015059 .policy = nl80211_policy,
Johannes Berg489111e2016-10-24 14:40:03 +020015060 .netnsok = true,
15061 .pre_doit = nl80211_pre_doit,
15062 .post_doit = nl80211_post_doit,
15063 .module = THIS_MODULE,
15064 .ops = nl80211_ops,
15065 .n_ops = ARRAY_SIZE(nl80211_ops),
15066 .mcgrps = nl80211_mcgrps,
15067 .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps),
Johannes Berg50508d92019-07-29 16:31:09 +020015068 .parallel_ops = true,
Johannes Berg489111e2016-10-24 14:40:03 +020015069};
15070
Johannes Berg55682962007-09-20 13:09:35 -040015071/* notification functions */
15072
Johannes Berg3bb20552014-05-26 13:52:25 +020015073void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
15074 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040015075{
15076 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020015077 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040015078
Johannes Berg3bb20552014-05-26 13:52:25 +020015079 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
15080 cmd != NL80211_CMD_DEL_WIPHY);
15081
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015082 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040015083 if (!msg)
15084 return;
15085
Johannes Berg3bb20552014-05-26 13:52:25 +020015086 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040015087 nlmsg_free(msg);
15088 return;
15089 }
15090
Johannes Berg68eb5502013-11-19 15:19:38 +010015091 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015092 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040015093}
15094
Denis Kenzior896ff062016-08-03 16:58:33 -050015095void nl80211_notify_iface(struct cfg80211_registered_device *rdev,
15096 struct wireless_dev *wdev,
15097 enum nl80211_commands cmd)
15098{
15099 struct sk_buff *msg;
15100
Denis Kenzior896ff062016-08-03 16:58:33 -050015101 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15102 if (!msg)
15103 return;
15104
Andrew Zaborowski3d1a5bb2018-10-19 23:19:06 +020015105 if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, cmd) < 0) {
Denis Kenzior896ff062016-08-03 16:58:33 -050015106 nlmsg_free(msg);
15107 return;
15108 }
15109
15110 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15111 NL80211_MCGRP_CONFIG, GFP_KERNEL);
15112}
15113
Johannes Berg362a4152009-05-24 16:43:15 +020015114static int nl80211_add_scan_req(struct sk_buff *msg,
15115 struct cfg80211_registered_device *rdev)
15116{
15117 struct cfg80211_scan_request *req = rdev->scan_req;
15118 struct nlattr *nest;
15119 int i;
15120
15121 if (WARN_ON(!req))
15122 return 0;
15123
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015124 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_SSIDS);
Johannes Berg362a4152009-05-24 16:43:15 +020015125 if (!nest)
15126 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040015127 for (i = 0; i < req->n_ssids; i++) {
15128 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
15129 goto nla_put_failure;
15130 }
Johannes Berg362a4152009-05-24 16:43:15 +020015131 nla_nest_end(msg, nest);
15132
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015133 nest = nla_nest_start_noflag(msg, NL80211_ATTR_SCAN_FREQUENCIES);
Johannes Berg362a4152009-05-24 16:43:15 +020015134 if (!nest)
15135 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040015136 for (i = 0; i < req->n_channels; i++) {
15137 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
15138 goto nla_put_failure;
15139 }
Johannes Berg362a4152009-05-24 16:43:15 +020015140 nla_nest_end(msg, nest);
15141
David S. Miller9360ffd2012-03-29 04:41:26 -040015142 if (req->ie &&
15143 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
15144 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020015145
Johannes Bergae917c92013-10-25 11:05:22 +020015146 if (req->flags &&
15147 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
15148 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070015149
Avraham Stern1d762502016-07-05 17:10:13 +030015150 if (req->info.scan_start_tsf &&
15151 (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF,
15152 req->info.scan_start_tsf, NL80211_BSS_PAD) ||
15153 nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN,
15154 req->info.tsf_bssid)))
15155 goto nla_put_failure;
15156
Johannes Berg362a4152009-05-24 16:43:15 +020015157 return 0;
15158 nla_put_failure:
15159 return -ENOBUFS;
15160}
15161
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015162static int nl80211_prep_scan_msg(struct sk_buff *msg,
Johannes Berga538e2d2009-06-16 19:56:42 +020015163 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020015164 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000015165 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020015166 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010015167{
15168 void *hdr;
15169
Eric W. Biederman15e47302012-09-07 20:12:54 +000015170 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010015171 if (!hdr)
15172 return -1;
15173
David S. Miller9360ffd2012-03-29 04:41:26 -040015174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020015175 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15176 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015177 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15178 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015179 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010015180
Johannes Berg362a4152009-05-24 16:43:15 +020015181 /* ignore errors and send incomplete event anyway */
15182 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010015183
Johannes Berg053c0952015-01-16 22:09:00 +010015184 genlmsg_end(msg, hdr);
15185 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010015186
15187 nla_put_failure:
15188 genlmsg_cancel(msg, hdr);
15189 return -EMSGSIZE;
15190}
15191
Luciano Coelho807f8a82011-05-11 17:09:35 +030015192static int
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015193nl80211_prep_sched_scan_msg(struct sk_buff *msg,
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015194 struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030015195{
15196 void *hdr;
15197
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015198 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015199 if (!hdr)
15200 return -1;
15201
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015202 if (nla_put_u32(msg, NL80211_ATTR_WIPHY,
15203 wiphy_to_rdev(req->wiphy)->wiphy_idx) ||
15204 nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) ||
15205 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid,
15206 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015207 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030015208
Johannes Berg053c0952015-01-16 22:09:00 +010015209 genlmsg_end(msg, hdr);
15210 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030015211
15212 nla_put_failure:
15213 genlmsg_cancel(msg, hdr);
15214 return -EMSGSIZE;
15215}
15216
Johannes Berga538e2d2009-06-16 19:56:42 +020015217void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020015218 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020015219{
15220 struct sk_buff *msg;
15221
Thomas Graf58050fc2012-06-28 03:57:45 +000015222 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020015223 if (!msg)
15224 return;
15225
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015226 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020015227 NL80211_CMD_TRIGGER_SCAN) < 0) {
15228 nlmsg_free(msg);
15229 return;
15230 }
15231
Johannes Berg68eb5502013-11-19 15:19:38 +010015232 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015233 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020015234}
15235
Johannes Bergf9d15d12014-01-22 11:14:19 +020015236struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
15237 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010015238{
15239 struct sk_buff *msg;
15240
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015241 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010015242 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020015243 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010015244
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015245 if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020015246 aborted ? NL80211_CMD_SCAN_ABORTED :
15247 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010015248 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020015249 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010015250 }
15251
Johannes Bergf9d15d12014-01-22 11:14:19 +020015252 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010015253}
15254
Arend Van Spriel505a2e82016-12-16 11:21:54 +000015255/* send message created by nl80211_build_scan_msg() */
15256void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev,
15257 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010015258{
Johannes Berg2a519312009-02-10 21:25:55 +010015259 if (!msg)
15260 return;
15261
Johannes Berg68eb5502013-11-19 15:19:38 +010015262 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015263 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010015264}
15265
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015266void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030015267{
15268 struct sk_buff *msg;
15269
Thomas Graf58050fc2012-06-28 03:57:45 +000015270 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015271 if (!msg)
15272 return;
15273
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015274 if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) {
Luciano Coelho807f8a82011-05-11 17:09:35 +030015275 nlmsg_free(msg);
15276 return;
15277 }
15278
Arend Van Spriel96b08fd2017-04-13 13:06:27 +010015279 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015280 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030015281}
15282
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015283static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
15284 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015285{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015286 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040015287 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
15288 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015289
David S. Miller9360ffd2012-03-29 04:41:26 -040015290 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
15291 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15292 NL80211_REGDOM_TYPE_WORLD))
15293 goto nla_put_failure;
15294 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
15295 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15296 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
15297 goto nla_put_failure;
15298 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
15299 request->intersect) {
15300 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15301 NL80211_REGDOM_TYPE_INTERSECTION))
15302 goto nla_put_failure;
15303 } else {
15304 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
15305 NL80211_REGDOM_TYPE_COUNTRY) ||
15306 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
15307 request->alpha2))
15308 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015309 }
15310
Arik Nemtsovad30ca22014-12-15 19:25:59 +020015311 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
15312 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
15313
15314 if (wiphy &&
15315 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
15316 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020015317
15318 if (wiphy &&
15319 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
15320 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
15321 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020015322 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015323
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015324 return true;
15325
15326nla_put_failure:
15327 return false;
15328}
15329
15330/*
15331 * This can happen on global regulatory changes or device specific settings
15332 * based on custom regulatory domains.
15333 */
15334void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
15335 struct regulatory_request *request)
15336{
15337 struct sk_buff *msg;
15338 void *hdr;
15339
15340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15341 if (!msg)
15342 return;
15343
15344 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
zhong jiang24f6d762019-09-05 12:25:37 +080015345 if (!hdr)
15346 goto nla_put_failure;
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015347
zhong jiang24f6d762019-09-05 12:25:37 +080015348 if (!nl80211_reg_change_event_fill(msg, request))
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020015349 goto nla_put_failure;
15350
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015351 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015352
Johannes Bergbc43b282009-07-25 10:54:13 +020015353 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015354 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015355 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020015356 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015357
15358 return;
15359
15360nla_put_failure:
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040015361 nlmsg_free(msg);
15362}
15363
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015364static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
15365 struct net_device *netdev,
15366 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015367 enum nl80211_commands cmd, gfp_t gfp,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015368 int uapsd_queues, const u8 *req_ies,
15369 size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015370{
15371 struct sk_buff *msg;
15372 void *hdr;
15373
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015374 msg = nlmsg_new(100 + len + req_ies_len, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015375 if (!msg)
15376 return;
15377
15378 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15379 if (!hdr) {
15380 nlmsg_free(msg);
15381 return;
15382 }
15383
David S. Miller9360ffd2012-03-29 04:41:26 -040015384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15385 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015386 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
15387 (req_ies &&
15388 nla_put(msg, NL80211_ATTR_REQ_IE, req_ies_len, req_ies)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015389 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015390
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015391 if (uapsd_queues >= 0) {
15392 struct nlattr *nla_wmm =
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015393 nla_nest_start_noflag(msg, NL80211_ATTR_STA_WME);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030015394 if (!nla_wmm)
15395 goto nla_put_failure;
15396
15397 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
15398 uapsd_queues))
15399 goto nla_put_failure;
15400
15401 nla_nest_end(msg, nla_wmm);
15402 }
15403
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015404 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015405
Johannes Berg68eb5502013-11-19 15:19:38 +010015406 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015407 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015408 return;
15409
15410 nla_put_failure:
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015411 nlmsg_free(msg);
15412}
15413
15414void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015415 struct net_device *netdev, const u8 *buf,
15416 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015417{
15418 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015419 NL80211_CMD_AUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015420}
15421
15422void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
15423 struct net_device *netdev, const u8 *buf,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015424 size_t len, gfp_t gfp, int uapsd_queues,
15425 const u8 *req_ies, size_t req_ies_len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015426{
Johannes Berge6d6e342009-07-01 21:26:47 +020015427 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015428 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues,
15429 req_ies, req_ies_len);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015430}
15431
Jouni Malinen53b46b82009-03-27 20:53:56 +020015432void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015433 struct net_device *netdev, const u8 *buf,
15434 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015435{
15436 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015437 NL80211_CMD_DEAUTHENTICATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015438}
15439
Jouni Malinen53b46b82009-03-27 20:53:56 +020015440void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
15441 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020015442 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015443{
15444 nl80211_send_mlme_event(rdev, netdev, buf, len,
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015445 NL80211_CMD_DISASSOCIATE, gfp, -1, NULL, 0);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020015446}
15447
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015448void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
15449 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020015450{
Johannes Berg947add32013-02-22 22:05:20 +010015451 struct wireless_dev *wdev = dev->ieee80211_ptr;
15452 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015453 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015454 const struct ieee80211_mgmt *mgmt = (void *)buf;
15455 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020015456
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015457 if (WARN_ON(len < 2))
15458 return;
15459
15460 if (ieee80211_is_deauth(mgmt->frame_control))
15461 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
15462 else
15463 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
15464
15465 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Jouni Malinen4d9ec732019-02-15 02:14:33 +020015466 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1,
15467 NULL, 0);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015468}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020015469EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020015470
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040015471static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
15472 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020015473 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015474{
15475 struct sk_buff *msg;
15476 void *hdr;
15477
Johannes Berge6d6e342009-07-01 21:26:47 +020015478 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015479 if (!msg)
15480 return;
15481
15482 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15483 if (!hdr) {
15484 nlmsg_free(msg);
15485 return;
15486 }
15487
David S. Miller9360ffd2012-03-29 04:41:26 -040015488 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15489 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15490 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
15491 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
15492 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030015493
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015494 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030015495
Johannes Berg68eb5502013-11-19 15:19:38 +010015496 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015497 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015498 return;
15499
15500 nla_put_failure:
Jouni Malinen1965c852009-04-22 21:38:25 +030015501 nlmsg_free(msg);
15502}
15503
15504void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015505 struct net_device *netdev, const u8 *addr,
15506 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015507{
15508 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020015509 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015510}
15511
15512void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020015513 struct net_device *netdev, const u8 *addr,
15514 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030015515{
Johannes Berge6d6e342009-07-01 21:26:47 +020015516 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
15517 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030015518}
15519
Samuel Ortizb23aa672009-07-01 21:26:54 +020015520void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015521 struct net_device *netdev,
15522 struct cfg80211_connect_resp_params *cr,
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015523 gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015524{
15525 struct sk_buff *msg;
15526 void *hdr;
15527
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015528 msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len +
Arend Van Spriel76804d22018-05-22 10:19:06 +020015529 cr->fils.kek_len + cr->fils.pmk_len +
15530 (cr->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015531 if (!msg)
15532 return;
15533
15534 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
15535 if (!hdr) {
15536 nlmsg_free(msg);
15537 return;
15538 }
15539
David S. Miller9360ffd2012-03-29 04:41:26 -040015540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015542 (cr->bssid &&
15543 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) ||
Jouni Malinenbf1ecd22016-05-31 00:16:50 +030015544 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE,
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015545 cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE :
15546 cr->status) ||
15547 (cr->status < 0 &&
Purushottam Kushwaha3093ebbeab2017-01-13 01:12:21 +020015548 (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
Vidyullatha Kanchanapally5349a0f2017-03-31 00:22:33 +030015549 nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON,
15550 cr->timeout_reason))) ||
15551 (cr->req_ie &&
15552 nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) ||
15553 (cr->resp_ie &&
15554 nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len,
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015555 cr->resp_ie)) ||
Arend Van Spriel76804d22018-05-22 10:19:06 +020015556 (cr->fils.update_erp_next_seq_num &&
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015557 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
Arend Van Spriel76804d22018-05-22 10:19:06 +020015558 cr->fils.erp_next_seq_num)) ||
Vidyullatha Kanchanapallya3caf742017-03-31 00:22:34 +030015559 (cr->status == WLAN_STATUS_SUCCESS &&
Arend Van Spriel76804d22018-05-22 10:19:06 +020015560 ((cr->fils.kek &&
15561 nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils.kek_len,
15562 cr->fils.kek)) ||
15563 (cr->fils.pmk &&
15564 nla_put(msg, NL80211_ATTR_PMK, cr->fils.pmk_len, cr->fils.pmk)) ||
15565 (cr->fils.pmkid &&
15566 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->fils.pmkid)))))
David S. Miller9360ffd2012-03-29 04:41:26 -040015567 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015568
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015569 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015570
Johannes Berg68eb5502013-11-19 15:19:38 +010015571 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015572 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015573 return;
15574
15575 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015576 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015577}
15578
15579void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015580 struct net_device *netdev,
15581 struct cfg80211_roam_info *info, gfp_t gfp)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015582{
15583 struct sk_buff *msg;
15584 void *hdr;
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015585 const u8 *bssid = info->bss ? info->bss->bssid : info->bssid;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015586
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015587 msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len +
15588 info->fils.kek_len + info->fils.pmk_len +
15589 (info->fils.pmkid ? WLAN_PMKID_LEN : 0), gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015590 if (!msg)
15591 return;
15592
15593 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
15594 if (!hdr) {
15595 nlmsg_free(msg);
15596 return;
15597 }
15598
David S. Miller9360ffd2012-03-29 04:41:26 -040015599 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15600 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15601 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
Avraham Stern29ce6ec2017-04-26 10:58:49 +030015602 (info->req_ie &&
15603 nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len,
15604 info->req_ie)) ||
15605 (info->resp_ie &&
15606 nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len,
Arend Van Spriele841b7b2018-05-22 10:19:07 +020015607 info->resp_ie)) ||
15608 (info->fils.update_erp_next_seq_num &&
15609 nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM,
15610 info->fils.erp_next_seq_num)) ||
15611 (info->fils.kek &&
15612 nla_put(msg, NL80211_ATTR_FILS_KEK, info->fils.kek_len,
15613 info->fils.kek)) ||
15614 (info->fils.pmk &&
15615 nla_put(msg, NL80211_ATTR_PMK, info->fils.pmk_len, info->fils.pmk)) ||
15616 (info->fils.pmkid &&
15617 nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, info->fils.pmkid)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015618 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015619
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015620 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015621
Johannes Berg68eb5502013-11-19 15:19:38 +010015622 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015623 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015624 return;
15625
15626 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015627 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015628}
15629
Avraham Stern503c1fb2017-09-29 14:21:49 +020015630void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev,
15631 struct net_device *netdev, const u8 *bssid)
15632{
15633 struct sk_buff *msg;
15634 void *hdr;
15635
15636 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
15637 if (!msg)
15638 return;
15639
15640 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED);
15641 if (!hdr) {
15642 nlmsg_free(msg);
15643 return;
15644 }
15645
Chung-Hsien Hsuf4d75992019-05-09 09:48:25 +000015646 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15647 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15648 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
Avraham Stern503c1fb2017-09-29 14:21:49 +020015649 goto nla_put_failure;
15650
15651 genlmsg_end(msg, hdr);
15652
15653 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
15654 NL80211_MCGRP_MLME, GFP_KERNEL);
15655 return;
15656
15657 nla_put_failure:
Avraham Stern503c1fb2017-09-29 14:21:49 +020015658 nlmsg_free(msg);
15659}
15660
Samuel Ortizb23aa672009-07-01 21:26:54 +020015661void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
15662 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020015663 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020015664{
15665 struct sk_buff *msg;
15666 void *hdr;
15667
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015668 msg = nlmsg_new(100 + ie_len, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015669 if (!msg)
15670 return;
15671
15672 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
15673 if (!hdr) {
15674 nlmsg_free(msg);
15675 return;
15676 }
15677
David S. Miller9360ffd2012-03-29 04:41:26 -040015678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15679 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
David Spinadel86b6c462017-12-18 12:14:05 +020015680 (reason &&
David S. Miller9360ffd2012-03-29 04:41:26 -040015681 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
15682 (from_ap &&
15683 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
15684 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
15685 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020015686
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015687 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015688
Johannes Berg68eb5502013-11-19 15:19:38 +010015689 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015690 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015691 return;
15692
15693 nla_put_failure:
Samuel Ortizb23aa672009-07-01 21:26:54 +020015694 nlmsg_free(msg);
Samuel Ortizb23aa672009-07-01 21:26:54 +020015695}
15696
Johannes Berg04a773a2009-04-19 21:24:32 +020015697void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
15698 struct net_device *netdev, const u8 *bssid,
15699 gfp_t gfp)
15700{
15701 struct sk_buff *msg;
15702 void *hdr;
15703
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015704 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015705 if (!msg)
15706 return;
15707
15708 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
15709 if (!hdr) {
15710 nlmsg_free(msg);
15711 return;
15712 }
15713
David S. Miller9360ffd2012-03-29 04:41:26 -040015714 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15715 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15716 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
15717 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020015718
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015719 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020015720
Johannes Berg68eb5502013-11-19 15:19:38 +010015721 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015722 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020015723 return;
15724
15725 nla_put_failure:
Johannes Berg04a773a2009-04-19 21:24:32 +020015726 nlmsg_free(msg);
15727}
15728
Johannes Berg947add32013-02-22 22:05:20 +010015729void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
Bob Copelandecbc12a2018-10-26 10:03:50 -040015730 const u8 *ie, u8 ie_len,
15731 int sig_dbm, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070015732{
Johannes Berg947add32013-02-22 22:05:20 +010015733 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015734 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015735 struct sk_buff *msg;
15736 void *hdr;
15737
Johannes Berg947add32013-02-22 22:05:20 +010015738 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
15739 return;
15740
15741 trace_cfg80211_notify_new_peer_candidate(dev, addr);
15742
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010015743 msg = nlmsg_new(100 + ie_len, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015744 if (!msg)
15745 return;
15746
15747 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
15748 if (!hdr) {
15749 nlmsg_free(msg);
15750 return;
15751 }
15752
David S. Miller9360ffd2012-03-29 04:41:26 -040015753 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010015754 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
15755 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015756 (ie_len && ie &&
Bob Copelandecbc12a2018-10-26 10:03:50 -040015757 nla_put(msg, NL80211_ATTR_IE, ie_len, ie)) ||
15758 (sig_dbm &&
15759 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)))
David S. Miller9360ffd2012-03-29 04:41:26 -040015760 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070015761
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015762 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015763
Johannes Berg68eb5502013-11-19 15:19:38 +010015764 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015765 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015766 return;
15767
15768 nla_put_failure:
Javier Cardonac93b5e72011-04-07 15:08:34 -070015769 nlmsg_free(msg);
15770}
Johannes Berg947add32013-02-22 22:05:20 +010015771EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070015772
Jouni Malinena3b8b052009-03-27 21:59:49 +020015773void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
15774 struct net_device *netdev, const u8 *addr,
15775 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020015776 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020015777{
15778 struct sk_buff *msg;
15779 void *hdr;
15780
Johannes Berge6d6e342009-07-01 21:26:47 +020015781 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015782 if (!msg)
15783 return;
15784
15785 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
15786 if (!hdr) {
15787 nlmsg_free(msg);
15788 return;
15789 }
15790
David S. Miller9360ffd2012-03-29 04:41:26 -040015791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
15792 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
15793 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
15794 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
15795 (key_id != -1 &&
15796 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
15797 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
15798 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020015799
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015800 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015801
Johannes Berg68eb5502013-11-19 15:19:38 +010015802 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015803 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020015804 return;
15805
15806 nla_put_failure:
Jouni Malinena3b8b052009-03-27 21:59:49 +020015807 nlmsg_free(msg);
15808}
15809
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015810void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
15811 struct ieee80211_channel *channel_before,
15812 struct ieee80211_channel *channel_after)
15813{
15814 struct sk_buff *msg;
15815 void *hdr;
15816 struct nlattr *nl_freq;
15817
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070015818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015819 if (!msg)
15820 return;
15821
15822 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
15823 if (!hdr) {
15824 nlmsg_free(msg);
15825 return;
15826 }
15827
15828 /*
15829 * Since we are applying the beacon hint to a wiphy we know its
15830 * wiphy_idx is valid
15831 */
David S. Miller9360ffd2012-03-29 04:41:26 -040015832 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
15833 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015834
15835 /* Before */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015836 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_BEFORE);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015837 if (!nl_freq)
15838 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015839
15840 if (nl80211_msg_put_channel(msg, wiphy, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015841 goto nla_put_failure;
15842 nla_nest_end(msg, nl_freq);
15843
15844 /* After */
Michal Kubecekae0be8d2019-04-26 11:13:06 +020015845 nl_freq = nla_nest_start_noflag(msg, NL80211_ATTR_FREQ_AFTER);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015846 if (!nl_freq)
15847 goto nla_put_failure;
Haim Dreyfuss50f32712018-04-20 13:49:26 +030015848
15849 if (nl80211_msg_put_channel(msg, wiphy, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015850 goto nla_put_failure;
15851 nla_nest_end(msg, nl_freq);
15852
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015853 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015854
Johannes Berg463d0182009-07-14 00:33:35 +020015855 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010015856 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015857 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020015858 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015859
15860 return;
15861
15862nla_put_failure:
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040015863 nlmsg_free(msg);
15864}
15865
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015866static void nl80211_send_remain_on_chan_event(
15867 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020015868 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015869 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015870 unsigned int duration, gfp_t gfp)
15871{
15872 struct sk_buff *msg;
15873 void *hdr;
15874
15875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
15876 if (!msg)
15877 return;
15878
15879 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
15880 if (!hdr) {
15881 nlmsg_free(msg);
15882 return;
15883 }
15884
David S. Miller9360ffd2012-03-29 04:41:26 -040015885 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020015886 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
15887 wdev->netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015888 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
15889 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040015890 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010015891 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
15892 NL80211_CHAN_NO_HT) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020015893 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
15894 NL80211_ATTR_PAD))
David S. Miller9360ffd2012-03-29 04:41:26 -040015895 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015896
David S. Miller9360ffd2012-03-29 04:41:26 -040015897 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
15898 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
15899 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015900
Johannes Berg3b7b72e2011-10-22 19:05:51 +020015901 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015902
Johannes Berg68eb5502013-11-19 15:19:38 +010015903 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015904 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015905 return;
15906
15907 nla_put_failure:
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015908 nlmsg_free(msg);
15909}
15910
Johannes Berg947add32013-02-22 22:05:20 +010015911void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
15912 struct ieee80211_channel *chan,
15913 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015914{
Johannes Berg947add32013-02-22 22:05:20 +010015915 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015916 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015917
15918 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015919 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020015920 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010015921 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015922}
Johannes Berg947add32013-02-22 22:05:20 +010015923EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015924
Johannes Berg947add32013-02-22 22:05:20 +010015925void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
15926 struct ieee80211_channel *chan,
15927 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015928{
Johannes Berg947add32013-02-22 22:05:20 +010015929 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015930 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010015931
15932 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015933 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010015934 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015935}
Johannes Berg947add32013-02-22 22:05:20 +010015936EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010015937
James Prestwood1c38c7f2019-06-12 12:35:09 -070015938void cfg80211_tx_mgmt_expired(struct wireless_dev *wdev, u64 cookie,
15939 struct ieee80211_channel *chan,
15940 gfp_t gfp)
15941{
15942 struct wiphy *wiphy = wdev->wiphy;
15943 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
15944
15945 trace_cfg80211_tx_mgmt_expired(wdev, cookie, chan);
15946 nl80211_send_remain_on_chan_event(NL80211_CMD_FRAME_WAIT_CANCEL,
15947 rdev, wdev, cookie, chan, 0, gfp);
15948}
15949EXPORT_SYMBOL(cfg80211_tx_mgmt_expired);
15950
Johannes Berg947add32013-02-22 22:05:20 +010015951void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
15952 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010015953{
Johannes Berg947add32013-02-22 22:05:20 +010015954 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015955 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010015956 struct sk_buff *msg;
15957
Johannes Berg947add32013-02-22 22:05:20 +010015958 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
15959
Thomas Graf58050fc2012-06-28 03:57:45 +000015960 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015961 if (!msg)
15962 return;
15963
Johannes Bergcf5ead82014-11-14 17:14:00 +010015964 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040015965 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010015966 nlmsg_free(msg);
15967 return;
15968 }
15969
Johannes Berg68eb5502013-11-19 15:19:38 +010015970 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010015971 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010015972}
Johannes Berg947add32013-02-22 22:05:20 +010015973EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010015974
Johannes Bergcf5ead82014-11-14 17:14:00 +010015975void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
15976 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020015977{
Johannes Berg947add32013-02-22 22:05:20 +010015978 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080015979 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020015980 struct sk_buff *msg;
Johannes Berg73887fd2018-05-18 09:57:55 +020015981 struct station_info empty_sinfo = {};
Johannes Bergcf5ead82014-11-14 17:14:00 +010015982
Johannes Berg73887fd2018-05-18 09:57:55 +020015983 if (!sinfo)
15984 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020015985
Johannes Berg947add32013-02-22 22:05:20 +010015986 trace_cfg80211_del_sta(dev, mac_addr);
15987
Thomas Graf58050fc2012-06-28 03:57:45 +000015988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg7ea3e112018-05-18 11:40:44 +020015989 if (!msg) {
15990 cfg80211_sinfo_release_content(sinfo);
Johannes Berg73887fd2018-05-18 09:57:55 +020015991 return;
Johannes Berg7ea3e112018-05-18 11:40:44 +020015992 }
Jouni Malinenec15e682011-03-23 15:29:52 +020015993
Johannes Bergcf5ead82014-11-14 17:14:00 +010015994 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010015995 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020015996 nlmsg_free(msg);
Johannes Berg73887fd2018-05-18 09:57:55 +020015997 return;
Jouni Malinenec15e682011-03-23 15:29:52 +020015998 }
15999
Johannes Berg68eb5502013-11-19 15:19:38 +010016000 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016001 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020016002}
Johannes Bergcf5ead82014-11-14 17:14:00 +010016003EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020016004
Johannes Berg947add32013-02-22 22:05:20 +010016005void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
16006 enum nl80211_connect_failed_reason reason,
16007 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016008{
Johannes Berg947add32013-02-22 22:05:20 +010016009 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016010 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016011 struct sk_buff *msg;
16012 void *hdr;
16013
16014 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
16015 if (!msg)
16016 return;
16017
16018 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
16019 if (!hdr) {
16020 nlmsg_free(msg);
16021 return;
16022 }
16023
16024 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16025 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
16026 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
16027 goto nla_put_failure;
16028
16029 genlmsg_end(msg, hdr);
16030
Johannes Berg68eb5502013-11-19 15:19:38 +010016031 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016032 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016033 return;
16034
16035 nla_put_failure:
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016036 nlmsg_free(msg);
16037}
Johannes Berg947add32013-02-22 22:05:20 +010016038EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053016039
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016040static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
16041 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010016042{
16043 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016044 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010016045 struct sk_buff *msg;
16046 void *hdr;
Mark Rutland6aa7de02017-10-23 14:07:29 -070016047 u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010016048
Eric W. Biederman15e47302012-09-07 20:12:54 +000016049 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010016050 return false;
16051
16052 msg = nlmsg_new(100, gfp);
16053 if (!msg)
16054 return true;
16055
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016056 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010016057 if (!hdr) {
16058 nlmsg_free(msg);
16059 return true;
16060 }
16061
David S. Miller9360ffd2012-03-29 04:41:26 -040016062 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16063 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16064 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
16065 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010016066
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016067 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000016068 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010016069 return true;
16070
16071 nla_put_failure:
Johannes Berg28946da2011-11-04 11:18:12 +010016072 nlmsg_free(msg);
16073 return true;
16074}
16075
Johannes Berg947add32013-02-22 22:05:20 +010016076bool cfg80211_rx_spurious_frame(struct net_device *dev,
16077 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016078{
Johannes Berg947add32013-02-22 22:05:20 +010016079 struct wireless_dev *wdev = dev->ieee80211_ptr;
16080 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016081
Johannes Berg947add32013-02-22 22:05:20 +010016082 trace_cfg80211_rx_spurious_frame(dev, addr);
16083
16084 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16085 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
16086 trace_cfg80211_return_bool(false);
16087 return false;
16088 }
16089 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
16090 addr, gfp);
16091 trace_cfg80211_return_bool(ret);
16092 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016093}
Johannes Berg947add32013-02-22 22:05:20 +010016094EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
16095
16096bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
16097 const u8 *addr, gfp_t gfp)
16098{
16099 struct wireless_dev *wdev = dev->ieee80211_ptr;
16100 bool ret;
16101
16102 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
16103
16104 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
16105 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
16106 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
16107 trace_cfg80211_return_bool(false);
16108 return false;
16109 }
16110 ret = __nl80211_unexpected_frame(dev,
16111 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
16112 addr, gfp);
16113 trace_cfg80211_return_bool(ret);
16114 return ret;
16115}
16116EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010016117
Johannes Berg2e161f782010-08-12 15:38:38 +020016118int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000016119 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010016120 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030016121 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020016122{
Johannes Berg71bbc992012-06-15 15:30:18 +020016123 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020016124 struct sk_buff *msg;
16125 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020016126
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016127 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016128 if (!msg)
16129 return -ENOMEM;
16130
Johannes Berg2e161f782010-08-12 15:38:38 +020016131 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020016132 if (!hdr) {
16133 nlmsg_free(msg);
16134 return -ENOMEM;
16135 }
16136
David S. Miller9360ffd2012-03-29 04:41:26 -040016137 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016138 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16139 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016140 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16141 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016142 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
16143 (sig_dbm &&
16144 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030016145 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
16146 (flags &&
16147 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016148 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020016149
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016150 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020016151
Eric W. Biederman15e47302012-09-07 20:12:54 +000016152 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020016153
16154 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020016155 nlmsg_free(msg);
16156 return -ENOBUFS;
16157}
16158
Johannes Berg947add32013-02-22 22:05:20 +010016159void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
16160 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020016161{
Johannes Berg947add32013-02-22 22:05:20 +010016162 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016163 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020016164 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020016165 struct sk_buff *msg;
16166 void *hdr;
16167
Johannes Berg947add32013-02-22 22:05:20 +010016168 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
16169
Johannes Berg4ef8c1c2017-01-09 11:10:42 +010016170 msg = nlmsg_new(100 + len, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016171 if (!msg)
16172 return;
16173
Johannes Berg2e161f782010-08-12 15:38:38 +020016174 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020016175 if (!hdr) {
16176 nlmsg_free(msg);
16177 return;
16178 }
16179
David S. Miller9360ffd2012-03-29 04:41:26 -040016180 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020016181 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16182 netdev->ifindex)) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016183 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16184 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016185 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016186 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16187 NL80211_ATTR_PAD) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040016188 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
16189 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020016190
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016191 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020016192
Johannes Berg68eb5502013-11-19 15:19:38 +010016193 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016194 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020016195 return;
16196
16197 nla_put_failure:
Jouni Malinen026331c2010-02-15 12:53:10 +020016198 nlmsg_free(msg);
16199}
Johannes Berg947add32013-02-22 22:05:20 +010016200EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020016201
Denis Kenzior6a671a52018-03-26 12:52:41 -050016202static int __nl80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050016203 struct sk_buff *skb,
Denis Kenzior6a671a52018-03-26 12:52:41 -050016204 bool unencrypted, gfp_t gfp)
16205{
16206 struct wireless_dev *wdev = dev->ieee80211_ptr;
16207 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Denis Kenziora948f712018-07-03 15:05:48 -050016208 struct ethhdr *ehdr = eth_hdr(skb);
Johannes Berg8d74a622020-02-24 10:19:12 +010016209 const u8 *addr = ehdr->h_source;
Denis Kenziora948f712018-07-03 15:05:48 -050016210 u16 proto = be16_to_cpu(skb->protocol);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016211 struct sk_buff *msg;
16212 void *hdr;
Denis Kenziora948f712018-07-03 15:05:48 -050016213 struct nlattr *frame;
16214
Denis Kenzior6a671a52018-03-26 12:52:41 -050016215 u32 nlportid = READ_ONCE(wdev->conn_owner_nlportid);
16216
16217 if (!nlportid)
16218 return -ENOENT;
16219
Denis Kenziora948f712018-07-03 15:05:48 -050016220 msg = nlmsg_new(100 + skb->len, gfp);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016221 if (!msg)
16222 return -ENOMEM;
16223
16224 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONTROL_PORT_FRAME);
16225 if (!hdr) {
16226 nlmsg_free(msg);
16227 return -ENOBUFS;
16228 }
16229
16230 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16231 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16232 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16233 NL80211_ATTR_PAD) ||
Johannes Berg8d74a622020-02-24 10:19:12 +010016234 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Denis Kenzior6a671a52018-03-26 12:52:41 -050016235 nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) ||
16236 (unencrypted && nla_put_flag(msg,
16237 NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
16238 goto nla_put_failure;
16239
Denis Kenziora948f712018-07-03 15:05:48 -050016240 frame = nla_reserve(msg, NL80211_ATTR_FRAME, skb->len);
16241 if (!frame)
16242 goto nla_put_failure;
16243
16244 skb_copy_bits(skb, 0, nla_data(frame), skb->len);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016245 genlmsg_end(msg, hdr);
16246
16247 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
16248
16249 nla_put_failure:
16250 nlmsg_free(msg);
16251 return -ENOBUFS;
16252}
16253
16254bool cfg80211_rx_control_port(struct net_device *dev,
Denis Kenziora948f712018-07-03 15:05:48 -050016255 struct sk_buff *skb, bool unencrypted)
Denis Kenzior6a671a52018-03-26 12:52:41 -050016256{
16257 int ret;
16258
Denis Kenziora948f712018-07-03 15:05:48 -050016259 trace_cfg80211_rx_control_port(dev, skb, unencrypted);
16260 ret = __nl80211_rx_control_port(dev, skb, unencrypted, GFP_ATOMIC);
Denis Kenzior6a671a52018-03-26 12:52:41 -050016261 trace_cfg80211_return_bool(ret == 0);
16262 return ret == 0;
16263}
16264EXPORT_SYMBOL(cfg80211_rx_control_port);
16265
Johannes Berg5b97f492014-11-26 12:37:43 +010016266static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
16267 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016268{
Johannes Berg947add32013-02-22 22:05:20 +010016269 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010016270 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16271 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16272 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016273
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016274 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010016275 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016276
Johannes Berg5b97f492014-11-26 12:37:43 +010016277 cb = (void **)msg->cb;
16278
16279 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
16280 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016281 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010016282 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016283 }
16284
David S. Miller9360ffd2012-03-29 04:41:26 -040016285 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010016286 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040016287 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016288
Johannes Berg5b97f492014-11-26 12:37:43 +010016289 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016290 goto nla_put_failure;
16291
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016292 cb[1] = nla_nest_start_noflag(msg, NL80211_ATTR_CQM);
Johannes Berg5b97f492014-11-26 12:37:43 +010016293 if (!cb[1])
16294 goto nla_put_failure;
16295
16296 cb[2] = rdev;
16297
16298 return msg;
16299 nla_put_failure:
16300 nlmsg_free(msg);
16301 return NULL;
16302}
16303
16304static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
16305{
16306 void **cb = (void **)msg->cb;
16307 struct cfg80211_registered_device *rdev = cb[2];
16308
16309 nla_nest_end(msg, cb[1]);
16310 genlmsg_end(msg, cb[0]);
16311
16312 memset(msg->cb, 0, sizeof(msg->cb));
16313
16314 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16315 NL80211_MCGRP_MLME, gfp);
16316}
16317
16318void cfg80211_cqm_rssi_notify(struct net_device *dev,
16319 enum nl80211_cqm_rssi_threshold_event rssi_event,
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016320 s32 rssi_level, gfp_t gfp)
Johannes Berg5b97f492014-11-26 12:37:43 +010016321{
16322 struct sk_buff *msg;
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010016323 struct wireless_dev *wdev = dev->ieee80211_ptr;
16324 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg5b97f492014-11-26 12:37:43 +010016325
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016326 trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level);
Johannes Berg5b97f492014-11-26 12:37:43 +010016327
Johannes Berg98f03342014-11-26 12:42:02 +010016328 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
16329 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
16330 return;
16331
Andrew Zaborowski4a4b8162017-02-10 10:02:31 +010016332 if (wdev->cqm_config) {
16333 wdev->cqm_config->last_rssi_event_value = rssi_level;
16334
16335 cfg80211_cqm_rssi_update(rdev, dev);
16336
16337 if (rssi_level == 0)
16338 rssi_level = wdev->cqm_config->last_rssi_event_value;
16339 }
16340
Johannes Berg5b97f492014-11-26 12:37:43 +010016341 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16342 if (!msg)
16343 return;
16344
David S. Miller9360ffd2012-03-29 04:41:26 -040016345 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
16346 rssi_event))
16347 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016348
Andrzej Zaborowskibee427b2017-01-25 12:43:41 +010016349 if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL,
16350 rssi_level))
16351 goto nla_put_failure;
16352
Johannes Berg5b97f492014-11-26 12:37:43 +010016353 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016354
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016355 return;
16356
16357 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016358 nlmsg_free(msg);
16359}
Johannes Berg947add32013-02-22 22:05:20 +010016360EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020016361
Johannes Berg5b97f492014-11-26 12:37:43 +010016362void cfg80211_cqm_txe_notify(struct net_device *dev,
16363 const u8 *peer, u32 num_packets,
16364 u32 rate, u32 intvl, gfp_t gfp)
16365{
16366 struct sk_buff *msg;
16367
16368 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16369 if (!msg)
16370 return;
16371
16372 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
16373 goto nla_put_failure;
16374
16375 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
16376 goto nla_put_failure;
16377
16378 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
16379 goto nla_put_failure;
16380
16381 cfg80211_send_cqm(msg, gfp);
16382 return;
16383
16384 nla_put_failure:
16385 nlmsg_free(msg);
16386}
16387EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
16388
16389void cfg80211_cqm_pktloss_notify(struct net_device *dev,
16390 const u8 *peer, u32 num_packets, gfp_t gfp)
16391{
16392 struct sk_buff *msg;
16393
16394 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
16395
16396 msg = cfg80211_prepare_cqm(dev, peer, gfp);
16397 if (!msg)
16398 return;
16399
16400 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
16401 goto nla_put_failure;
16402
16403 cfg80211_send_cqm(msg, gfp);
16404 return;
16405
16406 nla_put_failure:
16407 nlmsg_free(msg);
16408}
16409EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
16410
Johannes Berg98f03342014-11-26 12:42:02 +010016411void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
16412{
16413 struct sk_buff *msg;
16414
16415 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
16416 if (!msg)
16417 return;
16418
16419 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
16420 goto nla_put_failure;
16421
16422 cfg80211_send_cqm(msg, gfp);
16423 return;
16424
16425 nla_put_failure:
16426 nlmsg_free(msg);
16427}
16428EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
16429
Johannes Berg947add32013-02-22 22:05:20 +010016430static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
16431 struct net_device *netdev, const u8 *bssid,
16432 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020016433{
16434 struct sk_buff *msg;
16435 struct nlattr *rekey_attr;
16436 void *hdr;
16437
Thomas Graf58050fc2012-06-28 03:57:45 +000016438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016439 if (!msg)
16440 return;
16441
16442 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
16443 if (!hdr) {
16444 nlmsg_free(msg);
16445 return;
16446 }
16447
David S. Miller9360ffd2012-03-29 04:41:26 -040016448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16449 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
16450 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
16451 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016452
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016453 rekey_attr = nla_nest_start_noflag(msg, NL80211_ATTR_REKEY_DATA);
Johannes Berge5497d72011-07-05 16:35:40 +020016454 if (!rekey_attr)
16455 goto nla_put_failure;
16456
David S. Miller9360ffd2012-03-29 04:41:26 -040016457 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
16458 NL80211_REPLAY_CTR_LEN, replay_ctr))
16459 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020016460
16461 nla_nest_end(msg, rekey_attr);
16462
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016463 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020016464
Johannes Berg68eb5502013-11-19 15:19:38 +010016465 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016466 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020016467 return;
16468
16469 nla_put_failure:
Johannes Berge5497d72011-07-05 16:35:40 +020016470 nlmsg_free(msg);
16471}
16472
Johannes Berg947add32013-02-22 22:05:20 +010016473void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
16474 const u8 *replay_ctr, gfp_t gfp)
16475{
16476 struct wireless_dev *wdev = dev->ieee80211_ptr;
16477 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016478 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016479
16480 trace_cfg80211_gtk_rekey_notify(dev, bssid);
16481 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
16482}
16483EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
16484
16485static void
16486nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
16487 struct net_device *netdev, int index,
16488 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016489{
16490 struct sk_buff *msg;
16491 struct nlattr *attr;
16492 void *hdr;
16493
Thomas Graf58050fc2012-06-28 03:57:45 +000016494 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016495 if (!msg)
16496 return;
16497
16498 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
16499 if (!hdr) {
16500 nlmsg_free(msg);
16501 return;
16502 }
16503
David S. Miller9360ffd2012-03-29 04:41:26 -040016504 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16505 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16506 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016507
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016508 attr = nla_nest_start_noflag(msg, NL80211_ATTR_PMKSA_CANDIDATE);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016509 if (!attr)
16510 goto nla_put_failure;
16511
David S. Miller9360ffd2012-03-29 04:41:26 -040016512 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
16513 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
16514 (preauth &&
16515 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
16516 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016517
16518 nla_nest_end(msg, attr);
16519
Johannes Berg3b7b72e2011-10-22 19:05:51 +020016520 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016521
Johannes Berg68eb5502013-11-19 15:19:38 +010016522 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016523 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016524 return;
16525
16526 nla_put_failure:
Jouni Malinenc9df56b2011-09-16 18:56:23 +030016527 nlmsg_free(msg);
16528}
16529
Johannes Berg947add32013-02-22 22:05:20 +010016530void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
16531 const u8 *bssid, bool preauth, gfp_t gfp)
16532{
16533 struct wireless_dev *wdev = dev->ieee80211_ptr;
16534 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016535 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016536
16537 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
16538 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
16539}
16540EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
16541
16542static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
16543 struct net_device *netdev,
16544 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020016545 gfp_t gfp,
16546 enum nl80211_commands notif,
16547 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070016548{
16549 struct sk_buff *msg;
16550 void *hdr;
16551
Thomas Graf58050fc2012-06-28 03:57:45 +000016552 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016553 if (!msg)
16554 return;
16555
Luciano Coelhof8d75522014-11-07 14:31:35 +020016556 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070016557 if (!hdr) {
16558 nlmsg_free(msg);
16559 return;
16560 }
16561
Johannes Berg683b6d32012-11-08 21:25:48 +010016562 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
16563 goto nla_put_failure;
16564
16565 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040016566 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070016567
Luciano Coelhof8d75522014-11-07 14:31:35 +020016568 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
16569 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
16570 goto nla_put_failure;
16571
Thomas Pedersen53145262012-04-06 13:35:47 -070016572 genlmsg_end(msg, hdr);
16573
Johannes Berg68eb5502013-11-19 15:19:38 +010016574 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016575 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070016576 return;
16577
16578 nla_put_failure:
Thomas Pedersen53145262012-04-06 13:35:47 -070016579 nlmsg_free(msg);
16580}
16581
Johannes Berg947add32013-02-22 22:05:20 +010016582void cfg80211_ch_switch_notify(struct net_device *dev,
16583 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070016584{
Johannes Berg947add32013-02-22 22:05:20 +010016585 struct wireless_dev *wdev = dev->ieee80211_ptr;
16586 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016587 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010016588
Simon Wunderliche487eae2013-11-21 18:19:51 +010016589 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010016590
Simon Wunderliche487eae2013-11-21 18:19:51 +010016591 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010016592
Michal Kazior9e0e2962014-01-29 14:22:27 +010016593 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010016594 wdev->preset_chandef = *chandef;
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016595
16596 if (wdev->iftype == NL80211_IFTYPE_STATION &&
16597 !WARN_ON(!wdev->current_bss))
Sergey Matyukevich0afd4252019-07-26 16:39:34 +000016598 cfg80211_update_assoc_bss_entry(wdev, chandef->chan);
Sergey Matyukevich5dc8cdc2019-03-26 09:27:37 +000016599
Michael Vassernisd34990b2019-07-29 06:01:16 +000016600 cfg80211_sched_dfs_chan_update(rdev);
16601
Luciano Coelhof8d75522014-11-07 14:31:35 +020016602 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16603 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010016604}
16605EXPORT_SYMBOL(cfg80211_ch_switch_notify);
16606
Luciano Coelhof8d75522014-11-07 14:31:35 +020016607void cfg80211_ch_switch_started_notify(struct net_device *dev,
16608 struct cfg80211_chan_def *chandef,
16609 u8 count)
16610{
16611 struct wireless_dev *wdev = dev->ieee80211_ptr;
16612 struct wiphy *wiphy = wdev->wiphy;
16613 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
16614
16615 trace_cfg80211_ch_switch_started_notify(dev, chandef);
16616
16617 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
16618 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
16619}
16620EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
16621
Thomas Pedersen84f10702012-07-12 16:17:33 -070016622void
Simon Wunderlich04f39042013-02-08 18:16:19 +010016623nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010016624 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010016625 enum nl80211_radar_event event,
16626 struct net_device *netdev, gfp_t gfp)
16627{
16628 struct sk_buff *msg;
16629 void *hdr;
16630
16631 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16632 if (!msg)
16633 return;
16634
16635 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
16636 if (!hdr) {
16637 nlmsg_free(msg);
16638 return;
16639 }
16640
16641 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16642 goto nla_put_failure;
16643
16644 /* NOP and radar events don't need a netdev parameter */
16645 if (netdev) {
16646 struct wireless_dev *wdev = netdev->ieee80211_ptr;
16647
16648 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016649 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16650 NL80211_ATTR_PAD))
Simon Wunderlich04f39042013-02-08 18:16:19 +010016651 goto nla_put_failure;
16652 }
16653
16654 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
16655 goto nla_put_failure;
16656
16657 if (nl80211_send_chandef(msg, chandef))
16658 goto nla_put_failure;
16659
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016660 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016661
Johannes Berg68eb5502013-11-19 15:19:38 +010016662 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016663 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010016664 return;
16665
16666 nla_put_failure:
Simon Wunderlich04f39042013-02-08 18:16:19 +010016667 nlmsg_free(msg);
16668}
16669
tamizhr@codeaurora.org466b9932018-01-31 16:24:49 +053016670void cfg80211_sta_opmode_change_notify(struct net_device *dev, const u8 *mac,
16671 struct sta_opmode_info *sta_opmode,
16672 gfp_t gfp)
16673{
16674 struct sk_buff *msg;
16675 struct wireless_dev *wdev = dev->ieee80211_ptr;
16676 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
16677 void *hdr;
16678
16679 if (WARN_ON(!mac))
16680 return;
16681
16682 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
16683 if (!msg)
16684 return;
16685
16686 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STA_OPMODE_CHANGED);
16687 if (!hdr) {
16688 nlmsg_free(msg);
16689 return;
16690 }
16691
16692 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
16693 goto nla_put_failure;
16694
16695 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
16696 goto nla_put_failure;
16697
16698 if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
16699 goto nla_put_failure;
16700
16701 if ((sta_opmode->changed & STA_OPMODE_SMPS_MODE_CHANGED) &&
16702 nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, sta_opmode->smps_mode))
16703 goto nla_put_failure;
16704
16705 if ((sta_opmode->changed & STA_OPMODE_MAX_BW_CHANGED) &&
16706 nla_put_u8(msg, NL80211_ATTR_CHANNEL_WIDTH, sta_opmode->bw))
16707 goto nla_put_failure;
16708
16709 if ((sta_opmode->changed & STA_OPMODE_N_SS_CHANGED) &&
16710 nla_put_u8(msg, NL80211_ATTR_NSS, sta_opmode->rx_nss))
16711 goto nla_put_failure;
16712
16713 genlmsg_end(msg, hdr);
16714
16715 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
16716 NL80211_MCGRP_MLME, gfp);
16717
16718 return;
16719
16720nla_put_failure:
16721 nlmsg_free(msg);
16722}
16723EXPORT_SYMBOL(cfg80211_sta_opmode_change_notify);
16724
Johannes Berg7f6cf312011-11-04 11:18:15 +010016725void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016726 u64 cookie, bool acked, s32 ack_signal,
16727 bool is_valid_ack_signal, gfp_t gfp)
Johannes Berg7f6cf312011-11-04 11:18:15 +010016728{
16729 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016730 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016731 struct sk_buff *msg;
16732 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016733
Beni Lev4ee3e062012-08-27 12:49:39 +030016734 trace_cfg80211_probe_status(dev, addr, cookie, acked);
16735
Thomas Graf58050fc2012-06-28 03:57:45 +000016736 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030016737
Johannes Berg7f6cf312011-11-04 11:18:15 +010016738 if (!msg)
16739 return;
16740
16741 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
16742 if (!hdr) {
16743 nlmsg_free(msg);
16744 return;
16745 }
16746
David S. Miller9360ffd2012-03-29 04:41:26 -040016747 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16748 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
16749 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016750 nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie,
16751 NL80211_ATTR_PAD) ||
Venkateswara Naralasettyc4b50cd2018-02-13 11:03:06 +053016752 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)) ||
16753 (is_valid_ack_signal && nla_put_s32(msg, NL80211_ATTR_ACK_SIGNAL,
16754 ack_signal)))
David S. Miller9360ffd2012-03-29 04:41:26 -040016755 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010016756
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016757 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016758
Johannes Berg68eb5502013-11-19 15:19:38 +010016759 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016760 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010016761 return;
16762
16763 nla_put_failure:
Johannes Berg7f6cf312011-11-04 11:18:15 +010016764 nlmsg_free(msg);
16765}
16766EXPORT_SYMBOL(cfg80211_probe_status);
16767
Johannes Berg5e760232011-11-04 11:18:17 +010016768void cfg80211_report_obss_beacon(struct wiphy *wiphy,
16769 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070016770 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010016771{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016772 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010016773 struct sk_buff *msg;
16774 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070016775 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010016776
Beni Lev4ee3e062012-08-27 12:49:39 +030016777 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
16778
Ben Greear37c73b52012-10-26 14:49:25 -070016779 spin_lock_bh(&rdev->beacon_registrations_lock);
16780 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
16781 msg = nlmsg_new(len + 100, GFP_ATOMIC);
16782 if (!msg) {
16783 spin_unlock_bh(&rdev->beacon_registrations_lock);
16784 return;
16785 }
Johannes Berg5e760232011-11-04 11:18:17 +010016786
Ben Greear37c73b52012-10-26 14:49:25 -070016787 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
16788 if (!hdr)
16789 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010016790
Ben Greear37c73b52012-10-26 14:49:25 -070016791 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
16792 (freq &&
16793 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
16794 (sig_dbm &&
16795 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
16796 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
16797 goto nla_put_failure;
16798
16799 genlmsg_end(msg, hdr);
16800
16801 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010016802 }
Ben Greear37c73b52012-10-26 14:49:25 -070016803 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016804 return;
16805
16806 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070016807 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010016808 nlmsg_free(msg);
16809}
16810EXPORT_SYMBOL(cfg80211_report_obss_beacon);
16811
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016812#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016813static int cfg80211_net_detect_results(struct sk_buff *msg,
16814 struct cfg80211_wowlan_wakeup *wakeup)
16815{
16816 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
16817 struct nlattr *nl_results, *nl_match, *nl_freqs;
16818 int i, j;
16819
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016820 nl_results = nla_nest_start_noflag(msg,
16821 NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016822 if (!nl_results)
16823 return -EMSGSIZE;
16824
16825 for (i = 0; i < nd->n_matches; i++) {
16826 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
16827
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016828 nl_match = nla_nest_start_noflag(msg, i);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016829 if (!nl_match)
16830 break;
16831
16832 /* The SSID attribute is optional in nl80211, but for
16833 * simplicity reasons it's always present in the
16834 * cfg80211 structure. If a driver can't pass the
16835 * SSID, that needs to be changed. A zero length SSID
16836 * is still a valid SSID (wildcard), so it cannot be
16837 * used for this purpose.
16838 */
16839 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
16840 match->ssid.ssid)) {
16841 nla_nest_cancel(msg, nl_match);
16842 goto out;
16843 }
16844
16845 if (match->n_channels) {
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016846 nl_freqs = nla_nest_start_noflag(msg,
16847 NL80211_ATTR_SCAN_FREQUENCIES);
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016848 if (!nl_freqs) {
16849 nla_nest_cancel(msg, nl_match);
16850 goto out;
16851 }
16852
16853 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020016854 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016855 nla_nest_cancel(msg, nl_freqs);
16856 nla_nest_cancel(msg, nl_match);
16857 goto out;
16858 }
16859 }
16860
16861 nla_nest_end(msg, nl_freqs);
16862 }
16863
16864 nla_nest_end(msg, nl_match);
16865 }
16866
16867out:
16868 nla_nest_end(msg, nl_results);
16869 return 0;
16870}
16871
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016872void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
16873 struct cfg80211_wowlan_wakeup *wakeup,
16874 gfp_t gfp)
16875{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016876 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016877 struct sk_buff *msg;
16878 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016879 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016880
16881 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
16882
16883 if (wakeup)
16884 size += wakeup->packet_present_len;
16885
16886 msg = nlmsg_new(size, gfp);
16887 if (!msg)
16888 return;
16889
16890 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
16891 if (!hdr)
16892 goto free_msg;
16893
16894 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020016895 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
16896 NL80211_ATTR_PAD))
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016897 goto free_msg;
16898
16899 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
16900 wdev->netdev->ifindex))
16901 goto free_msg;
16902
16903 if (wakeup) {
16904 struct nlattr *reasons;
16905
Michal Kubecekae0be8d2019-04-26 11:13:06 +020016906 reasons = nla_nest_start_noflag(msg,
16907 NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020016908 if (!reasons)
16909 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016910
16911 if (wakeup->disconnect &&
16912 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
16913 goto free_msg;
16914 if (wakeup->magic_pkt &&
16915 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
16916 goto free_msg;
16917 if (wakeup->gtk_rekey_failure &&
16918 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
16919 goto free_msg;
16920 if (wakeup->eap_identity_req &&
16921 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
16922 goto free_msg;
16923 if (wakeup->four_way_handshake &&
16924 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
16925 goto free_msg;
16926 if (wakeup->rfkill_release &&
16927 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
16928 goto free_msg;
16929
16930 if (wakeup->pattern_idx >= 0 &&
16931 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
16932 wakeup->pattern_idx))
16933 goto free_msg;
16934
Johannes Bergae917c92013-10-25 11:05:22 +020016935 if (wakeup->tcp_match &&
16936 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
16937 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016938
Johannes Bergae917c92013-10-25 11:05:22 +020016939 if (wakeup->tcp_connlost &&
16940 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
16941 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016942
Johannes Bergae917c92013-10-25 11:05:22 +020016943 if (wakeup->tcp_nomoretokens &&
16944 nla_put_flag(msg,
16945 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
16946 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010016947
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016948 if (wakeup->packet) {
16949 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
16950 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
16951
16952 if (!wakeup->packet_80211) {
16953 pkt_attr =
16954 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
16955 len_attr =
16956 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
16957 }
16958
16959 if (wakeup->packet_len &&
16960 nla_put_u32(msg, len_attr, wakeup->packet_len))
16961 goto free_msg;
16962
16963 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
16964 wakeup->packet))
16965 goto free_msg;
16966 }
16967
Luciano Coelho8cd4d452014-09-17 11:55:28 +030016968 if (wakeup->net_detect &&
16969 cfg80211_net_detect_results(msg, wakeup))
16970 goto free_msg;
16971
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016972 nla_nest_end(msg, reasons);
16973 }
16974
Johannes Berg9c90a9f2013-06-04 12:46:03 +020016975 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016976
Johannes Berg68eb5502013-11-19 15:19:38 +010016977 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010016978 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010016979 return;
16980
16981 free_msg:
16982 nlmsg_free(msg);
16983}
16984EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
16985#endif
16986
Jouni Malinen3475b092012-11-16 22:49:57 +020016987void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
16988 enum nl80211_tdls_operation oper,
16989 u16 reason_code, gfp_t gfp)
16990{
16991 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080016992 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020016993 struct sk_buff *msg;
16994 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020016995
16996 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
16997 reason_code);
16998
16999 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17000 if (!msg)
17001 return;
17002
17003 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
17004 if (!hdr) {
17005 nlmsg_free(msg);
17006 return;
17007 }
17008
17009 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17010 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17011 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
17012 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
17013 (reason_code > 0 &&
17014 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
17015 goto nla_put_failure;
17016
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017017 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020017018
Johannes Berg68eb5502013-11-19 15:19:38 +010017019 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017020 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020017021 return;
17022
17023 nla_put_failure:
Jouni Malinen3475b092012-11-16 22:49:57 +020017024 nlmsg_free(msg);
17025}
17026EXPORT_SYMBOL(cfg80211_tdls_oper_request);
17027
Jouni Malinen026331c2010-02-15 12:53:10 +020017028static int nl80211_netlink_notify(struct notifier_block * nb,
17029 unsigned long state,
17030 void *_notify)
17031{
17032 struct netlink_notify *notify = _notify;
17033 struct cfg80211_registered_device *rdev;
17034 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070017035 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020017036
Dmitry Ivanov8f815cd2016-04-06 17:23:18 +030017037 if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC)
Jouni Malinen026331c2010-02-15 12:53:10 +020017038 return NOTIFY_DONE;
17039
17040 rcu_read_lock();
17041
Johannes Berg5e760232011-11-04 11:18:17 +010017042 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017043 struct cfg80211_sched_scan_request *sched_scan_req;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020017044
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017045 list_for_each_entry_rcu(sched_scan_req,
17046 &rdev->sched_scan_req_list,
17047 list) {
17048 if (sched_scan_req->owner_nlportid == notify->portid) {
17049 sched_scan_req->nl_owner_dead = true;
Johannes Berg753aacf2017-01-05 10:57:14 +010017050 schedule_work(&rdev->sched_scan_stop_wk);
Arend Van Sprielca986ad2017-04-21 13:05:00 +010017051 }
Johannes Berg753aacf2017-01-05 10:57:14 +010017052 }
Johannes Berg78f22b62014-03-24 17:57:27 +010017053
Johannes Berg53873f12016-05-03 16:52:04 +030017054 list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000017055 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070017056
Johannes Bergab810072017-04-26 07:43:41 +020017057 if (wdev->owner_nlportid == notify->portid) {
17058 wdev->nl_owner_dead = true;
17059 schedule_work(&rdev->destroy_work);
17060 } else if (wdev->conn_owner_nlportid == notify->portid) {
Andrzej Zaborowskibd2522b2017-01-06 16:33:43 -050017061 schedule_work(&wdev->disconnect_wk);
Johannes Bergab810072017-04-26 07:43:41 +020017062 }
Johannes Berg9bb7e0f2018-09-10 13:29:12 +020017063
17064 cfg80211_release_pmsr(wdev, notify->portid);
Johannes Berg78f22b62014-03-24 17:57:27 +010017065 }
17066
Ben Greear37c73b52012-10-26 14:49:25 -070017067 spin_lock_bh(&rdev->beacon_registrations_lock);
17068 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
17069 list) {
17070 if (reg->nlportid == notify->portid) {
17071 list_del(&reg->list);
17072 kfree(reg);
17073 break;
17074 }
17075 }
17076 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010017077 }
Jouni Malinen026331c2010-02-15 12:53:10 +020017078
17079 rcu_read_unlock();
17080
Ilan peer05050752015-03-04 00:32:06 -050017081 /*
17082 * It is possible that the user space process that is controlling the
17083 * indoor setting disappeared, so notify the regulatory core.
17084 */
17085 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080017086 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020017087}
17088
17089static struct notifier_block nl80211_netlink_notifier = {
17090 .notifier_call = nl80211_netlink_notify,
17091};
17092
Jouni Malinen355199e2013-02-27 17:14:27 +020017093void cfg80211_ft_event(struct net_device *netdev,
17094 struct cfg80211_ft_event_params *ft_event)
17095{
17096 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017097 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020017098 struct sk_buff *msg;
17099 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020017100
17101 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
17102
17103 if (!ft_event->target_ap)
17104 return;
17105
Dedy Lansky1039d082018-05-17 16:25:03 +030017106 msg = nlmsg_new(100 + ft_event->ies_len + ft_event->ric_ies_len,
17107 GFP_KERNEL);
Jouni Malinen355199e2013-02-27 17:14:27 +020017108 if (!msg)
17109 return;
17110
17111 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020017112 if (!hdr)
17113 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020017114
Johannes Bergae917c92013-10-25 11:05:22 +020017115 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17116 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17117 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
17118 goto out;
17119
17120 if (ft_event->ies &&
17121 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
17122 goto out;
17123 if (ft_event->ric_ies &&
17124 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
17125 ft_event->ric_ies))
17126 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020017127
Johannes Berg9c90a9f2013-06-04 12:46:03 +020017128 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020017129
Johannes Berg68eb5502013-11-19 15:19:38 +010017130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010017131 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020017132 return;
17133 out:
17134 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020017135}
17136EXPORT_SYMBOL(cfg80211_ft_event);
17137
Arend van Spriel5de17982013-04-18 15:49:00 +020017138void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
17139{
17140 struct cfg80211_registered_device *rdev;
17141 struct sk_buff *msg;
17142 void *hdr;
17143 u32 nlportid;
17144
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017145 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020017146 if (!rdev->crit_proto_nlportid)
17147 return;
17148
17149 nlportid = rdev->crit_proto_nlportid;
17150 rdev->crit_proto_nlportid = 0;
17151
17152 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17153 if (!msg)
17154 return;
17155
17156 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
17157 if (!hdr)
17158 goto nla_put_failure;
17159
17160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017161 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17162 NL80211_ATTR_PAD))
Arend van Spriel5de17982013-04-18 15:49:00 +020017163 goto nla_put_failure;
17164
17165 genlmsg_end(msg, hdr);
17166
17167 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
17168 return;
17169
17170 nla_put_failure:
Arend van Spriel5de17982013-04-18 15:49:00 +020017171 nlmsg_free(msg);
Arend van Spriel5de17982013-04-18 15:49:00 +020017172}
17173EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
17174
Johannes Berg348baf02014-01-24 14:06:29 +010017175void nl80211_send_ap_stopped(struct wireless_dev *wdev)
17176{
17177 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080017178 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010017179 struct sk_buff *msg;
17180 void *hdr;
17181
17182 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
17183 if (!msg)
17184 return;
17185
17186 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
17187 if (!hdr)
17188 goto out;
17189
17190 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
Nicolas Dichtel2dad6242016-04-25 10:25:22 +020017192 nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev),
17193 NL80211_ATTR_PAD))
Johannes Berg348baf02014-01-24 14:06:29 +010017194 goto out;
17195
17196 genlmsg_end(msg, hdr);
17197
17198 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
17199 NL80211_MCGRP_MLME, GFP_KERNEL);
17200 return;
17201 out:
17202 nlmsg_free(msg);
17203}
17204
Srinivas Dasari40cbfa92018-01-25 17:13:38 +020017205int cfg80211_external_auth_request(struct net_device *dev,
17206 struct cfg80211_external_auth_params *params,
17207 gfp_t gfp)
17208{
17209 struct wireless_dev *wdev = dev->ieee80211_ptr;
17210 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
17211 struct sk_buff *msg;
17212 void *hdr;
17213
17214 if (!wdev->conn_owner_nlportid)
17215 return -EINVAL;
17216
17217 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17218 if (!msg)
17219 return -ENOMEM;
17220
17221 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_EXTERNAL_AUTH);
17222 if (!hdr)
17223 goto nla_put_failure;
17224
17225 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17226 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
17227 nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, params->key_mgmt_suite) ||
17228 nla_put_u32(msg, NL80211_ATTR_EXTERNAL_AUTH_ACTION,
17229 params->action) ||
17230 nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid) ||
17231 nla_put(msg, NL80211_ATTR_SSID, params->ssid.ssid_len,
17232 params->ssid.ssid))
17233 goto nla_put_failure;
17234
17235 genlmsg_end(msg, hdr);
17236 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg,
17237 wdev->conn_owner_nlportid);
17238 return 0;
17239
17240 nla_put_failure:
17241 nlmsg_free(msg);
17242 return -ENOBUFS;
17243}
17244EXPORT_SYMBOL(cfg80211_external_auth_request);
17245
Sunil Duttcb74e972019-02-20 16:18:07 +053017246void cfg80211_update_owe_info_event(struct net_device *netdev,
17247 struct cfg80211_update_owe_info *owe_info,
17248 gfp_t gfp)
17249{
17250 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
17251 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
17252 struct sk_buff *msg;
17253 void *hdr;
17254
17255 trace_cfg80211_update_owe_info_event(wiphy, netdev, owe_info);
17256
17257 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
17258 if (!msg)
17259 return;
17260
17261 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_UPDATE_OWE_INFO);
17262 if (!hdr)
17263 goto nla_put_failure;
17264
17265 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
17266 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
17267 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, owe_info->peer))
17268 goto nla_put_failure;
17269
17270 if (!owe_info->ie_len ||
17271 nla_put(msg, NL80211_ATTR_IE, owe_info->ie_len, owe_info->ie))
17272 goto nla_put_failure;
17273
17274 genlmsg_end(msg, hdr);
17275
17276 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
17277 NL80211_MCGRP_MLME, gfp);
17278 return;
17279
17280nla_put_failure:
17281 genlmsg_cancel(msg, hdr);
17282 nlmsg_free(msg);
17283}
17284EXPORT_SYMBOL(cfg80211_update_owe_info_event);
17285
Johannes Berg55682962007-09-20 13:09:35 -040017286/* initialisation/exit functions */
17287
Johannes Berg56989f62016-10-24 14:40:05 +020017288int __init nl80211_init(void)
Johannes Berg55682962007-09-20 13:09:35 -040017289{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000017290 int err;
Johannes Berg55682962007-09-20 13:09:35 -040017291
Johannes Berg489111e2016-10-24 14:40:03 +020017292 err = genl_register_family(&nl80211_fam);
Johannes Berg55682962007-09-20 13:09:35 -040017293 if (err)
17294 return err;
17295
Jouni Malinen026331c2010-02-15 12:53:10 +020017296 err = netlink_register_notifier(&nl80211_netlink_notifier);
17297 if (err)
17298 goto err_out;
17299
Johannes Berg55682962007-09-20 13:09:35 -040017300 return 0;
17301 err_out:
17302 genl_unregister_family(&nl80211_fam);
17303 return err;
17304}
17305
17306void nl80211_exit(void)
17307{
Jouni Malinen026331c2010-02-15 12:53:10 +020017308 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040017309 genl_unregister_family(&nl80211_fam);
17310}